diff options
Diffstat (limited to 'libsowatch/graphicswatchlet.cpp')
-rw-r--r-- | libsowatch/graphicswatchlet.cpp | 44 |
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> ®ion) 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(); +} |