Plasma
iconwidget.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef PLASMA_ICONWIDGET_H
00024 #define PLASMA_ICONWIDGET_H
00025
00026 #include <QtCore/QObject>
00027 #include <QtGui/QGraphicsTextItem>
00028 #include <QtGui/QIcon>
00029 #include <QtGui/QGraphicsWidget>
00030
00031 #include <plasma/dataengine.h>
00032 #include <plasma/animator.h>
00033 #include <plasma/plasma_export.h>
00034
00035 class QAction;
00036
00049 namespace Plasma
00050 {
00051
00052 class IconWidgetPrivate;
00053
00054 class PLASMA_EXPORT IconWidget : public QGraphicsWidget
00055 {
00056 Q_OBJECT
00057 Q_PROPERTY(QString text READ text WRITE setText)
00058 Q_PROPERTY(QString infoText READ infoText WRITE setInfoText)
00059 Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
00060 Q_PROPERTY(QColor textBackgroundColor READ textBackgroundColor WRITE setTextBackgroundColor)
00061 Q_PROPERTY(QSizeF iconSize READ iconSize)
00062 Q_PROPERTY(QString svg READ svg WRITE setSvg)
00063 Q_PROPERTY(QAction *action READ action WRITE setAction)
00064 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
00065 Q_PROPERTY(int numDisplayLines READ numDisplayLines WRITE setNumDisplayLines)
00066
00067 public:
00072 explicit IconWidget(QGraphicsItem *parent = 0);
00073
00079 explicit IconWidget(const QString &text, QGraphicsItem *parent = 0);
00080
00087 IconWidget(const QIcon &icon, const QString &text, QGraphicsItem *parent = 0);
00088
00092 virtual ~IconWidget();
00093
00097 QString text() const;
00098
00103 void setText(const QString &text);
00104
00110 void setSvg(const QString &svgFilePath, const QString &svgIconElement = QString());
00111
00115 QString svg() const;
00116
00120 QString infoText() const;
00121
00127 void setInfoText(const QString &text);
00128
00132 QIcon icon() const;
00133
00138 void setIcon(const QIcon &icon);
00139
00144 QColor textBackgroundColor() const;
00145
00151 void setTextBackgroundColor(const QColor &color);
00152
00158 Q_INVOKABLE void setIcon(const QString &icon);
00159
00163 QSizeF iconSize() const;
00164
00171 void addIconAction(QAction *action);
00172
00177 void removeIconAction(QAction *action);
00178
00185 void setAction(QAction *action);
00186
00190 QAction *action() const;
00191
00199 void setOrientation(Qt::Orientation orientation);
00200
00204 Qt::Orientation orientation() const;
00205
00211 void invertLayout(bool invert);
00212
00216 bool invertedLayout() const;
00217
00222 QSizeF sizeFromIconSize(const qreal iconWidth) const;
00223
00227 int numDisplayLines();
00228
00232 void setNumDisplayLines(int numLines);
00233
00239 void setDrawBackground(bool draw);
00240
00244 bool drawBackground() const;
00245
00249 QPainterPath shape() const;
00250
00251 public Q_SLOTS:
00257 void setPressed(bool pressed = true);
00258
00262 void setUnpressed();
00263
00264 protected:
00265 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00266
00267 Q_SIGNALS:
00271 void pressed(bool down);
00272
00276 void clicked();
00277
00281 void doubleClicked();
00282
00287 void activated();
00288
00293 void changed();
00294
00295 protected:
00296 bool isDown();
00297 void mousePressEvent(QGraphicsSceneMouseEvent *event);
00298 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
00299 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
00300 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
00301
00302 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
00303 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
00304
00305 bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
00306
00307 public:
00311 void drawActionButtonBase(QPainter *painter, const QSize &size, int element);
00312
00313 private:
00314 Q_PRIVATE_SLOT(d, void syncToAction())
00315 Q_PRIVATE_SLOT(d, void clearAction())
00316 Q_PRIVATE_SLOT(d, void svgChanged())
00317 Q_PRIVATE_SLOT(d, void actionDestroyed(QObject *obj))
00318 Q_PRIVATE_SLOT(d, void hoverAnimationUpdate(qreal progress))
00319 Q_PRIVATE_SLOT(d, void colorConfigChanged())
00320 Q_PRIVATE_SLOT(d, void iconConfigChanged())
00321
00322 IconWidgetPrivate * const d;
00323 friend class IconWidgetPrivate;
00324 };
00325
00326 }
00327
00328 #endif