Applets
windowtaskitem.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 WINDOWTASKITEM_H
00023 #define WINDOWTASKITEM_H
00024
00025
00026 #include <taskmanager/taskmanager.h>
00027
00028
00029 #include <QIcon>
00030 #include <QTextLayout>
00031 #include <QTime>
00032 #include <QGraphicsLinearLayout>
00033 #include <QGraphicsWidget>
00034
00035 #include <KColorScheme>
00036
00037 class QTimeLine;
00038
00039
00040 #include <plasma/animator.h>
00041
00042 namespace Plasma
00043 {
00044 class PanelSvg;
00045 }
00046
00047 class Tasks;
00048
00052 class WindowTaskItem : public QGraphicsWidget
00053 {
00054 Q_OBJECT
00055
00056 public:
00058 WindowTaskItem(Tasks *parent, const bool showTooltip);
00059
00061 void setStartupTask(TaskManager::StartupPtr task);
00062
00064 void setWindowTask(TaskManager::TaskPtr task);
00066 TaskManager::TaskPtr windowTask() const;
00067
00069 void publishIconGeometry();
00070
00072 void setShowTooltip(const bool showit);
00073
00075 void setText(const QString &text);
00076
00078 void setIcon(const QIcon &icon);
00079
00084 enum TaskFlag
00085 {
00090 TaskWantsAttention = 1,
00094 TaskHasFocus = 2,
00098 TaskIsMinimized = 4
00099 };
00100 Q_DECLARE_FLAGS(TaskFlags, TaskFlag)
00101
00102
00103 void setTaskFlags(TaskFlags flags);
00104
00106 TaskFlags taskFlags() const;
00107
00109 QString text() const;
00110
00112 QIcon icon() const;
00113
00114 virtual void close();
00115
00117 void setGeometry(const QRectF& geometry);
00118
00119 signals:
00121 void windowSelected(WindowTaskItem *);
00122
00123 void activated(WindowTaskItem *);
00124
00125 public slots:
00126 virtual void activate();
00127
00128 protected:
00129 virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
00130 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
00131 virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
00132 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
00133
00135 void queueUpdate();
00136
00137
00138 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
00139 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
00140 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
00141 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
00142 virtual void timerEvent(QTimerEvent *event);
00143 virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
00144 virtual void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget);
00145
00147 virtual void drawBackground(QPainter *painter,const QStyleOptionGraphicsItem *option,
00148 QWidget *widget);
00150 virtual void drawTask(QPainter *painter,const QStyleOptionGraphicsItem *option,
00151 QWidget *widget);
00152
00154 QTextOption textOption() const;
00155
00163 QSize layoutText(QTextLayout &layout, const QString &text, const QSize &constraints) const;
00164
00170 void drawTextLayout(QPainter *painter, const QTextLayout &layout, const QRect &rect) const;
00171
00172
00173 private slots:
00174 void updateTask();
00175 void animationUpdate(qreal progress);
00176
00177 private:
00178 Tasks *m_applet;
00179 TaskManager::TaskPtr m_task;
00180 QTimer* m_activateTimer;
00181
00182 bool m_showTooltip;
00183
00184 QRectF iconRect(const QRectF &bounds) const;
00185
00186 QRectF textRect(const QRectF &bounds) const;
00187
00188 TaskFlags m_flags;
00189
00190 QIcon m_icon;
00191 QString m_text;
00192
00193 int m_animId;
00194 qreal m_alpha;
00195 bool m_fadeIn;
00196
00197 QPointF _dragOffset;
00198 QTime m_lastUpdate;
00199 int m_updateTimerId;
00200 int m_attentionTimerId;
00201 int m_attentionTicks;
00202
00203
00204 static const int IconTextSpacing = 4;
00205
00206 static const int TaskItemHorizontalMargin = 4;
00207 static const int TaskItemVerticalMargin = 4;
00208 };
00209
00210 #endif