Applets
abstracttaskitem.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 ABSTRACTTASKITEM_H
00024 #define ABSTRACTTASKITEM_H
00025
00026
00027 #include <KColorScheme>
00028
00029 #include <taskmanager/taskgroup.h>
00030
00031
00032 #include <QTime>
00033 #include <QIcon>
00034 #include <QGraphicsWidget>
00035
00036 class QTextOption;
00037 class QTextLayout;
00038 class QString;
00039
00040
00041
00042 #include <Plasma/Animator>
00043
00044 class Tasks;
00045 class TaskGroupItem;
00046 class LayoutWidget;
00047
00051 class AbstractTaskItem : public QGraphicsWidget
00052 {
00053 Q_OBJECT
00054
00055 public:
00057 AbstractTaskItem(QGraphicsWidget *parent, Tasks *applet, const bool showTooltip);
00058
00060 ~AbstractTaskItem();
00061
00063 void setShowTooltip(const bool showit);
00064
00066 void setText(const QString &text);
00067
00069 void setIcon(const QIcon &icon);
00070
00075 enum TaskFlag
00076 {
00081 TaskWantsAttention = 1,
00085 TaskHasFocus = 2,
00089 TaskIsMinimized = 4
00090 };
00091 Q_DECLARE_FLAGS(TaskFlags, TaskFlag)
00092
00093
00094 void setTaskFlags(const TaskFlags flags);
00095
00097 TaskFlags taskFlags() const;
00098
00100 QString text() const;
00101
00103 QIcon icon() const;
00104
00105 virtual void close() = 0;
00106
00108 virtual void publishIconGeometry() const;
00109 virtual void publishIconGeometry(const QRect &rect) const;
00110 QRect iconGeometry() const;
00111
00113 void setGeometry(const QRectF& geometry);
00114
00117 bool isGrouped() const;
00118 bool isGroupMember(const TaskGroupItem *group) const;
00119 TaskGroupItem *parentGroup() const;
00120
00121 virtual bool isWindowItem() const = 0;
00122 virtual bool isActive() const = 0;
00123
00124 virtual void setAdditionalMimeData(QMimeData* mimeData) = 0;
00125
00126 void setLayoutWidget(LayoutWidget* widget);
00127 TaskManager::AbstractItemPtr abstractItem();
00128
00130 QSize basicPreferredSize() const;
00131
00132 Q_SIGNALS:
00133 void activated(AbstractTaskItem *);
00134
00135 public Q_SLOTS:
00136 virtual void activate() = 0;
00137 void toolTipAboutToShow();
00138 void toolTipHidden();
00139
00140 protected:
00141 void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
00142 void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
00143 void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
00144
00145
00146 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
00147 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
00148 void mousePressEvent(QGraphicsSceneMouseEvent *event);
00149 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
00150 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
00151 void timerEvent(QTimerEvent *event);
00152 void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget);
00153
00155 virtual void drawBackground(QPainter *painter,const QStyleOptionGraphicsItem *option,
00156 QWidget *widget);
00158 virtual void drawTask(QPainter *painter,const QStyleOptionGraphicsItem *option,
00159 QWidget *widget);
00160
00162 QTextOption textOption() const;
00163
00171 QSize layoutText(QTextLayout &layout, const QString &text, const QSize &constraints) const;
00172
00178 void drawTextLayout(QPainter *painter, const QTextLayout &layout, const QRect &rect) const;
00179
00180 virtual void updateTask(::TaskManager::TaskChanges changes) = 0;
00181 virtual void updateToolTip() = 0;
00182 QString expanderElement() const;
00183
00184 protected Q_SLOTS:
00186 void queueUpdate();
00187
00188 void animationUpdate(qreal progress);
00189 void syncActiveRect();
00190 void checkSettings();
00191
00192 protected:
00193
00194 QRectF iconRect(const QRectF &bounds) const;
00195
00196 QRectF expanderRect(const QRectF &b) const;
00197
00198 QRectF textRect(const QRectF &bounds) const;
00199
00200 void fadeBackground(const QString &newBackground, int duration, bool fadeIn);
00201
00202 QColor textColor() const;
00203
00204 TaskManager::AbstractItemPtr m_abstractItem;
00205 LayoutWidget *m_layoutWidget;
00206
00207 Tasks *m_applet;
00208 LayoutWidget *m_parentWidget;
00209 QTimer* m_activateTimer;
00210
00211
00212 TaskFlags m_flags;
00213
00214 QIcon m_icon;
00215 QString m_text;
00216
00217 int m_animId;
00218 qreal m_alpha;
00219 QString m_oldBackgroundPrefix;
00220 QString m_backgroundPrefix;
00221 QRectF m_activeRect;
00222
00223 QPointF _dragOffset;
00224 QTime m_lastUpdate;
00225 int m_updateTimerId;
00226 int m_attentionTimerId;
00227 int m_attentionTicks;
00228
00229 bool m_fadeIn : 1;
00230 bool m_showTooltip : 1;
00231 bool m_showingTooltip : 1;
00232
00233 static const int IconTextSpacing = 4;
00234
00235 static const int TaskItemHorizontalMargin = 4;
00236 static const int TaskItemVerticalMargin = 4;
00237 };
00238
00239 #endif