bind State
This commit is contained in:
parent
ed5e2e1981
commit
d408978213
|
@ -19,15 +19,17 @@
|
||||||
|
|
||||||
#include "qiconitem.h"
|
#include "qiconitem.h"
|
||||||
|
|
||||||
#include <kicon.h>
|
#include <KIcon>
|
||||||
#include <kiconloader.h>
|
#include <KIconLoader>
|
||||||
|
#include <KIconEffect>
|
||||||
#include <QtGui/QPainter>
|
#include <QtGui/QPainter>
|
||||||
|
|
||||||
|
|
||||||
QIconItem::QIconItem(QDeclarativeItem *parent)
|
QIconItem::QIconItem(QDeclarativeItem *parent)
|
||||||
: QDeclarativeItem(parent),
|
: QDeclarativeItem(parent),
|
||||||
m_smooth(false),
|
m_smooth(false),
|
||||||
m_group(NoGroup)
|
m_group(NoGroup),
|
||||||
|
m_state(DefaultState)
|
||||||
{
|
{
|
||||||
setFlag(QGraphicsItem::ItemHasNoContents, false);
|
setFlag(QGraphicsItem::ItemHasNoContents, false);
|
||||||
}
|
}
|
||||||
|
@ -63,6 +65,7 @@ void QIconItem::setGroup(QIconItem::Group group)
|
||||||
emit groupChanged(group);
|
emit groupChanged(group);
|
||||||
emit implicitWidthChanged(implicitWidth());
|
emit implicitWidthChanged(implicitWidth());
|
||||||
emit implicitHeightChanged(implicitHeight());
|
emit implicitHeightChanged(implicitHeight());
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QIconItem::Group QIconItem::group() const
|
QIconItem::Group QIconItem::group() const
|
||||||
|
@ -70,6 +73,22 @@ QIconItem::Group QIconItem::group() const
|
||||||
return m_group;
|
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
|
int QIconItem::implicitWidth() const
|
||||||
{
|
{
|
||||||
return KIconLoader::global()->currentSize((KIconLoader::Group)m_group);
|
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::Antialiasing, m_smooth);
|
||||||
painter->setRenderHint(QPainter::SmoothPixmapTransform, 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::Antialiasing, wasAntiAlias);
|
||||||
painter->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothTransform);
|
painter->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothTransform);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,10 @@ class QIconItem : public QDeclarativeItem
|
||||||
Q_PROPERTY(int implicitWidth READ implicitWidth NOTIFY implicitWidthChanged)
|
Q_PROPERTY(int implicitWidth READ implicitWidth NOTIFY implicitWidthChanged)
|
||||||
Q_PROPERTY(int implicitHeight READ implicitHeight NOTIFY implicitHeightChanged)
|
Q_PROPERTY(int implicitHeight READ implicitHeight NOTIFY implicitHeightChanged)
|
||||||
Q_PROPERTY(Group group READ group WRITE setGroup NOTIFY groupChanged)
|
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(Group)
|
||||||
|
Q_ENUMS(State)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Group {
|
enum Group {
|
||||||
|
@ -44,8 +47,12 @@ public:
|
||||||
Small, ///Small icons, e.g. for buttons.
|
Small, ///Small icons, e.g. for buttons.
|
||||||
Panel, ///Panel (Plasma Taskbar) icons.
|
Panel, ///Panel (Plasma Taskbar) icons.
|
||||||
Dialog, ///Icons for use in dialog titles, page lists, etc.
|
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);
|
QIconItem(QDeclarativeItem *parent=0);
|
||||||
|
@ -57,6 +64,9 @@ public:
|
||||||
void setGroup(Group group);
|
void setGroup(Group group);
|
||||||
Group group() const;
|
Group group() const;
|
||||||
|
|
||||||
|
QIconItem::State state() const;
|
||||||
|
void setState(State state);
|
||||||
|
|
||||||
int implicitWidth() const;
|
int implicitWidth() const;
|
||||||
int implicitHeight() const;
|
int implicitHeight() const;
|
||||||
|
|
||||||
|
@ -69,11 +79,13 @@ Q_SIGNALS:
|
||||||
void implicitWidthChanged(int implicitWidth);
|
void implicitWidthChanged(int implicitWidth);
|
||||||
void implicitHeightChanged(int implicitHeight);
|
void implicitHeightChanged(int implicitHeight);
|
||||||
void groupChanged(Group group);
|
void groupChanged(Group group);
|
||||||
|
void stateChanged(State state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
bool m_smooth;
|
bool m_smooth;
|
||||||
Group m_group;
|
Group m_group;
|
||||||
|
State m_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user