libplasma
icon.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 #ifndef ICON_H
00023 #define ICON_H
00024
00025 #include <QtCore/QObject>
00026 #include <QtGui/QGraphicsTextItem>
00027 #include <QtGui/QIcon>
00028
00029 #include <plasma/dataengine.h>
00030 #include <plasma/phase.h>
00031 #include <plasma/plasma_export.h>
00032 #include <plasma/widgets/widget.h>
00033
00034 class QAction;
00035
00045 namespace Plasma
00046 {
00047
00048 class PLASMA_EXPORT Icon : public Plasma::Widget
00049 {
00050 Q_OBJECT
00051 Q_PROPERTY( QString text READ text WRITE setText )
00052 Q_PROPERTY( QString infoText READ infoText WRITE setInfoText )
00053 Q_PROPERTY( QIcon icon READ icon WRITE setIcon )
00054 Q_PROPERTY( QSizeF iconSize READ iconSize )
00055 Q_PROPERTY( QString svg WRITE setSvg )
00056 public:
00061 explicit Icon(QGraphicsItem *parent = 0);
00062
00068 explicit Icon(const QString &text, QGraphicsItem *parent = 0);
00069
00076 Icon(const QIcon &icon, const QString &text, QGraphicsItem *parent = 0);
00077
00081 virtual ~Icon();
00082
00086 QString text() const;
00087
00092 void setText(const QString &text);
00093
00099 void setSvg(const QString &svgFilePath, const QString &svgIconElement = QString());
00100
00104 QString infoText() const;
00105
00111 void setInfoText(const QString &text);
00112
00116 QIcon icon() const;
00117
00122 void setIcon(const QIcon& icon);
00123
00129 Q_INVOKABLE void setIcon(const QString& icon);
00130
00134 QSizeF iconSize() const;
00135
00143 void addAction(QAction* action);
00144
00152 void setOrientation(Qt::Orientation orientation);
00153
00159 void invertLayout(bool invert);
00160
00164 bool invertedLayout() const;
00165
00170 QSizeF sizeFromIconSize(const qreal iconWidth) const;
00171
00175 int numDisplayLines();
00176
00180 void setNumDisplayLines(int numLines);
00181
00187 void setDrawBackground(bool draw);
00188
00192 bool drawBackground() const;
00193
00194 public Q_SLOTS:
00200 void setPressed(bool pressed = true);
00201
00205 void setUnpressed();
00206
00207 protected:
00208 void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00209
00210 Q_SIGNALS:
00214 void pressed(bool down);
00215
00219 void clicked();
00220
00224 void doubleClicked();
00225
00226 protected:
00227 bool isDown();
00228 void mousePressEvent(QGraphicsSceneMouseEvent *event);
00229 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
00230 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
00231 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
00232
00233 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
00234 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
00235
00236 public:
00237 class Private;
00238
00242 void drawActionButtonBase(QPainter* painter, const QSize &size, int element);
00243
00244 private:
00245 void init();
00246 void layoutIcons(const QStyleOptionGraphicsItem *option);
00247
00248 Private * const d;
00249
00250 private Q_SLOTS:
00251 void actionDestroyed(QObject* obj);
00252 };
00253
00254 }
00255
00256
00257
00258
00259
00260
00261
00262
00263 #endif