From bf083973efd101e05d75882b63aad9bdfa37dfbc Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 11 May 2013 19:17:07 +0200 Subject: store watchlets in model --- liveview/liveview.cpp | 72 ++++++++++++++++++++++++---------------- liveview/liveview.h | 11 ++++++ liveview/liveviewpaintengine.cpp | 6 ++-- liveview/liveviewplugin.cpp | 1 + 4 files changed, 60 insertions(+), 30 deletions(-) (limited to 'liveview') diff --git a/liveview/liveview.cpp b/liveview/liveview.cpp index df2b099..aa8a472 100644 --- a/liveview/liveview.cpp +++ b/liveview/liveview.cpp @@ -11,6 +11,7 @@ QTM_USE_NAMESPACE LiveView::LiveView(ConfigKey* settings, QObject* parent) : BluetoothWatch(QBluetoothAddress(settings->value("address").toString()), parent), _settings(settings->getSubkey(QString(), this)), + _watchlets(0), _24hMode(settings->value("24h-mode", false).toBool()), _screenWidth(0), _screenHeight(0), _sendTimer(new QTimer(this)) @@ -31,6 +32,7 @@ LiveView::~LiveView() QPaintEngine* LiveView::paintEngine() const { if (!_paintEngine) { + qDebug() << "Constructing paint engine"; _paintEngine = new LiveViewPaintEngine; } @@ -120,7 +122,10 @@ bool LiveView::charging() const void LiveView::displayIdleScreen() { - + if (_mode != RootMenuMode) { + _mode = RootMenuMode; + refreshMenu(); + } } void LiveView::displayNotification(Notification *notification) @@ -130,6 +135,7 @@ void LiveView::displayNotification(Notification *notification) void LiveView::displayApplication() { + _mode = ApplicationMode; setMenuSize(0); // TODO } @@ -138,6 +144,17 @@ void LiveView::vibrate(int msecs) // TODO } +void LiveView::setWatchletsModel(WatchletsModel *model) +{ + if (_watchlets) { + disconnect(_watchlets, 0, this, 0); + } + _watchlets = model; + if (_watchlets) { + connect(_watchlets, SIGNAL(modelChanged()), SLOT(handleWatchletsChanged())); + } +} + QImage* LiveView::image() { return &_image; @@ -149,6 +166,7 @@ void LiveView::renderImage(int x, int y, const QImage &image) buffer.open(QIODevice::WriteOnly); if (image.save(&buffer, "PNG")) { displayBitmap(x, y, buffer.buffer()); + qDebug() << "render image " << x << 'x' << y << "size" << image.size(); } else { qWarning() << "Failed to encode image"; } @@ -161,6 +179,8 @@ void LiveView::clear() void LiveView::setupBluetoothWatch() { + _mode = RootMenuMode; + connect(_socket, SIGNAL(readyRead()), SLOT(handleDataReceived())); updateDisplayProperties(); refreshMenu(); @@ -173,11 +193,14 @@ void LiveView::desetupBluetoothWatch() void LiveView::refreshMenu() { - setMenuSize(3); + if (_mode == RootMenuMode) { + setMenuSize(3); + } } void LiveView::send(const Message &msg) { + Q_ASSERT(_connected); _sendingMsgs.enqueue(msg); if (!_sendTimer->isActive()) { _sendTimer->start(); @@ -248,7 +271,7 @@ void LiveView::enableLed(const QColor& color, unsigned short delay, unsigned sho { QByteArray data; - quint16 rgb; + quint16 rgb = 0; rgb |= ((color.red() & 0xF8) << 8); rgb |= ((color.green() & 0xFC) << 3); rgb |= ((color.blue() & 0xF8) >> 3); @@ -308,13 +331,6 @@ void LiveView::handleDeviceStatusChange(const Message &msg) if (msg.data.size() == 1) { DeviceStatus status = static_cast(msg.data.at(0)); qDebug() << "liveview device status change" << status; - switch (status) { - case DeviceOn: - refreshMenu(); - break; - default: - break; - } } sendResponse(DeviceStatusChangeResponse, ResponseOk); } @@ -350,21 +366,8 @@ void LiveView::handleNavigation(const Message &msg) // TODO if (event == 32) { - qDebug() << "Navigation, sending bitmap"; - - setMenuSize(0); - - displayClear(); - - QFile f(SOWATCH_RESOURCES_DIR "/liveview/graphics/menu_missed_calls.png"); - f.open(QIODevice::ReadOnly); - displayBitmap(2, 22, f.readAll()); - f.close(); - - f.setFileName(SOWATCH_RESOURCES_DIR "/liveview/graphics/menu_messages.png"); - f.open(QIODevice::ReadOnly); - displayBitmap(12, 22, f.readAll()); - f.close(); + qDebug() << "Navigation, requesting watchlet"; + emit watchletRequested("com.javispedro.sowatch.neko"); } } @@ -414,8 +417,10 @@ void LiveView::handleDisplayProperties(const Message &msg) return; } - _screenWidth = msg.data[0]; - _screenHeight = msg.data[1]; + _screenWidth = static_cast(msg.data[0]); + _screenHeight = static_cast(msg.data[1]); + + qDebug() << "LiveView display properties:" << _screenWidth << 'x' << _screenHeight; // Recreate the display image _image = QImage(_screenWidth, _screenHeight, QImage::Format_RGB16); @@ -531,7 +536,11 @@ void LiveView::handleSendTimerTick() packet.replace(HEADER_SIZE, data_size, msg.data); #if PROTOCOL_DEBUG - qDebug() << "sending" << packet.toHex(); + if (packet.size() < 20) { + qDebug() << "sending" << packet.toHex(); + } else { + qDebug() << "sending" << packet.left(20).toHex() << "..."; + } #endif _socket->write(packet); @@ -542,3 +551,10 @@ void LiveView::handleSendTimerTick() _sendTimer->stop(); } } + +void LiveView::handleWatchletsChanged() +{ + if (_connected) { + refreshMenu(); + } +} diff --git a/liveview/liveview.h b/liveview/liveview.h index 4a2e165..65ce523 100644 --- a/liveview/liveview.h +++ b/liveview/liveview.h @@ -41,6 +41,8 @@ public: void vibrate(int msecs); + void setWatchletsModel(WatchletsModel *model); + // Only for application mode QImage* image(); /** Render a image in a certain position. */ @@ -98,6 +100,11 @@ protected: MenuOther = 1 }; + enum Mode { + RootMenuMode = 0, + ApplicationMode + }; + struct Message { MessageType type; QByteArray data; @@ -137,9 +144,11 @@ protected: private slots: void handleDataReceived(); void handleSendTimerTick(); + void handleWatchletsChanged(); private: ConfigKey *_settings; + WatchletsModel *_watchlets; bool _24hMode : 1; @@ -147,6 +156,8 @@ private: int _screenHeight; QStringList _buttons; + Mode _mode; + // Required by QPaintDevice mutable LiveViewPaintEngine* _paintEngine; QImage _image; diff --git a/liveview/liveviewpaintengine.cpp b/liveview/liveviewpaintengine.cpp index 1785d62..f774884 100644 --- a/liveview/liveviewpaintengine.cpp +++ b/liveview/liveviewpaintengine.cpp @@ -1,11 +1,13 @@ +#include + #include "liveviewpaintengine.h" using namespace sowatch; LiveViewPaintEngine::LiveViewPaintEngine() : - WatchPaintEngine() + WatchPaintEngine(), _watch(0) { - + qDebug() << "SE CCONS"; } bool LiveViewPaintEngine::begin(QPaintDevice *pdev) diff --git a/liveview/liveviewplugin.cpp b/liveview/liveviewplugin.cpp index c7d862e..1f34949 100644 --- a/liveview/liveviewplugin.cpp +++ b/liveview/liveviewplugin.cpp @@ -31,6 +31,7 @@ WatchScanner* LiveViewPlugin::getScanner(QObject *parent) QUrl LiveViewPlugin::getConfigQmlUrl(const QString &driver) { + Q_UNUSED(driver); return QUrl(); } -- cgit v1.2.3