1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
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 |
|
---|
66 | QT_BEGIN_NAMESPACE
|
---|
67 |
|
---|
68 | class QSystemTrayIconSys;
|
---|
69 | class QToolButton;
|
---|
70 | class QLabel;
|
---|
71 |
|
---|
72 | class QSystemTrayIconPrivate : public QObjectPrivate
|
---|
73 | {
|
---|
74 | Q_DECLARE_PUBLIC(QSystemTrayIcon)
|
---|
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 | static bool isSystemTrayAvailable_sys();
|
---|
87 |
|
---|
88 | QPointer<QMenu> menu;
|
---|
89 | QIcon icon;
|
---|
90 | QString toolTip;
|
---|
91 | QSystemTrayIconSys *sys;
|
---|
92 | bool visible;
|
---|
93 | };
|
---|
94 |
|
---|
95 | class QBalloonTip : public QWidget
|
---|
96 | {
|
---|
97 | public:
|
---|
98 | static void showBalloon(QSystemTrayIcon::MessageIcon icon, const QString& title,
|
---|
99 | const QString& msg, QSystemTrayIcon *trayIcon,
|
---|
100 | const QPoint& pos, int timeout, bool showArrow = true);
|
---|
101 | static void hideBalloon();
|
---|
102 | static bool isBalloonVisible();
|
---|
103 |
|
---|
104 | private:
|
---|
105 | QBalloonTip(QSystemTrayIcon::MessageIcon icon, const QString& title,
|
---|
106 | const QString& msg, QSystemTrayIcon *trayIcon);
|
---|
107 | ~QBalloonTip();
|
---|
108 | void balloon(const QPoint&, int, bool);
|
---|
109 |
|
---|
110 | protected:
|
---|
111 | void paintEvent(QPaintEvent *);
|
---|
112 | void resizeEvent(QResizeEvent *);
|
---|
113 | void mousePressEvent(QMouseEvent *e);
|
---|
114 | void timerEvent(QTimerEvent *e);
|
---|
115 |
|
---|
116 | private:
|
---|
117 | QSystemTrayIcon *trayIcon;
|
---|
118 | QPixmap pixmap;
|
---|
119 | int timerId;
|
---|
120 | };
|
---|
121 |
|
---|
122 | #if defined(Q_WS_X11)
|
---|
123 | QT_BEGIN_INCLUDE_NAMESPACE
|
---|
124 | #include <QtCore/qcoreapplication.h>
|
---|
125 | #include <X11/Xlib.h>
|
---|
126 | #include <X11/Xatom.h>
|
---|
127 | #include <X11/Xutil.h>
|
---|
128 | QT_END_INCLUDE_NAMESPACE
|
---|
129 |
|
---|
130 | class QSystemTrayIconSys : public QWidget
|
---|
131 | {
|
---|
132 | friend class QSystemTrayIconPrivate;
|
---|
133 |
|
---|
134 | public:
|
---|
135 | QSystemTrayIconSys(QSystemTrayIcon *q);
|
---|
136 | ~QSystemTrayIconSys();
|
---|
137 | enum {
|
---|
138 | SYSTEM_TRAY_REQUEST_DOCK = 0,
|
---|
139 | SYSTEM_TRAY_BEGIN_MESSAGE = 1,
|
---|
140 | SYSTEM_TRAY_CANCEL_MESSAGE =2
|
---|
141 | };
|
---|
142 |
|
---|
143 | void addToTray();
|
---|
144 | void updateIcon();
|
---|
145 | XVisualInfo* getSysTrayVisualInfo();
|
---|
146 |
|
---|
147 | // QObject::event is public but QWidget's ::event() re-implementation
|
---|
148 | // is protected ;(
|
---|
149 | inline bool deliverToolTipEvent(QEvent *e)
|
---|
150 | { return QWidget::event(e); }
|
---|
151 |
|
---|
152 | static Window sysTrayWindow;
|
---|
153 | static QList<QSystemTrayIconSys *> trayIcons;
|
---|
154 | static QCoreApplication::EventFilter oldEventFilter;
|
---|
155 | static bool sysTrayTracker(void *message, long *result);
|
---|
156 | static Window locateSystemTray();
|
---|
157 | static Atom sysTraySelection;
|
---|
158 | static XVisualInfo sysTrayVisual;
|
---|
159 |
|
---|
160 | protected:
|
---|
161 | void paintEvent(QPaintEvent *pe);
|
---|
162 | void resizeEvent(QResizeEvent *re);
|
---|
163 | bool x11Event(XEvent *event);
|
---|
164 | void mousePressEvent(QMouseEvent *event);
|
---|
165 | void mouseDoubleClickEvent(QMouseEvent *event);
|
---|
166 | void wheelEvent(QWheelEvent *event);
|
---|
167 | bool event(QEvent *e);
|
---|
168 |
|
---|
169 | private:
|
---|
170 | QPixmap background;
|
---|
171 | QSystemTrayIcon *q;
|
---|
172 | Colormap colormap;
|
---|
173 | };
|
---|
174 | #endif // Q_WS_X11
|
---|
175 |
|
---|
176 | QT_END_NAMESPACE
|
---|
177 |
|
---|
178 | #endif // QT_NO_SYSTEMTRAYICON
|
---|
179 |
|
---|
180 | #endif // QSYSTEMTRAYICON_P_H
|
---|
181 |
|
---|