summaryrefslogtreecommitdiff
path: root/libsowatch/graphicswatchlet.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-09-27 04:51:30 +0200
committerJavier S. Pedro <maemo@javispedro.com>2011-09-27 04:51:30 +0200
commita644a7cc6749f8dd5ca20589ee6e59acc2892b3e (patch)
treeb995528dc14d1f58d9d7c958d1eaad855b2a2412 /libsowatch/graphicswatchlet.cpp
parent0822b88738e00625efd27ccca9119885272924d2 (diff)
downloadsowatch-a644a7cc6749f8dd5ca20589ee6e59acc2892b3e.tar.gz
sowatch-a644a7cc6749f8dd5ca20589ee6e59acc2892b3e.zip
new qmafw watchlet
Diffstat (limited to 'libsowatch/graphicswatchlet.cpp')
-rw-r--r--libsowatch/graphicswatchlet.cpp44
1 files changed, 34 insertions, 10 deletions
diff --git a/libsowatch/graphicswatchlet.cpp b/libsowatch/graphicswatchlet.cpp
index 195d11b..e11d5cc 100644
--- a/libsowatch/graphicswatchlet.cpp
+++ b/libsowatch/graphicswatchlet.cpp
@@ -8,8 +8,15 @@
using namespace sowatch;
GraphicsWatchlet::GraphicsWatchlet(WatchServer* server, const QString& id) :
- Watchlet(server, id), _scene(0), _damaged()
+ Watchlet(server, id), _scene(0), _frameTimer(), _damaged()
{
+ _frameTimer.setSingleShot(true);
+ connect(&_frameTimer, SIGNAL(timeout()), SLOT(frameTimeout()));
+}
+
+GraphicsWatchlet::~GraphicsWatchlet()
+{
+
}
QGraphicsScene* GraphicsWatchlet::scene()
@@ -20,7 +27,7 @@ QGraphicsScene* GraphicsWatchlet::scene()
void GraphicsWatchlet::setScene(QGraphicsScene *scene)
{
if (_scene) {
- disconnect(this, SLOT(sceneChanged(QList<QRectF>)));
+ disconnect(_scene, 0, this, 0);
}
_scene = scene;
if (_scene) {
@@ -34,15 +41,26 @@ void GraphicsWatchlet::sceneChanged(const QList<QRectF> &region)
foreach(const QRectF& r, region) {
_damaged += r.toRect();
}
- if (!_damaged.isEmpty() && _active && !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();
+ if (!_damaged.isEmpty()) {
+ _frameTimer.start(frameDelay);
+ }
+}
+
+void GraphicsWatchlet::frameTimeout()
+{
+ if (!_active) return; // Watchlet was ejected, do not draw.
+ if (watch()->busy()) {
+ _frameTimer.start(busyFrameDelay);
+ return;
+ }
+
+ const QVector<QRect> rects = _damaged.rects();
+ QPainter p(watch());
+
+ foreach(const QRect& r, rects) {
+ _scene->render(&p, r, r, Qt::IgnoreAspectRatio);
}
+ _damaged = QRegion();
}
void GraphicsWatchlet::activate()
@@ -53,3 +71,9 @@ void GraphicsWatchlet::activate()
_damaged += area;
_scene->update(area);
}
+
+void GraphicsWatchlet::deactivate()
+{
+ _frameTimer.stop();
+ Watchlet::deactivate();
+}