From d4089782135e73c2db4223c05c80249d26bd772f Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 20 Feb 2012 13:32:28 +0100 Subject: [PATCH] bind State --- .../qtextracomponents/qiconitem.cpp | 34 ++++++++++++++++--- .../qtextracomponents/qiconitem.h | 16 +++++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/declarativeimports/qtextracomponents/qiconitem.cpp b/declarativeimports/qtextracomponents/qiconitem.cpp index 6efbb3f07..4c0f5c741 100644 --- a/declarativeimports/qtextracomponents/qiconitem.cpp +++ b/declarativeimports/qtextracomponents/qiconitem.cpp @@ -19,15 +19,17 @@ #include "qiconitem.h" -#include -#include +#include +#include +#include #include QIconItem::QIconItem(QDeclarativeItem *parent) : QDeclarativeItem(parent), m_smooth(false), - m_group(NoGroup) + m_group(NoGroup), + m_state(DefaultState) { setFlag(QGraphicsItem::ItemHasNoContents, false); } @@ -63,6 +65,7 @@ void QIconItem::setGroup(QIconItem::Group group) emit groupChanged(group); emit implicitWidthChanged(implicitWidth()); emit implicitHeightChanged(implicitHeight()); + update(); } QIconItem::Group QIconItem::group() const @@ -70,6 +73,22 @@ QIconItem::Group QIconItem::group() const return m_group; } +QIconItem::State QIconItem::state() const +{ + return m_state; +} + +void QIconItem::setState(QIconItem::State state) +{ + if (m_state == state) { + return; + } + + m_state = state; + emit stateChanged(state); + update(); +} + int QIconItem::implicitWidth() const { return KIconLoader::global()->currentSize((KIconLoader::Group)m_group); @@ -108,7 +127,14 @@ void QIconItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->setRenderHint(QPainter::Antialiasing, m_smooth); painter->setRenderHint(QPainter::SmoothPixmapTransform, m_smooth); - m_icon.paint(painter, boundingRect().toRect(), Qt::AlignCenter, isEnabled()?QIcon::Normal:QIcon::Disabled); + if (m_state == DefaultState) { + m_icon.paint(painter, boundingRect().toRect(), Qt::AlignCenter, isEnabled()?QIcon::Normal:QIcon::Disabled); + } else { + QPixmap result = m_icon.pixmap(boundingRect().size().toSize()); + KIconLoader::global()->iconEffect()->apply(result, KIconLoader::Desktop, KIconLoader::ActiveState); + painter->drawPixmap(0, 0, result); + } + painter->setRenderHint(QPainter::Antialiasing, wasAntiAlias); painter->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothTransform); } diff --git a/declarativeimports/qtextracomponents/qiconitem.h b/declarativeimports/qtextracomponents/qiconitem.h index 2f5542510..845175e31 100644 --- a/declarativeimports/qtextracomponents/qiconitem.h +++ b/declarativeimports/qtextracomponents/qiconitem.h @@ -32,7 +32,10 @@ class QIconItem : public QDeclarativeItem Q_PROPERTY(int implicitWidth READ implicitWidth NOTIFY implicitWidthChanged) Q_PROPERTY(int implicitHeight READ implicitHeight NOTIFY implicitHeightChanged) Q_PROPERTY(Group group READ group WRITE setGroup NOTIFY groupChanged) + Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged) + Q_ENUMS(Group) + Q_ENUMS(State) public: enum Group { @@ -44,8 +47,12 @@ public: Small, ///Small icons, e.g. for buttons. Panel, ///Panel (Plasma Taskbar) icons. Dialog, ///Icons for use in dialog titles, page lists, etc. - LastGroup, ///Last group. - User ///User icons. + }; + + enum State { + DefaultState, ///The default state. + ActiveState, ///Icon is active. + DisabledState ///Icon is disabled. }; QIconItem(QDeclarativeItem *parent=0); @@ -57,6 +64,9 @@ public: void setGroup(Group group); Group group() const; + QIconItem::State state() const; + void setState(State state); + int implicitWidth() const; int implicitHeight() const; @@ -69,11 +79,13 @@ Q_SIGNALS: void implicitWidthChanged(int implicitWidth); void implicitHeightChanged(int implicitHeight); void groupChanged(Group group); + void stateChanged(State state); private: QIcon m_icon; bool m_smooth; Group m_group; + State m_state; }; #endif