summaryrefslogtreecommitdiff
path: root/graphicswatchlet.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-09-16 17:47:24 +0200
committerJavier <javier@pcjavier.(none)>2011-09-16 17:47:24 +0200
commitaa1c0fd3146b4ed055d181c99d52463afa6bedbb (patch)
treef6fb8d9693ad8c545ddabf76312f8f33b5b9878f /graphicswatchlet.cpp
downloadsowatch-aa1c0fd3146b4ed055d181c99d52463afa6bedbb.tar.gz
sowatch-aa1c0fd3146b4ed055d181c99d52463afa6bedbb.zip
Initial import
Diffstat (limited to 'graphicswatchlet.cpp')
-rw-r--r--graphicswatchlet.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/graphicswatchlet.cpp b/graphicswatchlet.cpp
new file mode 100644
index 0000000..130e1cc
--- /dev/null
+++ b/graphicswatchlet.cpp
@@ -0,0 +1,47 @@
+#include <QtCore/QDebug>
+#include <QtGui/QPainter>
+
+#include "watch.h"
+#include "graphicswatchlet.h"
+
+using namespace sowatch;
+
+GraphicsWatchlet::GraphicsWatchlet(WatchServer* server, const QString& id) :
+ Watchlet(server, id), _scene(0), _damaged()
+{
+}
+
+QGraphicsScene* GraphicsWatchlet::scene()
+{
+ return _scene;
+}
+
+void GraphicsWatchlet::setScene(QGraphicsScene *scene)
+{
+ if (_scene) {
+ disconnect(this, SLOT(sceneChanged(QList<QRectF>)));
+ }
+ _scene = scene;
+ if (_scene) {
+ connect(_scene, SIGNAL(changed(QList<QRectF>)),
+ this, SLOT(sceneChanged(QList<QRectF>)));
+ }
+}
+
+void GraphicsWatchlet::sceneChanged(const QList<QRectF> &region)
+{
+ foreach(const QRectF& r, region)
+ {
+ _damaged += r.toRect();
+ }
+
+ if (!_damaged.isEmpty() && !watch()->busy()) {
+ const QVector<QRect> rects = _damaged.rects();
+ QPainter p(watch());
+ foreach(const QRect& r, rects)
+ {
+ _scene->render(&p, r, r, Qt::IgnoreAspectRatio);
+ }
+ _damaged = QRegion();
+ }
+}