From abdf3b1eaba8151f1b8e862750c38cb7a5411d2a Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Mon, 13 Aug 2012 21:31:52 +0200 Subject: make watchsimulator work again --- metawatch/metawatchdigitalsimulator.cpp | 119 ++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 metawatch/metawatchdigitalsimulator.cpp (limited to 'metawatch/metawatchdigitalsimulator.cpp') diff --git a/metawatch/metawatchdigitalsimulator.cpp b/metawatch/metawatchdigitalsimulator.cpp new file mode 100644 index 0000000..f12e987 --- /dev/null +++ b/metawatch/metawatchdigitalsimulator.cpp @@ -0,0 +1,119 @@ +#include +#include + +#include "metawatchdigitalsimulator.h" + +#define SIMULATE_DAMAGES 1 +#define SIMULATE_FRAMERATE 1 + +using namespace sowatch; + +MetaWatchDigitalSimulator::MetaWatchDigitalSimulator(ConfigKey *config, QObject *parent) : + MetaWatchDigital(config, parent), + _form(new MetaWatchDigitalSimulatorForm), + _nextFrame(QTime::currentTime()) +{ + _pixmap[IdleMode] = QPixmap(screenWidth, screenHeight); + _pixmap[ApplicationMode] = QPixmap(screenWidth, screenHeight); + _pixmap[NotificationMode] = QPixmap(screenWidth, screenHeight); + _form->showNormal(); + connect(_form, SIGNAL(buttonPressed(int)), SIGNAL(buttonPressed(int))); + connect(_form, SIGNAL(buttonReleased(int)), SIGNAL(buttonReleased(int))); +} + +MetaWatchDigitalSimulator::~MetaWatchDigitalSimulator() +{ + delete _form; +} + +bool MetaWatchDigitalSimulator::busy() const +{ +#if SIMULATE_FRAMERATE + return _nextFrame > QTime::currentTime(); +#else + return false; +#endif +} + +void MetaWatchDigitalSimulator::displayIdleScreen() +{ + MetaWatchDigital::displayIdleScreen(); + _form->refreshScreen(_pixmap[_currentMode]); +} + +void MetaWatchDigitalSimulator::displayNotification(Notification *notification) +{ + MetaWatchDigital::displayNotification(notification); + _form->refreshScreen(_pixmap[_currentMode]); +} + +void MetaWatchDigitalSimulator::displayApplication() +{ + MetaWatchDigital::displayApplication(); + // No need to refresh. +} + +void MetaWatchDigitalSimulator::clear(Mode mode, bool black) +{ + _pixmap[mode].fill(black ? Qt::black : Qt::white); + if (mode == _currentMode) { + _form->refreshScreen(_pixmap[mode]); + } +} + +void MetaWatchDigitalSimulator::update(Mode mode, const QList &rects) +{ +#if SIMULATE_DAMAGES + const QRect imageRect = _image[mode].rect(); + QPainter p; + QVector rows(96, false); + + p.begin(&_pixmap[mode]); + foreach (const QRect& rect, rects) { + QRect r = rect.intersect(imageRect); + for (int i = r.top(); i <= r.bottom(); i++) { + rows[i] = true; + } + + p.drawImage(r, _image[mode], r); + } + p.end(); + + int totalRows = rows.count(true); + + qDebug() << "updated" << totalRows << "lines"; + _nextFrame = QTime::currentTime().addMSecs(((totalRows / 2) + 1) * DelayBetweenMessages); +#else + Q_UNUSED(rects); + _pixmap[mode] = QPixmap::fromImage(_image[mode]); + _nextFrame = QTime::currentTime().addMSecs(DelayBetweenMessages); +#endif + if (mode == _currentMode) { + _form->refreshScreen(_pixmap[mode]); + } +} + +void MetaWatchDigitalSimulator::vibrate(bool on) +{ + qDebug() << "vibrate" << on; +} + +void MetaWatchDigitalSimulator::retryConnect() +{ + if (!_connected && _form) { + qDebug() << "connected"; + + _connected = true; + _currentMode = IdleMode; + _paintMode = IdleMode; + + handleWatchConnected(); + + emit connected(); + } +} + +void MetaWatchDigitalSimulator::send(const Message &msg) +{ + // Do not send messages +} -- cgit v1.2.3