Plasma
iconwidget.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2007 by Siraj Razick <siraj@kde.org> 00003 * Copyright (C) 2007 by Riccardo Iaconelli <riccardo@kde.org> 00004 * Copyright (C) 2007 by Matt Broadstone <mbroadst@gmail.com> 00005 * Copyright 2008 by Alexis Ménard <darktears31@gmail.com> 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU Library General Public License as 00009 * published by the Free Software Foundation; either version 2, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details 00016 * 00017 * You should have received a copy of the GNU Library General Public 00018 * License along with this program; if not, write to the 00019 * Free Software Foundation, Inc., 00020 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef PLASMA_ICONWIDGET_H 00024 #define PLASMA_ICONWIDGET_H 00025 00026 #include <QtCore/QObject> 00027 #include <QtCore/QWeakPointer> 00028 #include <QtGui/QGraphicsTextItem> 00029 #include <QtGui/QIcon> 00030 #include <QtGui/QGraphicsWidget> 00031 00032 #include <plasma/dataengine.h> 00033 #include <plasma/animator.h> 00034 #include <plasma/plasma_export.h> 00035 00036 class QAction; 00037 class QPropertyAnimation; 00038 00051 namespace Plasma 00052 { 00053 00054 class IconWidgetPrivate; 00055 00056 class PLASMA_EXPORT IconWidget : public QGraphicsWidget 00057 { 00058 Q_OBJECT 00059 Q_PROPERTY(QString text READ text WRITE setText) 00060 Q_PROPERTY(QString infoText READ infoText WRITE setInfoText) 00061 Q_PROPERTY(QIcon icon READ icon WRITE setIcon) 00062 Q_PROPERTY(QColor textBackgroundColor READ textBackgroundColor WRITE setTextBackgroundColor) 00063 Q_PROPERTY(QSizeF iconSize READ iconSize) 00064 Q_PROPERTY(QString svg READ svg WRITE setSvg) 00065 Q_PROPERTY(bool drawBackground READ drawBackground WRITE setDrawBackground) 00066 Q_PROPERTY(QAction *action READ action WRITE setAction) 00067 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) 00068 Q_PROPERTY(int numDisplayLines READ numDisplayLines WRITE setNumDisplayLines) 00069 Q_PROPERTY(QSizeF preferredIconSize READ preferredIconSize WRITE setPreferredIconSize) 00070 Q_PROPERTY(QSizeF minimumIconSize READ minimumIconSize WRITE setMinimumIconSize) 00071 Q_PROPERTY(QSizeF maximumIconSize READ maximumIconSize WRITE setMaximumIconSize) 00072 00073 public: 00078 explicit IconWidget(QGraphicsItem *parent = 0); 00079 00085 explicit IconWidget(const QString &text, QGraphicsItem *parent = 0); 00086 00093 IconWidget(const QIcon &icon, const QString &text, QGraphicsItem *parent = 0); 00094 00098 virtual ~IconWidget(); 00099 00103 QString text() const; 00104 00109 void setText(const QString &text); 00110 00116 void setSvg(const QString &svgFilePath, const QString &svgIconElement = QString()); 00117 00121 QString svg() const; 00122 00126 QString infoText() const; 00127 00133 void setInfoText(const QString &text); 00134 00138 QIcon icon() const; 00139 00144 void setIcon(const QIcon &icon); 00145 00150 QColor textBackgroundColor() const; 00151 00157 void setTextBackgroundColor(const QColor &color); 00158 00164 Q_INVOKABLE void setIcon(const QString &icon); 00165 00169 QSizeF iconSize() const; 00170 00177 void setPreferredIconSize(const QSizeF &size); 00178 00186 QSizeF preferredIconSize() const; 00187 00195 void setMinimumIconSize(const QSizeF &size); 00196 00205 QSizeF minimumIconSize() const; 00206 00214 void setMaximumIconSize(const QSizeF &size); 00215 00224 QSizeF maximumIconSize() const; 00225 00232 void addIconAction(QAction *action); 00233 00240 void removeIconAction(QAction *action); 00241 00248 void setAction(QAction *action); 00249 00253 QAction *action() const; 00254 00262 void setOrientation(Qt::Orientation orientation); 00263 00267 Qt::Orientation orientation() const; 00268 00274 void invertLayout(bool invert); 00275 00279 bool invertedLayout() const; 00280 00285 Q_INVOKABLE QSizeF sizeFromIconSize(const qreal iconWidth) const; 00286 00290 int numDisplayLines(); 00291 00295 void setNumDisplayLines(int numLines); 00296 00302 void setDrawBackground(bool draw); 00303 00307 bool drawBackground() const; 00308 00312 QPainterPath shape() const; 00313 00314 public Q_SLOTS: 00320 void setPressed(bool pressed = true); 00321 00325 void setUnpressed(); 00326 00327 protected: 00328 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); 00329 QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const; 00330 00331 Q_SIGNALS: 00335 void pressed(bool down); 00336 00340 void clicked(); 00341 00345 void doubleClicked(); 00346 00351 void activated(); 00352 00357 void changed(); 00358 00359 protected: 00360 bool isDown(); 00361 void mousePressEvent(QGraphicsSceneMouseEvent *event); 00362 void mouseMoveEvent(QGraphicsSceneMouseEvent *event); 00363 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); 00364 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); 00365 00366 void hoverEnterEvent(QGraphicsSceneHoverEvent *event); 00367 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); 00368 00369 bool sceneEventFilter(QGraphicsItem *watched, QEvent *event); 00370 void changeEvent(QEvent *event); 00371 00372 public: 00376 void drawActionButtonBase(QPainter *painter, const QSize &size, int element); 00377 00378 private: 00379 Q_PRIVATE_SLOT(d, void syncToAction()) 00380 Q_PRIVATE_SLOT(d, void clearAction()) 00381 Q_PRIVATE_SLOT(d, void svgChanged()) 00382 Q_PRIVATE_SLOT(d, void actionDestroyed(QObject *obj)) 00383 Q_PRIVATE_SLOT(d, void hoverAnimationFinished()) 00384 Q_PRIVATE_SLOT(d, void colorConfigChanged()) 00385 Q_PRIVATE_SLOT(d, void iconConfigChanged()) 00386 Q_PRIVATE_SLOT(d, void setPalette()) 00387 00388 IconWidgetPrivate * const d; 00389 friend class IconWidgetPrivate; 00390 friend class PopupAppletPrivate; 00391 }; 00392 00393 } // namespace Plasma 00394 00395 #endif
KDE 4.6 API Reference