~ubuntu-branches/ubuntu/trusty/kdeplasma-addons/trusty

« back to all changes in this revision

Viewing changes to wallpapers/weather/weatherwallpaper.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-05-25 09:50:14 UTC
  • mfrom: (1.1.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100525095014-6mlrm9z9bkws0zkt
Tags: 4:4.4.80-0ubuntu1
* New upstream beta release:
  - Bump kde-sc-dev-latest build-dep version to 4.4.80
  - Refresh kubuntu_04_kimpanel_disable_scim.diff
  - Update various .install files
  - Drop liblancelot0a and liblancelot-dev packages; Upstream has broken ABI
    without an .so version bump, and after discussion with Debian it was
    decided it was not worth it to ship an unstable library.
  - Add liblancelot files to plasma-widget-lancelot, adding appropriate
    Replaces: entries
* Switch to source format 3.0 (quilt):
  - Bump debhelper build-depend version to 7.3.16 or greater

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
// Qt includes
25
25
#include <QPainter>
 
26
#include <QEasingCurve>
 
27
#include <QPropertyAnimation>
26
28
 
27
29
// KDE includes
28
30
#include <KFileDialog>
49
51
    , m_weatherLocation(0)
50
52
    , m_advancedDialog(0)
51
53
    , m_fileDialog(0)
 
54
    , m_fadeValue(0)
 
55
    , m_animation(0)
52
56
    , m_model(0)
53
57
    , m_newStuffDialog(0)
54
58
{
57
61
 
58
62
WeatherWallpaper::~WeatherWallpaper()
59
63
{
 
64
    delete m_animation;
60
65
}
61
66
 
62
67
void WeatherWallpaper::init(const KConfigGroup & config)
73
78
    m_usersWallpapers = config.readEntry("userswallpapers", QStringList());
74
79
    m_resizeMethod = (ResizeMethod)config.readEntry("wallpaperposition", (int)ScaledResize);
75
80
 
76
 
    m_weatherMap["weather-none-available"] = Plasma::Theme::defaultTheme()->wallpaperPath();
 
81
    m_animation = new QPropertyAnimation(this, "fadeValue");
 
82
    m_animation->setProperty("easingCurve", QEasingCurve::InQuad);
 
83
    m_animation->setProperty("duration", 1000);
 
84
    m_animation->setProperty("startValue", 0.0);
 
85
    m_animation->setProperty("endValue", 1.0);
 
86
 
77
87
    m_weatherMap["weather-clear"] = config.readEntry("clearPaper", m_dir + "Fields_of_Peace/");
78
88
    m_weatherMap["weather-few-clouds"] = config.readEntry("partlyCloudyPaper", m_dir + "Evening/");
79
89
    m_weatherMap["weather-clouds"] = config.readEntry("cloudyPaper", m_dir + "Colorado_Farm/");
83
93
    m_weatherMap["weather-rain"] = config.readEntry("rainPaper", m_dir + "There_is_Rain_on_the_Table/");
84
94
    m_weatherMap["weather-mist"] = config.readEntry("mistPaper", m_dir + "Fresh_Morning/");
85
95
    m_weatherMap["weather-storm"] = config.readEntry("stormPaper", m_dir + "Lightning/");
 
96
    m_weatherMap["weather-scattered-storms"] = m_weatherMap["weather-storm"];
86
97
    m_weatherMap["weather-hail"] = config.readEntry("hailPaper", m_dir + "Hail/");
87
98
    m_weatherMap["weather-snow"] = config.readEntry("snowPaper", m_dir + "Winter_Track/");
88
99
    m_weatherMap["weather-snow-scattered"] = config.readEntry("snowScatteredPaper", m_dir + "Winter_Track/");
213
224
 
214
225
void WeatherWallpaper::loadImage()
215
226
{
216
 
    m_wallpaper = m_weatherMap[m_condition];
 
227
    m_wallpaper = m_weatherMap.value(m_condition);
 
228
 
 
229
    if (m_wallpaper.isEmpty()) {
 
230
       QHashIterator<QString, QString> it(m_weatherMap);
 
231
       while (it.hasNext()) {
 
232
           it.next();
 
233
           if (m_condition.startsWith(it.key())) {
 
234
               m_wallpaper = it.value();
 
235
               break;
 
236
           }
 
237
       }
 
238
    }
217
239
 
218
240
    if (m_wallpaper.isEmpty()) {
219
241
        m_wallpaper = Plasma::Theme::defaultTheme()->wallpaperPath();
254
276
        m_advancedUi.m_wallpaperView->view()->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
255
277
 
256
278
        connect(m_advancedUi.m_conditionCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(conditionChanged(int)));
257
 
        m_advancedUi.m_conditionCombo->addItem(KIcon("weather-clear"), i18n("Clear"), "weather-clear");
 
279
        m_advancedUi.m_conditionCombo->addItem(KIcon("weather-clear"), i18nc("weather condition", "Clear"), "weather-clear");
258
280
        m_advancedUi.m_conditionCombo->addItem(KIcon("weather-few-clouds"), i18n("Partly Cloudy"), "weather-few-clouds");
259
281
        m_advancedUi.m_conditionCombo->addItem(KIcon("weather-clouds"), i18n("Cloudy"), "weather-clouds");
260
282
        m_advancedUi.m_conditionCombo->addItem(KIcon("weather-many-clouds"), i18n("Very Cloudy"), "weather-many-clouds");
526
548
    m_pixmap = QPixmap::fromImage(img);
527
549
 
528
550
    if (!m_oldPixmap.isNull()) {
529
 
        Plasma::Animator::self()->customAnimation(254, 1000, Plasma::Animator::EaseInCurve, this, "updateFadedImage");
 
551
        m_animation->start();
530
552
    } else {
531
553
        emit update(boundingRect());
532
554
    }
534
556
 
535
557
void WeatherWallpaper::updateScreenshot(QPersistentModelIndex index)
536
558
{
537
 
    m_advancedUi.m_wallpaperView->view()->update(index);
538
 
}
539
 
 
540
 
void WeatherWallpaper::updateFadedImage(qreal frame)
541
 
{
 
559
    if (m_advancedDialog) {
 
560
        m_advancedUi.m_wallpaperView->view()->update(index);
 
561
    }
 
562
}
 
563
 
 
564
qreal WeatherWallpaper::fadeValue()
 
565
{
 
566
    return m_fadeValue;
 
567
}
 
568
 
 
569
void WeatherWallpaper::setFadeValue(qreal value)
 
570
{
 
571
    m_fadeValue = value;
 
572
 
542
573
    //If we are done, delete the pixmaps and don't draw.
543
 
    if (frame == 1) {
 
574
    if (qFuzzyCompare(m_fadeValue, qreal(1.0))) {
544
575
        m_oldFadedPixmap = QPixmap();
545
576
        m_oldPixmap = QPixmap();
546
577
        emit update(boundingRect());
555
586
    p.drawPixmap(0, 0, m_oldPixmap);
556
587
 
557
588
    p.setCompositionMode(QPainter::CompositionMode_DestinationIn);  
558
 
    p.fillRect(m_oldFadedPixmap.rect(), QColor(0, 0, 0, 254 * (1-frame)));//255*((150 - frame)/150)));
 
589
    p.fillRect(m_oldFadedPixmap.rect(), QColor(0, 0, 0, 254 * (1-m_fadeValue)));//255*((150 - m_fadeValue)/150)));
 
590
 
559
591
    p.end();
560
592
 
561
593
    emit update(boundingRect());