Made the icon property a QVariant.

If a string is passed a KIcon(string) object will be created.
If a QIcon is passed that will be used.

REVIEW: 103009
This commit is contained in:
Mark Gaiser 2011-11-02 21:28:30 +01:00
parent 270b6296b9
commit 41bd519f43
3 changed files with 12 additions and 5 deletions

View File

@ -19,7 +19,7 @@ qt4_automoc(${qtextracomponents_SRCS})
add_library(qtextracomponentsplugin SHARED ${qtextracomponents_SRCS}) add_library(qtextracomponentsplugin SHARED ${qtextracomponents_SRCS})
target_link_libraries(qtextracomponentsplugin ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY}) target_link_libraries(qtextracomponentsplugin ${KDE4_KDEUI_LIBS} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY})
install(TARGETS qtextracomponentsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/qtextracomponents) install(TARGETS qtextracomponentsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/qtextracomponents)

View File

@ -19,6 +19,7 @@
#include "qiconitem.h" #include "qiconitem.h"
#include <kicon.h>
#include <QtGui/QPainter> #include <QtGui/QPainter>
@ -34,9 +35,14 @@ QIconItem::~QIconItem()
{ {
} }
void QIconItem::setIcon(const QIcon &icon) void QIconItem::setIcon(QVariant &icon)
{ {
m_icon = icon; if(icon.canConvert<QIcon>()) {
m_icon = icon.value<QIcon>();
}
else if(icon.canConvert<QString>()) {
m_icon = KIcon(icon.toString());
}
update(); update();
} }

View File

@ -21,19 +21,20 @@
#include <QDeclarativeItem> #include <QDeclarativeItem>
#include <QPixmap> #include <QPixmap>
#include <QVariant>
class QIconItem : public QDeclarativeItem class QIconItem : public QDeclarativeItem
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QIcon icon READ icon WRITE setIcon) Q_PROPERTY(QVariant icon READ icon WRITE setIcon)
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth) Q_PROPERTY(bool smooth READ smooth WRITE setSmooth)
public: public:
QIconItem(QDeclarativeItem *parent=0); QIconItem(QDeclarativeItem *parent=0);
~QIconItem(); ~QIconItem();
void setIcon(const QIcon &icon); void setIcon(QVariant &icon);
QIcon icon() const; QIcon icon() const;
void setSmooth(const bool smooth); void setSmooth(const bool smooth);