qsystemtrayicon.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qsystemtrayicon.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qsystemtrayicon.h"-
35#include "qsystemtrayicon_p.h"-
36-
37#ifndef QT_NO_SYSTEMTRAYICON-
38-
39#include "qmenu.h"-
40#include "qlist.h"-
41#include "qevent.h"-
42#include "qpoint.h"-
43#include "qlabel.h"-
44#include "qpushbutton.h"-
45#include "qpainterpath.h"-
46#include "qpainter.h"-
47#include "qstyle.h"-
48#include "qgridlayout.h"-
49#include "qapplication.h"-
50#include "qdesktopwidget.h"-
51#include "qbitmap.h"-
52#include "private/qlabel_p.h"-
53-
54QT_BEGIN_NAMESPACE-
55-
56/*!-
57 \class QSystemTrayIcon-
58 \brief The QSystemTrayIcon class provides an icon for an application in the system tray.-
59 \since 4.2-
60 \ingroup desktop-
61 \inmodule QtWidgets-
62-
63 Modern operating systems usually provide a special area on the desktop,-
64 called the \e{system tray} or \e{notification area}, where long-running-
65 applications can display icons and short messages.-
66-
67 \image system-tray.png The system tray on Windows XP.-
68-
69 The QSystemTrayIcon class can be used on the following platforms:-
70-
71 \list-
72 \li All supported versions of Windows.-
73 \li All window managers and independent tray implementations for X11 that implement the-
74 \l{http://standards.freedesktop.org/systemtray-spec/systemtray-spec-0.2.html freedesktop.org}-
75 XEmbed system tray specification.-
76 \li All X11 desktop environments that implement the D-Bus-
77 \l{http://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem}-
78 specification, including recent versions of KDE and Unity.-
79 \li All supported versions of \macos. Note that the Growl-
80 notification system must be installed for-
81 QSystemTrayIcon::showMessage() to display messages on \macos prior to 10.8 (Mountain Lion).-
82 \endlist-
83-
84 To check whether a system tray is present on the user's desktop,-
85 call the QSystemTrayIcon::isSystemTrayAvailable() static function.-
86-
87 To add a system tray entry, create a QSystemTrayIcon object, call setContextMenu()-
88 to provide a context menu for the icon, and call show() to make it visible in the-
89 system tray. Status notification messages ("balloon messages") can be displayed at-
90 any time using showMessage().-
91-
92 If the system tray is unavailable when a system tray icon is constructed, but-
93 becomes available later, QSystemTrayIcon will automatically add an entry for the-
94 application in the system tray if the icon is \l visible.-
95-
96 The activated() signal is emitted when the user activates the icon.-
97-
98 Only on X11, when a tooltip is requested, the QSystemTrayIcon receives a QHelpEvent-
99 of type QEvent::ToolTip. Additionally, the QSystemTrayIcon receives wheel events of-
100 type QEvent::Wheel. These are not supported on any other platform.-
101-
102 \sa QDesktopServices, QDesktopWidget, {Desktop Integration}, {System Tray Icon Example}-
103*/-
104-
105/*!-
106 \enum QSystemTrayIcon::MessageIcon-
107-
108 This enum describes the icon that is shown when a balloon message is displayed.-
109-
110 \value NoIcon No icon is shown.-
111 \value Information An information icon is shown.-
112 \value Warning A standard warning icon is shown.-
113 \value Critical A critical warning icon is shown.-
114-
115 \sa QMessageBox-
116*/-
117-
118/*!-
119 Constructs a QSystemTrayIcon object with the given \a parent.-
120-
121 The icon is initially invisible.-
122-
123 \sa visible-
124*/-
125QSystemTrayIcon::QSystemTrayIcon(QObject *parent)-
126: QObject(*new QSystemTrayIconPrivate(), parent)-
127{-
128}
never executed: end of block
0
129-
130/*!-
131 Constructs a QSystemTrayIcon object with the given \a icon and \a parent.-
132-
133 The icon is initially invisible.-
134-
135 \sa visible-
136*/-
137QSystemTrayIcon::QSystemTrayIcon(const QIcon &icon, QObject *parent)-
138: QObject(*new QSystemTrayIconPrivate(), parent)-
139{-
140 setIcon(icon);-
141}
never executed: end of block
0
142-
143/*!-
144 Removes the icon from the system tray and frees all allocated resources.-
145*/-
146QSystemTrayIcon::~QSystemTrayIcon()-
147{-
148 Q_D(QSystemTrayIcon);-
149 d->remove_sys();-
150}
never executed: end of block
0
151-
152#ifndef QT_NO_MENU-
153-
154/*!-
155 Sets the specified \a menu to be the context menu for the system tray icon.-
156-
157 The menu will pop up when the user requests the context menu for the system-
158 tray icon by clicking the mouse button.-
159-
160 On \macos, this is currenly converted to a NSMenu, so the-
161 aboutToHide() signal is not emitted.-
162-
163 \note The system tray icon does not take ownership of the menu. You must-
164 ensure that it is deleted at the appropriate time by, for example, creating-
165 the menu with a suitable parent object.-
166*/-
167void QSystemTrayIcon::setContextMenu(QMenu *menu)-
168{-
169 Q_D(QSystemTrayIcon);-
170 d->menu = menu;-
171 d->updateMenu_sys();-
172}
never executed: end of block
0
173-
174/*!-
175 Returns the current context menu for the system tray entry.-
176*/-
177QMenu* QSystemTrayIcon::contextMenu() const-
178{-
179 Q_D(const QSystemTrayIcon);-
180 return d->menu;
never executed: return d->menu;
0
181}-
182-
183#endif // QT_NO_MENU-
184-
185/*!-
186 \property QSystemTrayIcon::icon-
187 \brief the system tray icon-
188-
189 On Windows, the system tray icon size is 16x16; on X11, the preferred size is-
190 22x22. The icon will be scaled to the appropriate size as necessary.-
191*/-
192void QSystemTrayIcon::setIcon(const QIcon &icon)-
193{-
194 Q_D(QSystemTrayIcon);-
195 d->icon = icon;-
196 d->updateIcon_sys();-
197}
never executed: end of block
0
198-
199QIcon QSystemTrayIcon::icon() const-
200{-
201 Q_D(const QSystemTrayIcon);-
202 return d->icon;
never executed: return d->icon;
0
203}-
204-
205/*!-
206 \property QSystemTrayIcon::toolTip-
207 \brief the tooltip for the system tray entry-
208-
209 On some systems, the tooltip's length is limited. The tooltip will be truncated-
210 if necessary.-
211*/-
212void QSystemTrayIcon::setToolTip(const QString &tooltip)-
213{-
214 Q_D(QSystemTrayIcon);-
215 d->toolTip = tooltip;-
216 d->updateToolTip_sys();-
217}
never executed: end of block
0
218-
219QString QSystemTrayIcon::toolTip() const-
220{-
221 Q_D(const QSystemTrayIcon);-
222 return d->toolTip;
never executed: return d->toolTip;
0
223}-
224-
225/*!-
226 \fn void QSystemTrayIcon::show()-
227-
228 Shows the icon in the system tray.-
229-
230 \sa hide(), visible-
231*/-
232-
233/*!-
234 \fn void QSystemTrayIcon::hide()-
235-
236 Hides the system tray entry.-
237-
238 \sa show(), visible-
239*/-
240-
241/*!-
242 \since 4.3-
243 Returns the geometry of the system tray icon in screen coordinates.-
244-
245 \sa visible-
246*/-
247QRect QSystemTrayIcon::geometry() const-
248{-
249 Q_D(const QSystemTrayIcon);-
250 if (!d->visible)
!d->visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
251 return QRect();
never executed: return QRect();
0
252 return d->geometry_sys();
never executed: return d->geometry_sys();
0
253}-
254-
255/*!-
256 \property QSystemTrayIcon::visible-
257 \brief whether the system tray entry is visible-
258-
259 Setting this property to true or calling show() makes the system tray icon-
260 visible; setting this property to false or calling hide() hides it.-
261*/-
262void QSystemTrayIcon::setVisible(bool visible)-
263{-
264 Q_D(QSystemTrayIcon);-
265 if (visible == d->visible)
visible == d->visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
266 return;
never executed: return;
0
267 if (d->icon.isNull() && visible)
d->icon.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
268 qWarning("QSystemTrayIcon::setVisible: No Icon set");
never executed: QMessageLogger(__FILE__, 268, __PRETTY_FUNCTION__).warning("QSystemTrayIcon::setVisible: No Icon set");
0
269 d->visible = visible;-
270 if (d->visible)
d->visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
271 d->install_sys();
never executed: d->install_sys();
0
272 else-
273 d->remove_sys();
never executed: d->remove_sys();
0
274}-
275-
276bool QSystemTrayIcon::isVisible() const-
277{-
278 Q_D(const QSystemTrayIcon);-
279 return d->visible;
never executed: return d->visible;
0
280}-
281-
282/*!-
283 \reimp-
284*/-
285bool QSystemTrayIcon::event(QEvent *e)-
286{-
287 return QObject::event(e);
never executed: return QObject::event(e);
0
288}-
289-
290/*!-
291 \enum QSystemTrayIcon::ActivationReason-
292-
293 This enum describes the reason the system tray was activated.-
294-
295 \value Unknown Unknown reason-
296 \value Context The context menu for the system tray entry was requested-
297 \value DoubleClick The system tray entry was double clicked-
298 \value Trigger The system tray entry was clicked-
299 \value MiddleClick The system tray entry was clicked with the middle mouse button-
300-
301 \sa activated()-
302*/-
303-
304/*!-
305 \fn void QSystemTrayIcon::activated(QSystemTrayIcon::ActivationReason reason)-
306-
307 This signal is emitted when the user activates the system tray icon. \a reason-
308 specifies the reason for activation. QSystemTrayIcon::ActivationReason enumerates-
309 the various reasons.-
310-
311 \sa QSystemTrayIcon::ActivationReason-
312*/-
313-
314/*!-
315 \fn void QSystemTrayIcon::messageClicked()-
316-
317 This signal is emitted when the message displayed using showMessage()-
318 was clicked by the user.-
319-
320 Currently this signal is not sent on \macos.-
321-
322 \note We follow Microsoft Windows XP/Vista behavior, so the-
323 signal is also emitted when the user clicks on a tray icon with-
324 a balloon message displayed.-
325-
326 \sa activated()-
327*/-
328-
329-
330/*!-
331 Returns \c true if the system tray is available; otherwise returns \c false.-
332-
333 If the system tray is currently unavailable but becomes available later,-
334 QSystemTrayIcon will automatically add an entry in the system tray if it-
335 is \l visible.-
336*/-
337-
338bool QSystemTrayIcon::isSystemTrayAvailable()-
339{-
340 return QSystemTrayIconPrivate::isSystemTrayAvailable_sys();
never executed: return QSystemTrayIconPrivate::isSystemTrayAvailable_sys();
0
341}-
342-
343/*!-
344 Returns \c true if the system tray supports balloon messages; otherwise returns \c false.-
345-
346 \sa showMessage()-
347*/-
348bool QSystemTrayIcon::supportsMessages()-
349{-
350 return QSystemTrayIconPrivate::supportsMessages_sys();
never executed: return QSystemTrayIconPrivate::supportsMessages_sys();
0
351}-
352-
353/*!-
354 \fn void QSystemTrayIcon::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint)-
355 \since 4.3-
356-
357 Shows a balloon message for the entry with the given \a title, \a message and-
358 \a icon for the time specified in \a millisecondsTimeoutHint. \a title and \a message-
359 must be plain text strings.-
360-
361 Message can be clicked by the user; the messageClicked() signal will emitted when-
362 this occurs.-
363-
364 Note that display of messages are dependent on the system configuration and user-
365 preferences, and that messages may not appear at all. Hence, it should not be-
366 relied upon as the sole means for providing critical information.-
367-
368 On Windows, the \a millisecondsTimeoutHint is usually ignored by the system-
369 when the application has focus.-
370-
371 On \macos, the Growl notification system must be installed for this function to-
372 display messages.-
373-
374 Has been turned into a slot in Qt 5.2.-
375-
376 \sa show(), supportsMessages()-
377 */-
378void QSystemTrayIcon::showMessage(const QString& title, const QString& msg,-
379 QSystemTrayIcon::MessageIcon icon, int msecs)-
380{-
381 Q_D(QSystemTrayIcon);-
382 if (d->visible)
d->visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
383 d->showMessage_sys(title, msg, icon, msecs);
never executed: d->showMessage_sys(title, msg, icon, msecs);
0
384}
never executed: end of block
0
385-
386void QSystemTrayIconPrivate::_q_emitActivated(QPlatformSystemTrayIcon::ActivationReason reason)-
387{-
388 Q_Q(QSystemTrayIcon);-
389 emit q->activated(static_cast<QSystemTrayIcon::ActivationReason>(reason));-
390}
never executed: end of block
0
391-
392//////////////////////////////////////////////////////////////////////-
393static QBalloonTip *theSolitaryBalloonTip = 0;-
394-
395void QBalloonTip::showBalloon(QSystemTrayIcon::MessageIcon icon, const QString& title,-
396 const QString& message, QSystemTrayIcon *trayIcon,-
397 const QPoint& pos, int timeout, bool showArrow)-
398{-
399 hideBalloon();-
400 if (message.isEmpty() && title.isEmpty())
message.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
title.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
401 return;
never executed: return;
0
402-
403 theSolitaryBalloonTip = new QBalloonTip(icon, title, message, trayIcon);-
404 if (timeout < 0)
timeout < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
405 timeout = 10000; //10 s default
never executed: timeout = 10000;
0
406 theSolitaryBalloonTip->balloon(pos, timeout, showArrow);-
407}
never executed: end of block
0
408-
409void QBalloonTip::hideBalloon()-
410{-
411 if (!theSolitaryBalloonTip)
!theSolitaryBalloonTipDescription
TRUEnever evaluated
FALSEnever evaluated
0
412 return;
never executed: return;
0
413 theSolitaryBalloonTip->hide();-
414 delete theSolitaryBalloonTip;-
415 theSolitaryBalloonTip = 0;-
416}
never executed: end of block
0
417-
418void QBalloonTip::updateBalloonPosition(const QPoint& pos)-
419{-
420 if (!theSolitaryBalloonTip)
!theSolitaryBalloonTipDescription
TRUEnever evaluated
FALSEnever evaluated
0
421 return;
never executed: return;
0
422 theSolitaryBalloonTip->hide();-
423 theSolitaryBalloonTip->balloon(pos, 0, theSolitaryBalloonTip->showArrow);-
424}
never executed: end of block
0
425-
426bool QBalloonTip::isBalloonVisible()-
427{-
428 return theSolitaryBalloonTip;
never executed: return theSolitaryBalloonTip;
0
429}-
430-
431QBalloonTip::QBalloonTip(QSystemTrayIcon::MessageIcon icon, const QString& title,-
432 const QString& message, QSystemTrayIcon *ti)-
433 : QWidget(0, Qt::ToolTip),-
434 trayIcon(ti),-
435 timerId(-1),-
436 showArrow(true)-
437{-
438 setAttribute(Qt::WA_DeleteOnClose);-
439 QObject::connect(ti, SIGNAL(destroyed()), this, SLOT(close()));-
440-
441 QLabel *titleLabel = new QLabel;-
442 titleLabel->installEventFilter(this);-
443 titleLabel->setText(title);-
444 QFont f = titleLabel->font();-
445 f.setBold(true);-
446#ifdef Q_OS_WINCE-
447 f.setPointSize(f.pointSize() - 2);-
448#endif-
449 titleLabel->setFont(f);-
450 titleLabel->setTextFormat(Qt::PlainText); // to maintain compat with windows-
451-
452#ifdef Q_OS_WINCE-
453 const int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize);-
454 const int closeButtonSize = style()->pixelMetric(QStyle::PM_SmallIconSize) - 2;-
455#else-
456 const int iconSize = 18;-
457 const int closeButtonSize = 15;-
458#endif-
459-
460 QPushButton *closeButton = new QPushButton;-
461 closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));-
462 closeButton->setIconSize(QSize(closeButtonSize, closeButtonSize));-
463 closeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);-
464 closeButton->setFixedSize(closeButtonSize, closeButtonSize);-
465 QObject::connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));-
466-
467 QLabel *msgLabel = new QLabel;-
468#ifdef Q_OS_WINCE-
469 f.setBold(false);-
470 msgLabel->setFont(f);-
471#endif-
472 msgLabel->installEventFilter(this);-
473 msgLabel->setText(message);-
474 msgLabel->setTextFormat(Qt::PlainText);-
475 msgLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);-
476-
477 // smart size for the message label-
478#ifdef Q_OS_WINCE-
479 int limit = QApplication::desktop()->availableGeometry(msgLabel).size().width() / 2;-
480#else-
481 int limit = QApplication::desktop()->availableGeometry(msgLabel).size().width() / 3;-
482#endif-
483 if (msgLabel->sizeHint().width() > limit) {
msgLabel->size...idth() > limitDescription
TRUEnever evaluated
FALSEnever evaluated
0
484 msgLabel->setWordWrap(true);-
485 if (msgLabel->sizeHint().width() > limit) {
msgLabel->size...idth() > limitDescription
TRUEnever evaluated
FALSEnever evaluated
0
486 msgLabel->d_func()->ensureTextControl();-
487 if (QWidgetTextControl *control = msgLabel->d_func()->control) {
QWidgetTextCon...unc()->controlDescription
TRUEnever evaluated
FALSEnever evaluated
0
488 QTextOption opt = control->document()->defaultTextOption();-
489 opt.setWrapMode(QTextOption::WrapAnywhere);-
490 control->document()->setDefaultTextOption(opt);-
491 }
never executed: end of block
0
492 }
never executed: end of block
0
493#ifdef Q_OS_WINCE-
494 // Make sure that the text isn't wrapped "somewhere" in the balloon widget-
495 // in the case that we have a long title label.-
496 setMaximumWidth(limit);-
497#else-
498 // Here we allow the text being much smaller than the balloon widget-
499 // to emulate the weird standard windows behavior.-
500 msgLabel->setFixedSize(limit, msgLabel->heightForWidth(limit));-
501#endif-
502 }
never executed: end of block
0
503-
504 QIcon si;-
505 switch (icon) {-
506 case QSystemTrayIcon::Warning:
never executed: case QSystemTrayIcon::Warning:
0
507 si = style()->standardIcon(QStyle::SP_MessageBoxWarning);-
508 break;
never executed: break;
0
509 case QSystemTrayIcon::Critical:
never executed: case QSystemTrayIcon::Critical:
0
510 si = style()->standardIcon(QStyle::SP_MessageBoxCritical);-
511 break;
never executed: break;
0
512 case QSystemTrayIcon::Information:
never executed: case QSystemTrayIcon::Information:
0
513 si = style()->standardIcon(QStyle::SP_MessageBoxInformation);-
514 break;
never executed: break;
0
515 case QSystemTrayIcon::NoIcon:
never executed: case QSystemTrayIcon::NoIcon:
0
516 default:
never executed: default:
0
517 break;
never executed: break;
0
518 }-
519-
520 QGridLayout *layout = new QGridLayout;-
521 if (!si.isNull()) {
!si.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
522 QLabel *iconLabel = new QLabel;-
523 iconLabel->setPixmap(si.pixmap(iconSize, iconSize));-
524 iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);-
525 iconLabel->setMargin(2);-
526 layout->addWidget(iconLabel, 0, 0);-
527 layout->addWidget(titleLabel, 0, 1);-
528 } else {
never executed: end of block
0
529 layout->addWidget(titleLabel, 0, 0, 1, 2);-
530 }
never executed: end of block
0
531-
532 layout->addWidget(closeButton, 0, 2);-
533 layout->addWidget(msgLabel, 1, 0, 1, 3);-
534 layout->setSizeConstraint(QLayout::SetFixedSize);-
535 layout->setMargin(3);-
536 setLayout(layout);-
537-
538 QPalette pal = palette();-
539 pal.setColor(QPalette::Window, QColor(0xff, 0xff, 0xe1));-
540 pal.setColor(QPalette::WindowText, Qt::black);-
541 setPalette(pal);-
542}
never executed: end of block
0
543-
544QBalloonTip::~QBalloonTip()-
545{-
546 theSolitaryBalloonTip = 0;-
547}
never executed: end of block
0
548-
549void QBalloonTip::paintEvent(QPaintEvent *)-
550{-
551 QPainter painter(this);-
552 painter.drawPixmap(rect(), pixmap);-
553}
never executed: end of block
0
554-
555void QBalloonTip::resizeEvent(QResizeEvent *ev)-
556{-
557 QWidget::resizeEvent(ev);-
558}
never executed: end of block
0
559-
560void QBalloonTip::balloon(const QPoint& pos, int msecs, bool showArrow)-
561{-
562 this->showArrow = showArrow;-
563 QRect scr = QApplication::desktop()->screenGeometry(pos);-
564 QSize sh = sizeHint();-
565 const int border = 1;-
566 const int ah = 18, ao = 18, aw = 18, rc = 7;-
567 bool arrowAtTop = (pos.y() + sh.height() + ah < scr.height());-
568 bool arrowAtLeft = (pos.x() + sh.width() - ao < scr.width());-
569 setContentsMargins(border + 3, border + (arrowAtTop ? ah : 0) + 2, border + 3, border + (arrowAtTop ? 0 : ah) + 2);-
570 updateGeometry();-
571 sh = sizeHint();-
572-
573 int ml, mr, mt, mb;-
574 QSize sz = sizeHint();-
575 if (!arrowAtTop) {
!arrowAtTopDescription
TRUEnever evaluated
FALSEnever evaluated
0
576 ml = mt = 0;-
577 mr = sz.width() - 1;-
578 mb = sz.height() - ah - 1;-
579 } else {
never executed: end of block
0
580 ml = 0;-
581 mt = ah;-
582 mr = sz.width() - 1;-
583 mb = sz.height() - 1;-
584 }
never executed: end of block
0
585-
586 QPainterPath path;-
587#if defined(QT_NO_XSHAPE) && defined(Q_DEAD_CODE_FROM_QT4_X11)-
588 // XShape is required for setting the mask, so we just-
589 // draw an ugly square when its not available-
590 path.moveTo(0, 0);-
591 path.lineTo(sz.width() - 1, 0);-
592 path.lineTo(sz.width() - 1, sz.height() - 1);-
593 path.lineTo(0, sz.height() - 1);-
594 path.lineTo(0, 0);-
595 move(qMax(pos.x() - sz.width(), scr.left()), pos.y());-
596#else-
597 path.moveTo(ml + rc, mt);-
598 if (arrowAtTop && arrowAtLeft) {
arrowAtTopDescription
TRUEnever evaluated
FALSEnever evaluated
arrowAtLeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
599 if (showArrow) {
showArrowDescription
TRUEnever evaluated
FALSEnever evaluated
0
600 path.lineTo(ml + ao, mt);-
601 path.lineTo(ml + ao, mt - ah);-
602 path.lineTo(ml + ao + aw, mt);-
603 }
never executed: end of block
0
604 move(qMax(pos.x() - ao, scr.left() + 2), pos.y());-
605 } else if (arrowAtTop && !arrowAtLeft) {
never executed: end of block
arrowAtTopDescription
TRUEnever evaluated
FALSEnever evaluated
!arrowAtLeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
606 if (showArrow) {
showArrowDescription
TRUEnever evaluated
FALSEnever evaluated
0
607 path.lineTo(mr - ao - aw, mt);-
608 path.lineTo(mr - ao, mt - ah);-
609 path.lineTo(mr - ao, mt);-
610 }
never executed: end of block
0
611 move(qMin(pos.x() - sh.width() + ao, scr.right() - sh.width() - 2), pos.y());-
612 }
never executed: end of block
0
613 path.lineTo(mr - rc, mt);-
614 path.arcTo(QRect(mr - rc*2, mt, rc*2, rc*2), 90, -90);-
615 path.lineTo(mr, mb - rc);-
616 path.arcTo(QRect(mr - rc*2, mb - rc*2, rc*2, rc*2), 0, -90);-
617 if (!arrowAtTop && !arrowAtLeft) {
!arrowAtTopDescription
TRUEnever evaluated
FALSEnever evaluated
!arrowAtLeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
618 if (showArrow) {
showArrowDescription
TRUEnever evaluated
FALSEnever evaluated
0
619 path.lineTo(mr - ao, mb);-
620 path.lineTo(mr - ao, mb + ah);-
621 path.lineTo(mr - ao - aw, mb);-
622 }
never executed: end of block
0
623 move(qMin(pos.x() - sh.width() + ao, scr.right() - sh.width() - 2),-
624 pos.y() - sh.height());-
625 } else if (!arrowAtTop && arrowAtLeft) {
never executed: end of block
!arrowAtTopDescription
TRUEnever evaluated
FALSEnever evaluated
arrowAtLeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
626 if (showArrow) {
showArrowDescription
TRUEnever evaluated
FALSEnever evaluated
0
627 path.lineTo(ao + aw, mb);-
628 path.lineTo(ao, mb + ah);-
629 path.lineTo(ao, mb);-
630 }
never executed: end of block
0
631 move(qMax(pos.x() - ao, scr.x() + 2), pos.y() - sh.height());-
632 }
never executed: end of block
0
633 path.lineTo(ml + rc, mb);-
634 path.arcTo(QRect(ml, mb - rc*2, rc*2, rc*2), -90, -90);-
635 path.lineTo(ml, mt + rc);-
636 path.arcTo(QRect(ml, mt, rc*2, rc*2), 180, -90);-
637-
638 // Set the mask-
639 QBitmap bitmap = QBitmap(sizeHint());-
640 bitmap.fill(Qt::color0);-
641 QPainter painter1(&bitmap);-
642 painter1.setPen(QPen(Qt::color1, border));-
643 painter1.setBrush(QBrush(Qt::color1));-
644 painter1.drawPath(path);-
645 setMask(bitmap);-
646#endif-
647-
648 // Draw the border-
649 pixmap = QPixmap(sz);-
650 QPainter painter2(&pixmap);-
651 painter2.setPen(QPen(palette().color(QPalette::Window).darker(160), border));-
652 painter2.setBrush(palette().color(QPalette::Window));-
653 painter2.drawPath(path);-
654-
655 if (msecs > 0)
msecs > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
656 timerId = startTimer(msecs);
never executed: timerId = startTimer(msecs);
0
657 show();-
658}
never executed: end of block
0
659-
660void QBalloonTip::mousePressEvent(QMouseEvent *e)-
661{-
662 close();-
663 if(e->button() == Qt::LeftButton)
e->button() == Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
664 emit trayIcon->messageClicked();
never executed: trayIcon->messageClicked();
0
665}
never executed: end of block
0
666-
667void QBalloonTip::timerEvent(QTimerEvent *e)-
668{-
669 if (e->timerId() == timerId) {
e->timerId() == timerIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
670 killTimer(timerId);-
671 if (!underMouse())
!underMouse()Description
TRUEnever evaluated
FALSEnever evaluated
0
672 close();
never executed: close();
0
673 return;
never executed: return;
0
674 }-
675 QWidget::timerEvent(e);-
676}
never executed: end of block
0
677-
678//////////////////////////////////////////////////////////////////////-
679void QSystemTrayIconPrivate::install_sys_qpa()-
680{-
681 qpa_sys->init();-
682 QObject::connect(qpa_sys, SIGNAL(activated(QPlatformSystemTrayIcon::ActivationReason)),-
683 q_func(), SLOT(_q_emitActivated(QPlatformSystemTrayIcon::ActivationReason)));-
684 QObject::connect(qpa_sys, &QPlatformSystemTrayIcon::messageClicked,-
685 q_func(), &QSystemTrayIcon::messageClicked);-
686 updateMenu_sys();-
687 updateIcon_sys();-
688 updateToolTip_sys();-
689}
never executed: end of block
0
690-
691void QSystemTrayIconPrivate::remove_sys_qpa()-
692{-
693 QObject::disconnect(qpa_sys, SIGNAL(activated(QPlatformSystemTrayIcon::ActivationReason)),-
694 q_func(), SLOT(_q_emitActivated(QPlatformSystemTrayIcon::ActivationReason)));-
695 QObject::disconnect(qpa_sys, &QPlatformSystemTrayIcon::messageClicked,-
696 q_func(), &QSystemTrayIcon::messageClicked);-
697 qpa_sys->cleanup();-
698}
never executed: end of block
0
699-
700QRect QSystemTrayIconPrivate::geometry_sys_qpa() const-
701{-
702 return qpa_sys->geometry();
never executed: return qpa_sys->geometry();
0
703}-
704-
705void QSystemTrayIconPrivate::updateIcon_sys_qpa()-
706{-
707 qpa_sys->updateIcon(icon);-
708}
never executed: end of block
0
709-
710void QSystemTrayIconPrivate::updateMenu_sys_qpa()-
711{-
712 if (menu) {
menuDescription
TRUEnever evaluated
FALSEnever evaluated
0
713 addPlatformMenu(menu);-
714 qpa_sys->updateMenu(menu->platformMenu());-
715 }
never executed: end of block
0
716}
never executed: end of block
0
717-
718void QSystemTrayIconPrivate::updateToolTip_sys_qpa()-
719{-
720 qpa_sys->updateToolTip(toolTip);-
721}
never executed: end of block
0
722-
723void QSystemTrayIconPrivate::showMessage_sys_qpa(const QString &title,-
724 const QString &message,-
725 QSystemTrayIcon::MessageIcon icon,-
726 int msecs)-
727{-
728 QIcon notificationIcon;-
729 switch (icon) {-
730 case QSystemTrayIcon::Information:
never executed: case QSystemTrayIcon::Information:
0
731 notificationIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation);-
732 break;
never executed: break;
0
733 case QSystemTrayIcon::Warning:
never executed: case QSystemTrayIcon::Warning:
0
734 notificationIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning);-
735 break;
never executed: break;
0
736 case QSystemTrayIcon::Critical:
never executed: case QSystemTrayIcon::Critical:
0
737 notificationIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical);-
738 break;
never executed: break;
0
739 default:
never executed: default:
0
740 break;
never executed: break;
0
741 }-
742 qpa_sys->showMessage(title, message, notificationIcon,-
743 static_cast<QPlatformSystemTrayIcon::MessageIcon>(icon), msecs);-
744}
never executed: end of block
0
745-
746void QSystemTrayIconPrivate::addPlatformMenu(QMenu *menu) const-
747{-
748 if (menu->platformMenu())
menu->platformMenu()Description
TRUEnever evaluated
FALSEnever evaluated
0
749 return; // The platform menu already exists.
never executed: return;
0
750-
751 // The recursion depth is the same as menu depth, so should not-
752 // be higher than 3 levels.-
753 QListIterator<QAction *> it(menu->actions());-
754 while (it.hasNext()) {
it.hasNext()Description
TRUEnever evaluated
FALSEnever evaluated
0
755 QAction *action = it.next();-
756 if (action->menu())
action->menu()Description
TRUEnever evaluated
FALSEnever evaluated
0
757 addPlatformMenu(action->menu());
never executed: addPlatformMenu(action->menu());
0
758 }
never executed: end of block
0
759-
760 // This menu should be processed *after* its children, otherwise-
761 // setMenu() is not called on respective QPlatformMenuItems.-
762 QPlatformMenu *platformMenu = qpa_sys->createMenu();-
763 if (platformMenu)
platformMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
764 menu->setPlatformMenu(platformMenu);
never executed: menu->setPlatformMenu(platformMenu);
0
765}
never executed: end of block
0
766-
767QT_END_NAMESPACE-
768-
769#endif // QT_NO_SYSTEMTRAYICON-
770-
771#include "moc_qsystemtrayicon.cpp"-
772#include "moc_qsystemtrayicon_p.cpp"-
Source codeSwitch to Preprocessed file

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