[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 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 | **
|
---|
[561] | 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.
|
---|
[2] | 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 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 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);
|
---|
[846] | 86 |
|
---|
[2] | 87 | static bool isSystemTrayAvailable_sys();
|
---|
[846] | 88 | static bool supportsMessages_sys();
|
---|
[2] | 89 |
|
---|
| 90 | QPointer<QMenu> menu;
|
---|
| 91 | QIcon icon;
|
---|
| 92 | QString toolTip;
|
---|
| 93 | QSystemTrayIconSys *sys;
|
---|
| 94 | bool visible;
|
---|
| 95 | };
|
---|
| 96 |
|
---|
| 97 | class QBalloonTip : public QWidget
|
---|
| 98 | {
|
---|
[561] | 99 | Q_OBJECT
|
---|
[2] | 100 | public:
|
---|
| 101 | static void showBalloon(QSystemTrayIcon::MessageIcon icon, const QString& title,
|
---|
| 102 | const QString& msg, QSystemTrayIcon *trayIcon,
|
---|
| 103 | const QPoint& pos, int timeout, bool showArrow = true);
|
---|
| 104 | static void hideBalloon();
|
---|
| 105 | static bool isBalloonVisible();
|
---|
| 106 |
|
---|
| 107 | private:
|
---|
| 108 | QBalloonTip(QSystemTrayIcon::MessageIcon icon, const QString& title,
|
---|
| 109 | const QString& msg, QSystemTrayIcon *trayIcon);
|
---|
| 110 | ~QBalloonTip();
|
---|
| 111 | void balloon(const QPoint&, int, bool);
|
---|
| 112 |
|
---|
| 113 | protected:
|
---|
| 114 | void paintEvent(QPaintEvent *);
|
---|
| 115 | void resizeEvent(QResizeEvent *);
|
---|
| 116 | void mousePressEvent(QMouseEvent *e);
|
---|
| 117 | void timerEvent(QTimerEvent *e);
|
---|
| 118 |
|
---|
| 119 | private:
|
---|
| 120 | QSystemTrayIcon *trayIcon;
|
---|
| 121 | QPixmap pixmap;
|
---|
| 122 | int timerId;
|
---|
| 123 | };
|
---|
| 124 |
|
---|
| 125 | #if defined(Q_WS_X11)
|
---|
| 126 | QT_BEGIN_INCLUDE_NAMESPACE
|
---|
| 127 | #include <QtCore/qcoreapplication.h>
|
---|
| 128 | #include <X11/Xlib.h>
|
---|
| 129 | #include <X11/Xatom.h>
|
---|
| 130 | #include <X11/Xutil.h>
|
---|
| 131 | QT_END_INCLUDE_NAMESPACE
|
---|
| 132 |
|
---|
| 133 | class QSystemTrayIconSys : public QWidget
|
---|
| 134 | {
|
---|
| 135 | friend class QSystemTrayIconPrivate;
|
---|
| 136 |
|
---|
| 137 | public:
|
---|
| 138 | QSystemTrayIconSys(QSystemTrayIcon *q);
|
---|
| 139 | ~QSystemTrayIconSys();
|
---|
| 140 | enum {
|
---|
| 141 | SYSTEM_TRAY_REQUEST_DOCK = 0,
|
---|
| 142 | SYSTEM_TRAY_BEGIN_MESSAGE = 1,
|
---|
| 143 | SYSTEM_TRAY_CANCEL_MESSAGE =2
|
---|
| 144 | };
|
---|
| 145 |
|
---|
| 146 | void addToTray();
|
---|
| 147 | void updateIcon();
|
---|
| 148 | XVisualInfo* getSysTrayVisualInfo();
|
---|
| 149 |
|
---|
| 150 | // QObject::event is public but QWidget's ::event() re-implementation
|
---|
| 151 | // is protected ;(
|
---|
| 152 | inline bool deliverToolTipEvent(QEvent *e)
|
---|
| 153 | { return QWidget::event(e); }
|
---|
| 154 |
|
---|
| 155 | static Window sysTrayWindow;
|
---|
| 156 | static QList<QSystemTrayIconSys *> trayIcons;
|
---|
| 157 | static QCoreApplication::EventFilter oldEventFilter;
|
---|
| 158 | static bool sysTrayTracker(void *message, long *result);
|
---|
| 159 | static Window locateSystemTray();
|
---|
| 160 | static Atom sysTraySelection;
|
---|
| 161 | static XVisualInfo sysTrayVisual;
|
---|
| 162 |
|
---|
| 163 | protected:
|
---|
| 164 | void paintEvent(QPaintEvent *pe);
|
---|
| 165 | void resizeEvent(QResizeEvent *re);
|
---|
| 166 | bool x11Event(XEvent *event);
|
---|
| 167 | void mousePressEvent(QMouseEvent *event);
|
---|
| 168 | void mouseDoubleClickEvent(QMouseEvent *event);
|
---|
[769] | 169 | #ifndef QT_NO_WHEELEVENT
|
---|
[2] | 170 | void wheelEvent(QWheelEvent *event);
|
---|
[769] | 171 | #endif
|
---|
[2] | 172 | bool event(QEvent *e);
|
---|
| 173 |
|
---|
| 174 | private:
|
---|
| 175 | QPixmap background;
|
---|
| 176 | QSystemTrayIcon *q;
|
---|
| 177 | Colormap colormap;
|
---|
| 178 | };
|
---|
| 179 | #endif // Q_WS_X11
|
---|
| 180 |
|
---|
| 181 | QT_END_NAMESPACE
|
---|
| 182 |
|
---|
| 183 | #endif // QT_NO_SYSTEMTRAYICON
|
---|
| 184 |
|
---|
| 185 | #endif // QSYSTEMTRAYICON_P_H
|
---|
| 186 |
|
---|