TrayIcon.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "TrayIcon.h"
00018
00019 #include <QSysInfo>
00020
00021
00022 #if defined(Q_WS_MAC)
00023
00024
00025 void qt_mac_set_dock_menu(QMenu *menu);
00026 #endif
00027
00028
00029
00030 TrayIcon::TrayIcon(QWidget *parent)
00031 : TrayIconImpl(parent)
00032 {
00033 }
00034
00035
00036 bool
00037 TrayIcon::event(QEvent *event)
00038 {
00039 switch (event->type()) {
00040 case QEvent::MouseButtonDblClick:
00041 mouseButtonDblClick((QMouseEvent *)event);
00042 break;
00043
00044 default:
00045 return TrayIconImpl::event(event);
00046 }
00047 event->accept();
00048 return true;
00049 }
00050
00051
00052
00053
00054 void
00055 TrayIcon::mouseButtonDblClick(QMouseEvent *event)
00056 {
00057 if (event->button() == Qt::LeftButton) {
00058 emit doubleClicked();
00059 }
00060 }
00061
00062
00063 void
00064 TrayIcon::update(const QString &iconFile, const QString &toolTip)
00065 {
00066 setIcon(iconFile);
00067 setToolTip(toolTip);
00068 }
00069
00070
00071 void
00072 TrayIcon::show()
00073 {
00074 TrayIconImpl::show();
00075 }
00076
00077
00078 void
00079 TrayIcon::hide()
00080 {
00081 TrayIconImpl::hide();
00082 }
00083
00084
00085 void
00086 TrayIcon::setToolTip(const QString &toolTip)
00087 {
00088 TrayIconImpl::setToolTip(toolTip);
00089 }
00090
00091
00092 void
00093 TrayIcon::setIcon(const QString &iconFile)
00094 {
00095 TrayIconImpl::setIcon(iconFile);
00096 }
00097
00098
00099
00100 void
00101 TrayIcon::setContextMenu(QMenu *menu)
00102 {
00103 #if defined(Q_WS_MAC)
00104 qt_mac_set_dock_menu(menu);
00105 #else
00106 TrayIconImpl::setContextMenu(menu);
00107 #endif
00108 }
00109
00110
00111 void
00112 TrayIcon::showBalloonMessage(const QString &title, const QString &message,
00113 BalloonMessageIcon balloonIcon)
00114 {
00115 #if defined(Q_WS_MAC)
00116 Q_UNUSED(title)
00117 Q_UNUSED(message)
00118 Q_UNUSED(balloonIcon)
00119 #else
00120 QSystemTrayIcon::MessageIcon icon;
00121 switch (balloonIcon) {
00122 case NoIcon: icon = QSystemTrayIcon::NoIcon; break;
00123 case Warning: icon = QSystemTrayIcon::Warning; break;
00124 case Critical: icon = QSystemTrayIcon::Critical; break;
00125 default: icon = QSystemTrayIcon::Information; break;
00126 }
00127 TrayIconImpl::showMessage(title, message, icon);
00128 #endif
00129 }
00130
00131
00132
00133 bool
00134 TrayIcon::isTrayIconSupported()
00135 {
00136 #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
00137
00138 return true;
00139 #else
00140
00141 return QSystemTrayIcon::isSystemTrayAvailable();
00142 #endif
00143 }
00144
00145
00146
00147 bool
00148 TrayIcon::supportsBalloonMessages()
00149 {
00150 #if defined(Q_WS_WIN)
00151 return (QSystemTrayIcon::supportsMessages()
00152 && QSysInfo::WindowsVersion > QSysInfo::WV_2000);
00153 #elif defined(Q_WS_MAC)
00154 return false;
00155 #else
00156 return QSystemTrayIcon::supportsMessages();
00157 #endif
00158 }
00159