summaryrefslogtreecommitdiff
path: root/core/launcher/appicons.cpp
Unidiff
Diffstat (limited to 'core/launcher/appicons.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/appicons.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/core/launcher/appicons.cpp b/core/launcher/appicons.cpp
new file mode 100644
index 0000000..c51ee5a
--- a/dev/null
+++ b/core/launcher/appicons.cpp
@@ -0,0 +1,129 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#include "appicons.h"
23
24#include <qpe/qcopenvelope_qws.h>
25
26#include <qtooltip.h>
27#include <qpixmap.h>
28
29
30AppIcons::AppIcons( QWidget *parent ) :
31 QHBox(parent)
32{
33 buttons.setAutoDelete(TRUE);
34
35#ifndef QT_NO_COP
36 QCopChannel* channel = new QCopChannel("Qt/Tray", this);
37 connect(channel, SIGNAL(received(const QCString&, const QByteArray&)),
38 this, SLOT(receive(const QCString&, const QByteArray&)));
39#endif
40}
41
42void AppIcons::setIcon(int id, const QPixmap& pm)
43{
44 button(id)->setPixmap(pm);
45}
46
47class FlatButton : public QLabel {
48 Q_OBJECT
49public:
50 FlatButton(QWidget* parent) : QLabel(parent) { }
51
52 void mouseDoubleClickEvent(QMouseEvent* e)
53 {
54 emit clicked(e->pos(),e->button(),TRUE);
55 }
56 void mouseReleaseEvent(QMouseEvent* e)
57 {
58 if ( rect().contains(e->pos()) )
59 emit clicked(e->pos(),e->button(),FALSE);
60 }
61
62signals:
63 void clicked(const QPoint&, int, bool);
64};
65
66QLabel* AppIcons::button(int id)
67{
68 QLabel* f = buttons.find(id);
69 if ( !f ) {
70 buttons.insert(id,f=new FlatButton(this));
71 connect(f,SIGNAL(clicked(const QPoint&, int, bool)),this,SLOT(clicked(const QPoint&, int, bool)));
72 f->show();
73 }
74 return f;
75}
76
77int AppIcons::findId(QLabel* b)
78{
79 QIntDictIterator<QLabel> it(buttons);
80 for ( ; ; ++it )
81 if ( it.current() == b ) return it.currentKey();
82}
83
84void AppIcons::clicked(const QPoint& relpos, int button, bool dbl)
85{
86#ifndef QT_NO_COP
87 QLabel* s = (QLabel*)sender();
88 if ( button == RightButton ) {
89 QCopEnvelope("Qt/Tray","popup(int,QPoint)")
90 << findId(s) << s->mapToGlobal(QPoint(0,0));
91 } else {
92 QCopEnvelope("Qt/Tray",
93 dbl ? "doubleClicked(int,QPoint)" : "clicked(int,QPoint)")
94 << findId(s) << relpos;
95 }
96#endif
97}
98
99void AppIcons::setToolTip(int id, const QString& tip)
100{
101 QToolTip::add(button(id),tip);
102}
103
104void AppIcons::remove(int id)
105{
106 buttons.remove(id);
107}
108
109void AppIcons::receive( const QCString &msg, const QByteArray &data )
110{
111 QDataStream stream( data, IO_ReadOnly );
112 if ( msg == "remove(int)" ) {
113 int id;
114 stream >> id;
115 remove(id);
116 } else if ( msg == "setIcon(int,QPixmap)" ) {
117 int id;
118 QPixmap pm;
119 stream >> id >> pm;
120 setIcon(id,pm);
121 } else if ( msg == "setToolTip(int,QString)" ) {
122 int id;
123 QString s;
124 stream >> id >> s;
125 setToolTip(id,s);
126 }
127}
128
129#include "appicons.moc"