util/qsystemtrayicon.cpp

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

Generated by Squish Coco Non-Commercial