From 3a755f46d9cf6e3650d40a960d0d0db8c1ad9fa1 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 17 Sep 2011 03:03:23 +0200 Subject: preparing for library package --- libsowatch/graphicswatchlet.cpp | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 libsowatch/graphicswatchlet.cpp (limited to 'libsowatch/graphicswatchlet.cpp') diff --git a/libsowatch/graphicswatchlet.cpp b/libsowatch/graphicswatchlet.cpp new file mode 100644 index 0000000..538723a --- /dev/null +++ b/libsowatch/graphicswatchlet.cpp @@ -0,0 +1,47 @@ +#include +#include + +#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))); + } + _scene = scene; + if (_scene) { + connect(_scene, SIGNAL(changed(QList)), + this, SLOT(sceneChanged(QList))); + } +} + +void GraphicsWatchlet::sceneChanged(const QList ®ion) +{ + foreach(const QRectF& r, region) + { + _damaged += r.toRect(); + } + + if (!_damaged.isEmpty() && _active && !watch()->busy()) { + const QVector rects = _damaged.rects(); + QPainter p(watch()); + foreach(const QRect& r, rects) + { + _scene->render(&p, r, r, Qt::IgnoreAspectRatio); + } + _damaged = QRegion(); + } +} -- cgit v1.2.3