[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kontaminuti] src: show remaining time in icon
From: "R.F. Pels" <rfpels () gmail ! com>
Date: 2011-09-30 21:52:09
Message-ID: 20110930215209.EBA66A60A6 () git ! kde ! org
[Download RAW message or body]
Git commit 44f7a9006c34b1df53bfaff17f63304bcfed338f by R.F. Pels.
Committed on 30/09/2011 at 22:36.
Pushed by ruurd into branch 'master'.
show remaining time in icon
M +39 -1 src/toplevel.cpp
M +1 -0 src/toplevel.h
http://commits.kde.org/kontaminuti/44f7a9006c34b1df53bfaff17f63304bcfed338f
diff --git a/src/toplevel.cpp b/src/toplevel.cpp
index 9875cda..e7db3cc 100644
--- a/src/toplevel.cpp
+++ b/src/toplevel.cpp
@@ -30,6 +30,7 @@
#include <KActionCollection>
#include <KHelpMenu>
#include <KPassivePopup>
+#include <KColorScheme>
#include <KGlobalSettings>
#include <KNotification>
#include <KAboutData>
@@ -37,6 +38,7 @@
TopLevel::TopLevel(const KAboutData *aboutData, const QString &icon, QWidget \
*parent) : KStatusNotifierItem(parent),
+ m_iconname(icon),
m_popup(new KPassivePopup),
m_runningTomatoTime(0),
m_nextNotificationTime(0)
@@ -240,7 +242,43 @@ void TopLevel::repaintTrayIcon()
{
if (m_runningTomatoTime != 0 && m_usevisualize)
{
- setOverlayIconByName(QLatin1String("task-ongoing"));
+ int oldWidth = 22;
+
+ QString countStr = QString::number(m_runningTomatoTime / 60);
+ QFont f = KGlobalSettings::generalFont();
+ f.setBold(true);
+
+ float pointSize = f.pointSizeF();
+ QFontMetrics fm(f);
+ int w = fm.width(countStr);
+ if (w > (oldWidth - 2) )
+ {
+ pointSize *= float(oldWidth - 2) / float(w);
+ f.setPointSizeF(pointSize);
+ }
+
+ // overlay
+ QPixmap overlayImg = KIcon(m_iconname).pixmap(22, 22);
+ QPainter p(&overlayImg);
+ p.setFont(f);
+ KColorScheme scheme(QPalette::Active, KColorScheme::View);
+
+ fm = QFontMetrics(f);
+ QRect boundingRect = fm.tightBoundingRect(countStr);
+ boundingRect.adjust(0, 0, 0, 2);
+ boundingRect.setHeight(qMin(boundingRect.height(), oldWidth));
+ boundingRect.moveTo((oldWidth - boundingRect.width()) / 2, ((oldWidth - \
boundingRect.height()) / 2) - 1); + p.setOpacity(0.7);
+ QBrush br(QColor(255, 255, 255), Qt::SolidPattern);
+ p.setBrush(br);
+ p.setPen(QColor(255, 255, 255));
+ p.drawRoundedRect(boundingRect, 2.0, 2.0);
+
+ p.setBrush(Qt::NoBrush);
+ p.setPen(QColor(0, 0, 0));
+ p.setOpacity(1.0);
+ p.drawText(overlayImg.rect(), Qt::AlignCenter, countStr);
+ setIconByPixmap(overlayImg);
}
else
{
diff --git a/src/toplevel.h b/src/toplevel.h
index 7324401..4412630 100644
--- a/src/toplevel.h
+++ b/src/toplevel.h
@@ -63,6 +63,7 @@ private:
void setTooltipText(const QString& content);
private:
+ QString m_iconname;
QList<Tomato> m_tomatolist;
QAction *m_stopAct, *m_confAct, *m_anonAct, *m_exitAct;
QActionGroup *m_tomatoActionGroup;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic