[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Berlin-Clock mode for kclockapplet
From: Malte Starostik <malte () kde ! org>
Date: 2001-07-30 18:07:15
[Download RAW message or body]
Hi,
I needed a little "recreative" work to get a little time off (not from the
few KDE things I did the last weeks but from Real Life :)
The result is a "Berlin-Clock" mode for Kicker's clock applet. The colours
are hardcoded to red and yellow like on the original outdoor clock in Berlin
- guess where the name comes from :)
Short explanation: the round light on top toggles every second, the following
rows of lights mean:
1. row: one light per 5 hours
2. row: one light per hour (mod 5)
3. row: one light per 5 minutes (3rd, 6th and 9th light show full quarters
and are red while the others are yellow)
4. row: one light per minute (mod 5)
Enjoy,
--
Malte Starostik
PGP: 1024D/D2F3C787 [C138 2121 FAF3 410A 1C2A 27CD 5431 7745 D2F3 C787]
["clock.diff" (text/x-diff)]
Index: clock.cpp
===================================================================
RCS file: /home/kde/kdebase/kicker/applets/clock/clock.cpp,v
retrieving revision 1.56
diff -u -3 -d -p -r1.56 clock.cpp
--- clock.cpp 2001/06/05 12:57:44 1.56
+++ clock.cpp 2001/07/30 18:02:58
@@ -94,8 +94,11 @@ ClockSettings::ClockSettings(QWidget* ap
_type = Digital;
else if (s == "Analog")
_type = Analog;
- else
+ else if (s == "Fuzzy")
_type = Fuzzy;
+ else
+ _type = Berlin;
+
config->setGroup("Date");
_useColDate = config->readBoolEntry("Use_Custom_Colors",false);
@@ -168,6 +171,9 @@ void ClockSettings::writeSettings()
case Fuzzy:
config->writeEntry("Type", "Fuzzy");
break;
+ case Berlin:
+ config->writeEntry("Type", "Berlin");
+ break;
}
config->setGroup("Date");
@@ -981,7 +987,87 @@ void FuzzyClock::drawContents(QPainter *
//************************************************************
+BerlinClock::BerlinClock(ClockApplet *applet, ClockSettings* settings, QWidget \
*parent, const char *name) + : QFrame(parent, name), ClockWidget(applet, settings)
+{
+}
+
+BerlinClock::~BerlinClock()
+{
+}
+
+int BerlinClock::preferedWidthForHeight(int h) const
+{
+ return h * 60 / 45;
+}
+
+int BerlinClock::preferedHeightForWidth(int w) const
+{
+ return w * 45 / 60;
+}
+
+void BerlinClock::updateClock()
+{
+ QTime time = QTime::currentTime();
+
+ _buffer.fill(this, 0, 0);
+ QPainter p(&_buffer);
+ QColor color = time.second() % 2 ? black : yellow;
+ p.setPen(color);
+ p.setBrush(color);
+ p.drawEllipse(5 * width() / 12, 0, width() / 6 - 1, height() / 5 - 1);
+
+ bool all = time.hour() == 0 && time.minute() == 0;
+ for (int i = 0; i < 4; ++i)
+ drawLight(&p, 0, i, all || time.hour() / 5 > i);
+ for (int i = 0; i < 4; ++i)
+ drawLight(&p, 1, i, all || time.hour() % 5 > i);
+ for (int i = 0; i < 11; ++i)
+ drawLight(&p, 2, i, all || time.minute() / 5 > i);
+ for (int i = 0; i < 4; ++i)
+ drawLight(&p, 3, i, all || time.minute() % 5 > i);
+
+ p.end();
+
+ repaint();
+}
+
+void BerlinClock::drawContents(QPainter *p)
+{
+ p->drawPixmap(0, 0, _buffer);
+}
+
+void BerlinClock::resizeEvent(QResizeEvent *)
+{
+ _buffer.resize(width(), height());
+ updateClock();
+}
+
+void BerlinClock::drawLight(QPainter *p, int row, int col, bool on)
+{
+ QColor color = black;
+ if (on)
+ {
+ // hours are red, minutes are yellow except for 15, 30, 45
+ if (row < 2 || ((row == 2) && (col % 3 == 2)))
+ color = red;
+ else
+ color = yellow;
+ }
+
+ p->setPen(color);
+ p->setBrush(color);
+ QRect rect(row == 2 ? (col * 2 + 1) * width() / 24 : col * width() / 4,
+ (row + 1) * height() / 5,
+ (row == 2 ? width() / 12 : width() / 4) - 1,
+ height() / 5 - 1);
+ p->drawRoundRect(rect);
+}
+
+//************************************************************
+
+
ClockApplet::ClockApplet(const QString& configFile, Type t, int actions,
QWidget *parent, const char *name)
: KPanelApplet(configFile, t, actions, parent, name),
@@ -1092,6 +1178,9 @@ void ClockApplet::slotApplySettings()
case ClockSettings::Fuzzy:
_clock = new FuzzyClock(this, _settings, this);
break;
+ case ClockSettings::Berlin:
+ _clock = new BerlinClock(this, _settings, this);
+ break;
}
QToolTip::add(_clock->widget(),KGlobal::locale()->formatDate(_lastDate, false));
Index: clock.h
===================================================================
RCS file: /home/kde/kdebase/kicker/applets/clock/clock.h,v
retrieving revision 1.21
diff -u -3 -d -p -r1.21 clock.h
--- clock.h 2001/02/23 15:08:02 1.21
+++ clock.h 2001/07/30 18:02:59
@@ -56,7 +56,7 @@ class ClockSettings : public QObject
Q_OBJECT
public:
- enum ClockType { Plain = 0, Digital, Analog, Fuzzy };
+ enum ClockType { Plain = 0, Digital, Analog, Fuzzy, Berlin };
ClockSettings(QWidget* app, KConfig* conf);
~ClockSettings();
@@ -215,6 +215,28 @@ protected:
QString _timeStr;
};
+class BerlinClock : public QFrame, public ClockWidget
+{
+ Q_OBJECT
+public:
+ BerlinClock(ClockApplet *applet, ClockSettings *settings, QWidget *parent=0, const \
char *name=0); + virtual ~BerlinClock();
+
+ virtual QWidget *widget() { return this; }
+ virtual int preferedWidthForHeight(int h) const;
+ virtual int preferedHeightForWidth(int w) const;
+ virtual void updateClock();
+
+protected:
+ virtual void drawContents(QPainter *p);
+ virtual void resizeEvent(QResizeEvent *);
+
+private:
+ void drawLight(QPainter *p, int row, int col, bool on);
+
+private:
+ QPixmap _buffer;
+};
class ClockApplet : public KPanelApplet
{
Index: conf.ui
===================================================================
RCS file: /home/kde/kdebase/kicker/applets/clock/conf.ui,v
retrieving revision 1.11
diff -u -3 -d -p -r1.11 conf.ui
--- conf.ui 2001/06/05 12:57:44 1.11
+++ conf.ui 2001/07/30 18:02:59
@@ -124,6 +124,12 @@
<string>Fuzzy Clock</string>
</property>
</item>
+ <item>
+ <property>
+ <name>text</name>
+ <string>Berlin-Clock</string>
+ </property>
+ </item>
<property stdset="1">
<name>name</name>
<cstring>clockCombo</cstring>
["bclock.png" (image/png)]
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic