[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-03 11:45:04
Message-ID: 1251978304.105900.12661.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1019365 by ruphy:
more kinetic stuff
Signed-off-by: Riccardo Iaconelli <riccardo@kde.org>
M +98 -28 clock.cpp
M +1 -1 clock.h
M +19 -0 clocknumber.cpp
M +22 -0 clocknumber.h
--- trunk/playground/base/plasma/applets/train-clock/clock.cpp #1019364:1019365
@@ -33,7 +33,10 @@
#include <QGraphicsGridLayout>
#include <QSequentialAnimationGroup>
#include <QPropertyAnimation>
+#include <QAbstractTransition>
#include <QSizePolicy>
+#include <QState>
+#include <QStateMachine>
#include <KConfigDialog>
#include <KDebug>
@@ -186,7 +189,7 @@
// animateUpdate();
// }
// update();
- adjustElements();
+// adjustElements();
animateUpdate();
speakTime(m_time);
@@ -223,7 +226,7 @@
Plasma::DataEngine* timeEngine = dataEngine("time");
// if (m_showSecondHand) {
- timeEngine->connectSource(newTimezone, this, 500);
+ timeEngine->connectSource(newTimezone, this, 5000);
// } else { FIXME reenable
// timeEngine->connectSource(newTimezone, this, 6000, \
Plasma::AlignToMinute); // }
@@ -256,6 +259,10 @@
void Clock::adjustElements()
{
+ kDebug();
+ m_animatingWidget->hide();
+ m_animatingWidget2->hide();
+
QGraphicsGridLayout *l = dynamic_cast<QGraphicsGridLayout *>(layout());
if(!l) return;
@@ -281,43 +288,105 @@
void Clock::animateUpdate()
{
-
QGraphicsGridLayout *l = dynamic_cast<QGraphicsGridLayout *>(layout());
if(!l) return;
- Plasma::SvgWidget *item = dynamic_cast<Plasma::SvgWidget *>(l->itemAt(0, 4));
- QPropertyAnimation *flip1 = new QPropertyAnimation(m_animatingWidget, \
"geometry"); + Plasma::SvgWidget *item;
- m_animatingWidget->setElementID(item->elementID());
- m_animatingWidget->show();
- QPropertyAnimation *flip2 = new QPropertyAnimation(m_animatingWidget2, \
"geometry");
- flip1->setDuration(500);
- flip1->setStartValue(item->geometry());
- QRectF endRect(QPointF(item->geometry().x(), \
item->geometry().y()+item->geometry().height()), \
QSize(item->geometry().width(), 0));
- flip1->setEndValue(endRect);
-
+ item = dynamic_cast<Plasma::SvgWidget *>(l->itemAt(0, 4));
+ QRectF start1Rect = item->geometry();
+ QRectF end1Rect(QPointF(item->geometry().x(), \
item->geometry().y()+item->geometry().height()), + \
QSize(item->geometry().width(), 0)); +
item = dynamic_cast<Plasma::SvgWidget *>(l->itemAt(1, 4));
+ QRectF start2Rect(QPointF(item->geometry().x(), item->geometry().y()), \
QSize(item->geometry().width(), 0)); + QRectF end2Rect = item->geometry();
- m_animatingWidget2->setElementID(item->elementID());
- m_animatingWidget2->show();
+// QPropertyAnimation *flip1 = new QPropertyAnimation(m_animatingWidget, \
"geometry");
- QPropertyAnimation *elementChange = new QPropertyAnimation(m_animatingWidget, \
"elementID");
- elementChange->setDuration(10);
- kDebug() << m_animatingWidget->elementID();
+ QString time = timeString();
+ int second = time[4].digitValue();
+// second++;
+
+// item->setElementID('e'+QString::number(second)+"-p1");
+
+// m_animatingWidget->setElementID('e'+QString::number(second)+"-p1");
+// kDebug() << m_animatingWidget;
+// m_animatingWidget->show();
+// QPropertyAnimation *flip2 = new QPropertyAnimation(m_animatingWidget2, \
"geometry"); +// flip1->setDuration(300);
+// flip1->setStartValue(item->geometry());
+//
+// flip1->setEndValue(endRect);
+//
+
+// m_animatingWidget2->setElementID(
+// m_animatingWidget2->setElementID('e'+QString::number(second+1)+"-p2");
+// m_animatingWidget2->show();
+
+// QPropertyAnimation *elementChange = new QPropertyAnimation(m_animatingWidget, \
"elementID"); +// elementChange->setDuration(10);
+// kDebug() << m_animatingWidget->elementID();
// elementChange->setStartValue(m_animatingWidget->elementID());
- elementChange->setEndValue(QString("e0-p2"));
+// elementChange->setEndValue(QString("e0-p2"));
- flip2->setDuration(400);
- QRectF startRect(QPointF(item->geometry().x(), item->geometry().y()), \
QSize(item->geometry().width(), 0));
- flip2->setStartValue(startRect);
- flip2->setEndValue(item->geometry());
+// flip2->setDuration(300);
+
+// flip2->setStartValue(startRect);
+// flip2->setEndValue(item->geometry());
// flip2->start();
- QSequentialAnimationGroup *group = new QSequentialAnimationGroup(this);
- group->addAnimation(flip1);
- group->addAnimation(elementChange);
- group->addAnimation(flip2);
- group->start();
+
+ QPropertyAnimation *flip1 = new QPropertyAnimation(m_animatingWidget, \
"geometry"); + flip1->setDuration(300);
+ flip1->setEasingCurve(QEasingCurve::InSine);
+ QPropertyAnimation *flip2 = new QPropertyAnimation(m_animatingWidget, \
"geometry"); + flip2->setDuration(300);
+ flip2->setEasingCurve(QEasingCurve::OutSine);
+
+// flip2->setEasingCurve(QEasingCurve::OutSine);
+ QStateMachine *states = new QStateMachine(this);
+ QState *rootState = new QState;
+ QState *beginState = new QState(rootState);
+ QState *halfFlip = new QState(rootState);
+ QState *endState = new QState(rootState);
+
+ beginState->assignProperty(m_animatingWidget, "visible", true);
+ beginState->assignProperty(m_animatingWidget, "elementID", \
'e'+QString::number(second)+"-p1"); + \
beginState->assignProperty(m_animatingWidget, "geometry", start1Rect); + \
halfFlip->assignProperty(m_animatingWidget, "geometry", end1Rect); + \
halfFlip->assignProperty(m_animatingWidget, "elementID", \
'e'+QString::number(second)+"-p1"); + endState->assignProperty(m_animatingWidget, \
"geometry", end2Rect); + endState->assignProperty(m_animatingWidget, "visible", \
false); +
+ states->addState(rootState);
+ states->setInitialState(rootState);
+ rootState->setInitialState(beginState);
+ QAbstractTransition *trans = rootState->addTransition(halfFlip);
+ trans->addAnimation(flip1);
+ trans = rootState->addTransition(endState);
+ trans->addAnimation(flip2);
+
+ states->start();
+
+// halfFlip.assignProperty(m_animatingWidget, "geometry", endRect);
+// end.assignProperty(m_animatingWidget, "geometry", endRect);
+/*
+ NumberAnimation *hide = new NumberAnimation(m_animatingWidget2, "visible");
+ hide->setDuration(100);
+ hide->setStartValue(true);
+ hide->setEndValue(false);
+ hide->start();*/
+
+// QSequentialAnimationGroup *group = new QSequentialAnimationGroup(this);
+// group->addAnimation(flip1);
+ // group->addAnimation(elementChange);
+// group->addAnimation(flip2);
+// group->addAnimation(hide);
+// group->start();
+
+// connect(flip2, SIGNAL(finished()), m_animatingWidget, SLOT(hide()));
+// connect(flip2, SIGNAL(finished()), this, SLOT(adjustElements()));
}
QString Clock::timeString()
@@ -327,6 +396,7 @@
#endif
+
void Clock::repaintNeeded()
{
m_repaintCache = RepaintAll;
--- trunk/playground/base/plasma/applets/train-clock/clock.h #1019364:1019365
@@ -67,10 +67,10 @@
void repaintNeeded();
void animationSlot(int step);
void finishAnimation();
+ void adjustElements();
private:
void initElements();
- void adjustElements();
void connectToEngine();
QString timeString();
QRect tzRect();
--- trunk/playground/base/plasma/applets/train-clock/clocknumber.cpp #1019364:1019365
@@ -18,6 +18,8 @@
***************************************************************************/
#include "clocknumber.h"
+#include <QtCore/QVariant>
+#include <KDebug>
class Number::Private
{
@@ -69,3 +71,20 @@
return d->data;
}
+QVariant NumberAnimation::interpolated(const QVariant & from, const QVariant & to, \
qreal progress) +{
+ kDebug();
+ if (from.canConvert(QVariant::Bool) && progress) {
+ kDebug() << "bool";
+ return to;
+ }
+
+ if (from.canConvert(QVariant::String) && progress) {
+ return to;
+ }
+
+ QPropertyAnimation::interpolated(from, to, progress);
+// return QVariant();
+}
+
+
--- trunk/playground/base/plasma/applets/train-clock/clocknumber.h #1019364:1019365
@@ -21,7 +21,13 @@
#define CLOCKNUMBER_H
#include <QtCore/QChar>
+#include <QtCore/QPropertyAnimation>
+#include <KDebug>
+class QVariant;
+class QObject;
+class QByteArray;
+
class Number
{
public:
@@ -38,5 +44,21 @@
Private * const d;
};
+class NumberAnimation : public QPropertyAnimation
+{
+ public:
+ NumberAnimation ( QObject * target, const QByteArray & propertyName, QObject \
* parent = 0 ) + : QPropertyAnimation ( target, propertyName, parent)
+ {};
+ protected:
+ virtual QVariant interpolated(const QVariant & from, const QVariant & to, \
qreal progress); // animate qstring and bool. + virtual void \
updateCurrentValue ( const QVariant & value ) + {
+ kDebug() << value.toBool();
+ QPropertyAnimation::updateCurrentValue ( value );
+ }
+
+};
+
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic