00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include <kpopupmenu.h>
00027 #include <kiconloader.h>
00028 #include <kaboutapplication.h>
00029 #include <kaction.h>
00030 #include <klocale.h>
00031 #include <kglobalsettings.h>
00032 #include <kiconeffect.h>
00033 #include <kdebug.h>
00034
00035 #include <qpainter.h>
00036 #include <qimage.h>
00037 #include <qstring.h>
00038 #include <qtimer.h>
00039 #include <qbitmap.h>
00040 #include <qtooltip.h>
00041
00042 #include "wsystray.h"
00043 #include "kwebsnap.h"
00044
00045 WSysTray::WSysTray( QWidget *parent, const char *name )
00046 : KSystemTray( parent, name ),
00047 m_startId(-1),
00048 m_stopId(-1),
00049 m_configId(-1)
00050 {
00051 m_defaultIcon = KSystemTray::loadIcon("kwebsnap");
00052 setPixmap(m_defaultIcon);
00053
00054 m_parent = reinterpret_cast<KWebSnap*> (parent);
00055
00056 m_menu = new KPopupMenu();
00057
00058 KPopupMenu* popupmenu = contextMenu();
00059
00060 popupmenu->changeTitle( popupmenu->idAt( 0 ), loadIcon("kwebsnap"), "KWebSnap");
00061 popupmenu->insertItem(SmallIcon("ksnapshot"), i18n("Snapshot"), m_parent, SLOT(slotSnapshot()));
00062 popupmenu->insertSeparator();
00063 m_startId = popupmenu->insertItem(SmallIcon("run"), i18n("Start"), m_parent, SLOT(slotStart()));
00064 m_stopId = popupmenu->insertItem(SmallIcon("stop"), i18n("Stop"), m_parent, SLOT(slotStop()));
00065 popupmenu->insertSeparator();
00066 m_configId = popupmenu->insertItem(SmallIcon("configure"), i18n("Configure..."), m_parent, SLOT(slotConfig()));
00067 popupmenu->insertSeparator();
00068 popupmenu->insertItem(SmallIcon("help"), i18n("Help"), m_parent, SLOT(slotHelp()));
00069 popupmenu->insertItem(SmallIcon("kwebsnap"), i18n("About KWebSnap"), m_parent, SLOT(slotAbout()));
00070
00071 connect(this, SIGNAL(quitSelected()), m_parent, SLOT(slotQuit()));
00072
00073 QToolTip::add(this, i18n("KWebSnap"));
00074
00075 show();
00076 }
00077
00078 WSysTray::~WSysTray()
00079 {
00080 delete m_menu;
00081 m_menu = 0;
00082 }
00083
00084
00085 void WSysTray::setNumber(int n)
00086 {
00087 QString string;
00088 string = string.setNum(n);
00089
00090 setText(string);
00091 QToolTip::add(this, string);
00092 }
00093
00094
00095 void WSysTray::setText(const QString & text)
00096 {
00097 int oldW = pixmap()->size().width();
00098 int oldH = pixmap()->size().height();
00099
00100 QFont f = KGlobalSettings::generalFont();
00101 f.setBold(true);
00102 float pointSize = f.pointSizeFloat();
00103 QFontMetrics fm(f);
00104 int w = fm.width(text);
00105 if( w > (oldW) )
00106 {
00107 pointSize *= float(oldW) / float(w);
00108 f.setPointSizeFloat(pointSize);
00109 }
00110
00111 QPixmap pix(oldW, oldH);
00112 pix.fill(Qt::white);
00113 QPainter p(&pix);
00114 p.setFont(f);
00115 p.setPen(Qt::red);
00116 p.drawText(pix.rect(), Qt::AlignCenter, text);
00117
00118 pix.setMask(pix.createHeuristicMask());
00119 QImage img = pix.convertToImage();
00120
00121
00122 drawImage(img);
00123 }
00124
00125 void WSysTray::drawFlash()
00126 {
00127 QPixmap flash(KGlobal::iconLoader()->loadIcon("ksnapshot",KIcon::Small,0,false));
00128
00129 drawPixmap(flash);
00130
00131 }
00132
00133 void WSysTray::drawSave()
00134 {
00135 QPixmap saveIcon(KGlobal::iconLoader()->loadIcon("filesave",KIcon::Small,0,false));
00136
00137 drawPixmap(saveIcon);
00138
00139 }
00140
00141 void WSysTray::drawSend()
00142 {
00143 QPixmap send(KGlobal::iconLoader()->loadIcon("forward",KIcon::Small,0,false));
00144
00145 drawPixmap(send);
00146
00147 }
00148
00149
00150 void WSysTray::drawPixmap(const QPixmap& pixmap)
00151 {
00152 blendOverlay(pixmap, m_defaultIcon);
00153 }
00154
00155
00156 void WSysTray::blendOverlay(const QPixmap& overlay, const QPixmap& sourcePixmap)
00157 {
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 int opW = overlay.width(),
00168 opH = overlay.height(),
00169 opX = 1,
00170 opY = sourcePixmap.height() - opH;
00171
00172
00173 QPixmap sourceCropped( opW, opH, sourcePixmap.depth() );
00174 copyBlt( &sourceCropped, 0,0, &sourcePixmap, opX,opY, opW,opH );
00175
00176
00177
00178 if( sourceCropped.isNull() )
00179 return setPixmap( sourcePixmap );
00180
00181
00182 QImage blendedImage = sourceCropped.convertToImage();
00183 QImage overlayImage = overlay.convertToImage();
00184 KIconEffect::overlay( blendedImage, overlayImage );
00185 sourceCropped.convertFromImage( blendedImage );
00186
00187
00188 QPixmap sourcePixmapCopy = sourcePixmap;
00189 copyBlt( &sourcePixmapCopy, opX,opY, &sourceCropped, 0,0, opW,opH );
00190
00191 setPixmap( sourcePixmapCopy );
00192 }
00193
00194
00195 void WSysTray::drawImage(const QImage& image)
00196 {
00197 drawPixmap(QPixmap(image));
00198 }
00199
00200
00201 void WSysTray::resetIcon()
00202 {
00203 setPixmap(m_defaultIcon);
00204 QToolTip::add(this, i18n("KWebSnap"));
00205 }
00206
00207 void WSysTray::disableMenues()
00208 {
00209 setEnableMenues(false);
00210 }
00211
00212 void WSysTray::enableMenues()
00213 {
00214 setEnableMenues(true);
00215 }
00216
00217 void WSysTray::setEnableMenues(bool enable)
00218 {
00219 KPopupMenu* popupmenu = contextMenu();
00220
00221 popupmenu->setItemEnabled(m_startId, enable);
00222 popupmenu->setItemEnabled(m_configId, enable);
00223 popupmenu->setItemEnabled(m_stopId, !enable);
00224 }