28 #include <kapplication.h>
29 #include <kwindowsystem.h>
32 #include <kglobalsettings.h>
35 #include <kiconloader.h>
36 #include <KColorScheme>
40 #include <QDesktopWidget>
45 TrayIcon* TrayIcon::m_instance = 0;
54 m_instance = trayIcon;
61 setToolTipTitle( i18n(
"Akregator") );
62 setToolTipIconByName( i18n(
"Akregator") );
63 setIconByName( QLatin1String(
"akregator") );
64 m_defaultIcon = KIcon( QLatin1String(
"akregator") );
75 this->setToolTip( m_defaultIcon.name(), i18n(
"Akregator"), unread == 0 ? i18n(
"There are no unread articles") : i18np(
"1 unread article",
"%1 unread articles", unread ) );
76 setStatus( unread > 0 ? KStatusNotifierItem::Active : KStatusNotifierItem::Passive );
80 setIconByName( m_defaultIcon.name() );
85 int oldWidth = KIconLoader::SizeSmallMedium;
87 QString countStr = QString::number( unread );
88 QFont f = KGlobalSettings::generalFont();
91 float pointSize = f.pointSizeF();
93 int w = fm.width(countStr);
94 if( w > (oldWidth - 2) )
96 pointSize *= float(oldWidth - 2) / float(w);
97 f.setPointSizeF(pointSize);
101 QPixmap overlayImg( oldWidth, oldWidth );
102 overlayImg.fill( Qt::transparent );
104 QPainter p(&overlayImg);
106 KColorScheme scheme(QPalette::Active, KColorScheme::View);
108 fm = QFontMetrics(f);
109 QRect boundingRect = fm.tightBoundingRect(countStr);
110 boundingRect.adjust(0, 0, 0, 2);
111 boundingRect.setHeight(qMin(boundingRect.height(), oldWidth));
112 boundingRect.moveTo((oldWidth - boundingRect.width()) / 2,
113 ((oldWidth - boundingRect.height()) / 2) - 1);
115 p.setBrush(scheme.background(KColorScheme::LinkBackground));
116 p.setPen(scheme.background(KColorScheme::LinkBackground).color());
117 p.drawRoundedRect(boundingRect, 2.0, 2.0);
119 p.setBrush(Qt::NoBrush);
120 p.setPen(scheme.foreground(KColorScheme::LinkText).color());
122 p.drawText(overlayImg.rect(), Qt::AlignCenter, countStr);
125 QPixmap iconPixmap = m_defaultIcon.pixmap( oldWidth, oldWidth );
127 QPainter pp( &iconPixmap );
128 pp.drawPixmap( 0, 0, overlayImg );
131 setIconByPixmap( iconPixmap );
138 KWindowSystem::activateWindow(p->winId());
148 #include "trayicon.moc"
static bool enableTrayIconUnreadArticleCount()
Get Display an unread article count in the tray icon.
void slotSetUnread(int unread)
static void setInstance(TrayIcon *trayIcon)
static TrayIcon * getInstance()
TrayIcon(QObject *parent=0)