1
/***************************************************************************
4
* Copyright (C) 2008 Jason Stubbs <jasonbstubbs@gmail.com> *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
20
***************************************************************************/
25
#include <Plasma/Label>
30
class HiddenTaskLabel : public Plasma::Label
36
HiddenTaskLabel(QGraphicsWidget *taskIcon, const QString &label, Plasma::ItemBackground *itemBackground, Plasma::Applet *applet, QGraphicsWidget *parent = 0)
37
: Plasma::Label(parent),
39
m_itemBackground(itemBackground),
42
taskIcon->setMaximumHeight(48);
43
taskIcon->setMinimumHeight(24);
44
taskIcon->setMinimumWidth(24);
46
nativeWidget()->setIndent(6);
47
setContentsMargins(6, 0, 0, 0);
51
if (!itemBackground->scene()) {
52
scene()->addItem(itemBackground);
53
takeItemBackgroundOwnership();
58
void taskChanged(SystemTray::Task *task)
60
setText(task->name());
64
void takeItemBackgroundOwnership()
67
QRectF totalRect = geometry().united(m_taskIcon.data()->geometry());
68
totalRect.moveTopLeft(QPoint(0,0));
69
totalRect = m_taskIcon.data()->mapToScene(totalRect).boundingRect();
70
qreal left, top, right, bottom;
71
m_itemBackground->getContentsMargins(&left, &top, &right, &bottom);
72
totalRect.adjust(-left/2, -top/2, right/2, bottom/2);
73
m_itemBackground->setTarget(totalRect);
77
template<class T> void forwardEvent(T *event)
80
QGraphicsWidget *item = m_taskIcon.data();
81
QPointF delta = item->sceneBoundingRect().center() - event->scenePos();
82
event->setScenePos(item->sceneBoundingRect().center());
83
event->setScreenPos((event->screenPos() + delta).toPoint());
84
if (dynamic_cast<QGraphicsSceneContextMenuEvent *>(event) &&
85
qobject_cast<Plasma::Applet*>(item) &&
86
m_applet->containment()) {
87
event->setPos(m_applet->containment()->mapFromScene(event->scenePos()));
88
scene()->sendEvent(m_applet->containment(), event);
89
} else if (qobject_cast<Plasma::Applet*>(item)) {
90
event->setPos(scene()->itemAt(event->scenePos())->mapFromScene(event->scenePos()));
91
scene()->sendEvent(scene()->itemAt(event->scenePos()), event);
93
event->setPos(item->boundingRect().center());
94
scene()->sendEvent(item, event);
99
void mousePressEvent(QGraphicsSceneMouseEvent *event)
104
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
109
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
114
void wheelEvent(QGraphicsSceneWheelEvent *event)
119
void hoverEnterEvent(QGraphicsSceneHoverEvent * event)
121
takeItemBackgroundOwnership();
125
void hoverLeaveEvent(QGraphicsSceneHoverEvent * event)
130
void hoverMoveEvent(QGraphicsSceneHoverEvent * event)
136
QWeakPointer<QGraphicsWidget> m_taskIcon;
137
Plasma::ItemBackground *m_itemBackground;
138
Plasma::Applet *m_applet;