qsystemtrayicon_x11.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qsystemtrayicon_x11.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5static inline unsigned long locateSystemTray()-
6{-
7 return (unsigned long)QGuiApplication::platformNativeInterface()->nativeResourceForScreen(([]() -> QByteArray { enum { Size = sizeof("traywindow") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "traywindow" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()), QGuiApplication::primaryScreen());-
8}-
9-
10-
11-
12class QSystemTrayIconSys : public QWidget-
13{-
14 public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }-
15#pragma GCC diagnostic push-
16 static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);-
17#pragma GCC diagnostic pop-
18 struct QPrivateSignal {};-
19public:-
20 explicit QSystemTrayIconSys(QSystemTrayIcon *q);-
21-
22 inline void updateIcon() { update(); }-
23 inline QSystemTrayIcon *systemTrayIcon() const { return q; }-
24-
25 QRect globalGeometry() const;-
26-
27protected:-
28 virtual void mousePressEvent(QMouseEvent *ev) override;-
29 virtual void mouseDoubleClickEvent(QMouseEvent *ev) override;-
30 virtual bool event(QEvent *) override;-
31 virtual void paintEvent(QPaintEvent *) override;-
32 virtual void resizeEvent(QResizeEvent *) override;-
33 virtual void moveEvent(QMoveEvent *) override;-
34-
35private :-
36 void systemTrayWindowChanged(QScreen *screen);-
37-
38private:-
39 bool addToTray();-
40-
41 QSystemTrayIcon *q;-
42 QPixmap background;-
43};-
44-
45QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *qIn)-
46 : QWidget(0, Qt::Window | Qt::FramelessWindowHint | Qt::BypassWindowManagerHint)-
47 , q(qIn)-
48{-
49 setObjectName(([]() -> QString { enum { Size = sizeof(u"" "QSystemTrayIconSys")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "QSystemTrayIconSys" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
50 setToolTip(q->toolTip());-
51 setAttribute(Qt::WA_AlwaysShowToolTips, true);-
52 setAttribute(Qt::WA_QuitOnClose, false);-
53 const QSize size(22, 22);-
54 setGeometry(QRect(QPoint(0, 0), size));-
55 setMinimumSize(size);-
56 bool hasAlphaChannel = QXcbIntegrationFunctions::xEmbedSystemTrayVisualHasAlphaChannel();-
57 setAttribute(Qt::WA_TranslucentBackground, hasAlphaChannel);-
58 if (!hasAlphaChannel) {-
59 createWinId();-
60 QXcbWindowFunctions::setParentRelativeBackPixmap(windowHandle());-
61-
62-
63-
64-
65-
66-
67-
68 }-
69-
70 addToTray();-
71}-
72-
73bool QSystemTrayIconSys::addToTray()-
74{-
75 if (!locateSystemTray())-
76 return false;-
77-
78 createWinId();-
79 setMouseTracking(true);-
80-
81 if (!QXcbWindowFunctions::requestSystemTrayWindowDock(windowHandle()))-
82 return false;-
83-
84 if (!background.isNull())-
85 background = QPixmap();-
86 show();-
87 return true;-
88}-
89-
90void QSystemTrayIconSys::systemTrayWindowChanged(QScreen *)-
91{-
92 if (locateSystemTray()) {-
93 addToTray();-
94 } else {-
95 QBalloonTip::hideBalloon();-
96 hide();-
97 destroy();-
98 }-
99}-
100-
101QRect QSystemTrayIconSys::globalGeometry() const-
102{-
103 return QXcbWindowFunctions::systemTrayWindowGlobalGeometry(windowHandle());-
104}-
105-
106void QSystemTrayIconSys::mousePressEvent(QMouseEvent *ev)-
107{-
108 QPoint globalPos = ev->globalPos();-
109-
110 if (ev->button() == Qt::RightButton
ev->button() =...t::RightButtonDescription
TRUEnever evaluated
FALSEnever evaluated
&& q->contextMenu()
q->contextMenu()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
111 q->contextMenu()->popup(globalPos);
never executed: q->contextMenu()->popup(globalPos);
0
112-
113-
114-
115-
116 if (QBalloonTip::isBalloonVisible()
QBalloonTip::i...lloonVisible()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
117 q->messageClicked();-
118 QBalloonTip::hideBalloon();-
119 }
never executed: end of block
0
120-
121 if (ev->button() == Qt::LeftButton
ev->button() == Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
122 q->activated(QSystemTrayIcon::Trigger);
never executed: q->activated(QSystemTrayIcon::Trigger);
0
123 else if (ev->button() == Qt::RightButton
ev->button() =...t::RightButtonDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
124 q->activated(QSystemTrayIcon::Context);
never executed: q->activated(QSystemTrayIcon::Context);
0
125 else if (ev->button() == Qt::MidButton
ev->button() == Qt::MidButtonDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
126 q->activated(QSystemTrayIcon::MiddleClick);
never executed: q->activated(QSystemTrayIcon::MiddleClick);
0
127}
never executed: end of block
0
128-
129void QSystemTrayIconSys::mouseDoubleClickEvent(QMouseEvent *ev)-
130{-
131 if (ev->button() == Qt::LeftButton)-
132 q->activated(QSystemTrayIcon::DoubleClick);-
133}-
134-
135bool QSystemTrayIconSys::event(QEvent *e)-
136{-
137 switch (e->type()) {-
138 case QEvent::ToolTip:-
139 QApplication::sendEvent(q, e);-
140 break;-
141-
142 case QEvent::Wheel:-
143 return QApplication::sendEvent(q, e);-
144-
145 default:-
146 break;-
147 }-
148 return QWidget::event(e);-
149}-
150-
151void QSystemTrayIconSys::paintEvent(QPaintEvent *)-
152{-
153 const QRect rect(QPoint(0, 0), geometry().size());-
154 QPainter painter(this);-
155-
156-
157-
158 if (testAttribute(Qt::WA_TranslucentBackground)) {-
159 painter.setCompositionMode(QPainter::CompositionMode_Source);-
160 painter.fillRect(rect, Qt::transparent);-
161 } else {-
162-
163-
164 if (background.isNull()) {-
165 background = QGuiApplication::primaryScreen()->grabWindow(winId(),-
166 0, 0, rect.size().width(), rect.size().height());-
167 }-
168-
169 painter.drawPixmap(QPoint(0, 0), background);-
170 }-
171 painter.setCompositionMode(QPainter::CompositionMode_SourceOver);-
172 q->icon().paint(&painter, rect);-
173}-
174-
175void QSystemTrayIconSys::moveEvent(QMoveEvent *event)-
176{-
177 QWidget::moveEvent(event);-
178 if (QBalloonTip::isBalloonVisible())-
179 QBalloonTip::updateBalloonPosition(globalGeometry().center());-
180}-
181-
182void QSystemTrayIconSys::resizeEvent(QResizeEvent *event)-
183{-
184 update();-
185 QWidget::resizeEvent(event);-
186 if (QBalloonTip::isBalloonVisible())-
187 QBalloonTip::updateBalloonPosition(globalGeometry().center());-
188}-
189-
190-
191QSystemTrayIconPrivate::QSystemTrayIconPrivate()-
192 : sys(0),-
193 qpa_sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon()),-
194 visible(false)-
195{-
196}-
197-
198QSystemTrayIconPrivate::~QSystemTrayIconPrivate()-
199{-
200 delete qpa_sys;-
201}-
202-
203void QSystemTrayIconPrivate::install_sys()-
204{-
205 if (qpa_sys) {-
206 install_sys_qpa();-
207 return;-
208 }-
209 QSystemTrayIcon * const q = q_func();-
210 if (!sys && locateSystemTray()) {-
211 sys = new QSystemTrayIconSys(q);-
212 QObject::connect(QGuiApplication::platformNativeInterface(), qFlagLocation("2""systemTrayWindowChanged(QScreen*)" "\0" __FILE__ ":" "271""279"),-
213 sys, qFlagLocation("1""systemTrayWindowChanged(QScreen*)" "\0" __FILE__ ":" "272""280"));-
214 }-
215}-
216-
217QRect QSystemTrayIconPrivate::geometry_sys() const-
218{-
219 if (qpa_sys)-
220 return geometry_sys_qpa();-
221 if (!sys)-
222 return QRect();-
223 return sys->globalGeometry();-
224}-
225-
226void QSystemTrayIconPrivate::remove_sys()-
227{-
228 if (qpa_sys) {-
229 remove_sys_qpa();-
230 return;-
231 }-
232 if (!sys)-
233 return;-
234 QBalloonTip::hideBalloon();-
235 sys->hide();-
236 delete sys;-
237 sys = 0;-
238}-
239-
240void QSystemTrayIconPrivate::updateIcon_sys()-
241{-
242 if (qpa_sys) {-
243 updateIcon_sys_qpa();-
244 return;-
245 }-
246 if (sys)-
247 sys->updateIcon();-
248}-
249-
250void QSystemTrayIconPrivate::updateMenu_sys()-
251{-
252 if (qpa_sys)-
253 updateMenu_sys_qpa();-
254}-
255-
256void QSystemTrayIconPrivate::updateToolTip_sys()-
257{-
258 if (qpa_sys) {-
259 updateToolTip_sys_qpa();-
260 return;-
261 }-
262 if (!sys)-
263 return;-
264-
265 sys->setToolTip(toolTip);-
266-
267}-
268-
269bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys()-
270{-
271 QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon());-
272 if (sys && sys->isSystemTrayAvailable())-
273 return true;-
274-
275-
276 const QString platform = QGuiApplication::platformName();-
277 if (platform.compare(QLatin1String("xcb"), Qt::CaseInsensitive) == 0)-
278 return locateSystemTray();-
279 return false;-
280}-
281-
282bool QSystemTrayIconPrivate::supportsMessages_sys()-
283{-
284 QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon());-
285 if (sys)-
286 return sys->supportsMessages();-
287-
288-
289 return true;-
290}-
291-
292void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message,-
293 QSystemTrayIcon::MessageIcon icon, int msecs)-
294{-
295 if (qpa_sys) {-
296 showMessage_sys_qpa(title, message, icon, msecs);-
297 return;-
298 }-
299 if (!sys)-
300 return;-
301 QBalloonTip::showBalloon(icon, title, message, sys->systemTrayIcon(),-
302 sys->globalGeometry().center(),-
303 msecs);-
304}-
305-
306-
307-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9