|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
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 |
|
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 |