Qt 4.8
qsystemtrayicon_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QSYSTEMTRAYICON_P_H
43 #define QSYSTEMTRAYICON_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists for the convenience
50 // of a number of Qt sources files. This header file may change from
51 // version to version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "qsystemtrayicon.h"
57 #include "private/qobject_p.h"
58 
59 #ifndef QT_NO_SYSTEMTRAYICON
60 
61 #include "QtGui/qmenu.h"
62 #include "QtGui/qpixmap.h"
63 #include "QtCore/qstring.h"
64 #include "QtCore/qpointer.h"
65 
67 
68 class QSystemTrayIconSys;
69 class QToolButton;
70 class QLabel;
71 
73 {
75 
76 public:
77  QSystemTrayIconPrivate() : sys(0), visible(false) { }
78 
79  void install_sys();
80  void remove_sys();
81  void updateIcon_sys();
82  void updateToolTip_sys();
83  void updateMenu_sys();
84  QRect geometry_sys() const;
85  void showMessage_sys(const QString &msg, const QString &title, QSystemTrayIcon::MessageIcon icon, int secs);
86 
87  static bool isSystemTrayAvailable_sys();
88  static bool supportsMessages_sys();
89 
94  bool visible;
95 };
96 
97 class QBalloonTip : public QWidget
98 {
99  Q_OBJECT
100 public:
101  static void showBalloon(QSystemTrayIcon::MessageIcon icon, const QString& title,
102  const QString& msg, QSystemTrayIcon *trayIcon,
103  const QPoint& pos, int timeout, bool showArrow = true);
104  static void hideBalloon();
105  static bool isBalloonVisible();
106 
107 private:
109  const QString& msg, QSystemTrayIcon *trayIcon);
110  ~QBalloonTip();
111  void balloon(const QPoint&, int, bool);
112 
113 protected:
114  void paintEvent(QPaintEvent *);
115  void resizeEvent(QResizeEvent *);
116  void mousePressEvent(QMouseEvent *e);
117  void timerEvent(QTimerEvent *e);
118 
119 private:
122  int timerId;
123 };
124 
125 #if defined(Q_WS_X11)
127 #include <QtCore/qcoreapplication.h>
128 #include <X11/Xlib.h>
129 #include <X11/Xatom.h>
130 #include <X11/Xutil.h>
132 
133 class QSystemTrayIconSys : public QWidget
134 {
136 
137 public:
140  enum {
141  SYSTEM_TRAY_REQUEST_DOCK = 0,
142  SYSTEM_TRAY_BEGIN_MESSAGE = 1,
143  SYSTEM_TRAY_CANCEL_MESSAGE =2
144  };
145 
146  void addToTray();
147  void updateIcon();
148  XVisualInfo* getSysTrayVisualInfo();
149 
150  // QObject::event is public but QWidget's ::event() re-implementation
151  // is protected ;(
152  inline bool deliverToolTipEvent(QEvent *e)
153  { return QWidget::event(e); }
154 
158  static bool sysTrayTracker(void *message, long *result);
159  static Window locateSystemTray();
161  static XVisualInfo sysTrayVisual;
162 
163 protected:
164  void paintEvent(QPaintEvent *pe);
165  void resizeEvent(QResizeEvent *re);
166  bool x11Event(XEvent *event);
167  void mousePressEvent(QMouseEvent *event);
168  void mouseDoubleClickEvent(QMouseEvent *event);
169 #ifndef QT_NO_WHEELEVENT
170  void wheelEvent(QWheelEvent *event);
171 #endif
172  bool event(QEvent *e);
173 
174 private:
177  Colormap colormap;
178 };
179 #endif // Q_WS_X11
180 
182 
183 #endif // QT_NO_SYSTEMTRAYICON
184 
185 #endif // QSYSTEMTRAYICON_P_H
186 
void showMessage_sys(const QString &msg, const QString &title, QSystemTrayIcon::MessageIcon icon, int secs)
QPointer< QMenu > menu
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
The QWheelEvent class contains parameters that describe a wheel event.
Definition: qevent.h:139
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
bool deliverToolTipEvent(QEvent *e)
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
QSystemTrayIcon * q
static Window sysTrayWindow
The QString class provides a Unicode character string.
Definition: qstring.h:83
union _XEvent XEvent
Definition: qwindowdefs.h:116
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool isSystemTrayAvailable_sys()
static QList< QSystemTrayIconSys * > trayIcons
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
QSystemTrayIconSys * sys
QSystemTrayIcon * trayIcon
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
bool(* EventFilter)(void *message, long *result)
A function with the following signature that can be used as an event filter:
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QLabel widget provides a text or image display.
Definition: qlabel.h:55
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
static Atom sysTraySelection
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition: qtoolbutton.h:59
MessageIcon
This enum describes the icon that is shown when a balloon message is displayed.
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
static QCoreApplication::EventFilter oldEventFilter
The QSystemTrayIcon class provides an icon for an application in the system tray. ...
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static XVisualInfo sysTrayVisual
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60