00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "akregatorconfig.h"
00026 #include "trayicon.h"
00027
00028 #include <tdeapplication.h>
00029 #include <twin.h>
00030 #include <kiconeffect.h>
00031 #include <kdebug.h>
00032 #include <tdelocale.h>
00033 #include <tdeglobalsettings.h>
00034 #include <dcopclient.h>
00035 #include <dcopref.h>
00036 #include <tdepopupmenu.h>
00037 #include <kiconloader.h>
00038
00039 #include <tqbitmap.h>
00040 #include <tqpainter.h>
00041 #include <tqfont.h>
00042 #include <tqtooltip.h>
00043
00044
00045 namespace Akregator {
00046
00047 TrayIcon* TrayIcon::m_instance = 0;
00048
00049 TrayIcon* TrayIcon::getInstance()
00050 {
00051 return m_instance;
00052 }
00053
00054 void TrayIcon::setInstance(TrayIcon* trayIcon)
00055 {
00056 m_instance = trayIcon;
00057 }
00058
00059
00060 TrayIcon::TrayIcon(TQWidget *parent, const char *name)
00061 : KSystemTray(parent, name), m_unread(0)
00062 {
00063 m_defaultIcon=KSystemTray::loadIcon("akregator");
00064 TQPixmap m_unreadIcon=KSystemTray::loadIcon("akregator_empty");
00065 m_lightIconImage=m_unreadIcon.convertToImage();
00066 TDEIconEffect::deSaturate(m_lightIconImage, 0.60);
00067 setPixmap(m_defaultIcon);
00068 TQToolTip::add(this, i18n("Akregator - RSS Feed Reader"));
00069 }
00070
00071
00072 TrayIcon::~TrayIcon()
00073 {}
00074
00075
00076 void TrayIcon::mousePressEvent(TQMouseEvent *e) {
00077 if (e->button() == Qt::LeftButton) {
00078 emit showPart();
00079 }
00080
00081 KSystemTray::mousePressEvent(e);
00082 }
00083
00084
00085 TQPixmap TrayIcon::takeScreenshot() const
00086 {
00087 TQPoint g = mapToGlobal(pos());
00088 int desktopWidth = kapp->desktop()->width();
00089 int desktopHeight = kapp->desktop()->height();
00090 int tw = width();
00091 int th = height();
00092 int w = desktopWidth / 4;
00093 int h = desktopHeight / 9;
00094 int x = g.x() + tw/2 - w/2;
00095 int y = g.y() + th/2 - h/2;
00096 if (x < 0)
00097 x = 0;
00098 if (y < 0)
00099 y = 0;
00100 if (x + w > desktopWidth)
00101 x = desktopWidth - w;
00102 if (y + h > desktopHeight)
00103 y = desktopHeight - h;
00104
00105
00106 TQPixmap shot = TQPixmap::grabWindow(tqt_xrootwin(), x, y, w, h);
00107 TQPainter painter(&shot);
00108 const int MARGINS = 6;
00109 const int WIDTH = 3;
00110 int ax = g.x() - x - MARGINS -1;
00111 int ay = g.y() - y - MARGINS -1;
00112 painter.setPen( TQPen(TQt::red, WIDTH) );
00113 painter.drawArc(ax, ay, tw + 2*MARGINS, th + 2*MARGINS, 0, 16*360);
00114 painter.end();
00115
00116
00117 const int BORDER = 1;
00118 TQPixmap finalShot(w + 2*BORDER, h + 2*BORDER);
00119 finalShot.fill(TDEApplication::palette().active().foreground());
00120 painter.begin(&finalShot);
00121 painter.drawPixmap(BORDER, BORDER, shot);
00122 painter.end();
00123 return shot;
00124 }
00125
00126 void TrayIcon::resizeEvent(TQResizeEvent *)
00127 {
00128 setUnread(m_unread, true);
00129 }
00130
00131 void TrayIcon::slotSetUnread(int unread)
00132 {
00133 setUnread(unread, false);
00134 }
00135
00136 void TrayIcon::setUnread(int unread, bool force)
00137 {
00138 if ((unread==m_unread) && (!force))
00139 {
00140 return;
00141 }
00142
00143 m_unread=unread;
00144
00145 TQToolTip::remove(this);
00146 TQToolTip::add(this, i18n("Akregator - 1 unread article", "Akregator - %n unread articles", unread > 0 ? unread : 0));
00147
00148 if (unread <= 0)
00149 {
00150 setPixmap(m_defaultIcon);
00151 }
00152 else
00153 {
00154
00155 int oldW = pixmap()->size().width();
00156 int oldH = pixmap()->size().height();
00157
00158 TQString uStr=TQString::number( unread );
00159 TQFont f=TDEGlobalSettings::generalFont();
00160 f.setBold(true);
00161
00162
00163
00164
00165 int realIconHeight = height();
00166 if (realIconHeight < 22) {
00167 f.setPointSizeFloat( f.pointSizeFloat() * 2.0 );
00168 }
00169
00170
00171
00172 float pointSize=f.pointSizeFloat();
00173 TQFontMetrics fm(f);
00174 int w=fm.width(uStr);
00175 if( w > (oldW) )
00176 {
00177 pointSize *= float(oldW) / float(w);
00178 f.setPointSizeFloat(pointSize);
00179 }
00180
00181 TQPixmap pix(oldW, oldH);
00182 pix.fill(TQt::white);
00183 TQPainter p(&pix);
00184 p.setFont(f);
00185 p.setPen(Settings::unreadTextColor());
00186 p.drawText(pix.rect(), TQt::AlignCenter, uStr);
00187
00188 pix.setMask(pix.createHeuristicMask());
00189 TQImage img=pix.convertToImage();
00190
00191
00192 TQImage overlayImg=m_lightIconImage.copy();
00193 TDEIconEffect::overlay(overlayImg, img);
00194
00195 TQPixmap icon;
00196 icon.convertFromImage(overlayImg);
00197 setPixmap(icon);
00198 }
00199 }
00200
00201 void TrayIcon::viewButtonClicked()
00202 {
00203 TQWidget *p=TQT_TQWIDGET(parent());
00204 KWin::forceActiveWindow(p->winId());
00205 }
00206
00207 void TrayIcon::settingsChanged()
00208 {
00209 if ( Settings::showTrayIcon() ) {
00210 show();
00211 setUnread(m_unread, true);
00212 }
00213 else {
00214 hide();
00215 }
00216 }
00217 }
00218 #include "trayicon.moc"