diff --git a/autotests/iconitemtest.cpp b/autotests/iconitemtest.cpp index 3bd114c10..026dda46e 100644 --- a/autotests/iconitemtest.cpp +++ b/autotests/iconitemtest.cpp @@ -372,5 +372,43 @@ void IconItemTest::changeColorGroup() QVERIFY(img1 != img2); } +void IconItemTest::animatingActiveChange() +{ + QQuickItem *item1 = createIconItem(); + item1->setProperty("animated", false); + item1->setProperty("source", "tst-plasma-framework-test-icon"); + QImage img1 = grabImage(item1); + + QQuickItem *item2 = createIconItem(); + item2->setProperty("animated", false); + item2->setProperty("active", true); + item2->setProperty("source", "tst-plasma-framework-test-icon"); + QImage img2 = grabImage(item2); + QVERIFY(img1 != img2); + + item1->setProperty("active", true); + img1 = grabImage(item1); + QVERIFY(img1 != img2); // animation is running +} + +void IconItemTest::animatingEnabledChange() +{ + QQuickItem *item1 = createIconItem(); + item1->setProperty("animated", false); + item1->setProperty("source", "tst-plasma-framework-test-icon"); + QImage img1 = grabImage(item1); + + QQuickItem *item2 = createIconItem(); + item2->setProperty("animated", false); + item2->setProperty("enabled", false); + item2->setProperty("source", "tst-plasma-framework-test-icon"); + QImage img2 = grabImage(item2); + QVERIFY(img1 != img2); + + item1->setProperty("enabled", false); + img1 = grabImage(item1); + QVERIFY(img1 != img2); // animation is running +} + QTEST_MAIN(IconItemTest) diff --git a/autotests/iconitemtest.h b/autotests/iconitemtest.h index 47eb445e7..99ecc6cdb 100644 --- a/autotests/iconitemtest.h +++ b/autotests/iconitemtest.h @@ -50,6 +50,8 @@ private Q_SLOTS: void themeChange(); void qiconFromTheme(); void changeColorGroup(); + void animatingActiveChange(); + void animatingEnabledChange(); private: QQuickItem *createIconItem(); diff --git a/src/declarativeimports/core/iconitem.cpp b/src/declarativeimports/core/iconitem.cpp index 5798234d0..e1995614e 100644 --- a/src/declarativeimports/core/iconitem.cpp +++ b/src/declarativeimports/core/iconitem.cpp @@ -46,6 +46,7 @@ IconItem::IconItem(QQuickItem *parent) m_usesPlasmaTheme(true), m_textureChanged(false), m_sizeChanged(false), + m_allowNextAnimation(false), m_colorGroup(Plasma::Theme::NormalColorGroup), m_animValue(0) { @@ -65,8 +66,8 @@ IconItem::IconItem(QQuickItem *parent) connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()), this, SIGNAL(implicitHeightChanged())); - connect(this, SIGNAL(enabledChanged()), - this, SLOT(schedulePixmapUpdate())); + connect(this, &QQuickItem::enabledChanged, + this, &IconItem::enabledChanged); //initialize implicit size to the Dialog size setImplicitWidth(KIconLoader::global()->currentSize(KIconLoader::Dialog)); @@ -218,6 +219,7 @@ void IconItem::setActive(bool active) m_active = active; if (isComponentComplete()) { + m_allowNextAnimation = true; schedulePixmapUpdate(); } emit activeChanged(); @@ -359,6 +361,12 @@ void IconItem::valueChanged(const QVariant &value) update(); } +void IconItem::enabledChanged() +{ + m_allowNextAnimation = true; + schedulePixmapUpdate(); +} + void IconItem::animationFinished() { m_oldIconPixmap = QPixmap(); @@ -429,11 +437,12 @@ void IconItem::loadPixmap() m_textureChanged = true; //don't animate initial setting - if (m_animated && !m_oldIconPixmap.isNull() && !m_sizeChanged) { + if ((m_animated || m_allowNextAnimation) && !m_oldIconPixmap.isNull() && !m_sizeChanged) { m_animValue = 0.0; m_animation->setStartValue((qreal)0); m_animation->setEndValue((qreal)1); m_animation->start(); + m_allowNextAnimation = false; } else { m_animValue = 1.0; m_animation->stop(); diff --git a/src/declarativeimports/core/iconitem.h b/src/declarativeimports/core/iconitem.h index 558994a7f..38a9c7a8f 100644 --- a/src/declarativeimports/core/iconitem.h +++ b/src/declarativeimports/core/iconitem.h @@ -72,7 +72,7 @@ class IconItem : public QQuickItem Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) /** - * If set, icon will blend when the source is changed or resized + * If set, icon will blend when the source is changed */ Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated NOTIFY animatedChanged) @@ -149,6 +149,7 @@ private Q_SLOTS: void schedulePixmapUpdate(); void animationFinished(); void valueChanged(const QVariant &value); + void enabledChanged(); private: void loadPixmap(); @@ -171,6 +172,7 @@ private: bool m_textureChanged; bool m_sizeChanged; + bool m_allowNextAnimation; QPixmap m_iconPixmap; QPixmap m_oldIconPixmap;