[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/plasma/applets/train-clock
From: Riccardo Iaconelli <riccardo () kde ! org>
Date: 2009-09-01 12:33:38
Message-ID: 1251808418.149580.21520.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1018186 by ruphy:
fix intendation, begin refactoring
Signed-off-by: Riccardo Iaconelli <riccardo@kde.org>
M +84 -52 clock.cpp
M +2 -0 clock.h
--- trunk/playground/base/plasma/applets/train-clock/clock.cpp #1018185:1018186
@@ -30,6 +30,7 @@
#include <QCheckBox>
#include <QPushButton>
#include <QTimeLine>
+#include <QGraphicsGridLayout>
#include <KConfigDialog>
#include <KDebug>
@@ -43,22 +44,23 @@
#include <Plasma/FrameSvg>
#include <Plasma/PaintUtils>
#include <Plasma/Svg>
+#include <Plasma/SvgWidget>
#include <Plasma/Theme>
#include "clocknumber.h"
Clock::Clock(QObject *parent, const QVariantList &args)
-: ClockApplet(parent, args),
-m_showSecondHand(false),
-m_showTimezoneString(false),
-m_showingTimezone(false),
-m_tzFrame(0),
-m_repaintCache(RepaintAll),
-m_faceCache(QPixmap()),
-m_handsCache(QPixmap()),
-m_glassCache(QPixmap()),
-m_secondHandUpdateTimer(0),
-m_animateSeconds(false)
+ : ClockApplet(parent, args),
+ m_showSecondHand(false),
+ m_showTimezoneString(false),
+ m_showingTimezone(false),
+ m_tzFrame(0),
+ m_repaintCache(RepaintAll),
+ m_faceCache(QPixmap()),
+ m_handsCache(QPixmap()),
+ m_glassCache(QPixmap()),
+ m_secondHandUpdateTimer(0),
+ m_animateSeconds(false)
{
KGlobal::locale()->insertCatalog("libplasmaclock");
// this catalog is only used once on the first start of the clock to translate the timezone in the configuration file
@@ -106,6 +108,7 @@
connectToEngine();
updateSizes();
+ initElements();
}
void Clock::connectToEngine()
@@ -113,11 +116,11 @@
m_lastTimeSeen = QTime();
Plasma::DataEngine* timeEngine = dataEngine("time");
- if (m_showSecondHand) {
+// if (m_showSecondHand) {
timeEngine->connectSource(currentTimezone(), this, 500);
- } else {
- timeEngine->connectSource(currentTimezone(), this, 6000, Plasma::AlignToMinute);
- }
+// } else {
+// timeEngine->connectSource(currentTimezone(), this, 6000, Plasma::AlignToMinute);
+// }
}
void Clock::constraintsEvent(Plasma::Constraints constraints)
@@ -175,7 +178,12 @@
m_animateSeconds = true;
m_lastTimeSeen = m_time;
- update();
+// if (m_time.minute() != m_lastTimeSeen.minute()) {
+// m_lastTimeSeen = m_time;
+// animateUpdate();
+// }
+// update();
+ animateUpdate();
speakTime(m_time);
}
@@ -187,7 +195,6 @@
ui.setupUi(widget);
parent->addPage(widget, i18n("Appearance"), "view-media-visualization");
-// ui.showSecondHandCheckBox->setChecked(m_showSecondHand);
// ui.showTimezoneStringCheckBox->setChecked(m_showTimezoneString);
}
@@ -211,11 +218,11 @@
dataEngine("time")->disconnectSource(oldTimezone, this);
Plasma::DataEngine* timeEngine = dataEngine("time");
- if (m_showSecondHand) {
+// if (m_showSecondHand) {
timeEngine->connectSource(newTimezone, this, 500);
- } else {
- timeEngine->connectSource(newTimezone, this, 6000, Plasma::AlignToMinute);
- }
+// } else { FIXME reenable
+// timeEngine->connectSource(newTimezone, this, 6000, Plasma::AlignToMinute);
+// }
if (m_showingTimezone != (m_showTimezoneString || shouldDisplayTimezone())) {
m_showingTimezone = !m_showingTimezone;
@@ -224,6 +231,21 @@
m_repaintCache = RepaintAll;
}
+#undef waaa
+#ifndef waaa
+void Clock::initElements()
+{
+ QGraphicsGridLayout l;
+ for (int i = 0; i <= 5; i++) {
+ Plasma::SvgWidget *w = new Plasma::SvgWidget(m_theme, QString(), this);
+ l.addItem(w, i, 0);
+ w = new Plasma::SvgWidget(m_theme, QString(), this);
+ l.addItem(w, i, 1);
+ }
+
+}
+#endif
+
void Clock::repaintNeeded()
{
m_repaintCache = RepaintAll;
@@ -283,11 +305,20 @@
// kDebug();
QTimeLine *tl = new QTimeLine(200, this);
tl->setFrameRange(0, 4);
- //tl->setCurveShape(QTimeLine::EaseInCurve),
+// tl->setCurveShape(QTimeLine::EaseInCurve);
connect(tl, SIGNAL(frameChanged(int)), this, SLOT(animationSlot(int)));
+ connect(tl, SIGNAL(finished()), this, SLOT(finishAnimation()));
tl->start();
}
+void Clock::finishAnimation()
+{
+ m_animating = false;
+ m_lastTimeSeen = m_time;
+ update();
+ kDebug() << "finished";
+}
+
void Clock::animationSlot(const int step)
{
// kDebug();
@@ -299,7 +330,7 @@
} else {
m_animating = true;
m_animationStep = step;
- // kDebug() << "step:" << m_animationStep;
+ kDebug() << "step:" << m_animationStep;
update();
}
}
@@ -323,6 +354,7 @@
void Clock::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &rect)
{
+ #if 0
// kDebug() << "time" << m_time.isValid() << "date" << m_date.isValid();
// p->drawRect(contentsRect());
// TODO implement flipping seconds, disabled by default, and disable anyway when
@@ -339,28 +371,28 @@
// Paint the text
QString dateString;
-// if (m_showDate || m_showTimezone) {
-//
-// if (m_showDate) {
-// dateString = m_date.toString("d MMM");
-// if (m_showDay) {
-// QString weekday = QDate::shortDayName(m_date.dayOfWeek());
-// dateString = weekday + ", " + dateString;
-// }
-// if (m_showYear) {
-// dateString = dateString + m_date.toString(" yyyy");
-// }
-// }
-//
-// if (m_showTimezone) {
-// dateString = dateString + " " + m_prettyTimezone;
-// dateString.replace("_", " ");
-// }
-//
-// p->drawText(m_dateRect, dateString,
-// QTextOption (Qt::AlignCenter));
+ if (m_showDate || m_showTimezone) {
+
+ if (m_showDate) {
+ dateString = m_date.toString("d MMM");
+ if (m_showDay) {
+ QString weekday = QDate::shortDayName(m_date.dayOfWeek());
+ dateString = weekday + ", " + dateString;
+ }
+ if (m_showYear) {
+ dateString = dateString + m_date.toString(" yyyy");
+ }
+ }
+
+ if (m_showTimezone) {
+ dateString = dateString + " " + m_prettyTimezone;
+ dateString.replace("_", " ");
+ }
+
+ p->drawText(m_dateRect, dateString,
+ QTextOption (Qt::AlignCenter));
// kDebug() << "Painting" << dateString;
-// }
+ }
m_theme->resize(m_timeRect.width(), m_timeRect.height());
@@ -376,14 +408,14 @@
int bottomElementTop = upperElementTop + m_elHeight + m_verticalSpacing;
QString show_time;
- if (m_twentyFour) {
- show_time = m_time.toString("hh:mm");
- } else {
- show_time = m_time.toString("hh:mm AP");
- }
+// if (m_twentyFour) {
+ show_time = m_time.toString("hh:ss");
+// } else {
+// show_time = m_time.toString("hh:mm AP");
+// }
const QString timeString = show_time;
- kDebug() << QRectF(leftOffset, upperElementTop, m_elWidth, m_elHeight);
+// kDebug() << "time:" << timeString;
// 10-hours-digit
m_theme->paint(p, QRectF(leftOffset, upperElementTop, m_elWidth, m_elHeight), 'e'+timeString[0]+"-p1");
@@ -409,7 +441,7 @@
leftOffset = getOffsetForDigit(4);
m_theme->paint(p, QRectF(leftOffset, upperElementTop, m_elWidth, m_elHeight), 'e'+timeString[4]+"-p1");
m_theme->paint(p, QRectF(leftOffset, bottomElementTop, m_elWidth, m_elHeight), 'e'+timeString[4]+"-p2");
-#if 0
+
// Make sure we don't get artifacts if an update gets called while animating
if (m_animating) {
// If we are aninmating, this digit is for sure.
@@ -485,8 +517,8 @@
}
}
}
- #endif
}
+ #endif
}
QRect Clock::tzRect()
--- trunk/playground/base/plasma/applets/train-clock/clock.h #1018185:1018186
@@ -65,8 +65,10 @@
void clockConfigAccepted();
void repaintNeeded();
void animationSlot(int step);
+ void finishAnimation();
private:
+ void initElements();
void connectToEngine();
QRect tzRect();
Plasma::FrameSvg *tzFrame();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic