25 #include "akregatorconfig.h"
28 #include <tdeapplication.h>
30 #include <kiconeffect.h>
32 #include <tdelocale.h>
33 #include <tdeglobalsettings.h>
34 #include <dcopclient.h>
36 #include <tdepopupmenu.h>
37 #include <kiconloader.h>
40 #include <tqpainter.h>
42 #include <tqtooltip.h>
47 TrayIcon* TrayIcon::m_instance = 0;
49 TrayIcon* TrayIcon::getInstance()
54 void TrayIcon::setInstance(TrayIcon* trayIcon)
56 m_instance = trayIcon;
60 TrayIcon::TrayIcon(TQWidget *parent,
const char *name)
61 : KSystemTray(parent, name), m_unread(0)
63 m_defaultIcon=KSystemTray::loadIcon(
"akregator");
64 TQPixmap m_unreadIcon=KSystemTray::loadIcon(
"akregator_empty");
65 m_lightIconImage=m_unreadIcon.convertToImage();
66 TDEIconEffect::deSaturate(m_lightIconImage, 0.60);
67 setPixmap(m_defaultIcon);
68 TQToolTip::add(
this, i18n(
"Akregator - RSS Feed Reader"));
76 void TrayIcon::mousePressEvent(TQMouseEvent *e) {
77 if (e->button() == TQt::LeftButton) {
81 KSystemTray::mousePressEvent(e);
85 TQPixmap TrayIcon::takeScreenshot()
const
87 TQPoint g = mapToGlobal(pos());
88 int desktopWidth = kapp->desktop()->width();
89 int desktopHeight = kapp->desktop()->height();
92 int w = desktopWidth / 4;
93 int h = desktopHeight / 9;
94 int x = g.x() + tw/2 - w/2;
95 int y = g.y() + th/2 - h/2;
100 if (x + w > desktopWidth)
101 x = desktopWidth - w;
102 if (y + h > desktopHeight)
103 y = desktopHeight - h;
106 TQPixmap shot = TQPixmap::grabWindow(tqt_xrootwin(), x, y, w, h);
107 TQPainter painter(&shot);
108 const int MARGINS = 6;
110 int ax = g.x() - x - MARGINS -1;
111 int ay = g.y() - y - MARGINS -1;
112 painter.setPen( TQPen(TQt::red, WIDTH) );
113 painter.drawArc(ax, ay, tw + 2*MARGINS, th + 2*MARGINS, 0, 16*360);
117 const int BORDER = 1;
118 TQPixmap finalShot(w + 2*BORDER, h + 2*BORDER);
119 finalShot.fill(TDEApplication::palette().active().foreground());
120 painter.begin(&finalShot);
121 painter.drawPixmap(BORDER, BORDER, shot);
126 void TrayIcon::resizeEvent(TQResizeEvent *)
128 setUnread(m_unread,
true);
131 void TrayIcon::slotSetUnread(
int unread)
133 setUnread(unread,
false);
136 void TrayIcon::setUnread(
int unread,
bool force)
138 if ((unread==m_unread) && (!force))
145 TQToolTip::remove(
this);
146 TQToolTip::add(
this, i18n(
"Akregator - 1 unread article",
"Akregator - %n unread articles", unread > 0 ? unread : 0));
150 setPixmap(m_defaultIcon);
155 int oldW = pixmap()->size().width();
156 int oldH = pixmap()->size().height();
158 TQString uStr=TQString::number( unread );
159 TQFont f=TDEGlobalSettings::generalFont();
165 int realIconHeight = height();
166 if (realIconHeight < 22) {
167 f.setPointSizeFloat( f.pointSizeFloat() * 2.0 );
172 float pointSize=f.pointSizeFloat();
174 int w=fm.width(uStr);
177 pointSize *= float(oldW) / float(w);
178 f.setPointSizeFloat(pointSize);
181 TQPixmap pix(oldW, oldH);
182 pix.fill(TQt::white);
185 p.setPen(Settings::unreadTextColor());
186 p.drawText(pix.rect(), TQt::AlignCenter, uStr);
188 pix.setMask(pix.createHeuristicMask());
189 TQImage img=pix.convertToImage();
192 TQImage overlayImg=m_lightIconImage.copy();
193 TDEIconEffect::overlay(overlayImg, img);
196 icon.convertFromImage(overlayImg);
201 void TrayIcon::viewButtonClicked()
203 TQWidget *p=
static_cast<TQWidget*
>(parent());
204 KWin::forceActiveWindow(p->winId());
207 void TrayIcon::settingsChanged()
209 if ( Settings::showTrayIcon() ) {
211 setUnread(m_unread,
true);
218 #include "trayicon.moc"