From 65312797713bccd078b20a42a537a57865396c45 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Mon, 15 Dec 2014 20:21:06 +0100 Subject: [PATCH] Load IconItem immediately upon componentComplete() This makes the IconItem load the icon immediately after component creation and not wait 150ms there for no reason which prevents eg. flickering in the OSD when it shows up. REVIEW: 121219 --- src/declarativeimports/core/iconitem.cpp | 26 ++++++++++++++++++++---- src/declarativeimports/core/iconitem.h | 3 +++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/declarativeimports/core/iconitem.cpp b/src/declarativeimports/core/iconitem.cpp index 493f63f7f..08bb47d57 100644 --- a/src/declarativeimports/core/iconitem.cpp +++ b/src/declarativeimports/core/iconitem.cpp @@ -84,6 +84,8 @@ void IconItem::setSource(const QVariant &source) m_source = source; + const bool oldValid = isValid(); + if (source.canConvert()) { m_icon = source.value(); m_imageIcon = QImage(); @@ -96,8 +98,8 @@ void IconItem::setSource(const QVariant &source) delete m_svgIcon; m_svgIcon = 0; m_icon = QIcon(); - m_loadPixmapTimer.start(); emit validChanged(); + loadPixmap(); return; } @@ -158,7 +160,11 @@ void IconItem::setSource(const QVariant &source) } if (width() > 0 && height() > 0) { - m_loadPixmapTimer.start(); + if (!oldValid) { + loadPixmap(); + } else { + m_loadPixmapTimer.start(); + } } emit sourceChanged(); @@ -202,7 +208,9 @@ void IconItem::setActive(bool active) } m_active = active; - m_loadPixmapTimer.start(); + if (isComponentComplete()) { + m_loadPixmapTimer.start(); + } emit activeChanged(); } @@ -297,6 +305,10 @@ void IconItem::animationFinished() void IconItem::loadPixmap() { + if (!isComponentComplete()) { + return; + } + const int size = Units::roundToIconSize(qMin(width(), height())); //final pixmap to paint @@ -351,7 +363,7 @@ void IconItem::geometryChanged(const QRectF &newGeometry, m_sizeChanged = true; update(); if (newGeometry.width() > 0 && newGeometry.height() > 0) { - if (!m_loadPixmapTimer.isActive()) { + if (!m_loadPixmapTimer.isActive() && isComponentComplete()) { m_loadPixmapTimer.start(); } } @@ -360,4 +372,10 @@ void IconItem::geometryChanged(const QRectF &newGeometry, QQuickItem::geometryChanged(newGeometry, oldGeometry); } +void IconItem::componentComplete() +{ + QQuickItem::componentComplete(); + loadPixmap(); +} + #include "iconitem.moc" diff --git a/src/declarativeimports/core/iconitem.h b/src/declarativeimports/core/iconitem.h index 8aecd1737..d3b9305ac 100644 --- a/src/declarativeimports/core/iconitem.h +++ b/src/declarativeimports/core/iconitem.h @@ -69,6 +69,8 @@ public: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); + void componentComplete() Q_DECL_OVERRIDE; + Q_SIGNALS: void activeChanged(); void sourceChanged(); @@ -107,6 +109,7 @@ private: //animation on pixmap change QPropertyAnimation *m_animation; qreal m_animValue; + }; #endif