1
/****************************************************************************
2
** trayicon.cpp - system-independent tray app class (adapted from Qt example)
3
** Copyright (C) 2001, 2002 Justin Karneges
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.
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.
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.
19
****************************************************************************/
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)
55
Removes the icon from the system tray and frees all allocated resources.
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.
66
void TrayIcon::setPopup( QPopupMenu* popup )
72
Returns the current popup menu.
76
QPopupMenu* TrayIcon::popup() const
82
\property TrayIcon::icon
83
\brief the system tray icon.
85
void TrayIcon::setIcon( const QPixmap &icon )
95
QPixmap TrayIcon::icon() const
101
\property TrayIcon::toolTip
102
\brief the tooltip for the system tray entry
104
On some systems, the tooltip's length is limited and will be truncated as necessary.
106
void TrayIcon::setToolTip( const QString &tooltip )
112
QString TrayIcon::toolTip() const
118
Shows the icon in the system tray.
122
void TrayIcon::show()
128
Hides the system tray entry.
130
void TrayIcon::hide()
138
bool TrayIcon::event( QEvent *e )
140
switch ( e->type() ) {
141
case QEvent::MouseMove:
142
mouseMoveEvent( (QMouseEvent*)e );
145
case QEvent::MouseButtonPress:
146
mousePressEvent( (QMouseEvent*)e );
149
case QEvent::MouseButtonRelease:
150
mouseReleaseEvent( (QMouseEvent*)e );
153
case QEvent::MouseButtonDblClick:
154
mouseDoubleClickEvent( (QMouseEvent*)e );
157
return QObject::event( e );
164
This event handler can be reimplemented in a subclass to receive
165
mouse move events for the system tray entry.
167
\sa mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), QMouseEvent
169
void TrayIcon::mouseMoveEvent( QMouseEvent *e )
175
This event handler can be reimplemented in a subclass to receive
176
mouse press events for the system tray entry.
178
\sa mouseReleaseEvent(), mouseDoubleClickEvent(),
179
mouseMoveEvent(), QMouseEvent
181
void TrayIcon::mousePressEvent( QMouseEvent *e )
187
This event handler can be reimplemented in a subclass to receive
188
mouse release events for the system tray entry.
190
The default implementations opens the context menu when the entry
191
has been clicked with the right mouse button.
193
\sa setPopup(), mousePressEvent(), mouseDoubleClickEvent(),
194
mouseMoveEvent(), QMouseEvent
196
void TrayIcon::mouseReleaseEvent( QMouseEvent *e )
198
switch ( e->button() ) {
201
// Necessary to make keyboard focus
202
// and menu closing work on Windows.
204
pop->setActiveWindow();
206
pop->popup( e->globalPos() );
208
pop->setActiveWindow();
215
emit clicked( e->globalPos(), e->button() );
224
This event handler can be reimplemented in a subclass to receive
225
mouse double click events for the system tray entry.
227
Note that the system tray entry gets a mousePressEvent() and a
228
mouseReleaseEvent() before the mouseDoubleClickEvent().
230
\sa mousePressEvent(), mouseReleaseEvent(),
231
mouseMoveEvent(), QMouseEvent
233
void TrayIcon::mouseDoubleClickEvent( QMouseEvent *e )
235
if ( e->button() == LeftButton )
236
emit doubleClicked( e->globalPos() );
241
\fn void TrayIcon::clicked( const QPoint &p )
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
249
\fn void TrayIcon::doubleClicked( const QPoint &p )
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
256
void TrayIcon::gotCloseEvent()