From 3ca9235ddb93b52730099164a0dc387f7a301280 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 12 May 2013 03:49:38 +0200 Subject: weather rendering in metawatchwatchlets --- metawatch/metawatch.cpp | 9 +- metawatch/metawatchdigital.cpp | 106 ++++++--------------- metawatch/metawatchdigital.h | 16 ---- metawatch/metawatchdigitalsimulator.cpp | 8 ++ metawatch/metawatchdigitalsimulator.h | 1 + .../javispedro/sowatch/metawatch/MWScrollable.qml | 63 ++++++++++++ .../qml/com/javispedro/sowatch/metawatch/qmldir | 1 + metawatch/res/graphics/email.bmp | Bin 126 -> 0 bytes metawatch/res/graphics/message.bmp | Bin 126 -> 0 bytes metawatch/res/graphics/phone.bmp | Bin 126 -> 0 bytes metawatch/res/graphics/play.bmp | Bin 126 -> 0 bytes metawatch/res/graphics/timer.bmp | Bin 126 -> 0 bytes metawatch/res/graphics/weather_cloudy.bmp | Bin 158 -> 0 bytes metawatch/res/graphics/weather_rain.bmp | Bin 158 -> 0 bytes metawatch/res/graphics/weather_snow.bmp | Bin 158 -> 0 bytes metawatch/res/graphics/weather_sunny.bmp | Bin 158 -> 0 bytes metawatch/res/graphics/weather_thunderstorm.bmp | Bin 158 -> 0 bytes metawatch/res/graphics/weather_wind.bmp | Bin 158 -> 0 bytes 18 files changed, 107 insertions(+), 97 deletions(-) create mode 100644 metawatch/qml/com/javispedro/sowatch/metawatch/MWScrollable.qml delete mode 100644 metawatch/res/graphics/email.bmp delete mode 100644 metawatch/res/graphics/message.bmp delete mode 100644 metawatch/res/graphics/phone.bmp delete mode 100644 metawatch/res/graphics/play.bmp delete mode 100644 metawatch/res/graphics/timer.bmp delete mode 100644 metawatch/res/graphics/weather_cloudy.bmp delete mode 100644 metawatch/res/graphics/weather_rain.bmp delete mode 100644 metawatch/res/graphics/weather_snow.bmp delete mode 100644 metawatch/res/graphics/weather_sunny.bmp delete mode 100644 metawatch/res/graphics/weather_thunderstorm.bmp delete mode 100644 metawatch/res/graphics/weather_wind.bmp (limited to 'metawatch') diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp index b5aec49..3845817 100644 --- a/metawatch/metawatch.cpp +++ b/metawatch/metawatch.cpp @@ -269,8 +269,12 @@ void MetaWatch::setupBluetoothWatch() _currentMode = IdleMode; _paintMode = IdleMode; - connect(_socket, SIGNAL(readyRead()), + if (_socket) { + // If we are running under the simulator, there might not be + // a socket. + connect(_socket, SIGNAL(readyRead()), SLOT(dataReceived())); + } // Configure the watch according to user preferences updateWatchProperties(); @@ -468,9 +472,6 @@ void MetaWatch::enableButton(Mode mode, Button button, ButtonPress press) // the pressed button and the event code were. msg.data[4] = 0x80 | ((press << 4) & 0x30) | (button & 0xF); - qDebug() << "enable button" << button << "(" << press << ")" << - "in mode" << mode << "to" << static_cast(msg.data[4]); - send(msg); } diff --git a/metawatch/metawatchdigital.cpp b/metawatch/metawatchdigital.cpp index e3f8431..0d2a3cf 100644 --- a/metawatch/metawatchdigital.cpp +++ b/metawatch/metawatchdigital.cpp @@ -3,9 +3,7 @@ using namespace sowatch; MetaWatchDigital::MetaWatchDigital(ConfigKey* settings, QObject *parent) : - MetaWatch(settings, parent), - _nMails(0), _nCalls(0), _nIms(0), _nSms(0), _nMms(0), - _wForecast(WeatherNotification::UnknownWeather) + MetaWatch(settings, parent) { QImage baseImage(screenWidth, screenHeight, QImage::Format_MonoLSB); baseImage.setColor(0, QColor(Qt::white).rgb()); @@ -67,6 +65,12 @@ void MetaWatchDigital::displayApplication() MetaWatch::displayApplication(); } +void MetaWatchDigital::clear(Mode mode, bool black) +{ + if (!_connected) return; + loadLcdTemplate(mode, black ? 1 : 0); +} + void MetaWatchDigital::update(Mode mode, const QList &rects) { if (!_connected) return; @@ -86,20 +90,32 @@ void MetaWatchDigital::update(Mode mode, const QList &rects) } } -void MetaWatchDigital::clear(Mode mode, bool black) -{ - if (!_connected) return; - loadLcdTemplate(mode, black ? 1 : 0); -} - -void MetaWatchDigital::renderIdleScreen() +#if 0 +QUrl MetaWatchDigital::iconForNotification(const Notification *n) { - + switch (n->type()) { + case Notification::CallNotification: + case Notification::MissedCallNotification: + return QUrl::fromLocalFile(SOWATCH_RESOURCES_DIR "/metawatch/graphics/phone.png"); + break; + case Notification::SmsNotification: + case Notification::MmsNotification: + case Notification::ImNotification: + return QUrl::fromLocalFile(SOWATCH_RESOURCES_DIR "/metawatch/graphics/message.png"); + break; + case Notification::EmailNotification: + return QUrl::fromLocalFile(SOWATCH_RESOURCES_DIR "/metawatch/graphics/email.bmp"); + break; + case Notification::CalendarNotification: + return QUrl::fromLocalFile(SOWATCH_RESOURCES_DIR "/metawatch/graphics/timer.bmp"); + break; + default: + return QUrl(); + } } void MetaWatchDigital::renderIdleWeather() { -#if 0 _paintMode = IdleMode; QFont sf("MetaWatch Small caps 8pt"); QFont lf("MetaWatch Large 16pt"); @@ -128,7 +144,6 @@ void MetaWatchDigital::renderIdleWeather() } _paintMode = _currentMode; -#endif } QImage MetaWatchDigital::iconForWeather(WeatherNotification::WeatherType w) @@ -151,67 +166,6 @@ QImage MetaWatchDigital::iconForWeather(WeatherNotification::WeatherType w) } } -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; - QTextOption option; - QRect rect, titleRect; - QString text; - - p.begin(this); - - p.fillRect(0, 0, screenWidth, screenHeight, Qt::white); - p.drawImage(x, iconY, icon); - - p.setPen(Qt::black); - option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); - option.setAlignment(Qt::AlignRight | Qt::AlignVCenter); - - // Render "N minutes ago" - p.setFont(sf); - rect.setRect(dateX, iconY, (screenWidth - dateX) - margin, iconH); - text = n->displayTime(); - p.drawText(rect, text, option); - - option.setAlignment(Qt::AlignLeft | Qt::AlignTop); - - // Render title - p.setFont(lf); - rect.setRect(x, titleY, screenWidth - x*2, screenHeight - titleY); - text = n->title(); - titleRect = p.boundingRect(rect, text, option).toRect(); - p.drawText(rect, text, option); - - // Do not try to draw body if title was large - int bodyY = titleRect.y() + titleRect.height(); - if (bodyY >= screenHeight) return; - - // Render body - p.setFont(mf); - rect.setRect(x, bodyY, screenWidth - x*2, screenHeight - bodyY); - text = n->body(); - p.drawText(rect, text, option); - - p.end(); - _paintMode = _currentMode; -} - QImage MetaWatchDigital::iconForNotification(const Notification *n) { switch (n->type()) { @@ -234,6 +188,7 @@ QImage MetaWatchDigital::iconForNotification(const Notification *n) return QImage(); } } +#endif void MetaWatchDigital::setupBluetoothWatch() { @@ -256,7 +211,4 @@ void MetaWatchDigital::setupBluetoothWatch() // Configure to show watch-rendered clock in idle screen configureLcdIdleSystemArea(false); - - // Render the idle screen assuming previous contents were lost - renderIdleScreen(); } diff --git a/metawatch/metawatchdigital.h b/metawatch/metawatchdigital.h index 1e1a62b..8baed46 100644 --- a/metawatch/metawatchdigital.h +++ b/metawatch/metawatchdigital.h @@ -29,22 +29,6 @@ public: protected: void setupBluetoothWatch(); - -private: - // Idle screen: notifications unread count - ushort _nMails, _nCalls, _nIms, _nSms, _nMms; - // Idle screen: weather information - WeatherNotification::WeatherType _wForecast; - QString _wBody; - short _wTemperature; - bool _wMetric; - - void renderIdleScreen(); - void renderIdleWeather(); - QImage iconForWeather(WeatherNotification::WeatherType w); - - void renderNotification(Notification *n); - QImage iconForNotification(const Notification *n); }; } diff --git a/metawatch/metawatchdigitalsimulator.cpp b/metawatch/metawatchdigitalsimulator.cpp index f808515..41b924a 100644 --- a/metawatch/metawatchdigitalsimulator.cpp +++ b/metawatch/metawatchdigitalsimulator.cpp @@ -20,6 +20,7 @@ MetaWatchDigitalSimulator::MetaWatchDigitalSimulator(ConfigKey *config, QObject // Connect form signals connect(_form, SIGNAL(buttonPressed(int)), SIGNAL(buttonPressed(int))); connect(_form, SIGNAL(buttonReleased(int)), SIGNAL(buttonReleased(int))); + connect(_form, SIGNAL(buttonPressed(int)), SLOT(handleButtonPressed(int))); connect(_form, SIGNAL(destroyed()), SLOT(handleFormDestroyed())); // Show the form @@ -146,3 +147,10 @@ void MetaWatchDigitalSimulator::handleFormDestroyed() _form = 0; } } + +void MetaWatchDigitalSimulator::handleButtonPressed(int button) +{ + if (button == BtnA) { + emit nextWatchletRequested(); + } +} diff --git a/metawatch/metawatchdigitalsimulator.h b/metawatch/metawatchdigitalsimulator.h index 8b424ec..d9d1295 100644 --- a/metawatch/metawatchdigitalsimulator.h +++ b/metawatch/metawatchdigitalsimulator.h @@ -31,6 +31,7 @@ public: private slots: void handleFormDestroyed(); + void handleButtonPressed(int button); private: MetaWatchDigitalSimulatorForm* _form; diff --git a/metawatch/qml/com/javispedro/sowatch/metawatch/MWScrollable.qml b/metawatch/qml/com/javispedro/sowatch/metawatch/MWScrollable.qml new file mode 100644 index 0000000..65952c1 --- /dev/null +++ b/metawatch/qml/com/javispedro/sowatch/metawatch/MWScrollable.qml @@ -0,0 +1,63 @@ +import Qt 4.7 + +Flickable { + id: flickable + + property bool selectable: true + property bool indicator: true + + interactive: false + boundsBehavior: Flickable.StopAtBounds + flickableDirection: Flickable.VerticalFlick + + function scrollDown() { + var maxY = contentHeight - height; + var newContentY = contentY + 96/3; + + if (newContentY > maxY) { + contentY = maxY; // Never overscroll. + } else { + contentY = newContentY; + } + } + + function scrollUp() { + var newContentY = contentY - 96/3; + + if (newContentY < 0) { + contentY = 0; // Never overscroll. + } else { + contentY = newContentY; + } + } + + function scrollTop() { + contentY = 0; + } + + Rectangle { + id: indicatorCont + visible: flickable.indicator && (flickable.contentHeight > flickable.height) + anchors.top: parent.top + anchors.right: parent.right + anchors.bottom: parent.bottom + width: 4 + + color: "white" + + Rectangle { + id: indicatorRect + + property int minHeight: 10 + + anchors.right: parent.right + anchors.left: parent.left + anchors.leftMargin: 1 + + y: flickable.visibleArea.yPosition * indicatorCont.height + height: Math.max(minHeight, flickable.visibleArea.heightRatio * indicatorCont.height) + + color: "black" + } + } +} diff --git a/metawatch/qml/com/javispedro/sowatch/metawatch/qmldir b/metawatch/qml/com/javispedro/sowatch/metawatch/qmldir index 10ca498..aff7045 100644 --- a/metawatch/qml/com/javispedro/sowatch/metawatch/qmldir +++ b/metawatch/qml/com/javispedro/sowatch/metawatch/qmldir @@ -2,3 +2,4 @@ MWPage 1.0 MWPage.qml MWLabel 1.0 MWLabel.qml MWTitle 1.0 MWTitle.qml MWListView 1.0 MWListView.qml +MWScrollable 1.0 MWScrollable.qml diff --git a/metawatch/res/graphics/email.bmp b/metawatch/res/graphics/email.bmp deleted file mode 100644 index 7c895af..0000000 Binary files a/metawatch/res/graphics/email.bmp and /dev/null differ diff --git a/metawatch/res/graphics/message.bmp b/metawatch/res/graphics/message.bmp deleted file mode 100644 index 53605b8..0000000 Binary files a/metawatch/res/graphics/message.bmp and /dev/null differ diff --git a/metawatch/res/graphics/phone.bmp b/metawatch/res/graphics/phone.bmp deleted file mode 100644 index a9da9d8..0000000 Binary files a/metawatch/res/graphics/phone.bmp and /dev/null differ diff --git a/metawatch/res/graphics/play.bmp b/metawatch/res/graphics/play.bmp deleted file mode 100644 index f6f507c..0000000 Binary files a/metawatch/res/graphics/play.bmp and /dev/null differ diff --git a/metawatch/res/graphics/timer.bmp b/metawatch/res/graphics/timer.bmp deleted file mode 100644 index 20ae04d..0000000 Binary files a/metawatch/res/graphics/timer.bmp and /dev/null differ diff --git a/metawatch/res/graphics/weather_cloudy.bmp b/metawatch/res/graphics/weather_cloudy.bmp deleted file mode 100644 index 506c24a..0000000 Binary files a/metawatch/res/graphics/weather_cloudy.bmp and /dev/null differ diff --git a/metawatch/res/graphics/weather_rain.bmp b/metawatch/res/graphics/weather_rain.bmp deleted file mode 100644 index fc12c6e..0000000 Binary files a/metawatch/res/graphics/weather_rain.bmp and /dev/null differ diff --git a/metawatch/res/graphics/weather_snow.bmp b/metawatch/res/graphics/weather_snow.bmp deleted file mode 100644 index d328105..0000000 Binary files a/metawatch/res/graphics/weather_snow.bmp and /dev/null differ diff --git a/metawatch/res/graphics/weather_sunny.bmp b/metawatch/res/graphics/weather_sunny.bmp deleted file mode 100644 index df9f774..0000000 Binary files a/metawatch/res/graphics/weather_sunny.bmp and /dev/null differ diff --git a/metawatch/res/graphics/weather_thunderstorm.bmp b/metawatch/res/graphics/weather_thunderstorm.bmp deleted file mode 100644 index f101610..0000000 Binary files a/metawatch/res/graphics/weather_thunderstorm.bmp and /dev/null differ diff --git a/metawatch/res/graphics/weather_wind.bmp b/metawatch/res/graphics/weather_wind.bmp deleted file mode 100644 index 59bd81b..0000000 Binary files a/metawatch/res/graphics/weather_wind.bmp and /dev/null differ -- cgit v1.2.3