diff options
-rw-r--r-- | metawatch/metawatch.cpp | 280 | ||||
-rw-r--r-- | metawatch/metawatch.h | 36 | ||||
-rw-r--r-- | metawatch/metawatch.pro | 8 | ||||
-rw-r--r-- | metawatch/metawatchdigital.cpp | 311 | ||||
-rw-r--r-- | metawatch/metawatchdigital.h | 49 | ||||
-rw-r--r-- | metawatch/metawatchpaintengine.cpp | 6 | ||||
-rw-r--r-- | metawatch/metawatchpaintengine.h | 2 | ||||
-rw-r--r-- | metawatch/metawatchplugin.cpp | 4 |
8 files changed, 390 insertions, 306 deletions
diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp index 0ffa5b4..4a57174 100644 --- a/metawatch/metawatch.cpp +++ b/metawatch/metawatch.cpp @@ -80,7 +80,6 @@ const quint16 MetaWatch::crcTable[256] = { MetaWatch::MetaWatch(const QBluetoothAddress& address, QSettings* settings, QObject* parent) : Watch(parent), - _nMails(0), _nCalls(0), _nIms(0), _nSms(0), _nMms(0), _idleTimer(new QTimer(this)), _ringTimer(new QTimer(this)), _currentMode(IdleMode), _paintMode(IdleMode), _paintEngine(0), @@ -90,15 +89,6 @@ MetaWatch::MetaWatch(const QBluetoothAddress& address, QSettings* settings, QObj _address(address), _socket(0), _sendTimer(new QTimer(this)) { - QImage baseImage(screenWidth, screenHeight, QImage::Format_MonoLSB); - baseImage.setColor(0, QColor(Qt::white).rgb()); - baseImage.setColor(1, QColor(Qt::black).rgb()); - _image[IdleMode] = baseImage; - _image[ApplicationMode] = baseImage; - _image[NotificationMode] = baseImage; - - _buttonNames << "A" << "B" << "C" << "D" << "E" << "F"; - if (settings) { _24hMode = settings->value("24hMode", false).toBool(); _dayMonthOrder = settings->value("DayMonthOrder", false).toBool(); @@ -108,6 +98,8 @@ MetaWatch::MetaWatch(const QBluetoothAddress& address, QSettings* settings, QObj _invertedApplications = settings->value("InvertedApplications", false).toBool(); } + _buttonNames << "A" << "B" << "C" << "D" << "E" << "F"; + _idleTimer->setInterval(_notificationTimeout * 1000); _idleTimer->setSingleShot(true); connect(_idleTimer, SIGNAL(timeout()), SIGNAL(idling())); @@ -140,36 +132,9 @@ QPaintEngine* MetaWatch::paintEngine() const return _paintEngine; } -int MetaWatch::metric(PaintDeviceMetric metric) const -{ - switch (metric) { - case PdmWidth: - return screenWidth; - case PdmHeight: - return _currentMode == IdleMode ? - screenHeight - systemAreaHeight: screenHeight; - case PdmWidthMM: - return 24; - case PdmHeightMM: - return _currentMode == IdleMode ? 16 : 24; - case PdmNumColors: - return 2; - case PdmDepth: - return 1; - case PdmDpiX: - case PdmPhysicalDpiX: - return 96; - case PdmDpiY: - case PdmPhysicalDpiY: - return 96; - } - - return -1; -} - QString MetaWatch::model() const { - return "metawatch-digital"; + return "metawatch"; } QStringList MetaWatch::buttons() const @@ -225,117 +190,20 @@ void MetaWatch::ungrabButton(int button) ungrabButton(_currentMode, (Button) button); } -void MetaWatch::updateNotificationCount(Notification::Type type, int count) -{ - switch (type) { - case Notification::MissedCallNotification: - _nCalls = count; - break; - case Notification::EmailNotification: - _nMails = count; - break; - case Notification::ImNotification: - _nIms = count; - break; - case Notification::SmsNotification: - _nSms = count; - break; - case Notification::MmsNotification: - _nMms = count; - break; - default: - return; // Since this notification won't show up in idle screen, we do not redraw. - break; - } - - if (isConnected()) { - renderIdleCounts(); - } -} - void MetaWatch::displayIdleScreen() { _currentMode = IdleMode; + _paintMode = IdleMode; _ringTimer->stop(); _idleTimer->stop(); setVibrateMode(false, 0, 0, 0); - updateDisplay(IdleMode); - // Usually, idle screen is kept updated, so we can show it already. - qDebug() << "displayIdle"; } -void MetaWatch::displayNotification(Notification *n) +void MetaWatch::displayNotification(Notification *notification) { - const bool shouldRing = n->type() == Notification::CallNotification; _currentMode = NotificationMode; _paintMode = NotificationMode; - configureWatchMode(NotificationMode, shouldRing ? 120 : 10, _invertedNotifications); - - QPainter p; - QFont sf("MetaWatch Small caps 8pt"); - QFont lf("MetaWatch Large 16pt"); - QFont mf("MetaWatch Large 16pt"); - QImage icon = iconForNotification(n); - - sf.setPixelSize(8); - mf.setPixelSize(14); - lf.setPixelSize(16); - - const int iconW = icon.width(), iconH = icon.height(); - const int margin = 4; - const int x = margin; - const int iconY = margin; - const int titleY = margin*2 + iconH; - const int dateX = x + iconW + margin; - int textFlags; - QString text; - - qDebug() << "displayNotification" << n->title() << n->body(); - - p.begin(this); - - p.fillRect(0, 0, screenWidth, screenHeight, Qt::white); - p.drawImage(x, iconY, icon); - - p.setPen(Qt::black); - - p.setFont(sf); - textFlags = Qt::AlignRight | Qt::AlignVCenter | Qt::TextWordWrap; - text = n->displayTime(); - QRect dateRect(dateX, iconY, (screenWidth - dateX) - margin, iconH); - p.drawText(dateRect, textFlags, text); - - p.setFont(lf); - textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap; - text = n->title(); - - QRect titleMaxRect(x, titleY, screenWidth - x*2, screenHeight - titleY); - QRect titleRect = p.boundingRect(titleMaxRect, textFlags, text); - if (titleRect.width() > titleMaxRect.width()) { - textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere; - titleRect = p.boundingRect(titleMaxRect, textFlags, text); - } - - p.drawText(titleMaxRect, textFlags, text); - - p.setFont(mf); - textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap; - text = n->body(); - - int bodyY = titleRect.y() + titleRect.height(); - if (bodyY >= screenHeight) return; - - QRect bodyMaxRect(x, bodyY, titleMaxRect.width(), screenHeight - bodyY); - QRect bodyRect = p.boundingRect(bodyMaxRect, textFlags, text); - if (bodyRect.width() > bodyMaxRect.width()) { - textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere; - } - - p.drawText(bodyMaxRect, textFlags, text); - - p.end(); - - if (n->type() == Notification::CallNotification) { + if (notification->type() == Notification::CallNotification) { timedRing(); _ringTimer->start(); _idleTimer->stop(); @@ -352,8 +220,6 @@ void MetaWatch::displayApplication() _paintMode = ApplicationMode; _ringTimer->stop(); _idleTimer->stop(); - configureWatchMode(ApplicationMode, 250, _invertedApplications); - qDebug() << "displayApplication"; } void MetaWatch::vibrate(int msecs) @@ -376,31 +242,6 @@ QImage* MetaWatch::imageFor(Mode mode) return &_image[mode]; } -void MetaWatch::update(Mode mode, const QList<QRect> &rects) -{ - if (!_connected) return; - const QRect clipRect(0, 0, screenWidth, screenHeight); - QVector<bool> lines(screenHeight, false); - - foreach (const QRect& rect, rects) { - QRect r = rect.intersect(clipRect); - for (int i = r.top(); i <= r.bottom(); i++) { - lines[i] = true; - } - } - - updateLines(mode, _image[mode], lines); - if (mode == _currentMode) { - updateDisplay(mode); - } -} - -void MetaWatch::clear(Mode mode, bool black) -{ - if (!_connected) return; - loadTemplate(mode, black ? 1 : 0); -} - void MetaWatch::grabButton(Mode mode, Button button) { enableButton(mode, button, PressOnly); @@ -413,107 +254,6 @@ void MetaWatch::ungrabButton(Mode mode, Button button) disableButton(mode, button, PressAndRelease); } -void MetaWatch::renderIdleScreen() -{ - QImage idle_call(QString(":/metawatch/graphics/idle_call.bmp")); - QImage idle_sms(QString(":/metawatch/graphics/idle_sms.bmp")); - QImage idle_mail(QString(":/metawatch/graphics/idle_gmail.bmp")); - QPainter p; - - _paintMode = IdleMode; - p.begin(this); - - p.fillRect(0, 0, screenWidth, screenHeight, Qt::white); - - p.setPen(QPen(Qt::black, 1.0, Qt::DashLine)); - p.drawLine(1, systemAreaHeight + 2, screenWidth - 2, systemAreaHeight + 2); - p.drawLine(1, systemAreaHeight * 2 + 4, screenWidth - 2, systemAreaHeight * 2 + 4); - - p.drawImage((32 * 0) + 4, systemAreaHeight * 2 + 7, idle_call); - p.drawImage((32 * 1) + 4, systemAreaHeight * 2 + 7, idle_sms); - p.drawImage((32 * 2) + 4, systemAreaHeight * 2 + 7, idle_mail); - - p.end(); - _paintMode = _currentMode; - - renderIdleWeather(); - renderIdleCounts(); -} - -void MetaWatch::renderIdleWeather() -{ - _paintMode = IdleMode; - QFont f("MetaWatch Small caps 8pt", 6); - QImage rain(QString(":/metawatch/graphics/weather_rain.bmp")); - QPainter p(this); - - p.setFont(f); - p.drawText(30, systemAreaHeight + 14, "No data!"); - p.drawImage(screenWidth - 26, systemAreaHeight + 6, rain); - - _paintMode = _currentMode; -} - -void MetaWatch::renderIdleCounts() -{ - _paintMode = IdleMode; - QFont f("MetaWatch Large caps 8pt"); - QString s; - QPainter p(this); - QTextOption opt(Qt::AlignCenter); - const int y = systemAreaHeight * 2 + 26; - const int w = 24; - const int h = screenHeight - (y + 1); - const int mails = _nMails; - const int calls = _nCalls; - const int sms = _nSms + _nIms; - - qDebug() << "unread counts" << calls << sms << mails; - - f.setPixelSize(8); // Seems to be the only way to get the desired size. - - p.setFont(f); - p.fillRect(QRect(0, y, screenWidth, h), Qt::white); - p.drawText(QRect((32 * 0) + 4, y, w, h), s.sprintf("%d", calls), opt); - p.drawText(QRect((32 * 1) + 4, y, w, h), s.sprintf("%d", sms), opt); - p.drawText(QRect((32 * 2) + 4, y, w, h), s.sprintf("%d", mails), opt); - - _paintMode = _currentMode; -} - -void MetaWatch::renderNotificationScreen() -{ - _paintMode = NotificationMode; - QPainter p(this); - - p.fillRect(0, 0, screenWidth, screenHeight, Qt::white); - - _paintMode = _currentMode; -} - -QImage MetaWatch::iconForNotification(const Notification *n) -{ - switch (n->type()) { - case Notification::CallNotification: - case Notification::MissedCallNotification: - return QImage(QString(":/metawatch/graphics/phone.bmp")); - break; - case Notification::SmsNotification: - case Notification::MmsNotification: - case Notification::ImNotification: - return QImage(QString(":/metawatch/graphics/message.bmp")); - break; - case Notification::EmailNotification: - return QImage(QString(":/metawatch/graphics/email.bmp")); - break; - case Notification::CalendarNotification: - return QImage(QString(":/metawatch/graphics/timer.bmp")); - break; - default: - return QImage(); - } -} - quint16 MetaWatch::calcCrc(const QByteArray &data, int size) { quint16 remainder = 0xFFFF; @@ -738,10 +478,6 @@ void MetaWatch::socketConnected() // Sync watch date & time setDateTime(QDateTime::currentDateTime()); - // Configure to show watch-rendered clock in idle screen - configureIdleSystemArea(false); - // Follow inverted screen user preference - configureWatchMode(IdleMode, 0, _invertedIdle); // Grab all buttons in both notification and application modes grabButton(ApplicationMode, BtnA); @@ -757,9 +493,7 @@ void MetaWatch::socketConnected() grabButton(NotificationMode, BtnE); grabButton(NotificationMode, BtnF); - // Render the idle screen from zero - renderIdleScreen(); - renderNotificationScreen(); + handleWatchConnected(); emit connected(); } diff --git a/metawatch/metawatch.h b/metawatch/metawatch.h index 9a25134..9c4680b 100644 --- a/metawatch/metawatch.h +++ b/metawatch/metawatch.h @@ -26,10 +26,6 @@ public: explicit MetaWatch(const QBluetoothAddress& address, QSettings* settings = 0, QObject *parent = 0); ~MetaWatch(); - static const int screenWidth = 96; - static const int screenHeight = 96; - static const int systemAreaHeight = 30; - enum MessageType { NoMessage = 0, GetDeviceType = 0x01, @@ -83,7 +79,7 @@ public: }; QPaintEngine* paintEngine() const; - int metric(PaintDeviceMetric metric) const; + int metric(PaintDeviceMetric metric) const = 0; QString model() const; QStringList buttons() const; @@ -106,19 +102,15 @@ public: Mode currentMode() const; Mode paintTargetMode() const; + QImage* imageFor(Mode mode); - void clear(Mode mode, bool black = false); - void update(Mode mode, const QList<QRect>& rects = QList<QRect>()); + QRect rectFor(Mode mode); + + virtual void clear(Mode mode, bool black = false) = 0; + virtual void update(Mode mode, const QList<QRect>& rects = QList<QRect>()) = 0; void grabButton(Mode mode, Button button); void ungrabButton(Mode mode, Button button); - void renderIdleScreen(); - void renderIdleWeather(); - void renderIdleCounts(); - void renderNotificationScreen(); - - QImage iconForNotification(const Notification *n); - protected: // Some configurable stuff. bool _24hMode : 1; @@ -128,9 +120,6 @@ protected: bool _invertedApplications : 1; short _notificationTimeout; - // Notifications: Unread count - uint _nMails, _nCalls, _nIms, _nSms, _nMms; - // Notifications: timers QTimer* _idleTimer; QTimer* _ringTimer; @@ -175,11 +164,10 @@ protected: static const quint8 bitRevTable[16]; static const quint16 crcTable[256]; - quint16 calcCrc(const QByteArray& data, int size); - quint16 calcCrc(const Message& msg); + static quint16 calcCrc(const QByteArray& data, int size); + static quint16 calcCrc(const Message& msg); void send(const Message& msg); - void handleMessage(const Message& msg); void setVibrateMode(bool enable, uint on, uint off, uint cycles); void updateLine(Mode mode, const QImage& image, int line); @@ -192,10 +180,12 @@ protected: void enableButton(Mode mode, Button button, ButtonPress press); void disableButton(Mode mode, Button button, ButtonPress press); - void handleStatusChange(const Message& msg); - void handleButtonEvent(const Message& msg); + virtual void handleWatchConnected() = 0; + virtual void handleStatusChange(const Message& msg); + virtual void handleButtonEvent(const Message& msg); -protected slots: +private slots: + void handleMessage(const Message& msg); void socketConnected(); void socketDisconnected(); void socketData(); diff --git a/metawatch/metawatch.pro b/metawatch/metawatch.pro index 6819c67..366695e 100644 --- a/metawatch/metawatch.pro +++ b/metawatch/metawatch.pro @@ -15,13 +15,15 @@ SOURCES += metawatchplugin.cpp \ metawatchsimulatorform.cpp \ metawatchsimulator.cpp \ metawatchpaintengine.cpp \ - metawatch.cpp + metawatch.cpp \ + metawatchdigital.cpp HEADERS += metawatchplugin.h \ metawatchsimulatorform.h \ metawatchsimulator.h \ metawatchpaintengine.h \ - metawatch.h + metawatch.h \ + metawatchdigital.h FORMS += \ metawatchsimulatorform.ui @@ -69,3 +71,5 @@ unix:!symbian { } INSTALLS += target } + + diff --git a/metawatch/metawatchdigital.cpp b/metawatch/metawatchdigital.cpp new file mode 100644 index 0000000..2a25249 --- /dev/null +++ b/metawatch/metawatchdigital.cpp @@ -0,0 +1,311 @@ +#include "metawatchdigital.h" + +using namespace sowatch; + +MetaWatchDigital::MetaWatchDigital(const QBluetoothAddress& address, QSettings* settings, QObject *parent) : + MetaWatch(address, settings, parent), + _nMails(0), _nCalls(0), _nIms(0), _nSms(0), _nMms(0) +{ + QImage baseImage(screenWidth, screenHeight, QImage::Format_MonoLSB); + baseImage.setColor(0, QColor(Qt::white).rgb()); + baseImage.setColor(1, QColor(Qt::black).rgb()); + _image[IdleMode] = baseImage; + _image[ApplicationMode] = baseImage; + _image[NotificationMode] = baseImage; + + +} + +int MetaWatchDigital::metric(PaintDeviceMetric metric) const +{ + switch (metric) { + case PdmWidth: + return screenWidth; + case PdmHeight: + return screenHeight; + case PdmWidthMM: + return 24; + case PdmHeightMM: + return 24; + case PdmNumColors: + return 2; + case PdmDepth: + return 1; + case PdmDpiX: + case PdmPhysicalDpiX: + return 96; + case PdmDpiY: + case PdmPhysicalDpiY: + return 96; + } + + return -1; +} + +QString MetaWatchDigital::model() const +{ + return "metawatch-digital"; +} + +void MetaWatchDigital::updateNotificationCount(Notification::Type type, int count) +{ + switch (type) { + case Notification::MissedCallNotification: + _nCalls = count; + break; + case Notification::EmailNotification: + _nMails = count; + break; + case Notification::ImNotification: + _nIms = count; + break; + case Notification::SmsNotification: + _nSms = count; + break; + case Notification::MmsNotification: + _nMms = count; + break; + default: + return; // Since this notification won't show up in idle screen, we do not redraw. + break; + } + + if (isConnected()) { + renderIdleCounts(); + } +} + +void MetaWatchDigital::displayIdleScreen() +{ + qDebug() << "displaying idle screen"; + MetaWatch::displayIdleScreen(); + + // Usually, idle screen is kept updated, so we can flip it right away. + updateDisplay(IdleMode); +} + +void MetaWatchDigital::displayNotification(Notification *n) +{ + const bool isCall = n->type() == Notification::CallNotification; + configureWatchMode(NotificationMode, isCall ? 120 : 10, _invertedNotifications); + + qDebug() << "display notification" << n->title() << n->body(); + + // Render the notification and display it before invoking haptic feedback + _currentMode = NotificationMode; + renderNotification(n); + + MetaWatch::displayNotification(n); +} + +void MetaWatchDigital::displayApplication() +{ + qDebug() << "entering application mode"; + configureWatchMode(ApplicationMode, 250, _invertedApplications); + MetaWatch::displayApplication(); +} + +void MetaWatchDigital::update(Mode mode, const QList<QRect> &rects) +{ + if (!_connected) return; + const QRect clipRect(0, 0, screenWidth, screenHeight); + QVector<bool> lines(screenHeight, false); + + foreach (const QRect& rect, rects) { + QRect r = rect.intersect(clipRect); + for (int i = r.top(); i <= r.bottom(); i++) { + lines[i] = true; + } + } + + updateLines(mode, _image[mode], lines); + if (mode == _currentMode) { + updateDisplay(mode); + } +} + +void MetaWatchDigital::clear(Mode mode, bool black) +{ + if (!_connected) return; + loadTemplate(mode, black ? 1 : 0); +} + +void MetaWatchDigital::renderIdleScreen() +{ + QImage idle_call(QString(":/metawatch/graphics/idle_call.bmp")); + QImage idle_sms(QString(":/metawatch/graphics/idle_sms.bmp")); + QImage idle_mail(QString(":/metawatch/graphics/idle_gmail.bmp")); + QPainter p; + + _paintMode = IdleMode; + p.begin(this); + + p.fillRect(0, 0, screenWidth, screenHeight, Qt::white); + + p.setPen(QPen(Qt::black, 1.0, Qt::DashLine)); + p.drawLine(1, systemAreaHeight + 2, screenWidth - 2, systemAreaHeight + 2); + p.drawLine(1, systemAreaHeight * 2 + 4, screenWidth - 2, systemAreaHeight * 2 + 4); + + p.drawImage((32 * 0) + 4, systemAreaHeight * 2 + 7, idle_call); + p.drawImage((32 * 1) + 4, systemAreaHeight * 2 + 7, idle_sms); + p.drawImage((32 * 2) + 4, systemAreaHeight * 2 + 7, idle_mail); + + p.end(); + _paintMode = _currentMode; + + renderIdleWeather(); + renderIdleCounts(); +} + +void MetaWatchDigital::renderIdleWeather() +{ + _paintMode = IdleMode; + QFont f("MetaWatch Small caps 8pt", 6); + QImage rain(QString(":/metawatch/graphics/weather_rain.bmp")); + QPainter p(this); + + p.setFont(f); + p.drawText(30, systemAreaHeight + 14, "No data!"); + p.drawImage(screenWidth - 26, systemAreaHeight + 6, rain); + + _paintMode = _currentMode; +} + +void MetaWatchDigital::renderIdleCounts() +{ + _paintMode = IdleMode; + QFont f("MetaWatch Large caps 8pt"); + QString s; + QPainter p(this); + QTextOption opt(Qt::AlignCenter); + const int y = systemAreaHeight * 2 + 26; + const int w = 24; + const int h = screenHeight - (y + 1); + const int mails = _nMails; + const int calls = _nCalls; + const int sms = _nSms + _nIms; + + qDebug() << "unread counts" << calls << sms << mails; + + f.setPixelSize(8); // Seems to be the only way to get the desired size. + + p.setFont(f); + p.fillRect(QRect(0, y, screenWidth, h), Qt::white); + p.drawText(QRect((32 * 0) + 4, y, w, h), s.sprintf("%d", calls), opt); + p.drawText(QRect((32 * 1) + 4, y, w, h), s.sprintf("%d", sms), opt); + p.drawText(QRect((32 * 2) + 4, y, w, h), s.sprintf("%d", mails), opt); + + _paintMode = _currentMode; +} + +void MetaWatchDigital::renderNotificationScreen() +{ + _paintMode = NotificationMode; + QPainter p(this); + + p.fillRect(0, 0, screenWidth, screenHeight, Qt::white); + + _paintMode = _currentMode; +} + +void MetaWatchDigital::renderNotification(Notification *n) +{ + _paintMode = NotificationMode; + QPainter p; + QFont sf("MetaWatch Small caps 8pt"); + QFont lf("MetaWatch Large 16pt"); + QFont mf("MetaWatch Large 16pt"); + QImage icon = iconForNotification(n); + + sf.setPixelSize(8); + mf.setPixelSize(14); + lf.setPixelSize(16); + + const int iconW = icon.width(), iconH = icon.height(); + const int margin = 4; + const int x = margin; + const int iconY = margin; + const int titleY = margin*2 + iconH; + const int dateX = x + iconW + margin; + int textFlags; + QString text; + + p.begin(this); + + p.fillRect(0, 0, screenWidth, screenHeight, Qt::white); + p.drawImage(x, iconY, icon); + + p.setPen(Qt::black); + + p.setFont(sf); + textFlags = Qt::AlignRight | Qt::AlignVCenter | Qt::TextWordWrap; + text = n->displayTime(); + QRect dateRect(dateX, iconY, (screenWidth - dateX) - margin, iconH); + p.drawText(dateRect, textFlags, text); + + p.setFont(lf); + textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap; + text = n->title(); + + QRect titleMaxRect(x, titleY, screenWidth - x*2, screenHeight - titleY); + QRect titleRect = p.boundingRect(titleMaxRect, textFlags, text); + if (titleRect.width() > titleMaxRect.width()) { + textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere; + titleRect = p.boundingRect(titleMaxRect, textFlags, text); + } + + p.drawText(titleMaxRect, textFlags, text); + + p.setFont(mf); + textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap; + text = n->body(); + + int bodyY = titleRect.y() + titleRect.height(); + if (bodyY >= screenHeight) return; + + QRect bodyMaxRect(x, bodyY, titleMaxRect.width(), screenHeight - bodyY); + QRect bodyRect = p.boundingRect(bodyMaxRect, textFlags, text); + if (bodyRect.width() > bodyMaxRect.width()) { + textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere; + } + + p.drawText(bodyMaxRect, textFlags, text); + + p.end(); + _paintMode = _currentMode; +} + +QImage MetaWatchDigital::iconForNotification(const Notification *n) +{ + switch (n->type()) { + case Notification::CallNotification: + case Notification::MissedCallNotification: + return QImage(QString(":/metawatch/graphics/phone.bmp")); + break; + case Notification::SmsNotification: + case Notification::MmsNotification: + case Notification::ImNotification: + return QImage(QString(":/metawatch/graphics/message.bmp")); + break; + case Notification::EmailNotification: + return QImage(QString(":/metawatch/graphics/email.bmp")); + break; + case Notification::CalendarNotification: + return QImage(QString(":/metawatch/graphics/timer.bmp")); + break; + default: + return QImage(); + } +} + +void MetaWatchDigital::handleWatchConnected() +{ + // Configure to show watch-rendered clock in idle screen + configureIdleSystemArea(false); + // Follow inverted screen user preference + configureWatchMode(IdleMode, 0, _invertedIdle); + + // Render the idle screen from zero + renderIdleScreen(); + renderNotificationScreen(); +} diff --git a/metawatch/metawatchdigital.h b/metawatch/metawatchdigital.h new file mode 100644 index 0000000..c75fc40 --- /dev/null +++ b/metawatch/metawatchdigital.h @@ -0,0 +1,49 @@ +#ifndef METAWATCHDIGITAL_H +#define METAWATCHDIGITAL_H + +#include "metawatch.h" + +namespace sowatch +{ + +class MetaWatchDigital : public MetaWatch +{ + Q_OBJECT +public: + explicit MetaWatchDigital(const QBluetoothAddress& address, QSettings* settings = 0, QObject *parent = 0); + + static const int screenWidth = 96; + static const int screenHeight = 96; + static const int systemAreaHeight = 30; + + int metric(PaintDeviceMetric metric) const; + + QString model() const; + + void updateNotificationCount(Notification::Type type, int count); + + void displayIdleScreen(); + void displayNotification(Notification *notification); + void displayApplication(); + + void clear(Mode mode, bool black = false); + void update(Mode mode, const QList<QRect>& rects = QList<QRect>()); + +protected: + // Notifications: Unread count + uint _nMails, _nCalls, _nIms, _nSms, _nMms; + + void handleWatchConnected(); + + void renderIdleScreen(); + void renderIdleWeather(); + void renderIdleCounts(); + + void renderNotificationScreen(); + void renderNotification(Notification *n); + QImage iconForNotification(const Notification *n); +}; + +} + +#endif // METAWATCHDIGITAL_H diff --git a/metawatch/metawatchpaintengine.cpp b/metawatch/metawatchpaintengine.cpp index 1b449ab..33f9490 100644 --- a/metawatch/metawatchpaintengine.cpp +++ b/metawatch/metawatchpaintengine.cpp @@ -3,8 +3,6 @@ using namespace sowatch; -const QRect MetaWatchPaintEngine::totalAreaRect(0, 0, MetaWatch::screenWidth, MetaWatch::screenHeight); - MetaWatchPaintEngine::MetaWatchPaintEngine(MetaWatch* watch) : WatchPaintEngine(), _watch(watch) @@ -95,7 +93,7 @@ void MetaWatchPaintEngine::updateState(const QPaintEngineState &state) bool MetaWatchPaintEngine::fillsEntireImage(const QRect& rect) { - return rect == totalAreaRect && + return rect == _area && (!_clipEnabled || - (_clipRegion.numRects() == 1 && _clipRegion.rects().at(0) == totalAreaRect)); + (_clipRegion.numRects() == 1 && _clipRegion.rects().at(0) == _area)); } diff --git a/metawatch/metawatchpaintengine.h b/metawatch/metawatchpaintengine.h index 98e85bb..ec5cf86 100644 --- a/metawatch/metawatchpaintengine.h +++ b/metawatch/metawatchpaintengine.h @@ -25,8 +25,6 @@ public: protected: bool fillsEntireImage(const QRect& rect); - static const QRect totalAreaRect; - MetaWatch* _watch; MetaWatch::Mode _mode; bool _isBrushBlack; diff --git a/metawatch/metawatchplugin.cpp b/metawatch/metawatchplugin.cpp index 23a4f63..5744196 100644 --- a/metawatch/metawatchplugin.cpp +++ b/metawatch/metawatchplugin.cpp @@ -1,6 +1,6 @@ #include <QtGui/QFontDatabase> #include <QtConnectivity/QBluetoothAddress> -#include "metawatch.h" +#include "metawatchdigital.h" #include "metawatchsimulator.h" #include "metawatchplugin.h" @@ -36,7 +36,7 @@ Watch* MetaWatchPlugin::getWatch(const QString& driver, QSettings& settings, QOb { if (driver == "metawatch-digital") { QBluetoothAddress address(settings.value("address").toString()); - return new MetaWatch(address, &settings, parent); + return new MetaWatchDigital(address, &settings, parent); } else { return 0; } |