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