~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/trayicon.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2005-01-10 17:41:43 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050110174143-ltocv5zapl6blf5d
Tags: 0.9.3-1
* New upstream release
* Cleaned up debian/rules (some things are done by upstream Makefiles now)
* Fixed some lintian warnings:
  - removed executable bit from some .png files
  - moved psi.desktop to /usr/share/applications
* Updated menu files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
** trayicon.cpp - system-independent tray app class (adapted from Qt example)
3
 
** Copyright (C) 2001, 2002  Justin Karneges
4
 
**
5
 
** This program is free software; you can redistribute it and/or
6
 
** modify it under the terms of the GNU General Public License
7
 
** as published by the Free Software Foundation; either version 2
8
 
** of the License, or (at your option) any later version.
9
 
**
10
 
** This program is distributed in the hope that it will be useful,
11
 
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
** GNU General Public License for more details.
14
 
**
15
 
** You should have received a copy of the GNU General Public License
16
 
** along with this program; if not, write to the Free Software
17
 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 
**
19
 
****************************************************************************/
20
 
 
21
 
#include "trayicon.h"
22
 
#include "qpopupmenu.h"
23
 
 
24
 
/*!
25
 
  \class TrayIcon qtrayicon.h
26
 
  \brief The TrayIcon class implements an entry in the system tray.
27
 
*/
28
 
 
29
 
/*!
30
 
  Creates a TrayIcon object. \a parent and \a name are propagated
31
 
  to the QObject constructor. The icon is initially invisible.
32
 
 
33
 
  \sa show
34
 
*/
35
 
TrayIcon::TrayIcon( QObject *parent, const char *name )
36
 
: QObject(parent, name), pop(0), d(0)
37
 
{
38
 
        v_isWMDock = FALSE;
39
 
}
40
 
 
41
 
/*!
42
 
  Creates a TrayIcon object displaying \a icon and \a tooltip, and opening
43
 
  \a popup when clicked with the right mousebutton. \a parent and \a name are
44
 
  propagated to the QObject constructor. The icon is initially invisible.
45
 
 
46
 
  \sa show
47
 
*/
48
 
TrayIcon::TrayIcon( const QPixmap &icon, const QString &tooltip, QPopupMenu *popup, QObject *parent, const char *name )
49
 
: QObject(parent, name), pop(popup), pm(icon), tip(tooltip), d(0)
50
 
{
51
 
        v_isWMDock = FALSE;
52
 
}
53
 
 
54
 
/*!
55
 
  Removes the icon from the system tray and frees all allocated resources.
56
 
*/
57
 
TrayIcon::~TrayIcon()
58
 
{
59
 
    sysRemove();
60
 
}
61
 
 
62
 
/*!
63
 
  Sets the context menu to \a popup. The context menu will pop up when the
64
 
  user clicks the system tray entry with the right mouse button.
65
 
*/
66
 
void TrayIcon::setPopup( QPopupMenu* popup )
67
 
{
68
 
    pop = popup;
69
 
}
70
 
 
71
 
/*!
72
 
  Returns the current popup menu.
73
 
 
74
 
  \sa setPopup
75
 
*/
76
 
QPopupMenu* TrayIcon::popup() const
77
 
{
78
 
    return pop;
79
 
}
80
 
 
81
 
/*!
82
 
  \property TrayIcon::icon
83
 
  \brief the system tray icon.
84
 
*/
85
 
void TrayIcon::setIcon( const QPixmap &icon )
86
 
{
87
 
    //if(!popup()) {
88
 
    //    tip = "";
89
 
    //}
90
 
 
91
 
    pm = icon;
92
 
    sysUpdateIcon();
93
 
}
94
 
 
95
 
QPixmap TrayIcon::icon() const
96
 
{
97
 
    return pm;
98
 
}
99
 
 
100
 
/*!
101
 
  \property TrayIcon::toolTip
102
 
  \brief the tooltip for the system tray entry
103
 
 
104
 
  On some systems, the tooltip's length is limited and will be truncated as necessary.
105
 
*/
106
 
void TrayIcon::setToolTip( const QString &tooltip )
107
 
{
108
 
    tip = tooltip;
109
 
    sysUpdateToolTip();
110
 
}
111
 
 
112
 
QString TrayIcon::toolTip() const
113
 
{
114
 
    return tip;
115
 
}
116
 
 
117
 
/*!
118
 
  Shows the icon in the system tray.
119
 
 
120
 
  \sa hide
121
 
*/
122
 
void TrayIcon::show()
123
 
{
124
 
    sysInstall();
125
 
}
126
 
 
127
 
/*!
128
 
  Hides the system tray entry.
129
 
*/
130
 
void TrayIcon::hide()
131
 
{
132
 
    sysRemove();
133
 
}
134
 
 
135
 
/*!
136
 
  \reimp
137
 
*/
138
 
bool TrayIcon::event( QEvent *e )
139
 
{
140
 
    switch ( e->type() ) {
141
 
    case QEvent::MouseMove:
142
 
        mouseMoveEvent( (QMouseEvent*)e );
143
 
        break;
144
 
 
145
 
    case QEvent::MouseButtonPress:
146
 
        mousePressEvent( (QMouseEvent*)e );
147
 
        break;
148
 
 
149
 
    case QEvent::MouseButtonRelease:
150
 
        mouseReleaseEvent( (QMouseEvent*)e );
151
 
        break;
152
 
 
153
 
    case QEvent::MouseButtonDblClick:
154
 
        mouseDoubleClickEvent( (QMouseEvent*)e );
155
 
        break;
156
 
    default:
157
 
        return QObject::event( e );
158
 
    }
159
 
 
160
 
    return TRUE;
161
 
}
162
 
 
163
 
/*!
164
 
  This event handler can be reimplemented in a subclass to receive
165
 
  mouse move events for the system tray entry.
166
 
 
167
 
  \sa mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(),  QMouseEvent
168
 
*/
169
 
void TrayIcon::mouseMoveEvent( QMouseEvent *e )
170
 
{
171
 
    e->ignore();
172
 
}
173
 
 
174
 
/*!
175
 
  This event handler can be reimplemented in a subclass to receive
176
 
  mouse press events for the system tray entry.
177
 
 
178
 
  \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
179
 
  mouseMoveEvent(), QMouseEvent
180
 
*/
181
 
void TrayIcon::mousePressEvent( QMouseEvent *e )
182
 
{
183
 
    e->ignore();
184
 
}
185
 
 
186
 
/*!
187
 
  This event handler can be reimplemented in a subclass to receive
188
 
  mouse release events for the system tray entry.
189
 
 
190
 
  The default implementations opens the context menu when the entry
191
 
  has been clicked with the right mouse button.
192
 
 
193
 
  \sa setPopup(), mousePressEvent(), mouseDoubleClickEvent(),
194
 
  mouseMoveEvent(), QMouseEvent
195
 
*/
196
 
void TrayIcon::mouseReleaseEvent( QMouseEvent *e )
197
 
{
198
 
    switch ( e->button() ) {
199
 
    case RightButton:
200
 
        if ( pop ) {
201
 
            // Necessary to make keyboard focus
202
 
            // and menu closing work on Windows.
203
 
#ifdef Q_WS_WIN
204
 
            pop->setActiveWindow();
205
 
#endif
206
 
            pop->popup( e->globalPos() );
207
 
#ifdef Q_WS_WIN
208
 
            pop->setActiveWindow();
209
 
#endif
210
 
            e->accept();
211
 
        }
212
 
        break;
213
 
    case LeftButton:
214
 
    case MidButton:
215
 
        emit clicked( e->globalPos(), e->button() );
216
 
        break;
217
 
    default:
218
 
        break;
219
 
    }
220
 
    e->ignore();
221
 
}
222
 
 
223
 
/*!
224
 
  This event handler can be reimplemented in a subclass to receive
225
 
  mouse double click events for the system tray entry.
226
 
 
227
 
  Note that the system tray entry gets a mousePressEvent() and a
228
 
  mouseReleaseEvent() before the mouseDoubleClickEvent().
229
 
 
230
 
  \sa mousePressEvent(), mouseReleaseEvent(),
231
 
  mouseMoveEvent(), QMouseEvent
232
 
*/
233
 
void TrayIcon::mouseDoubleClickEvent( QMouseEvent *e )
234
 
{
235
 
    if ( e->button() == LeftButton )
236
 
        emit doubleClicked( e->globalPos() );
237
 
    e->ignore();
238
 
}
239
 
 
240
 
/*!
241
 
  \fn void TrayIcon::clicked( const QPoint &p )
242
 
 
243
 
  This signal is emitted when the user clicks the system tray icon
244
 
  with the left mouse button, with \a p being the global mouse position
245
 
  at that moment.
246
 
*/
247
 
 
248
 
/*!
249
 
  \fn void TrayIcon::doubleClicked( const QPoint &p )
250
 
 
251
 
  This signal is emitted when the user double clicks the system tray
252
 
  icon with the left mouse button, with \a p being the global mouse position
253
 
  at that moment.
254
 
*/
255
 
 
256
 
void TrayIcon::gotCloseEvent()
257
 
{
258
 
        closed();
259
 
}