From bca10d6ab21bf0e49253fc01e313a4618b7fcae7 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Wed, 17 Sep 2014 01:24:22 +0200 Subject: Improve how notifications look --- src/controller.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- src/metawatch.cpp | 24 +++++++++++++++++++++--- src/metawatch.h | 3 ++- src/notificationmonitor.cpp | 5 ++--- 4 files changed, 63 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/controller.cpp b/src/controller.cpp index bd2b68b..70be33a 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -198,13 +198,49 @@ void Controller::handleIncomingNotification(const QString &sender, const QIcon & QImage image(96, 96, QImage::Format_MonoLSB); QPainter p(&image); + QFont small("MetaWatch Small caps 8pt"); + small.setPixelSize(8); + QFont large("MetaWatch Large 16pt"); + large.setPixelSize(16); + p.drawImage(0, 0, QImage(SailfishApp::pathTo("qml/watch/notification.png").toLocalFile())); icon.paint(&p, 0, 96 - 24, 24, 24, Qt::AlignLeft | Qt::AlignBottom); - p.drawText(QRect(2, 26, 92, 55), Qt::AlignLeft | Qt::AlignTop, body); + bool drawn_summary = false; + p.setFont(large); + if (!summary.isEmpty()) { + QRect area(2, 2, 96 - 20, 18); + QRect r; + p.drawText(area, + Qt::AlignLeft | Qt::AlignTop | Qt::TextSingleLine, + summary, &r); + if (area.contains(r)) { + drawn_summary = true; + } + } - image.invertPixels(); + const int x = 2, max_x = 96; + const int max_y = 96 - 24; + int y = 26; + + p.setFont(small); + if (!drawn_summary && !summary.isEmpty()) { + QRect r; + p.drawText(QRect(x, y, max_x - x, max_y - y), + Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, + summary, &r); + y = r.bottom() + 1; + } + if (!body.isEmpty() && y < max_y) { + QRect r; + p.drawText(QRect(x, y, max_x - x, max_y - y), + Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, + body, &r); + y = r.bottom() + 1; + } + image.invertPixels(); + _metawatch->clearModeImage(MetaWatch::WatchModeNotification); _metawatch->sendModeImage(MetaWatch::WatchModeNotification, image); _metawatch->updateLcdDisplayMode(MetaWatch::WatchModeNotification); _metawatch->setVibrateMode(true, 500, 500, 2); diff --git a/src/metawatch.cpp b/src/metawatch.cpp index 9b0bae2..ff05aca 100644 --- a/src/metawatch.cpp +++ b/src/metawatch.cpp @@ -155,15 +155,33 @@ void MetaWatch::updateWidgetList(const QList &widgets) } } +void MetaWatch::clearModeImage(WatchMode mode, bool black) +{ + _transport->sendMessage(MessageLoadTemplate, + mode & 0x3, + QByteArray(1, black ? 1 : 0)); +} + void MetaWatch::sendModeImage(WatchMode mode, const QImage &image) { + const int bytesPerLine = image.bytesPerLine(); Q_ASSERT(image.width() == 96 && image.height() == 96); - Q_ASSERT(image.bytesPerLine() == 12); - QByteArray data(1 + image.bytesPerLine(), '\0');//Qt::Uninitialized); + Q_ASSERT(bytesPerLine == 12); + QByteArray data(1 + bytesPerLine, '\0'); for (int i = 0; i < image.height(); i++) { + const uchar *scanline = image.scanLine(i); + + bool empty = true; + for (int j = 0; j < bytesPerLine; j++) { + empty &= scanline[j] == 0; + } + if (empty) { + continue; + } + data[0] = i; - memcpy(data.data() + 1, image.scanLine(i), image.bytesPerLine()); + memcpy(data.data() + 1, scanline, bytesPerLine); _transport->sendMessage(MessageWriteLcdBuffer, 0x10 | (mode & 0x3), diff --git a/src/metawatch.h b/src/metawatch.h index a83ad0c..61eaa3a 100644 --- a/src/metawatch.h +++ b/src/metawatch.h @@ -32,8 +32,8 @@ public: MessageModeChangeIndication = 0x33, MessageWriteLcdBuffer = 0x40, - MessageUpdateLcdDisplay = 0x43, + MessageLoadTemplate = 0x44, MessageGetBatteryStatus = 0x56, MessageReadBatteryStatusResponse = 0x57, @@ -91,6 +91,7 @@ public: void updateLcdDisplayMode(WatchMode mode); void updateWidgetList(const QList& widgets); + void clearModeImage(WatchMode mode, bool black = false); void sendModeImage(WatchMode mode, const QImage &image); signals: diff --git a/src/notificationmonitor.cpp b/src/notificationmonitor.cpp index c937b02..b0f66c9 100644 --- a/src/notificationmonitor.cpp +++ b/src/notificationmonitor.cpp @@ -36,9 +36,10 @@ NotificationMonitor *NotificationMonitor::instance() void NotificationMonitor::Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantHash &hints, int expire_timeout) { - qDebug() << "Got notification" << app_name << app_icon << summary << body; QIcon icon; + qDebug() << "Got notification" << app_name << app_icon << summary << body; + if (app_icon.startsWith("/")) { icon = QIcon(app_icon); } else if (app_icon.startsWith("file:")) { @@ -48,7 +49,5 @@ void NotificationMonitor::Notify(const QString &app_name, uint replaces_id, cons icon = QIcon::fromTheme(app_icon); } - qDebug() << "Icon:" << icon.availableSizes(); - emit incomingNotification(app_name, icon, summary, body); } -- cgit v1.2.3