IconItem: Animate active and enabled change even with animations disabled
animated: false should disable only animation when changing source, we still want the hover and enabled animations. Also fix docs. REVIEW: 127302
This commit is contained in:
parent
aaa85f3f98
commit
46a1181587
@ -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)
|
||||
|
||||
|
@ -50,6 +50,8 @@ private Q_SLOTS:
|
||||
void themeChange();
|
||||
void qiconFromTheme();
|
||||
void changeColorGroup();
|
||||
void animatingActiveChange();
|
||||
void animatingEnabledChange();
|
||||
|
||||
private:
|
||||
QQuickItem *createIconItem();
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user