00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "systemtrayicon.h"
00019
00020
00021 SystemTrayIcon::SystemTrayIcon( QWidget* parent, QIcon trayIcon, KAction* actionRefresh ) : KSystemTrayIcon( trayIcon, parent )
00022 {
00023
00024 _icon = trayIcon;
00025
00026
00027 setToolTip( i18n("KShowmail: a POP3 email checker") );
00028
00029
00030 flashingTimer = new QTimer( this );
00031 flashingTimer->setSingleShot( false );
00032 connect( flashingTimer, SIGNAL( timeout() ), this, SLOT( slotFlash() ) );
00033
00034
00035 contextMenu()->addAction( actionRefresh );
00036 }
00037
00038
00039 void SystemTrayIcon::drawNumber (int n, const QColor& color)
00040 {
00041
00042 flashingTimer->stop();
00043
00044
00045 setIcon( _icon );
00046
00047
00048 QPixmap pix = icon().pixmap( 22, 22 );
00049
00050
00051 QString num( QString::number( n ) );
00052
00053
00054 QPainter p( &pix );
00055 QFont font = KGlobalSettings::toolBarFont();
00056 font.setPixelSize( 14 );
00057 font.setBold( true );
00058 p.setFont( font );
00059 p.setPen( color );
00060 p.drawText( 0, 0, 22, 22, Qt::AlignCenter, num );
00061
00062
00063 QIcon iconWithNumber = QIcon();
00064 iconWithNumber.addPixmap( pix );
00065
00066
00067 setIcon( iconWithNumber );
00068 }
00069
00070 void SystemTrayIcon::clear ()
00071 {
00072
00073 flashingTimer->stop();
00074
00075 }
00076
00077 void SystemTrayIcon::showLooking() {
00078
00079
00080 flashingTimer->stop();
00081
00082
00083 drawLooking();
00084
00085
00086 flasherFlag = true;
00087
00088
00089 flashingTimer->start( 1000 );
00090
00091 }
00092
00093 void SystemTrayIcon::drawLooking() {
00094
00095
00096 setIcon( _icon );
00097
00098
00099 QPixmap pix = icon().pixmap( 22, 22 );
00100
00101
00102 QPainter p( &pix );
00103 QFont font = KGlobalSettings::toolBarFont();
00104 font.setPixelSize( 14 );
00105 font.setBold( true );
00106 p.setFont( font );
00107 p.setPen( Qt::black );
00108 p.drawText( 0, 0, 22, 22, Qt::AlignCenter, "?" );
00109
00110
00111 QIcon iconWithMark = QIcon();
00112 iconWithMark.addPixmap( pix );
00113
00114
00115 setIcon( iconWithMark );
00116 }
00117
00118 void SystemTrayIcon::slotFlash() {
00119
00120 if( flasherFlag ) {
00121
00122
00123 setIcon( _icon );
00124
00125 flasherFlag = false;
00126
00127 } else {
00128
00129
00130 drawLooking();
00131
00132 flasherFlag = true;
00133 }
00134
00135 }