2
* trayicon.cpp - system-independent trayicon class (adapted from Qt example)
3
* Copyright (C) 2003 Justin Karneges
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library 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 GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
#include "qpopupmenu.h"
25
\class TrayIcon qtrayicon.h
26
\brief The TrayIcon class implements an entry in the system tray.
30
Creates a TrayIcon object. \a parent and \a name are propagated
31
to the QObject constructor. The icon is initially invisible.
35
TrayIcon::TrayIcon( QObject *parent, const char *name )
36
: QObject(parent, name), pop(0), d(0)
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.
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)
53
if ( !pm.width() || !pm.height() )
54
pm = QPixmap( 16, 16 );
58
Removes the icon from the system tray and frees all allocated resources.
66
Informs the trayicon that the notification owner has probably been changed;
67
and that it should attempt to register or re-register.
69
void TrayIcon::newTrayOwner()
71
// detach ourself from any existing notification area.
73
// show ourself on the new notification area
79
Sets the context menu to \a popup. The context menu will pop up when the
80
user clicks the system tray entry with the right mouse button.
82
void TrayIcon::setPopup( QPopupMenu* popup )
88
Returns the current popup menu.
92
QPopupMenu* TrayIcon::popup() const
98
\property TrayIcon::icon
99
\brief the system tray icon.
101
void TrayIcon::setIcon( const QPixmap &icon )
111
QPixmap TrayIcon::icon() const
117
\property TrayIcon::toolTip
118
\brief the tooltip for the system tray entry
120
On some systems, the tooltip's length is limited and will be truncated as necessary.
122
void TrayIcon::setToolTip( const QString &tooltip )
128
QString TrayIcon::toolTip() const
134
Shows the icon in the system tray.
138
void TrayIcon::show()
144
Hides the system tray entry.
146
void TrayIcon::hide()
154
bool TrayIcon::event( QEvent *e )
156
switch ( e->type() ) {
157
case QEvent::MouseMove:
158
mouseMoveEvent( (QMouseEvent*)e );
161
case QEvent::MouseButtonPress:
162
mousePressEvent( (QMouseEvent*)e );
165
case QEvent::MouseButtonRelease:
166
mouseReleaseEvent( (QMouseEvent*)e );
169
case QEvent::MouseButtonDblClick:
170
mouseDoubleClickEvent( (QMouseEvent*)e );
173
return QObject::event( e );
180
This event handler can be reimplemented in a subclass to receive
181
mouse move events for the system tray entry.
183
\sa mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), QMouseEvent
185
void TrayIcon::mouseMoveEvent( QMouseEvent *e )
191
This event handler can be reimplemented in a subclass to receive
192
mouse press events for the system tray entry.
194
\sa mouseReleaseEvent(), mouseDoubleClickEvent(),
195
mouseMoveEvent(), QMouseEvent
197
void TrayIcon::mousePressEvent( QMouseEvent *e )
200
// This is for X11, menus appear on mouse press
201
// I'm not sure whether Mac should be here or below.. Somebody check?
202
switch ( e->button() ) {
205
pop->popup( e->globalPos() );
211
emit clicked( e->globalPos(), e->button() );
221
This event handler can be reimplemented in a subclass to receive
222
mouse release events for the system tray entry.
224
The default implementations opens the context menu when the entry
225
has been clicked with the right mouse button.
227
\sa setPopup(), mousePressEvent(), mouseDoubleClickEvent(),
228
mouseMoveEvent(), QMouseEvent
230
void TrayIcon::mouseReleaseEvent( QMouseEvent *e )
233
// This is for Windows, where menus appear on mouse release
234
switch ( e->button() ) {
237
// Necessary to make keyboard focus
238
// and menu closing work on Windows.
239
pop->setActiveWindow();
240
pop->popup( e->globalPos() );
241
pop->setActiveWindow();
247
emit clicked( e->globalPos(), e->button() );
257
This event handler can be reimplemented in a subclass to receive
258
mouse double click events for the system tray entry.
260
Note that the system tray entry gets a mousePressEvent() and a
261
mouseReleaseEvent() before the mouseDoubleClickEvent().
263
\sa mousePressEvent(), mouseReleaseEvent(),
264
mouseMoveEvent(), QMouseEvent
266
void TrayIcon::mouseDoubleClickEvent( QMouseEvent *e )
268
if ( e->button() == LeftButton )
269
emit doubleClicked( e->globalPos() );
274
\fn void TrayIcon::clicked( const QPoint &p )
276
This signal is emitted when the user clicks the system tray icon
277
with the left mouse button, with \a p being the global mouse position
282
\fn void TrayIcon::doubleClicked( const QPoint &p )
284
This signal is emitted when the user double clicks the system tray
285
icon with the left mouse button, with \a p being the global mouse position
289
void TrayIcon::gotCloseEvent()