summaryrefslogtreecommitdiff
path: root/metawatch/metawatchsimulator.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-09-17 03:58:13 +0200
committerJavier S. Pedro <maemo@javispedro.com>2011-09-17 03:58:13 +0200
commitf225345d4de3b198a557fe3566f9630163e76d51 (patch)
treecca7ba40e560226c138a1d4fc44b032f8fd6c808 /metawatch/metawatchsimulator.cpp
parentb0771d893865ca249bbf191636fad593901cce03 (diff)
downloadsowatch-f225345d4de3b198a557fe3566f9630163e76d51.tar.gz
sowatch-f225345d4de3b198a557fe3566f9630163e76d51.zip
Putting MetaWatch stuff in a plugin
Diffstat (limited to 'metawatch/metawatchsimulator.cpp')
-rw-r--r--metawatch/metawatchsimulator.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/metawatch/metawatchsimulator.cpp b/metawatch/metawatchsimulator.cpp
new file mode 100644
index 0000000..11b938a
--- /dev/null
+++ b/metawatch/metawatchsimulator.cpp
@@ -0,0 +1,82 @@
+#include <QtCore/QDebug>
+#include <QtGui/QPainter>
+
+#include "metawatchsimulator.h"
+
+#define SIMULATE_DAMAGES 1
+#define SIMULATE_FRAMERATE 1
+
+using namespace sowatch;
+
+MetaWatchSimulator::MetaWatchSimulator(QObject *parent) :
+ WatchSimulator(QImage(96, 96, QImage::Format_Mono), parent),
+ _screen(96, 96),
+ _form(new MetaWatchSimulatorForm),
+ _nextFrame(QTime::currentTime())
+{
+ _form->showNormal();
+ connect(_form, SIGNAL(destroyed()), SIGNAL(disconnected()));
+ connect(_form, SIGNAL(buttonPressed(int)), SIGNAL(buttonPressed(int)));
+ connect(_form, SIGNAL(buttonReleased(int)), SIGNAL(buttonReleased(int)));
+}
+
+MetaWatchSimulator::~MetaWatchSimulator()
+{
+ delete _form;
+}
+
+QString MetaWatchSimulator::model() const
+{
+ return "metawatch-digital";
+}
+
+bool MetaWatchSimulator::isConnected() const
+{
+ return true;
+}
+
+bool MetaWatchSimulator::busy() const
+{
+#if SIMULATE_FRAMERATE
+ return _nextFrame > QTime::currentTime();
+#else
+ return false;
+#endif
+}
+
+void MetaWatchSimulator::update(const QList<QRect> &rects)
+{
+#if SIMULATE_DAMAGES
+ const QRect imageRect = _image.rect();
+ QPainter p;
+ QVector<bool> rows(96, false);
+ unsigned total = 0, totalRows;
+
+ p.begin(&_screen);
+ foreach (const QRect& rect, rects) {
+ QRect r = rect.intersect(imageRect);
+ for (int i = r.top(); i <= r.bottom(); i++) {
+ rows[i] = true;
+ }
+ total += r.width() * r.height();
+
+ p.drawImage(r, _image, r);
+ }
+ p.end();
+
+ totalRows = rows.count(true);
+
+ _form->refreshScreen(_screen);
+
+ qDebug() << "updated " << total << " pixels " << totalRows << " lines";
+ _nextFrame = QTime::currentTime().addMSecs(((totalRows / 2) + 1) * 30);
+#else
+ _form->refreshScreen(QPixmap::fromImage(_image));
+ _nextFrame = QTime::currentTime().addMSecs(30);
+#endif
+}
+
+void MetaWatchSimulator::vibrate(bool on)
+{
+ qDebug() << "vibrate" << on;
+}