~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/applets/systemtray/ui/taskarea_p.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   taskarea.cpp                                                          *
 
3
 *                                                                         *
 
4
 *   Copyright (C) 2008 Jason Stubbs <jasonbstubbs@gmail.com>              *
 
5
 *                                                                         *
 
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.                                   *
 
10
 *                                                                         *
 
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.                          *
 
15
 *                                                                         *
 
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
 ***************************************************************************/
 
21
 
 
22
#ifndef TASKAREA_P_H
 
23
#define TASKAREA_P_H
 
24
 
 
25
#include <Plasma/Label>
 
26
 
 
27
namespace SystemTray
 
28
{
 
29
 
 
30
class HiddenTaskLabel : public Plasma::Label
 
31
{
 
32
 
 
33
    Q_OBJECT
 
34
 
 
35
public:
 
36
    HiddenTaskLabel(QGraphicsWidget *taskIcon, const QString &label, Plasma::ItemBackground *itemBackground, Plasma::Applet *applet, QGraphicsWidget *parent = 0)
 
37
        : Plasma::Label(parent),
 
38
          m_taskIcon(taskIcon),
 
39
          m_itemBackground(itemBackground),
 
40
          m_applet(applet)
 
41
    {
 
42
        taskIcon->setMaximumHeight(48);
 
43
        taskIcon->setMinimumHeight(24);
 
44
        taskIcon->setMinimumWidth(24);
 
45
 
 
46
        nativeWidget()->setIndent(6);
 
47
        setContentsMargins(6, 0, 0, 0);
 
48
 
 
49
        setWordWrap(false);
 
50
        setText(label);
 
51
        if (!itemBackground->scene()) {
 
52
            scene()->addItem(itemBackground);
 
53
            takeItemBackgroundOwnership();
 
54
        }
 
55
    }
 
56
 
 
57
public slots:
 
58
    void taskChanged(SystemTray::Task *task)
 
59
    {
 
60
        setText(task->name());
 
61
    }
 
62
 
 
63
protected:
 
64
    void takeItemBackgroundOwnership()
 
65
    {
 
66
        if (m_taskIcon) {
 
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);
 
74
        }
 
75
    }
 
76
 
 
77
    template<class T> void forwardEvent(T *event)
 
78
    {
 
79
        if (m_taskIcon) {
 
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);
 
92
            } else {
 
93
                event->setPos(item->boundingRect().center());
 
94
                scene()->sendEvent(item, event);
 
95
            }
 
96
        }
 
97
    }
 
98
 
 
99
    void mousePressEvent(QGraphicsSceneMouseEvent *event)
 
100
    {
 
101
        forwardEvent(event);
 
102
    }
 
103
 
 
104
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 
105
    {
 
106
        forwardEvent(event);
 
107
    }
 
108
 
 
109
    void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
 
110
    {
 
111
        forwardEvent(event);
 
112
    }
 
113
 
 
114
    void wheelEvent(QGraphicsSceneWheelEvent *event)
 
115
    {
 
116
        forwardEvent(event);
 
117
    }
 
118
 
 
119
    void hoverEnterEvent(QGraphicsSceneHoverEvent * event)
 
120
    {
 
121
        takeItemBackgroundOwnership();
 
122
        forwardEvent(event);
 
123
    }
 
124
 
 
125
    void hoverLeaveEvent(QGraphicsSceneHoverEvent * event)
 
126
    {
 
127
        forwardEvent(event);
 
128
    }
 
129
 
 
130
    void hoverMoveEvent(QGraphicsSceneHoverEvent * event)
 
131
    {
 
132
        forwardEvent(event);
 
133
    }
 
134
 
 
135
private:
 
136
    QWeakPointer<QGraphicsWidget> m_taskIcon;
 
137
    Plasma::ItemBackground *m_itemBackground;
 
138
    Plasma::Applet *m_applet;
 
139
};
 
140
 
 
141
}
 
142
 
 
143
#endif