SVN commit 866474 by aseigo: more best practices M +18 -10 SlideInSlideOut.cpp M +5 -17 SlideInSlideOut.h --- trunk/playground/base/plasma/applets/slideInSlideOut/SlideInSlideOut.cpp #866473:866474 @@ -19,10 +19,11 @@ #include "SlideInSlideOut.h" +#include + #include #include -#include #include #include #include @@ -34,11 +35,10 @@ : Plasma::Applet(parent, args), m_out(true) { - m_theme = new Plasma::Svg(this); - m_theme->setImagePath("widgets/connection-established"); - t = new QTimer(this); - connect(t, SIGNAL(timeout()), this, SLOT(moveMyself())); - resize(100,100); + m_theme.setImagePath("widgets/connection-established"); + t.setInterval(1000); + connect(&t, SIGNAL(timeout()), this, SLOT(moveMyself())); + resize(100, 100); } SlideInSlideOut::~SlideInSlideOut() @@ -47,13 +47,15 @@ void SlideInSlideOut::init() { - t->start(1000); + connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)), + this, SLOT(movementFinished(QGraphicsItem*))); + moveMyself(); } void SlideInSlideOut::constraintsEvent(Plasma::Constraints constraints) { if (constraints & Plasma::SizeConstraint) { - m_theme->resize(contentsRect().size()); + m_theme.resize(contentsRect().size()); } } @@ -63,7 +65,7 @@ Q_UNUSED(option); QRectF contRect = this->contentsRect(); p->setRenderHint(QPainter::SmoothPixmapTransform); - m_theme->paint(p, contRect.toRect(), "layer1"); + m_theme.paint(p, contRect.toRect(), "layer1"); } void SlideInSlideOut::moveMyself() @@ -77,8 +79,14 @@ } m_out = !m_out; - t->start(1000); } +void SlideInSlideOut::movementFinished(QGraphicsItem *item) +{ + if (item == this) { + t.start(); + } +} + #include "SlideInSlideOut.moc" --- trunk/playground/base/plasma/applets/slideInSlideOut/SlideInSlideOut.h #866473:866474 @@ -22,19 +22,12 @@ #include -#include #include -#include +#include -class QTimer; +class QPainter; - -namespace Plasma -{ - class Svg; -} - class SlideInSlideOut : public Plasma::Applet { Q_OBJECT @@ -48,17 +41,12 @@ private slots: void moveMyself(); + void movementFinished(QGraphicsItem *); private: - - QRectF m_bounds; - int m_pixelSize; - QString m_timezone; - Plasma::Svg* m_theme; + QTimer t; + Plasma::Svg m_theme; bool m_out; - int x; - int y; - QTimer *t; }; K_EXPORT_PLASMA_APPLET(slideInSlideOut, SlideInSlideOut)