From 3a755f46d9cf6e3650d40a960d0d0db8c1ad9fa1 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 17 Sep 2011 03:03:23 +0200 Subject: preparing for library package --- declarativewatchlet.cpp | 96 ---- declarativewatchlet.h | 39 -- declarativewatchwrapper.cpp | 42 -- declarativewatchwrapper.h | 44 -- graphicswatchlet.cpp | 47 -- graphicswatchlet.h | 31 -- libsowatch/declarativewatchlet.cpp | 96 ++++ libsowatch/declarativewatchlet.h | 39 ++ libsowatch/declarativewatchwrapper.cpp | 42 ++ libsowatch/declarativewatchwrapper.h | 44 ++ libsowatch/graphicswatchlet.cpp | 47 ++ libsowatch/graphicswatchlet.h | 31 ++ libsowatch/libsowatch.pro | 100 ++++ libsowatch/libsowatch.pro.user | 549 +++++++++++++++++++++ libsowatch/main.cpp | 35 ++ libsowatch/metawatch.cpp | 409 +++++++++++++++ libsowatch/metawatch.h | 122 +++++ libsowatch/metawatchpaintengine.cpp | 82 +++ libsowatch/metawatchpaintengine.h | 34 ++ libsowatch/metawatchsimulator.cpp | 82 +++ libsowatch/metawatchsimulator.h | 32 ++ libsowatch/metawatchsimulatorform.cpp | 82 +++ libsowatch/metawatchsimulatorform.h | 46 ++ libsowatch/metawatchsimulatorform.ui | 294 +++++++++++ libsowatch/qtc_packaging/debian_harmattan/README | 6 + .../qtc_packaging/debian_harmattan/changelog | 5 + libsowatch/qtc_packaging/debian_harmattan/compat | 1 + libsowatch/qtc_packaging/debian_harmattan/control | 14 + .../qtc_packaging/debian_harmattan/copyright | 40 ++ .../qtc_packaging/debian_harmattan/manifest.aegis | 0 libsowatch/qtc_packaging/debian_harmattan/rules | 91 ++++ libsowatch/sowatch.h | 12 + libsowatch/sowatch_global.h | 12 + libsowatch/testdeclarativewatchlet.cpp | 9 + libsowatch/testdeclarativewatchlet.h | 19 + libsowatch/testwatchlet.cpp | 40 ++ libsowatch/testwatchlet.h | 29 ++ libsowatch/watch.cpp | 62 +++ libsowatch/watch.h | 49 ++ libsowatch/watchlet.cpp | 44 ++ libsowatch/watchlet.h | 48 ++ libsowatch/watchmanager.cpp | 8 + libsowatch/watchmanager.h | 23 + libsowatch/watchpaintengine.cpp | 305 ++++++++++++ libsowatch/watchpaintengine.h | 62 +++ libsowatch/watchserver.cpp | 57 +++ libsowatch/watchserver.h | 46 ++ libsowatch/watchsimulator.cpp | 11 + libsowatch/watchsimulator.h | 20 + main.cpp | 35 -- metawatch.cpp | 409 --------------- metawatch.h | 122 ----- metawatchpaintengine.cpp | 82 --- metawatchpaintengine.h | 34 -- metawatchsimulator.cpp | 82 --- metawatchsimulator.h | 32 -- metawatchsimulatorform.cpp | 82 --- metawatchsimulatorform.h | 46 -- metawatchsimulatorform.ui | 294 ----------- qt.png | Bin 1307 -> 0 bytes qtc_packaging/debian_harmattan/README | 6 - qtc_packaging/debian_harmattan/changelog | 5 - qtc_packaging/debian_harmattan/compat | 1 - qtc_packaging/debian_harmattan/control | 14 - qtc_packaging/debian_harmattan/copyright | 40 -- qtc_packaging/debian_harmattan/rules | 91 ---- sowatch.h | 11 - sowatch.pro | 76 --- testdeclarativewatchlet.cpp | 9 - testdeclarativewatchlet.h | 19 - testdeclarativewatchlet.qml | 28 -- tests.qrc | 6 - testwatchlet.cpp | 40 -- testwatchlet.h | 29 -- watch.cpp | 62 --- watch.h | 49 -- watchlet.cpp | 44 -- watchlet.h | 47 -- watchmanager.cpp | 8 - watchmanager.h | 23 - watchpaintengine.cpp | 305 ------------ watchpaintengine.h | 62 --- watchserver.cpp | 57 --- watchserver.h | 46 -- watchsimulator.cpp | 11 - watchsimulator.h | 20 - 86 files changed, 3179 insertions(+), 2626 deletions(-) delete mode 100644 declarativewatchlet.cpp delete mode 100644 declarativewatchlet.h delete mode 100644 declarativewatchwrapper.cpp delete mode 100644 declarativewatchwrapper.h delete mode 100644 graphicswatchlet.cpp delete mode 100644 graphicswatchlet.h create mode 100644 libsowatch/declarativewatchlet.cpp create mode 100644 libsowatch/declarativewatchlet.h create mode 100644 libsowatch/declarativewatchwrapper.cpp create mode 100644 libsowatch/declarativewatchwrapper.h create mode 100644 libsowatch/graphicswatchlet.cpp create mode 100644 libsowatch/graphicswatchlet.h create mode 100644 libsowatch/libsowatch.pro create mode 100644 libsowatch/libsowatch.pro.user create mode 100644 libsowatch/main.cpp create mode 100644 libsowatch/metawatch.cpp create mode 100644 libsowatch/metawatch.h create mode 100644 libsowatch/metawatchpaintengine.cpp create mode 100644 libsowatch/metawatchpaintengine.h create mode 100644 libsowatch/metawatchsimulator.cpp create mode 100644 libsowatch/metawatchsimulator.h create mode 100644 libsowatch/metawatchsimulatorform.cpp create mode 100644 libsowatch/metawatchsimulatorform.h create mode 100644 libsowatch/metawatchsimulatorform.ui create mode 100644 libsowatch/qtc_packaging/debian_harmattan/README create mode 100644 libsowatch/qtc_packaging/debian_harmattan/changelog create mode 100644 libsowatch/qtc_packaging/debian_harmattan/compat create mode 100644 libsowatch/qtc_packaging/debian_harmattan/control create mode 100644 libsowatch/qtc_packaging/debian_harmattan/copyright create mode 100644 libsowatch/qtc_packaging/debian_harmattan/manifest.aegis create mode 100755 libsowatch/qtc_packaging/debian_harmattan/rules create mode 100644 libsowatch/sowatch.h create mode 100644 libsowatch/sowatch_global.h create mode 100644 libsowatch/testdeclarativewatchlet.cpp create mode 100644 libsowatch/testdeclarativewatchlet.h create mode 100644 libsowatch/testwatchlet.cpp create mode 100644 libsowatch/testwatchlet.h create mode 100644 libsowatch/watch.cpp create mode 100644 libsowatch/watch.h create mode 100644 libsowatch/watchlet.cpp create mode 100644 libsowatch/watchlet.h create mode 100644 libsowatch/watchmanager.cpp create mode 100644 libsowatch/watchmanager.h create mode 100644 libsowatch/watchpaintengine.cpp create mode 100644 libsowatch/watchpaintengine.h create mode 100644 libsowatch/watchserver.cpp create mode 100644 libsowatch/watchserver.h create mode 100644 libsowatch/watchsimulator.cpp create mode 100644 libsowatch/watchsimulator.h delete mode 100644 main.cpp delete mode 100644 metawatch.cpp delete mode 100644 metawatch.h delete mode 100644 metawatchpaintengine.cpp delete mode 100644 metawatchpaintengine.h delete mode 100644 metawatchsimulator.cpp delete mode 100644 metawatchsimulator.h delete mode 100644 metawatchsimulatorform.cpp delete mode 100644 metawatchsimulatorform.h delete mode 100644 metawatchsimulatorform.ui delete mode 100644 qt.png delete mode 100644 qtc_packaging/debian_harmattan/README delete mode 100644 qtc_packaging/debian_harmattan/changelog delete mode 100644 qtc_packaging/debian_harmattan/compat delete mode 100644 qtc_packaging/debian_harmattan/control delete mode 100644 qtc_packaging/debian_harmattan/copyright delete mode 100755 qtc_packaging/debian_harmattan/rules delete mode 100644 sowatch.h delete mode 100644 sowatch.pro delete mode 100644 testdeclarativewatchlet.cpp delete mode 100644 testdeclarativewatchlet.h delete mode 100644 testdeclarativewatchlet.qml delete mode 100644 tests.qrc delete mode 100644 testwatchlet.cpp delete mode 100644 testwatchlet.h delete mode 100644 watch.cpp delete mode 100644 watch.h delete mode 100644 watchlet.cpp delete mode 100644 watchlet.h delete mode 100644 watchmanager.cpp delete mode 100644 watchmanager.h delete mode 100644 watchpaintengine.cpp delete mode 100644 watchpaintengine.h delete mode 100644 watchserver.cpp delete mode 100644 watchserver.h delete mode 100644 watchsimulator.cpp delete mode 100644 watchsimulator.h diff --git a/declarativewatchlet.cpp b/declarativewatchlet.cpp deleted file mode 100644 index 7e6768e..0000000 --- a/declarativewatchlet.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include -#include "watchserver.h" -#include "declarativewatchwrapper.h" -#include "declarativewatchlet.h" - -using namespace sowatch; - -bool DeclarativeWatchlet::_registered = false; - -DeclarativeWatchlet::DeclarativeWatchlet(WatchServer* server, const QString& id) : - GraphicsWatchlet(server, id), - _engine(0), - _component(0), - _item(0), - _wrapper(0) -{ - setScene(new QGraphicsScene(this)); - - if (!_registered) { - qmlRegisterUncreatableType("com.javispedro.sowatch", 1, 0, - "Watch", "Watch is only available via the 'watch' object"); - _registered = true; - } - - _engine = new QDeclarativeEngine(this); - _wrapper = new DeclarativeWatchWrapper(server->watch(), this); - - _engine->rootContext()->setContextProperty("watch", _wrapper); -} - -void DeclarativeWatchlet::setSource(const QUrl &url) -{ - if (_item) { - scene()->removeItem(_item); - delete _item; - _item = 0; - } - if (_component) { - delete _component; - _component = 0; - } - if (!url.isEmpty()) { - _component = new QDeclarativeComponent(_engine, url, this); - connect(_component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), - SLOT(handleComponentStatus(QDeclarativeComponent::Status))); - if (!_component->isLoading()) { - /* No signals are going to be generated for this. */ - handleComponentStatus(_component->status()); - } else { - connect(_component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), - this, SLOT(handleComponentStatus(QDeclarativeComponent::Status))); - } - } -} - -void DeclarativeWatchlet::activate() -{ - Watchlet::activate(); - _wrapper->activate(); - _scene->update(); -} - -void DeclarativeWatchlet::deactivate() -{ - Watchlet::deactivate(); - _wrapper->deactivate(); -} - -void DeclarativeWatchlet::handleComponentStatus(QDeclarativeComponent::Status status) -{ - QObject *obj; - disconnect(_component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), - this, SLOT(handleComponentStatus(QDeclarativeComponent::Status))); - switch (status) { - case QDeclarativeComponent::Null: - case QDeclarativeComponent::Loading: - /* Nothing to do */ - break; - case QDeclarativeComponent::Ready: - obj = _component->create(); - if (_component->isError()) { - qWarning() << "QML has instantation errors:"; - qWarning() << _component->errors(); - return; - } - Q_ASSERT(_item == 0); - _item = qobject_cast(obj); - scene()->addItem(_item); - break; - case QDeclarativeComponent::Error: - qWarning() << "QML has errors:"; - qWarning() << _component->errors(); - break; - } -} diff --git a/declarativewatchlet.h b/declarativewatchlet.h deleted file mode 100644 index 1e94007..0000000 --- a/declarativewatchlet.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef DECLARATIVEWATCHLET_H -#define DECLARATIVEWATCHLET_H - -#include -#include -#include -#include "graphicswatchlet.h" - -namespace sowatch -{ - -class DeclarativeWatchWrapper; - -class DeclarativeWatchlet : public GraphicsWatchlet -{ - Q_OBJECT -public: - explicit DeclarativeWatchlet(WatchServer* server, const QString& id); - - void setSource(const QUrl& url); - -protected slots: - void handleComponentStatus(QDeclarativeComponent::Status status); - -protected: - void activate(); - void deactivate(); - - static bool _registered; - QDeclarativeEngine* _engine; - QDeclarativeComponent* _component; - QDeclarativeItem* _item; - DeclarativeWatchWrapper* _wrapper; - -}; - -} - -#endif // DECLARATIVEWATCHLET_H diff --git a/declarativewatchwrapper.cpp b/declarativewatchwrapper.cpp deleted file mode 100644 index 384a29d..0000000 --- a/declarativewatchwrapper.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include "watch.h" -#include "declarativewatchwrapper.h" - -using namespace sowatch; - -DeclarativeWatchWrapper::DeclarativeWatchWrapper(Watch* watch, QObject *parent) : - QObject(parent), _watch(watch), _active(false) -{ - -} - -QString DeclarativeWatchWrapper::model() const -{ - return _watch->model(); -} - -bool DeclarativeWatchWrapper::active() const -{ - return _active; -} - -void DeclarativeWatchWrapper::activate() -{ - if (!_active) { - connect(_watch, SIGNAL(buttonPressed(int)), this, SIGNAL(buttonPressed(int))); - connect(_watch, SIGNAL(buttonReleased(int)), this, SIGNAL(buttonReleased(int))); - _active = true; - emit activeChanged(); - } -} - -void DeclarativeWatchWrapper::deactivate() -{ - if (_active) { - disconnect(this, SIGNAL(buttonPressed(int))); - disconnect(this, SIGNAL(buttonReleased(int))); - _active = false; - emit activeChanged(); - } -} - diff --git a/declarativewatchwrapper.h b/declarativewatchwrapper.h deleted file mode 100644 index 5f78e75..0000000 --- a/declarativewatchwrapper.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef DECLARATIVEWATCHWRAPPER_H -#define DECLARATIVEWATCHWRAPPER_H - -#include - -namespace sowatch -{ - -class Watch; -class DeclarativeWatchlet; - -class DeclarativeWatchWrapper : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString model READ model CONSTANT) - Q_PROPERTY(bool active READ active NOTIFY activeChanged) - -public: - explicit DeclarativeWatchWrapper(Watch *watch, QObject *parent = 0); - - Q_INVOKABLE QString model() const; - Q_INVOKABLE bool active() const; - -signals: - void buttonPressed(int button); - void buttonReleased(int button); - - void activeChanged(); - -protected: - Watch* _watch; - bool _active; - - void activate(); - void deactivate(); - -friend class DeclarativeWatchlet; -}; - -} - -QML_DECLARE_TYPE(sowatch::DeclarativeWatchWrapper) - -#endif // DECLARATIVEWATCHWRAPPER_H diff --git a/graphicswatchlet.cpp b/graphicswatchlet.cpp deleted file mode 100644 index 538723a..0000000 --- a/graphicswatchlet.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include - -#include "watch.h" -#include "graphicswatchlet.h" - -using namespace sowatch; - -GraphicsWatchlet::GraphicsWatchlet(WatchServer* server, const QString& id) : - Watchlet(server, id), _scene(0), _damaged() -{ -} - -QGraphicsScene* GraphicsWatchlet::scene() -{ - return _scene; -} - -void GraphicsWatchlet::setScene(QGraphicsScene *scene) -{ - if (_scene) { - disconnect(this, SLOT(sceneChanged(QList))); - } - _scene = scene; - if (_scene) { - connect(_scene, SIGNAL(changed(QList)), - this, SLOT(sceneChanged(QList))); - } -} - -void GraphicsWatchlet::sceneChanged(const QList ®ion) -{ - foreach(const QRectF& r, region) - { - _damaged += r.toRect(); - } - - if (!_damaged.isEmpty() && _active && !watch()->busy()) { - const QVector rects = _damaged.rects(); - QPainter p(watch()); - foreach(const QRect& r, rects) - { - _scene->render(&p, r, r, Qt::IgnoreAspectRatio); - } - _damaged = QRegion(); - } -} diff --git a/graphicswatchlet.h b/graphicswatchlet.h deleted file mode 100644 index 9754062..0000000 --- a/graphicswatchlet.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef GRAPHICSWATCHLET_H -#define GRAPHICSWATCHLET_H - -#include -#include -#include "watchlet.h" - -namespace sowatch -{ - -class GraphicsWatchlet : public Watchlet -{ - Q_OBJECT -public: - explicit GraphicsWatchlet(WatchServer* server, const QString& id); - - QGraphicsScene* scene(); - void setScene(QGraphicsScene* scene); - -protected: - QGraphicsScene* _scene; - QRegion _damaged; - -protected slots: - void sceneChanged(const QList& region); - -}; - -} - -#endif // GRAPHICSWATCHLET_H diff --git a/libsowatch/declarativewatchlet.cpp b/libsowatch/declarativewatchlet.cpp new file mode 100644 index 0000000..7e6768e --- /dev/null +++ b/libsowatch/declarativewatchlet.cpp @@ -0,0 +1,96 @@ +#include +#include +#include "watchserver.h" +#include "declarativewatchwrapper.h" +#include "declarativewatchlet.h" + +using namespace sowatch; + +bool DeclarativeWatchlet::_registered = false; + +DeclarativeWatchlet::DeclarativeWatchlet(WatchServer* server, const QString& id) : + GraphicsWatchlet(server, id), + _engine(0), + _component(0), + _item(0), + _wrapper(0) +{ + setScene(new QGraphicsScene(this)); + + if (!_registered) { + qmlRegisterUncreatableType("com.javispedro.sowatch", 1, 0, + "Watch", "Watch is only available via the 'watch' object"); + _registered = true; + } + + _engine = new QDeclarativeEngine(this); + _wrapper = new DeclarativeWatchWrapper(server->watch(), this); + + _engine->rootContext()->setContextProperty("watch", _wrapper); +} + +void DeclarativeWatchlet::setSource(const QUrl &url) +{ + if (_item) { + scene()->removeItem(_item); + delete _item; + _item = 0; + } + if (_component) { + delete _component; + _component = 0; + } + if (!url.isEmpty()) { + _component = new QDeclarativeComponent(_engine, url, this); + connect(_component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), + SLOT(handleComponentStatus(QDeclarativeComponent::Status))); + if (!_component->isLoading()) { + /* No signals are going to be generated for this. */ + handleComponentStatus(_component->status()); + } else { + connect(_component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), + this, SLOT(handleComponentStatus(QDeclarativeComponent::Status))); + } + } +} + +void DeclarativeWatchlet::activate() +{ + Watchlet::activate(); + _wrapper->activate(); + _scene->update(); +} + +void DeclarativeWatchlet::deactivate() +{ + Watchlet::deactivate(); + _wrapper->deactivate(); +} + +void DeclarativeWatchlet::handleComponentStatus(QDeclarativeComponent::Status status) +{ + QObject *obj; + disconnect(_component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), + this, SLOT(handleComponentStatus(QDeclarativeComponent::Status))); + switch (status) { + case QDeclarativeComponent::Null: + case QDeclarativeComponent::Loading: + /* Nothing to do */ + break; + case QDeclarativeComponent::Ready: + obj = _component->create(); + if (_component->isError()) { + qWarning() << "QML has instantation errors:"; + qWarning() << _component->errors(); + return; + } + Q_ASSERT(_item == 0); + _item = qobject_cast(obj); + scene()->addItem(_item); + break; + case QDeclarativeComponent::Error: + qWarning() << "QML has errors:"; + qWarning() << _component->errors(); + break; + } +} diff --git a/libsowatch/declarativewatchlet.h b/libsowatch/declarativewatchlet.h new file mode 100644 index 0000000..1e94007 --- /dev/null +++ b/libsowatch/declarativewatchlet.h @@ -0,0 +1,39 @@ +#ifndef DECLARATIVEWATCHLET_H +#define DECLARATIVEWATCHLET_H + +#include +#include +#include +#include "graphicswatchlet.h" + +namespace sowatch +{ + +class DeclarativeWatchWrapper; + +class DeclarativeWatchlet : public GraphicsWatchlet +{ + Q_OBJECT +public: + explicit DeclarativeWatchlet(WatchServer* server, const QString& id); + + void setSource(const QUrl& url); + +protected slots: + void handleComponentStatus(QDeclarativeComponent::Status status); + +protected: + void activate(); + void deactivate(); + + static bool _registered; + QDeclarativeEngine* _engine; + QDeclarativeComponent* _component; + QDeclarativeItem* _item; + DeclarativeWatchWrapper* _wrapper; + +}; + +} + +#endif // DECLARATIVEWATCHLET_H diff --git a/libsowatch/declarativewatchwrapper.cpp b/libsowatch/declarativewatchwrapper.cpp new file mode 100644 index 0000000..384a29d --- /dev/null +++ b/libsowatch/declarativewatchwrapper.cpp @@ -0,0 +1,42 @@ +#include +#include "watch.h" +#include "declarativewatchwrapper.h" + +using namespace sowatch; + +DeclarativeWatchWrapper::DeclarativeWatchWrapper(Watch* watch, QObject *parent) : + QObject(parent), _watch(watch), _active(false) +{ + +} + +QString DeclarativeWatchWrapper::model() const +{ + return _watch->model(); +} + +bool DeclarativeWatchWrapper::active() const +{ + return _active; +} + +void DeclarativeWatchWrapper::activate() +{ + if (!_active) { + connect(_watch, SIGNAL(buttonPressed(int)), this, SIGNAL(buttonPressed(int))); + connect(_watch, SIGNAL(buttonReleased(int)), this, SIGNAL(buttonReleased(int))); + _active = true; + emit activeChanged(); + } +} + +void DeclarativeWatchWrapper::deactivate() +{ + if (_active) { + disconnect(this, SIGNAL(buttonPressed(int))); + disconnect(this, SIGNAL(buttonReleased(int))); + _active = false; + emit activeChanged(); + } +} + diff --git a/libsowatch/declarativewatchwrapper.h b/libsowatch/declarativewatchwrapper.h new file mode 100644 index 0000000..5f78e75 --- /dev/null +++ b/libsowatch/declarativewatchwrapper.h @@ -0,0 +1,44 @@ +#ifndef DECLARATIVEWATCHWRAPPER_H +#define DECLARATIVEWATCHWRAPPER_H + +#include + +namespace sowatch +{ + +class Watch; +class DeclarativeWatchlet; + +class DeclarativeWatchWrapper : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString model READ model CONSTANT) + Q_PROPERTY(bool active READ active NOTIFY activeChanged) + +public: + explicit DeclarativeWatchWrapper(Watch *watch, QObject *parent = 0); + + Q_INVOKABLE QString model() const; + Q_INVOKABLE bool active() const; + +signals: + void buttonPressed(int button); + void buttonReleased(int button); + + void activeChanged(); + +protected: + Watch* _watch; + bool _active; + + void activate(); + void deactivate(); + +friend class DeclarativeWatchlet; +}; + +} + +QML_DECLARE_TYPE(sowatch::DeclarativeWatchWrapper) + +#endif // DECLARATIVEWATCHWRAPPER_H diff --git a/libsowatch/graphicswatchlet.cpp b/libsowatch/graphicswatchlet.cpp new file mode 100644 index 0000000..538723a --- /dev/null +++ b/libsowatch/graphicswatchlet.cpp @@ -0,0 +1,47 @@ +#include +#include + +#include "watch.h" +#include "graphicswatchlet.h" + +using namespace sowatch; + +GraphicsWatchlet::GraphicsWatchlet(WatchServer* server, const QString& id) : + Watchlet(server, id), _scene(0), _damaged() +{ +} + +QGraphicsScene* GraphicsWatchlet::scene() +{ + return _scene; +} + +void GraphicsWatchlet::setScene(QGraphicsScene *scene) +{ + if (_scene) { + disconnect(this, SLOT(sceneChanged(QList))); + } + _scene = scene; + if (_scene) { + connect(_scene, SIGNAL(changed(QList)), + this, SLOT(sceneChanged(QList))); + } +} + +void GraphicsWatchlet::sceneChanged(const QList ®ion) +{ + foreach(const QRectF& r, region) + { + _damaged += r.toRect(); + } + + if (!_damaged.isEmpty() && _active && !watch()->busy()) { + const QVector rects = _damaged.rects(); + QPainter p(watch()); + foreach(const QRect& r, rects) + { + _scene->render(&p, r, r, Qt::IgnoreAspectRatio); + } + _damaged = QRegion(); + } +} diff --git a/libsowatch/graphicswatchlet.h b/libsowatch/graphicswatchlet.h new file mode 100644 index 0000000..9754062 --- /dev/null +++ b/libsowatch/graphicswatchlet.h @@ -0,0 +1,31 @@ +#ifndef GRAPHICSWATCHLET_H +#define GRAPHICSWATCHLET_H + +#include +#include +#include "watchlet.h" + +namespace sowatch +{ + +class GraphicsWatchlet : public Watchlet +{ + Q_OBJECT +public: + explicit GraphicsWatchlet(WatchServer* server, const QString& id); + + QGraphicsScene* scene(); + void setScene(QGraphicsScene* scene); + +protected: + QGraphicsScene* _scene; + QRegion _damaged; + +protected slots: + void sceneChanged(const QList& region); + +}; + +} + +#endif // GRAPHICSWATCHLET_H diff --git a/libsowatch/libsowatch.pro b/libsowatch/libsowatch.pro new file mode 100644 index 0000000..703845c --- /dev/null +++ b/libsowatch/libsowatch.pro @@ -0,0 +1,100 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2011-09-16T23:45:06 +# +#------------------------------------------------- + +QT += gui dbus declarative +CONFIG += mobility +MOBILITY += connectivity + +TARGET = libsowatch +TEMPLATE = lib + +DEFINES += SOWATCH_LIBRARY + +SOURCES += \ + watchsimulator.cpp \ + watchserver.cpp \ + watchpaintengine.cpp \ + watchmanager.cpp \ + watchlet.cpp \ + watch.cpp \ + testwatchlet.cpp \ + testdeclarativewatchlet.cpp \ + metawatchsimulatorform.cpp \ + metawatchsimulator.cpp \ + metawatchpaintengine.cpp \ + metawatch.cpp \ + main.cpp \ + graphicswatchlet.cpp \ + declarativewatchwrapper.cpp \ + declarativewatchlet.cpp + +HEADERS +=\ + watchsimulator.h \ + watchserver.h \ + watchpaintengine.h \ + watchmanager.h \ + watchlet.h \ + watch.h \ + testwatchlet.h \ + testdeclarativewatchlet.h \ + sowatch.h \ + metawatchsimulatorform.h \ + metawatchsimulator.h \ + metawatchpaintengine.h \ + metawatch.h \ + graphicswatchlet.h \ + declarativewatchwrapper.h \ + declarativewatchlet.h \ + sowatch_global.h + +FORMS += \ + metawatchsimulatorform.ui + +OTHER_FILES += \ + qtc_packaging/debian_harmattan/rules \ + qtc_packaging/debian_harmattan/README \ + qtc_packaging/debian_harmattan/copyright \ + qtc_packaging/debian_harmattan/control \ + qtc_packaging/debian_harmattan/compat \ + qtc_packaging/debian_harmattan/changelog + +install_headers.files =\ + watchsimulator.h \ + watchserver.h \ + watchpaintengine.h \ + watchmanager.h \ + watchlet.h \ + watch.h \ + testwatchlet.h \ + testdeclarativewatchlet.h \ + sowatch.h \ + graphicswatchlet.h \ + declarativewatchwrapper.h \ + declarativewatchlet.h \ + sowatch_global.h + + +symbian { + MMP_RULES += EXPORTUNFROZEN + TARGET.UID3 = 0xE6B95AFF + TARGET.CAPABILITY = + TARGET.EPOCALLOWDLLDATA = 1 + addFiles.sources = libsowatch.dll + addFiles.path = !:/sys/bin + DEPLOYMENT += addFiles +} + +unix:!symbian { + install_headers.path = /usr/include/sowatch + maemo5 { + target.path = /opt/maemo/usr/lib + } else { + target.path = /usr/lib + } + INSTALLS += install_headers target +} + + diff --git a/libsowatch/libsowatch.pro.user b/libsowatch/libsowatch.pro.user new file mode 100644 index 0000000..d20c31f --- /dev/null +++ b/libsowatch/libsowatch.pro.user @@ -0,0 +1,549 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + + Cpp + + false + CppGlobal + true + false + true + false + false + false + true + true + false + true + false + false + false + true + false + + + 1 + System + Global + 4 + true + 1 + true + false + true + + Cpp + + true + false + CppGlobal + 4 + 1 + false + true + 0 + 8 + + + + QmlJS + + true + false + QmlJSGlobal + 4 + 1 + false + true + 0 + 8 + + + 2 + 0 + 8 + true + 2 + true + true + true + false + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + Qt4ProjectManager.Target.DesktopTarget + 0 + 1 + 0 + + ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb + + + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Desktop Qt 4.7.4 for GCC (Qt SDK) Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /home/javier/maemo/qt/libsowatch-build-desktop-release + 13 + true + + + ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb + + + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Desktop Qt 4.7.4 for GCC (Qt SDK) Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /home/javier/maemo/qt/libsowatch-build-desktop-debug + 13 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + No deployment + + ProjectExplorer.DefaultDeployConfiguration + + + + + Create tarball + + MaemoTarPackageCreationStep + + + Deploy tarball via SFTP upload + + MaemoUploadAndInstallTarPackageStep + + + + + + 2 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Build Tarball and Install to Linux Host + + DeployToGenericLinux + 0 + + 2 + + true + true + + + false + false + false + false + false + false + false + false + true + true + 0.01 + 0.01 + 10 + 10 + true + true + 25 + 25 + + + true + true + valgrind + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 2 + + false + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + true + false + false + + 1 + + + + ProjectExplorer.Project.Target.1 + + Harmattan + Harmattan + Qt4ProjectManager.Target.HarmattanDeviceTarget + 0 + 0 + 0 + + Qt4ProjectManager.ToolChain.Maemo:/home/javier/opt/QtSDK/Madde/targets/harmattan-nokia-meego-api/bin/gcc.arm-linux-generic-elf-32bit./home/javier/opt/QtSDK/pythongdb/gdb + + + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + MeeGo 1.2 Harmattan API (Qt SDK) Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /home/javier/maemo/qt/libsowatch-build-harmattan-release + 10 + true + + + Qt4ProjectManager.ToolChain.Maemo:/home/javier/opt/QtSDK/Madde/targets/harmattan-nokia-meego-api/bin/gcc.arm-linux-generic-elf-32bit./home/javier/opt/QtSDK/pythongdb/gdb + + + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + MeeGo 1.2 Harmattan API (Qt SDK) Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /home/javier/maemo/qt/libsowatch-build-harmattan-debug + 10 + true + + 2 + + + + Create Debian Package + + MaemoDebianPackageCreationStep + + + + Install Debian package to sysroot + MaemoInstallDebianPackageToSysrootStep + + + Deploy Debian package via SFTP upload + + MaemoUploadAndInstallDpkgPackageStep + + + + + + 3 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Build Debian Package and Install to Harmattan Device + + DeployToHarmattan + 0 + + 1 + + true + true + + + false + false + false + false + false + false + false + false + true + true + 0.01 + 0.01 + 10 + 10 + true + true + 25 + 25 + + + true + true + valgrind + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 2 + + false + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + true + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 2 + + + ProjectExplorer.Project.Updater.EnvironmentId + {4e827e92-6882-4bad-8513-da5dad54ff3f} + + + ProjectExplorer.Project.Updater.FileVersion + 10 + + diff --git a/libsowatch/main.cpp b/libsowatch/main.cpp new file mode 100644 index 0000000..d0eae3f --- /dev/null +++ b/libsowatch/main.cpp @@ -0,0 +1,35 @@ +#include +#include + +#include "metawatchsimulator.h" +#include "metawatch.h" +#include "watchserver.h" +#include "testwatchlet.h" +#include "testdeclarativewatchlet.h" + +using namespace sowatch; +QTM_USE_NAMESPACE + +static Watch *watch; +static WatchServer *server; + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + if (a.arguments().count() > 1) { + watch = new MetaWatch(QBluetoothAddress(a.arguments().at(1))); + } else { + watch = new MetaWatchSimulator(); + } + + /* D0:37:61:C3:C7:99 */ + server = new WatchServer(watch); + new TestDeclarativeWatchlet(server); + new TestWatchlet(server); + + server->runWatchlet("com.javispedro.sowatch.testdeclarativewatchlet"); + //server->runWatchlet("com.javispedro.sowatch.testwatchlet"); + + return a.exec(); +} diff --git a/libsowatch/metawatch.cpp b/libsowatch/metawatch.cpp new file mode 100644 index 0000000..b968fad --- /dev/null +++ b/libsowatch/metawatch.cpp @@ -0,0 +1,409 @@ +#include +#include + +#include "metawatchpaintengine.h" +#include "metawatch.h" + +using namespace sowatch; +QTM_USE_NAMESPACE + +#define SINGLE_LINE_UPDATE 0 + +const quint8 MetaWatch::bitRevTable[16] = { + 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 +}; + +const quint16 MetaWatch::crcTable[256] = { + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 +}; + +#if 0 /* This snippet was used to build the table seen above. */ + quint16 remainder; + int dividend; + quint8 bit; + + for (dividend = 0; dividend < 256; dividend++) { + remainder = dividend << 8; + for (bit = 8; bit > 0; bit--) { + if (remainder & 0x8000) { + remainder = (remainder << 1) ^ 0x1021; + } else { + remainder = (remainder << 1); + } + } + if ((dividend % 8) == 0) { + printf(",\n0x%04hx", remainder); + } else { + printf(", 0x%04hx", remainder); + } + } +#endif + +MetaWatch::MetaWatch(const QBluetoothAddress& address, QObject *parent) : + Watch(QImage(96, 96, QImage::Format_MonoLSB), parent), + _socket(new QBluetoothSocket(QBluetoothSocket::RfcommSocket)), + _sendTimer(new QTimer(this)) +{ + connect(_socket, SIGNAL(connected()), SLOT(socketConnected())); + connect(_socket, SIGNAL(disconnected()), SLOT(socketDisconnected())); + connect(_socket, SIGNAL(readyRead()), SLOT(socketData())); + connect(_socket, SIGNAL(error(QBluetoothSocket::SocketError)), + SLOT(socketError(QBluetoothSocket::SocketError))); + connect(_socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), + SLOT(socketState(QBluetoothSocket::SocketState))); + + _sendTimer->setInterval(30); + connect(_sendTimer, SIGNAL(timeout()), SLOT(timedSend())); + + _socket->connectToService(address, 1, QIODevice::ReadWrite | QIODevice::Unbuffered); +} + +QPaintEngine* MetaWatch::paintEngine() const +{ + if (!_paintEngine) { + _paintEngine = new MetaWatchPaintEngine(const_cast(this), + const_cast(&_image)); + } + + return _paintEngine; +} + +QString MetaWatch::model() const +{ + return "metawatch-digital"; +} + +bool MetaWatch::isConnected() const +{ + return _socket->state() == QBluetoothSocket::ConnectedState; +} + +bool MetaWatch::busy() const +{ + return _socket->state() != QBluetoothSocket::ConnectedState || + _toSend.size() > 20; +} + +void MetaWatch::update(const QList &rects) +{ + if (_socket->state() != QBluetoothSocket::ConnectedState) return; + const QRect imageRect = _image.rect(); + QVector lines(_image.height(), false); + + foreach (const QRect& rect, rects) { + QRect r = rect.intersect(imageRect); + for (int i = r.top(); i <= r.bottom(); i++) { + lines[i] = true; + } + } + + updateLines(ApplicationMode, _image, lines); + updateDisplay(ApplicationMode); +} + +void MetaWatch::clear(bool white) +{qDebug() << "MWclear" << white; + if (_socket->state() != QBluetoothSocket::ConnectedState) return; + loadTemplate(ApplicationMode, white ? 1 : 0); +} + +void MetaWatch::vibrate(bool on) +{ + +} + +void MetaWatch::setDateTime(const QDateTime &dateTime) +{ + Message msg(SetRealTimeClock, QByteArray(10, 0)); + const QDate& date = dateTime.date(); + const QTime& time = dateTime.time(); + + msg.data[0] = date.year() & 0xF00; + msg.data[1] = date.year() & 0xFF; + msg.data[2] = date.month(); + msg.data[3] = date.day(); + msg.data[4] = date.dayOfWeek() - 1; + msg.data[5] = time.hour(); + msg.data[6] = time.minute(); + msg.data[7] = time.second(); + msg.data[8] = 1; + msg.data[9] = 1; + + send(msg); +} + +quint16 MetaWatch::calcCrc(const QByteArray &data, int size) +{ + quint16 remainder = 0xFFFF; + + for (int i = 0; i < size; i++) { + quint8 byte = data[i]; + byte = (bitRevTable[byte & 0xF] << 4) | bitRevTable[(byte & 0xF0) >> 4]; + remainder = crcTable[byte ^ (remainder >> 8)] ^ (remainder << 8); + } + + return remainder; +} + +quint16 MetaWatch::calcCrc(const Message& msg) +{ + QByteArray data; + const int msgSize = msg.data.size(); + + data.resize(msgSize + 4); + data[0] = 0x01; + data[1] = msgSize + 6; + data[2] = msg.type; + data[3] = msg.options; + data.replace(4, msgSize, msg.data); + + return calcCrc(data, msgSize + 4); +} + +void MetaWatch::send(const Message &msg) +{ + _toSend.enqueue(msg); + if (!_sendTimer->isActive()) { + _sendTimer->start(); + } +} + +void MetaWatch::handleMessage(const Message &msg) +{ + switch (msg.type) { + case StatusChangeEvent: + handleStatusChange(msg); + break; + case ButtonEvent: + handleButtonEvent(msg); + break; + default: + qWarning() << "Unknown message of type" << msg.type << "received"; + break; + } +} + +void MetaWatch::updateLine(Mode mode, const QImage& image, int line) +{ + Message msg(WriteBuffer, QByteArray(13, 0), (1 << 4) | (mode & 0xF)); + const char * scanLine = (const char *) image.constScanLine(line); + + msg.data[0] = line; + msg.data.replace(1, 12, scanLine, 12); + + send(msg); +} + +void MetaWatch::updateLines(Mode mode, const QImage& image, int lineA, int lineB) +{ + Message msg(WriteBuffer, QByteArray(26, 0), mode & 0xF); + const char * scanLine = (const char *) image.constScanLine(lineA); + + msg.data[0] = lineA; + msg.data.replace(1, 12, scanLine, 12); + + scanLine = (const char *) image.constScanLine(lineB); + msg.data[13] = lineB; + msg.data.replace(14, 12, scanLine, 12); + + send(msg); +} + +void MetaWatch::updateLines(Mode mode, const QImage& image, const QVector& lines) +{ + int lineCount = lines.count(true); + int lineA = -1; + + if (lineCount == 0) return; + + for (int line = 0; line < lines.size(); line++) { + if (lines[line]) { + lineCount--; +#if SINGLE_LINE_UPDATE + updateLine(mode, image, line); + continue; +#endif + if (lineA >= 0) { + // We have a pair of lines to send. + updateLines(mode, image, lineA, line); + lineA = -1; + } else if (lineCount > 0) { + // Still another line to send. + lineA = line; + } else { + updateLine(mode, image, line); + break; // No more lines + } + } + } +} + +void MetaWatch::configureWatchMode(Mode mode, int timeout, bool invert) +{ + Message msg(ConfigureMode, QByteArray(2, 0), mode & 0xF); + msg.data[0] = timeout; + msg.data[1] = invert ? 1 : 0; + send(msg); +} + +void MetaWatch::updateDisplay(Mode mode, bool copy) +{ + Message msg(UpdateDisplay, QByteArray(), + (copy ? 0x10 : 0) | (mode & 0xF)); + send(msg); +} + +void MetaWatch::loadTemplate(Mode mode, int templ) +{ + Message msg(LoadTemplate, QByteArray(1, templ), mode & 0xF); + send(msg); +} + +void MetaWatch::handleStatusChange(const Message &msg) +{ + qDebug() << "watch status changed" << msg.data.size(); +} + +void MetaWatch::handleButtonEvent(const Message &msg) +{ + if (msg.data.size() < 1) return; + quint8 button = msg.data[0]; + + emit buttonPressed(button); // TODO This is completely broken +} + +void MetaWatch::socketConnected() +{ + qDebug() << "connected"; + _partialReceived.type = NoMessage; + _partialReceived.data.clear(); + _buttonState = 0; + setDateTime(QDateTime::currentDateTime()); + configureWatchMode(ApplicationMode); + emit connected(); +} + +void MetaWatch::socketDisconnected() +{ + _toSend.clear(); + _sendTimer->stop(); + emit disconnected(); +} + +void MetaWatch::socketData() +{ + qint64 dataRead; + + if (_partialReceived.type == 0) { + if (_socket->bytesAvailable() < 4) return; /* Wait for more. */ + char header[4]; + + dataRead = _socket->read(header, 4); + if (dataRead < 4 || header[0] != 0x01) { + qWarning() << "TODO: Resync/Handle Garbage"; + return; + } + + _partialReceived.type = static_cast(header[2]); + _partialReceived.data.resize(header[1] - 6); + _partialReceived.options = header[3]; + } + if (_socket->bytesAvailable() < _partialReceived.data.size() + 2) { + return; /* Wait for more. */ + } + dataRead = _socket->read(_partialReceived.data.data(), _partialReceived.data.size()); + if (dataRead < _partialReceived.data.size()) { + qWarning() << "Short read"; + return; + } + + char tail[2]; + dataRead = _socket->read(tail, 2); + if (dataRead < 2) { + qWarning() << "Short read"; + return; + } + + quint16 realCrc = calcCrc(_partialReceived); + quint16 expectedCrc = tail[1] << 8 | (tail[0] & 0xFFU); + if (realCrc == expectedCrc) { + handleMessage(_partialReceived); + } else { + qWarning() << "CRC error?"; + } + + _partialReceived.data.clear(); + _partialReceived.type = NoMessage; +} + +void MetaWatch::socketError(QBluetoothSocket::SocketError error) +{ + qWarning() << "Socket error:" << error; +} + +void MetaWatch::socketState(QBluetoothSocket::SocketState error) +{ + qDebug() << "socket is in" << error; +} + +void MetaWatch::timedSend() +{ + if (_toSend.count() > 0) { + realSend(_toSend.dequeue()); + } + if (_toSend.count() == 0) { + _sendTimer->stop(); + } +} + +void MetaWatch::realSend(const Message &msg) +{ + const int msgSize = msg.data.size(); + QByteArray data; + quint16 crc; + + data.resize(msgSize + 6); + data[0] = 0x01; + data[1] = msgSize + 6; + data[2] = msg.type; + data[3] = msg.options; + data.replace(4, msgSize, msg.data); + crc = calcCrc(data, msgSize + 4); + data[msgSize+4] = crc & 0xFF; + data[msgSize+5] = crc >> 8; + + //qDebug() << "Sending" << data.toHex(); + + _socket->write(data); +} diff --git a/libsowatch/metawatch.h b/libsowatch/metawatch.h new file mode 100644 index 0000000..80a1894 --- /dev/null +++ b/libsowatch/metawatch.h @@ -0,0 +1,122 @@ +#ifndef METAWATCH_H +#define METAWATCH_H + +#include +#include +#include +#include +#include "watch.h" + +using QTM_PREPEND_NAMESPACE(QBluetoothSocket); +using QTM_PREPEND_NAMESPACE(QBluetoothAddress); + +namespace sowatch +{ + +class MetaWatch : public Watch +{ + Q_OBJECT + Q_ENUMS(MessageType Mode) + +public: + explicit MetaWatch(const QBluetoothAddress& address, QObject *parent = 0); + + QPaintEngine* paintEngine() const; + + QString model() const; + bool isConnected() const; + bool busy() const; + void update(const QList& rects); + void clear(bool white = false); + void vibrate(bool on); + + void setDateTime(const QDateTime& dateTime); + + enum MessageType { + NoMessage = 0, + GetDeviceType = 0x01, + GetDeviceTypeResponse = 0x02, + GetInformationString = 0x03, + GetInformationStringResponse = 0x04, + AdvanceWatchHands = 0x20, + SetVibrateMode = 0x23, + SetRealTimeClock = 0x26, + GetRealTimeClock = 0x27, + GetRealTimeClockResponse = 0x28, + StatusChangeEvent = 0x33, + ButtonEvent = 0x34, + WriteBuffer = 0x40, + ConfigureMode = 0x41, + ConfigureIdleBufferSize = 0x42, + UpdateDisplay = 0x43, + LoadTemplate = 0x44, + EnableButton = 0x46, + DisableButton = 0x47, + ReadButtonConfiguration = 0x48, + ReadButtonConfigurationResponse = 0x49, + BatteryConfiguration = 0x53, + LowBatteryWarning = 0x54, + LowBatteryBluetoothOff = 0x55, + ReadBatteryVoltage = 0x56, + ReadBatteryVoltageResponse = 0x57, + Accelerometer = 0xea + }; + + enum Mode { + IdleMode = 0, + ApplicationMode = 1 + }; + +protected: + QBluetoothSocket* _socket; + + struct Message { + MessageType type; + quint8 options; + QByteArray data; + Message(MessageType ntype = NoMessage, QByteArray ndata = QByteArray(), quint8 noptions = 0) : + type(ntype), options(noptions), data(ndata) + { + + } + }; + + QQueue _toSend; + QTimer* _sendTimer; + Message _partialReceived; + + quint8 _buttonState; + + static const quint8 bitRevTable[16]; + static const quint16 crcTable[256]; + quint16 calcCrc(const QByteArray& data, int size); + quint16 calcCrc(const Message& msg); + + void send(const Message& msg); + void handleMessage(const Message& msg); + + void updateLine(Mode mode, const QImage& image, int line); + void updateLines(Mode mode, const QImage& image, int lineA, int lineB); + void updateLines(Mode mode, const QImage& image, const QVector& lines); + void configureWatchMode(Mode mode, int timeout = 10, bool invert = false); + void updateDisplay(Mode mode, bool copy = true); + void loadTemplate(Mode mode, int templ); + + void handleStatusChange(const Message& msg); + void handleButtonEvent(const Message& msg); + +protected slots: + void socketConnected(); + void socketDisconnected(); + void socketData(); + void socketError(QBluetoothSocket::SocketError error); + void socketState(QBluetoothSocket::SocketState error); + void timedSend(); + +private: + void realSend(const Message& msg); +}; + +} + +#endif // METAWATCH_H diff --git a/libsowatch/metawatchpaintengine.cpp b/libsowatch/metawatchpaintengine.cpp new file mode 100644 index 0000000..71ad452 --- /dev/null +++ b/libsowatch/metawatchpaintengine.cpp @@ -0,0 +1,82 @@ +#include "metawatch.h" +#include "metawatchpaintengine.h" + +using namespace sowatch; + +MetaWatchPaintEngine::MetaWatchPaintEngine(MetaWatch* watch, QImage* image) : + WatchPaintEngine(watch, image), _watch(watch), + _imageRect(image->rect()) +{ +} + +void MetaWatchPaintEngine::drawRects(const QRectF *rects, int rectCount) +{ + int i; + for (i = 0; i < rectCount; i++) { + const QRectF& r = rects[i]; + if (_hasBrush && fillsEntireImage(r.toRect()) && (_isBrushBlack | _isBrushWhite)) { + _watch->clear(_isBrushWhite); + _damaged = QRegion(); + continue; + } + if (_hasBrush) { + damageRect(r); + } + if (_hasPen) { + damagePenStroke(QLineF(r.left(), r.top(), r.right(), r.top())); + damagePenStroke(QLineF(r.right(), r.top(), r.right(), r.bottom())); + damagePenStroke(QLineF(r.left(), r.bottom(), r.right(), r.bottom())); + damagePenStroke(QLineF(r.left(), r.top(), r.left(), r.bottom())); + } + } + _painter.drawRects(rects, rectCount); +} + +void MetaWatchPaintEngine::drawRects(const QRect *rects, int rectCount) +{ + int i; + for (i = 0; i < rectCount; i++) { + const QRect& r = rects[i]; + if (_hasBrush && fillsEntireImage(r) && (_isBrushBlack | _isBrushWhite)) { + _watch->clear(_isBrushWhite); + _damaged = QRegion(); + continue; + } + if (_hasBrush) { + damageRect(r); + } + if (_hasPen) { + damagePenStroke(QLine(r.left(), r.top(), r.right(), r.top())); + damagePenStroke(QLine(r.right(), r.top(), r.right(), r.bottom())); + damagePenStroke(QLine(r.left(), r.bottom(), r.right(), r.bottom())); + damagePenStroke(QLine(r.left(), r.top(), r.left(), r.bottom())); + } + } + + _painter.drawRects(rects, rectCount); +} + +void MetaWatchPaintEngine::updateState(const QPaintEngineState &state) +{ + WatchPaintEngine::updateState(state); + if (state.state() & QPaintEngine::DirtyBrush) { + QBrush brush = state.brush(); + _isBrushBlack = false; + _isBrushWhite = false; + if (brush.style() == Qt::SolidPattern) { + const QColor color = brush.color(); + if (color == Qt::black) { + _isBrushBlack = true; + } else if (color == Qt::white) { + _isBrushWhite = true; + } + } + } +} + +bool MetaWatchPaintEngine::fillsEntireImage(const QRect& rect) +{ + return rect == _imageRect && + (!_clipEnabled || + (_clipRegion.numRects() == 1 && _clipRegion.rects().at(0) == _imageRect)); +} diff --git a/libsowatch/metawatchpaintengine.h b/libsowatch/metawatchpaintengine.h new file mode 100644 index 0000000..efc3d6e --- /dev/null +++ b/libsowatch/metawatchpaintengine.h @@ -0,0 +1,34 @@ +#ifndef METAWATCHPAINTENGINE_H +#define METAWATCHPAINTENGINE_H + +#include +#include "watchpaintengine.h" + +namespace sowatch +{ + +class MetaWatch; + +/** This WatchPaintEngine accelerates fillRects by using the MetaWatch's template command. */ +class MetaWatchPaintEngine : public WatchPaintEngine +{ +public: + explicit MetaWatchPaintEngine(MetaWatch* watch, QImage* image); + + void drawRects(const QRectF *rects, int rectCount); + void drawRects(const QRect *rects, int rectCount); + + void updateState(const QPaintEngineState &state); + +protected: + bool fillsEntireImage(const QRect& rect); + + MetaWatch* _watch; + QRect _imageRect; + bool _isBrushBlack; + bool _isBrushWhite; +}; + +} + +#endif // METAWATCHPAINTENGINE_H diff --git a/libsowatch/metawatchsimulator.cpp b/libsowatch/metawatchsimulator.cpp new file mode 100644 index 0000000..11b938a --- /dev/null +++ b/libsowatch/metawatchsimulator.cpp @@ -0,0 +1,82 @@ +#include +#include + +#include "metawatchsimulator.h" + +#define SIMULATE_DAMAGES 1 +#define SIMULATE_FRAMERATE 1 + +using namespace sowatch; + +MetaWatchSimulator::MetaWatchSimulator(QObject *parent) : + WatchSimulator(QImage(96, 96, QImage::Format_Mono), parent), + _screen(96, 96), + _form(new MetaWatchSimulatorForm), + _nextFrame(QTime::currentTime()) +{ + _form->showNormal(); + connect(_form, SIGNAL(destroyed()), SIGNAL(disconnected())); + connect(_form, SIGNAL(buttonPressed(int)), SIGNAL(buttonPressed(int))); + connect(_form, SIGNAL(buttonReleased(int)), SIGNAL(buttonReleased(int))); +} + +MetaWatchSimulator::~MetaWatchSimulator() +{ + delete _form; +} + +QString MetaWatchSimulator::model() const +{ + return "metawatch-digital"; +} + +bool MetaWatchSimulator::isConnected() const +{ + return true; +} + +bool MetaWatchSimulator::busy() const +{ +#if SIMULATE_FRAMERATE + return _nextFrame > QTime::currentTime(); +#else + return false; +#endif +} + +void MetaWatchSimulator::update(const QList &rects) +{ +#if SIMULATE_DAMAGES + const QRect imageRect = _image.rect(); + QPainter p; + QVector rows(96, false); + unsigned total = 0, totalRows; + + p.begin(&_screen); + foreach (const QRect& rect, rects) { + QRect r = rect.intersect(imageRect); + for (int i = r.top(); i <= r.bottom(); i++) { + rows[i] = true; + } + total += r.width() * r.height(); + + p.drawImage(r, _image, r); + } + p.end(); + + totalRows = rows.count(true); + + _form->refreshScreen(_screen); + + qDebug() << "updated " << total << " pixels " << totalRows << " lines"; + _nextFrame = QTime::currentTime().addMSecs(((totalRows / 2) + 1) * 30); +#else + _form->refreshScreen(QPixmap::fromImage(_image)); + _nextFrame = QTime::currentTime().addMSecs(30); +#endif +} + +void MetaWatchSimulator::vibrate(bool on) +{ + qDebug() << "vibrate" << on; +} diff --git a/libsowatch/metawatchsimulator.h b/libsowatch/metawatchsimulator.h new file mode 100644 index 0000000..674c3c6 --- /dev/null +++ b/libsowatch/metawatchsimulator.h @@ -0,0 +1,32 @@ +#ifndef METAWATCHSIMULATOR_H +#define METAWATCHSIMULATOR_H + +#include +#include "watchsimulator.h" +#include "metawatchsimulatorform.h" + +namespace sowatch { + +class MetaWatchSimulator : public WatchSimulator +{ + Q_OBJECT +public: + explicit MetaWatchSimulator(QObject *parent = 0); + ~MetaWatchSimulator(); + + QString model() const; + bool isConnected() const; + bool busy() const; + + void update(const QList &rects); + void vibrate(bool on); + +protected: + QPixmap _screen; + MetaWatchSimulatorForm* _form; + QTime _nextFrame; +}; + +} + +#endif // METAWATCHSIMULATOR_H diff --git a/libsowatch/metawatchsimulatorform.cpp b/libsowatch/metawatchsimulatorform.cpp new file mode 100644 index 0000000..f2323bd --- /dev/null +++ b/libsowatch/metawatchsimulatorform.cpp @@ -0,0 +1,82 @@ +#include "metawatchsimulatorform.h" +#include "ui_metawatchsimulatorform.h" + +using namespace sowatch; + +MetaWatchSimulatorForm::MetaWatchSimulatorForm(QWidget* parent) : + QWidget(parent), + ui(new Ui::MetaWatchSimulatorForm) +{ + ui->setupUi(this); +} + +MetaWatchSimulatorForm::~MetaWatchSimulatorForm() +{ + delete ui; +} + +void MetaWatchSimulatorForm::refreshScreen(const QPixmap& pixmap) +{ + ui->lblDisplay->setPixmap(pixmap); + ui->lblDisplay->update(); +} + +void MetaWatchSimulatorForm::btnAPressed() +{ + emit buttonPressed(0); +} + +void MetaWatchSimulatorForm::btnAReleased() +{ + emit buttonReleased(0); +} + +void MetaWatchSimulatorForm::btnBPressed() +{ + emit buttonPressed(1); +} + +void MetaWatchSimulatorForm::btnBReleased() +{ + emit buttonReleased(1); +} + +void MetaWatchSimulatorForm::btnCPressed() +{ + emit buttonPressed(2); +} + +void MetaWatchSimulatorForm::btnCReleased() +{ + emit buttonReleased(2); +} + +void MetaWatchSimulatorForm::btnDPressed() +{ + emit buttonPressed(3); +} + +void MetaWatchSimulatorForm::btnDReleased() +{ + emit buttonReleased(3); +} + +void MetaWatchSimulatorForm::btnEPressed() +{ + emit buttonPressed(4); +} + +void MetaWatchSimulatorForm::btnEReleased() +{ + emit buttonReleased(4); +} + +void MetaWatchSimulatorForm::btnFPressed() +{ + emit buttonPressed(5); +} + +void MetaWatchSimulatorForm::btnFReleased() +{ + emit buttonReleased(5); +} diff --git a/libsowatch/metawatchsimulatorform.h b/libsowatch/metawatchsimulatorform.h new file mode 100644 index 0000000..0b45746 --- /dev/null +++ b/libsowatch/metawatchsimulatorform.h @@ -0,0 +1,46 @@ +#ifndef METAWATCHSIMULATORFORM_H +#define METAWATCHSIMULATORFORM_H + +#include + +namespace Ui { + class MetaWatchSimulatorForm; +} + +namespace sowatch { + +class MetaWatchSimulatorForm : public QWidget +{ + Q_OBJECT + +public: + explicit MetaWatchSimulatorForm(QWidget *parent = 0); + ~MetaWatchSimulatorForm(); + + void refreshScreen(const QPixmap& screen); + +signals: + void buttonPressed(int button); + void buttonReleased(int button); + +protected slots: + void btnAPressed(); + void btnAReleased(); + void btnBPressed(); + void btnBReleased(); + void btnCPressed(); + void btnCReleased(); + void btnDPressed(); + void btnDReleased(); + void btnEPressed(); + void btnEReleased(); + void btnFPressed(); + void btnFReleased(); + +private: + Ui::MetaWatchSimulatorForm *ui; +}; + +} + +#endif // METAWATCHSIMULATORFORM_H diff --git a/libsowatch/metawatchsimulatorform.ui b/libsowatch/metawatchsimulatorform.ui new file mode 100644 index 0000000..39280b3 --- /dev/null +++ b/libsowatch/metawatchsimulatorform.ui @@ -0,0 +1,294 @@ + + + MetaWatchSimulatorForm + + + + 0 + 0 + 262 + 113 + + + + MetaWatch-Digital Simulator + + + + + + + + A + + + + + + + B + + + + + + + C + + + + + + + + + + 0 + 0 + + + + + + + Qt::AlignCenter + + + + + + + + + D + + + + + + + E + + + + + + + F + + + + + + + + + + + btnA + pressed() + MetaWatchSimulatorForm + btnAPressed() + + + 44 + 20 + + + 105 + 4 + + + + + btnA + released() + MetaWatchSimulatorForm + btnAReleased() + + + 71 + 21 + + + 4 + 10 + + + + + btnB + pressed() + MetaWatchSimulatorForm + btnBPressed() + + + 68 + 57 + + + 98 + 75 + + + + + btnB + released() + MetaWatchSimulatorForm + btnBReleased() + + + 86 + 56 + + + 98 + 58 + + + + + btnC + pressed() + MetaWatchSimulatorForm + btnCPressed() + + + 37 + 90 + + + 73 + 108 + + + + + btnC + released() + MetaWatchSimulatorForm + btnCReleased() + + + 21 + 89 + + + 19 + 105 + + + + + btnD + pressed() + MetaWatchSimulatorForm + btnDPressed() + + + 203 + 18 + + + 205 + 5 + + + + + btnD + released() + MetaWatchSimulatorForm + btnDReleased() + + + 244 + 22 + + + 258 + 21 + + + + + btnE + pressed() + MetaWatchSimulatorForm + btnEPressed() + + + 237 + 50 + + + 256 + 51 + + + + + btnE + released() + MetaWatchSimulatorForm + btnEReleased() + + + 174 + 46 + + + 164 + 40 + + + + + btnF + pressed() + MetaWatchSimulatorForm + btnFPressed() + + + 236 + 89 + + + 258 + 87 + + + + + btnF + released() + MetaWatchSimulatorForm + btnFReleased() + + + 185 + 90 + + + 187 + 108 + + + + + + btnAPressed() + btnAReleased() + btnBPressed() + btnBReleased() + btnCPressed() + btnCReleased() + btnDPressed() + btnDReleased() + btnEPressed() + btnEReleased() + btnFPressed() + btnFReleased() + + diff --git a/libsowatch/qtc_packaging/debian_harmattan/README b/libsowatch/qtc_packaging/debian_harmattan/README new file mode 100644 index 0000000..e9d95a7 --- /dev/null +++ b/libsowatch/qtc_packaging/debian_harmattan/README @@ -0,0 +1,6 @@ +The Debian Package libsowatch +---------------------------- + +Comments regarding the Package + + -- Javier Fri, 16 Sep 2011 23:45:08 +0200 diff --git a/libsowatch/qtc_packaging/debian_harmattan/changelog b/libsowatch/qtc_packaging/debian_harmattan/changelog new file mode 100644 index 0000000..a893c9c --- /dev/null +++ b/libsowatch/qtc_packaging/debian_harmattan/changelog @@ -0,0 +1,5 @@ +libsowatch (0.0.1) unstable; urgency=low + + * Initial Release. + + -- Javier Fri, 16 Sep 2011 23:45:08 +0200 diff --git a/libsowatch/qtc_packaging/debian_harmattan/compat b/libsowatch/qtc_packaging/debian_harmattan/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/libsowatch/qtc_packaging/debian_harmattan/compat @@ -0,0 +1 @@ +7 diff --git a/libsowatch/qtc_packaging/debian_harmattan/control b/libsowatch/qtc_packaging/debian_harmattan/control new file mode 100644 index 0000000..0319078 --- /dev/null +++ b/libsowatch/qtc_packaging/debian_harmattan/control @@ -0,0 +1,14 @@ +Source: libsowatch +Section: user/other +Priority: optional +Maintainer: Javier +Build-Depends: debhelper (>= 5), libqt4-dev +Standards-Version: 3.7.3 +Homepage: + +Package: libsowatch +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: + +XSBC-Maemo-Display-Name: libsowatch diff --git a/libsowatch/qtc_packaging/debian_harmattan/copyright b/libsowatch/qtc_packaging/debian_harmattan/copyright new file mode 100644 index 0000000..33b2cc7 --- /dev/null +++ b/libsowatch/qtc_packaging/debian_harmattan/copyright @@ -0,0 +1,40 @@ +This package was debianized by Javier on +Fri, 16 Sep 2011 23:45:08 +0200. + +It was downloaded from + +Upstream Author(s): + + + + +Copyright: + + + + +License: + + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this package; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +On Debian systems, the complete text of the GNU General +Public License can be found in `/usr/share/common-licenses/GPL'. + +The Debian packaging is (C) 2011, Javier and +is licensed under the GPL, see above. + + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. diff --git a/libsowatch/qtc_packaging/debian_harmattan/manifest.aegis b/libsowatch/qtc_packaging/debian_harmattan/manifest.aegis new file mode 100644 index 0000000..e69de29 diff --git a/libsowatch/qtc_packaging/debian_harmattan/rules b/libsowatch/qtc_packaging/debian_harmattan/rules new file mode 100755 index 0000000..f87e675 --- /dev/null +++ b/libsowatch/qtc_packaging/debian_harmattan/rules @@ -0,0 +1,91 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + + + + + +configure: configure-stamp +configure-stamp: + dh_testdir + # qmake PREFIX=/usr# Uncomment this line for use without Qt Creator + + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + # $(MAKE) # Uncomment this line for use without Qt Creator + #docbook-to-man debian/libsowatch.sgml > libsowatch.1 + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + $(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/libsowatch. + $(MAKE) INSTALL_ROOT="$(CURDIR)"/debian/libsowatch install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples +# dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip + dh_compress + dh_fixperms +# dh_perl +# dh_makeshlibs + dh_installdeb + # dh_shlibdeps # Uncomment this line for use without Qt Creator + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/libsowatch/sowatch.h b/libsowatch/sowatch.h new file mode 100644 index 0000000..a5044b3 --- /dev/null +++ b/libsowatch/sowatch.h @@ -0,0 +1,12 @@ +#ifndef SOWATCH_H +#define SOWATCH_H + +#include "sowatch_global.h" +#include "watch.h" +#include "watchlet.h" +#include "graphicswatchlet.h" +#include "declarativewatchlet.h" +#include "watchserver.h" +#include "watchsimulator.h" + +#endif // SOWATCH_H diff --git a/libsowatch/sowatch_global.h b/libsowatch/sowatch_global.h new file mode 100644 index 0000000..a3b40e6 --- /dev/null +++ b/libsowatch/sowatch_global.h @@ -0,0 +1,12 @@ +#ifndef SOWATCH_GLOBAL_H +#define SOWATCH_GLOBAL_H + +#include + +#if defined(SOWATCH_LIBRARY) +# define SOWATCH_EXPORT Q_DECL_EXPORT +#else +# define SOWATCH_EXPORT Q_DECL_IMPORT +#endif + +#endif // SOWATCH_GLOBAL_H diff --git a/libsowatch/testdeclarativewatchlet.cpp b/libsowatch/testdeclarativewatchlet.cpp new file mode 100644 index 0000000..432d525 --- /dev/null +++ b/libsowatch/testdeclarativewatchlet.cpp @@ -0,0 +1,9 @@ +#include "testdeclarativewatchlet.h" + +using namespace sowatch; + +TestDeclarativeWatchlet::TestDeclarativeWatchlet(WatchServer* server) : + DeclarativeWatchlet(server, "com.javispedro.sowatch.testdeclarativewatchlet") +{ + setSource(QUrl("qrc:/testdeclarativewatchlet.qml")); +} diff --git a/libsowatch/testdeclarativewatchlet.h b/libsowatch/testdeclarativewatchlet.h new file mode 100644 index 0000000..b7b6dcd --- /dev/null +++ b/libsowatch/testdeclarativewatchlet.h @@ -0,0 +1,19 @@ +#ifndef TESTDECLARATIVEWATCHLET_H +#define TESTDECLARATIVEWATCHLET_H + +#include "declarativewatchlet.h" + +namespace sowatch +{ + +class TestDeclarativeWatchlet : public DeclarativeWatchlet +{ + Q_OBJECT +public: + explicit TestDeclarativeWatchlet(WatchServer* server); + +}; + +} + +#endif // TESTDECLARATIVEWATCHLET_H diff --git a/libsowatch/testwatchlet.cpp b/libsowatch/testwatchlet.cpp new file mode 100644 index 0000000..ffc4097 --- /dev/null +++ b/libsowatch/testwatchlet.cpp @@ -0,0 +1,40 @@ +#include +#include + +#include "testwatchlet.h" +#include "watch.h" + +using namespace sowatch; + +TestWatchlet::TestWatchlet(WatchServer* server) : + Watchlet(server, "com.javispedro.sowatch.testwatchlet"), _timer(new QTimer(this)), _y(0) +{ + _timer->setInterval(50); + connect(_timer, SIGNAL(timeout()), SLOT(interv())); + connect(this, SIGNAL(activated()), SLOT(handleActivated())); + connect(this, SIGNAL(deactivated()), SLOT(handleDeactivated())); +} + +void TestWatchlet::interv() +{ + QPainter p(watch()); + //p.fillRect(8, _y, 8, 1, Qt::black); + _y = (_y + 1) % watch()->height(); + p.fillRect(0, _y, _y, 2, Qt::black); + //p.fillRect(0, 0, watch()->width(), watch()->height(), Qt::black); +} + + +void TestWatchlet::handleActivated() +{ + qDebug() << "test watchlet activated"; + QPainter p(watch()); + p.fillRect(0, 0, watch()->width(), watch()->height(), Qt::white); + _timer->start(); +} + +void TestWatchlet::handleDeactivated() +{ + _timer->stop(); + qDebug() << "test watchlet deactivated"; +} diff --git a/libsowatch/testwatchlet.h b/libsowatch/testwatchlet.h new file mode 100644 index 0000000..caa68da --- /dev/null +++ b/libsowatch/testwatchlet.h @@ -0,0 +1,29 @@ +#ifndef TESTWATCHLET_H +#define TESTWATCHLET_H + +#include +#include "watchlet.h" + +namespace sowatch +{ + +class TestWatchlet : public Watchlet +{ + Q_OBJECT +public: + explicit TestWatchlet(WatchServer* server); + +protected slots: + void interv(); + void handleActivated(); + void handleDeactivated(); + +private: + QTimer *_timer; + int _y; + +}; + +} + +#endif // TESTWATCHLET_H diff --git a/libsowatch/watch.cpp b/libsowatch/watch.cpp new file mode 100644 index 0000000..e8da790 --- /dev/null +++ b/libsowatch/watch.cpp @@ -0,0 +1,62 @@ +#include "watch.h" +#include "watchpaintengine.h" + +using namespace sowatch; + +Watch::Watch(const QImage& image, QObject* parent) : + QObject(parent), _image(image), _paintEngine(0) +{ + +} + +Watch::~Watch() +{ + if (_paintEngine) { + delete _paintEngine; + } +} + +QPaintEngine* Watch::paintEngine() const +{ + if (!_paintEngine) { + _paintEngine = new WatchPaintEngine(const_cast(this), + const_cast(&_image)); + } + + return _paintEngine; +} + +int Watch::metric(PaintDeviceMetric metric) const +{ + switch (metric) { + case PdmWidth: + return _image.width(); + case PdmHeight: + return _image.height(); + case PdmWidthMM: + return _image.widthMM(); + case PdmHeightMM: + return _image.heightMM(); + case PdmNumColors: + return _image.numColors(); + case PdmDepth: + return _image.depth(); + case PdmDpiX: + return _image.logicalDpiX(); + case PdmDpiY: + return _image.logicalDpiY(); + case PdmPhysicalDpiX: + return _image.physicalDpiX(); + case PdmPhysicalDpiY: + return _image.physicalDpiY(); + } + + return -1; +} + +void Watch::update(const QRect &rect) +{ + QList rects; + rects << rect; + update(rects); +} diff --git a/libsowatch/watch.h b/libsowatch/watch.h new file mode 100644 index 0000000..3581ada --- /dev/null +++ b/libsowatch/watch.h @@ -0,0 +1,49 @@ +#ifndef WATCH_H +#define WATCH_H + +#include +#include +#include + +namespace sowatch +{ + +class Watch : public QObject, public QPaintDevice +{ + Q_OBJECT + Q_PROPERTY(QString model READ model) + Q_PROPERTY(bool connected READ isConnected) +public: + explicit Watch(const QImage& image, QObject* parent = 0); + ~Watch(); + + QPaintEngine* paintEngine() const; + int metric(PaintDeviceMetric metric) const; + + Q_INVOKABLE virtual QString model() const = 0; + Q_INVOKABLE virtual bool isConnected() const = 0; + + /** Indicates if watch is too busy atm and we should limit frame rate. */ + Q_INVOKABLE virtual bool busy() const = 0; + +signals: + void connected(); + void disconnected(); + void buttonPressed(int button); + void buttonReleased(int button); + +public slots: + virtual void update(const QList& rects) = 0; + virtual void update(const QRect& rect); + virtual void vibrate(bool on) = 0; + +protected: + QImage _image; + mutable QPaintEngine* _paintEngine; + +friend class WatchPaintEngine; +}; + +} + +#endif // WATCH_H diff --git a/libsowatch/watchlet.cpp b/libsowatch/watchlet.cpp new file mode 100644 index 0000000..6d7fe68 --- /dev/null +++ b/libsowatch/watchlet.cpp @@ -0,0 +1,44 @@ +#include "watchlet.h" +#include "watchserver.h" + +using namespace sowatch; + +Watchlet::Watchlet(WatchServer *server, const QString& id) : + QObject(server), _id(id), _active(false), _server(server) +{ + _server->registerWatchlet(this); +} + +WatchServer* Watchlet::server() +{ + return _server; +} + +Watch* Watchlet::watch() +{ + return _server->watch(); +} + +QString Watchlet::id() const +{ + return _id; +} + +bool Watchlet::isActive() const +{ + return _active; +} + +void Watchlet::activate() +{ + _active = true; + emit activeChanged(); + emit activated(); +} + +void Watchlet::deactivate() +{ + _active = false; + emit activeChanged(); + emit deactivated(); +} diff --git a/libsowatch/watchlet.h b/libsowatch/watchlet.h new file mode 100644 index 0000000..06e43a0 --- /dev/null +++ b/libsowatch/watchlet.h @@ -0,0 +1,48 @@ +#ifndef WATCHLET_H +#define WATCHLET_H + +#include +#include "sowatch_global.h" + +namespace sowatch +{ + +class Watch; +class WatchServer; + +class SOWATCH_EXPORT Watchlet : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(bool isActive READ isActive NOTIFY activeChanged) + +public: + explicit Watchlet(WatchServer *server, const QString& id); + + WatchServer* server(); + Watch* watch(); + + Q_INVOKABLE QString id() const; + Q_INVOKABLE bool isActive() const; + +signals: + void activeChanged(); + void activated(); + void deactivated(); + +protected: + virtual void activate(); + virtual void deactivate(); + + const QString _id; + bool _active; + +private: + WatchServer* _server; + +friend class WatchServer; +}; + +} + +#endif // WATCHLET_H diff --git a/libsowatch/watchmanager.cpp b/libsowatch/watchmanager.cpp new file mode 100644 index 0000000..b511a31 --- /dev/null +++ b/libsowatch/watchmanager.cpp @@ -0,0 +1,8 @@ +#include "watchmanager.h" + +using namespace sowatch; + +WatchManager::WatchManager(QObject *parent) : + QObject(parent) +{ +} diff --git a/libsowatch/watchmanager.h b/libsowatch/watchmanager.h new file mode 100644 index 0000000..6d945ff --- /dev/null +++ b/libsowatch/watchmanager.h @@ -0,0 +1,23 @@ +#ifndef WATCHMANAGER_H +#define WATCHMANAGER_H + +#include + +namespace sowatch +{ + +class WatchManager : public QObject +{ + Q_OBJECT +public: + explicit WatchManager(QObject *parent = 0); + +signals: + +public slots: + +}; + +} + +#endif // WATCHMANAGER_H diff --git a/libsowatch/watchpaintengine.cpp b/libsowatch/watchpaintengine.cpp new file mode 100644 index 0000000..18cfb60 --- /dev/null +++ b/libsowatch/watchpaintengine.cpp @@ -0,0 +1,305 @@ +#include +#include + +#include "watch.h" +#include "watchpaintengine.h" + +using namespace sowatch; + +WatchPaintEngine::WatchPaintEngine(Watch* watch, QImage* image) + : QPaintEngine(QPaintEngine::AllFeatures), + _watch(watch), _painter(), + _hasPen(false), _hasBrush(false), _clipEnabled(false) +{ + Q_UNUSED(image); +} + +bool WatchPaintEngine::begin(QPaintDevice *pdev) +{ + _damaged = QRegion(); + _watch = static_cast(pdev); + + return _painter.begin(&_watch->_image); +} + +bool WatchPaintEngine::end() +{ + bool ret = _painter.end(); + if (ret) { + _watch->update(_damaged.rects().toList()); + } + return ret; +} + +void WatchPaintEngine::damageMappedRect(const QRect &r) +{ + if (_clipEnabled) { + _damaged += _clipRegion.intersected(r); + } else { + _damaged += r; + } +} + +void WatchPaintEngine::damageRect(const QRect &r) +{ + damageMappedRect(_transform.mapRect(r)); +} + +void WatchPaintEngine::damageRect(const QRectF &r) +{ + damageMappedRect(_transform.mapRect(r).toRect()); +} + +void WatchPaintEngine::damagePenStroke(const QLineF &line) +{ + if (!_hasPen) return; + + const qreal a = line.angle(); + const qreal sn = sinf(a); + const qreal cs = cosf(a); + const qreal w = _penWidth = 0.0 ? 1.0 : _penWidth; + const qreal x1 = line.x1(); + const qreal x2 = line.x2(); + const qreal y1 = line.x1(); + const qreal y2 = line.y2(); + + damageRect(QRectF(x1-(w*sn/2.0f), y1+(w*cs/2.0f), x2+(w*sn/2.0f), y2-(w*cs/2.0f)).normalized()); +} + +void WatchPaintEngine::updateClipRegion(const QRegion& region, Qt::ClipOperation op) +{ + switch(op) { + case Qt::NoClip: + _clipEnabled = false; + _clipRegion = QRegion(0, 0, _watch->width(), _watch->height()); + break; + case Qt::ReplaceClip: + _clipEnabled = true; + _clipRegion = region; + break; + case Qt::IntersectClip: + _clipEnabled = true; + _clipRegion &= region; + break; + case Qt::UniteClip: + _clipEnabled = true; + _clipRegion |= region; + break; + } +} + +void WatchPaintEngine::drawEllipse(const QRectF &r) +{ + damageRect(r); + _painter.drawEllipse(r); +} + +void WatchPaintEngine::drawEllipse(const QRect &r) +{ + damageRect(r); + _painter.drawEllipse(r); +} + +void WatchPaintEngine::drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags) +{ + damageRect(r); + _painter.drawImage(r, pm, sr, flags); +} + +void WatchPaintEngine::drawLines(const QLineF *lines, int lineCount) +{ + int i; + for (i = 0; i < lineCount; i++) { + const QLineF& line = lines[i]; + damagePenStroke(line); + } + _painter.drawLines(lines, lineCount); +} + +void WatchPaintEngine::drawLines(const QLine *lines, int lineCount) +{ + int i; + for (i = 0; i < lineCount; i++) { + const QLine& line = lines[i]; + damagePenStroke(line); + } + _painter.drawLines(lines, lineCount); +} + +void WatchPaintEngine::drawPath(const QPainterPath &path) +{ + damageRect(path.boundingRect()); + _painter.drawPath(path); +} + +void WatchPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) +{ + damageRect(r); + _painter.drawPixmap(r, pm, sr); +} + +void WatchPaintEngine::drawPoints(const QPointF *points, int pointCount) +{ + const qreal penWidth = _painter.pen().widthF(); + int i; + for (i = 0; i < pointCount; i++) { + const QPointF& p = points[i]; + damageRect(QRect(p.x() - penWidth/2, p.y() - penWidth/2, + p.x() + penWidth/2, p.y() + penWidth/2)); + } + _painter.drawPoints(points, pointCount); +} + +void WatchPaintEngine::drawPoints(const QPoint *points, int pointCount) +{ + const qreal penWidth = _painter.pen().widthF(); + int i; + for (i = 0; i < pointCount; i++) { + const QPoint& p = points[i]; + damageRect(QRect(p.x() - penWidth/2, p.y() - penWidth/2, + p.x() + penWidth/2, p.y() + penWidth/2)); + } + _painter.drawPoints(points, pointCount); +} + +void WatchPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) +{ + QPolygonF p(pointCount); + int i; + for (i = 0; i < pointCount; i++) { + p[i] = points[i]; + } + damageRect(p.boundingRect()); + _painter.drawPolygon(points, pointCount, + mode == WindingMode ? Qt::WindingFill : Qt::OddEvenFill); +} + +void WatchPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode) +{ + QPolygon p(pointCount); + int i; + for (i = 0; i < pointCount; i++) { + p[i] = points[i]; + } + damageRect(p.boundingRect()); + _painter.drawPolygon(points, pointCount, + mode == WindingMode ? Qt::WindingFill : Qt::OddEvenFill); +} + +void WatchPaintEngine::drawRects(const QRectF *rects, int rectCount) +{ + int i; + for (i = 0; i < rectCount; i++) { + const QRectF& r = rects[i]; + if (_hasBrush) { + damageRect(r); + } + if (_hasPen) { + damagePenStroke(QLineF(r.left(), r.top(), r.right(), r.top())); + damagePenStroke(QLineF(r.right(), r.top(), r.right(), r.bottom())); + damagePenStroke(QLineF(r.left(), r.bottom(), r.right(), r.bottom())); + damagePenStroke(QLineF(r.left(), r.top(), r.left(), r.bottom())); + } + } + _painter.drawRects(rects, rectCount); +} + +void WatchPaintEngine::drawRects(const QRect *rects, int rectCount) +{ + int i; + for (i = 0; i < rectCount; i++) { + const QRect& r = rects[i]; + if (_hasBrush) { + damageRect(r); + } + if (_hasPen) { + damagePenStroke(QLine(r.left(), r.top(), r.right(), r.top())); + damagePenStroke(QLine(r.right(), r.top(), r.right(), r.bottom())); + damagePenStroke(QLine(r.left(), r.bottom(), r.right(), r.bottom())); + damagePenStroke(QLine(r.left(), r.top(), r.left(), r.bottom())); + } + } + + _painter.drawRects(rects, rectCount); +} + +void WatchPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) +{ + const qreal height = textItem.ascent() + textItem.descent(); + damageRect(QRect(p.x(), p.y(), p.x() + textItem.width(), p.y() + height)); + _painter.drawTextItem(p, textItem); +} + +void WatchPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s) +{ + damageRect(r); + _painter.drawTiledPixmap(r, pixmap, s); +} + +QPaintEngine::Type WatchPaintEngine::type() const +{ + return QPaintEngine::Raster; +} + +void WatchPaintEngine::updateState(const QPaintEngineState &state) +{ + const QPaintEngine::DirtyFlags flags = state.state(); + if (flags & QPaintEngine::DirtyBackground) + { + _painter.setBackground(state.backgroundBrush()); + } + if (flags & QPaintEngine::DirtyBackgroundMode) + { + _painter.setBackgroundMode(state.backgroundMode()); + } + if (flags & QPaintEngine::DirtyBrush) + { + QBrush brush = state.brush(); + _hasBrush = brush.style() != Qt::NoBrush; + _painter.setBrush(brush); + } + if (flags & QPaintEngine::DirtyBrushOrigin) + { + _painter.setBrushOrigin(state.brushOrigin()); + } + if (flags & QPaintEngine::DirtyClipEnabled) + { + _clipEnabled = state.isClipEnabled(); + _painter.setClipping(_clipEnabled); + } + if (flags & QPaintEngine::DirtyClipPath) + { + QRegion region = state.clipPath().boundingRect().toRect(); + updateClipRegion(region, state.clipOperation()); + _painter.setClipPath(state.clipPath(), state.clipOperation()); + } + if (flags & QPaintEngine::DirtyClipRegion) + { + updateClipRegion(state.clipRegion(), state.clipOperation()); + _painter.setClipRegion(state.clipRegion(), state.clipOperation()); + } + if (flags & QPaintEngine::DirtyCompositionMode) + { + _painter.setCompositionMode(state.compositionMode()); + } + if (flags & QPaintEngine::DirtyFont) + { + _painter.setFont(state.font()); + } + if (flags & QPaintEngine::DirtyHints) + { + _painter.setRenderHints(state.renderHints()); + } + if (flags & QPaintEngine::DirtyPen) + { + QPen pen = state.pen(); + _hasPen = pen.style() != Qt::NoPen; + _penWidth = pen.widthF(); + _painter.setPen(pen); + } + if (flags & QPaintEngine::DirtyTransform) + { + _transform = state.transform(); + _painter.setTransform(_transform); + } +} diff --git a/libsowatch/watchpaintengine.h b/libsowatch/watchpaintengine.h new file mode 100644 index 0000000..14181fa --- /dev/null +++ b/libsowatch/watchpaintengine.h @@ -0,0 +1,62 @@ +#ifndef WATCHPAINTENGINE_H +#define WATCHPAINTENGINE_H + +#include + +namespace sowatch +{ + +class Watch; + +class WatchPaintEngine : public QPaintEngine +{ +public: + WatchPaintEngine(Watch* watch, QImage* image); + + bool begin(QPaintDevice *pdev); + bool end(); + + void drawEllipse(const QRectF &r); + void drawEllipse(const QRect &r); + void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags); + void drawLines(const QLineF *lines, int lineCount); + void drawLines(const QLine *lines, int lineCount); + void drawPath(const QPainterPath &path); + void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr); + void drawPoints(const QPointF *points, int pointCount); + void drawPoints(const QPoint *points, int pointCount); + void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode); + void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode); + void drawRects(const QRectF *rects, int rectCount); + void drawRects(const QRect *rects, int rectCount); + void drawTextItem(const QPointF &p, const QTextItem &textItem); + void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s); + + Type type() const; + void updateState(const QPaintEngineState &state); + +protected: + void damageMappedRect(const QRect& r); + void damageRect(const QRect& r); + void damageRect(const QRectF& r); + void damagePenStroke(const QLineF& line); + void updateClipRegion(const QRegion& region, Qt::ClipOperation op); + + Watch* _watch; + QPainter _painter; + QRegion _damaged; + + bool _hasPen; + qreal _penWidth; + + bool _hasBrush; + + bool _clipEnabled; + QRegion _clipRegion; + + QTransform _transform; +}; + +} + +#endif // WATCHPAINTENGINE_H diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp new file mode 100644 index 0000000..ad49995 --- /dev/null +++ b/libsowatch/watchserver.cpp @@ -0,0 +1,57 @@ +#include "watch.h" +#include "watchlet.h" +#include "watchserver.h" + +using namespace sowatch; + +WatchServer::WatchServer(Watch* watch, QObject* parent) : + QObject(parent), _watch(watch), _currentWatchlet(0) +{ + connect(_watch, SIGNAL(connected()), SLOT(watchConnected())); + connect(_watch, SIGNAL(disconnected()), SLOT(watchDisconnected())); +} + +Watch* WatchServer::watch() +{ + return _watch; +} + +void WatchServer::runWatchlet(const QString& id) +{ + if (_currentWatchlet) { + closeWatchlet(); + } + _currentWatchlet = watchlets[id]; + if (_watch->isConnected()) { + _currentWatchlet->activate(); + } +} + +void WatchServer::closeWatchlet() +{ + Q_ASSERT(_currentWatchlet != 0); + if (_watch->isConnected()) { + _currentWatchlet->deactivate(); + } + _currentWatchlet = 0; +} + +void WatchServer::registerWatchlet(Watchlet *watchlet) +{ + Q_ASSERT(watchlet->_server == this); + watchlets[watchlet->id()] = watchlet; +} + +void WatchServer::watchConnected() +{ + if (_currentWatchlet) { + _currentWatchlet->activate(); + } +} + +void WatchServer::watchDisconnected() +{ + if (_currentWatchlet) { + _currentWatchlet->deactivate(); + } +} diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h new file mode 100644 index 0000000..78454d4 --- /dev/null +++ b/libsowatch/watchserver.h @@ -0,0 +1,46 @@ +#ifndef WATCHSERVER_H +#define WATCHSERVER_H + +#include +#include + +namespace sowatch +{ + +class Watch; +class Watchlet; + +class WatchServer : public QObject +{ + Q_OBJECT + Q_PROPERTY(Watch* watch READ watch) +public: + explicit WatchServer(Watch* watch, QObject* parent = 0); + + Watch* watch(); + + void runWatchlet(const QString& id); + void closeWatchlet(); + +signals: + +public slots: + +protected: + Watch* _watch; + Watchlet* _currentWatchlet; + + QMap watchlets; + + void registerWatchlet(Watchlet *watchlet); + +protected slots: + void watchConnected(); + void watchDisconnected(); + +friend class Watchlet; +}; + +} + +#endif // WATCHSERVER_H diff --git a/libsowatch/watchsimulator.cpp b/libsowatch/watchsimulator.cpp new file mode 100644 index 0000000..464f3a5 --- /dev/null +++ b/libsowatch/watchsimulator.cpp @@ -0,0 +1,11 @@ +#include + +#include "watchsimulator.h" + +using namespace sowatch; + +WatchSimulator::WatchSimulator(const QImage& image, QObject* parent) : + Watch(image, parent) +{ + +} diff --git a/libsowatch/watchsimulator.h b/libsowatch/watchsimulator.h new file mode 100644 index 0000000..564118c --- /dev/null +++ b/libsowatch/watchsimulator.h @@ -0,0 +1,20 @@ +#ifndef WATCHSIMULATOR_H +#define WATCHSIMULATOR_H + +#include + +#include "watch.h" + +namespace sowatch +{ + +class WatchSimulator : public Watch +{ + Q_OBJECT +public: + explicit WatchSimulator(const QImage& image, QObject *parent = 0); +}; + +} + +#endif // WATCHSIMULATOR_H diff --git a/main.cpp b/main.cpp deleted file mode 100644 index d0eae3f..0000000 --- a/main.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include - -#include "metawatchsimulator.h" -#include "metawatch.h" -#include "watchserver.h" -#include "testwatchlet.h" -#include "testdeclarativewatchlet.h" - -using namespace sowatch; -QTM_USE_NAMESPACE - -static Watch *watch; -static WatchServer *server; - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - - if (a.arguments().count() > 1) { - watch = new MetaWatch(QBluetoothAddress(a.arguments().at(1))); - } else { - watch = new MetaWatchSimulator(); - } - - /* D0:37:61:C3:C7:99 */ - server = new WatchServer(watch); - new TestDeclarativeWatchlet(server); - new TestWatchlet(server); - - server->runWatchlet("com.javispedro.sowatch.testdeclarativewatchlet"); - //server->runWatchlet("com.javispedro.sowatch.testwatchlet"); - - return a.exec(); -} diff --git a/metawatch.cpp b/metawatch.cpp deleted file mode 100644 index b968fad..0000000 --- a/metawatch.cpp +++ /dev/null @@ -1,409 +0,0 @@ -#include -#include - -#include "metawatchpaintengine.h" -#include "metawatch.h" - -using namespace sowatch; -QTM_USE_NAMESPACE - -#define SINGLE_LINE_UPDATE 0 - -const quint8 MetaWatch::bitRevTable[16] = { - 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 -}; - -const quint16 MetaWatch::crcTable[256] = { - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, - 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, - 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, - 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, - 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, - 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, - 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, - 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, - 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, - 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, - 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, - 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, - 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, - 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, - 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, - 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, - 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, - 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, - 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, - 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, - 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, - 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, - 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, - 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, - 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 -}; - -#if 0 /* This snippet was used to build the table seen above. */ - quint16 remainder; - int dividend; - quint8 bit; - - for (dividend = 0; dividend < 256; dividend++) { - remainder = dividend << 8; - for (bit = 8; bit > 0; bit--) { - if (remainder & 0x8000) { - remainder = (remainder << 1) ^ 0x1021; - } else { - remainder = (remainder << 1); - } - } - if ((dividend % 8) == 0) { - printf(",\n0x%04hx", remainder); - } else { - printf(", 0x%04hx", remainder); - } - } -#endif - -MetaWatch::MetaWatch(const QBluetoothAddress& address, QObject *parent) : - Watch(QImage(96, 96, QImage::Format_MonoLSB), parent), - _socket(new QBluetoothSocket(QBluetoothSocket::RfcommSocket)), - _sendTimer(new QTimer(this)) -{ - connect(_socket, SIGNAL(connected()), SLOT(socketConnected())); - connect(_socket, SIGNAL(disconnected()), SLOT(socketDisconnected())); - connect(_socket, SIGNAL(readyRead()), SLOT(socketData())); - connect(_socket, SIGNAL(error(QBluetoothSocket::SocketError)), - SLOT(socketError(QBluetoothSocket::SocketError))); - connect(_socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), - SLOT(socketState(QBluetoothSocket::SocketState))); - - _sendTimer->setInterval(30); - connect(_sendTimer, SIGNAL(timeout()), SLOT(timedSend())); - - _socket->connectToService(address, 1, QIODevice::ReadWrite | QIODevice::Unbuffered); -} - -QPaintEngine* MetaWatch::paintEngine() const -{ - if (!_paintEngine) { - _paintEngine = new MetaWatchPaintEngine(const_cast(this), - const_cast(&_image)); - } - - return _paintEngine; -} - -QString MetaWatch::model() const -{ - return "metawatch-digital"; -} - -bool MetaWatch::isConnected() const -{ - return _socket->state() == QBluetoothSocket::ConnectedState; -} - -bool MetaWatch::busy() const -{ - return _socket->state() != QBluetoothSocket::ConnectedState || - _toSend.size() > 20; -} - -void MetaWatch::update(const QList &rects) -{ - if (_socket->state() != QBluetoothSocket::ConnectedState) return; - const QRect imageRect = _image.rect(); - QVector lines(_image.height(), false); - - foreach (const QRect& rect, rects) { - QRect r = rect.intersect(imageRect); - for (int i = r.top(); i <= r.bottom(); i++) { - lines[i] = true; - } - } - - updateLines(ApplicationMode, _image, lines); - updateDisplay(ApplicationMode); -} - -void MetaWatch::clear(bool white) -{qDebug() << "MWclear" << white; - if (_socket->state() != QBluetoothSocket::ConnectedState) return; - loadTemplate(ApplicationMode, white ? 1 : 0); -} - -void MetaWatch::vibrate(bool on) -{ - -} - -void MetaWatch::setDateTime(const QDateTime &dateTime) -{ - Message msg(SetRealTimeClock, QByteArray(10, 0)); - const QDate& date = dateTime.date(); - const QTime& time = dateTime.time(); - - msg.data[0] = date.year() & 0xF00; - msg.data[1] = date.year() & 0xFF; - msg.data[2] = date.month(); - msg.data[3] = date.day(); - msg.data[4] = date.dayOfWeek() - 1; - msg.data[5] = time.hour(); - msg.data[6] = time.minute(); - msg.data[7] = time.second(); - msg.data[8] = 1; - msg.data[9] = 1; - - send(msg); -} - -quint16 MetaWatch::calcCrc(const QByteArray &data, int size) -{ - quint16 remainder = 0xFFFF; - - for (int i = 0; i < size; i++) { - quint8 byte = data[i]; - byte = (bitRevTable[byte & 0xF] << 4) | bitRevTable[(byte & 0xF0) >> 4]; - remainder = crcTable[byte ^ (remainder >> 8)] ^ (remainder << 8); - } - - return remainder; -} - -quint16 MetaWatch::calcCrc(const Message& msg) -{ - QByteArray data; - const int msgSize = msg.data.size(); - - data.resize(msgSize + 4); - data[0] = 0x01; - data[1] = msgSize + 6; - data[2] = msg.type; - data[3] = msg.options; - data.replace(4, msgSize, msg.data); - - return calcCrc(data, msgSize + 4); -} - -void MetaWatch::send(const Message &msg) -{ - _toSend.enqueue(msg); - if (!_sendTimer->isActive()) { - _sendTimer->start(); - } -} - -void MetaWatch::handleMessage(const Message &msg) -{ - switch (msg.type) { - case StatusChangeEvent: - handleStatusChange(msg); - break; - case ButtonEvent: - handleButtonEvent(msg); - break; - default: - qWarning() << "Unknown message of type" << msg.type << "received"; - break; - } -} - -void MetaWatch::updateLine(Mode mode, const QImage& image, int line) -{ - Message msg(WriteBuffer, QByteArray(13, 0), (1 << 4) | (mode & 0xF)); - const char * scanLine = (const char *) image.constScanLine(line); - - msg.data[0] = line; - msg.data.replace(1, 12, scanLine, 12); - - send(msg); -} - -void MetaWatch::updateLines(Mode mode, const QImage& image, int lineA, int lineB) -{ - Message msg(WriteBuffer, QByteArray(26, 0), mode & 0xF); - const char * scanLine = (const char *) image.constScanLine(lineA); - - msg.data[0] = lineA; - msg.data.replace(1, 12, scanLine, 12); - - scanLine = (const char *) image.constScanLine(lineB); - msg.data[13] = lineB; - msg.data.replace(14, 12, scanLine, 12); - - send(msg); -} - -void MetaWatch::updateLines(Mode mode, const QImage& image, const QVector& lines) -{ - int lineCount = lines.count(true); - int lineA = -1; - - if (lineCount == 0) return; - - for (int line = 0; line < lines.size(); line++) { - if (lines[line]) { - lineCount--; -#if SINGLE_LINE_UPDATE - updateLine(mode, image, line); - continue; -#endif - if (lineA >= 0) { - // We have a pair of lines to send. - updateLines(mode, image, lineA, line); - lineA = -1; - } else if (lineCount > 0) { - // Still another line to send. - lineA = line; - } else { - updateLine(mode, image, line); - break; // No more lines - } - } - } -} - -void MetaWatch::configureWatchMode(Mode mode, int timeout, bool invert) -{ - Message msg(ConfigureMode, QByteArray(2, 0), mode & 0xF); - msg.data[0] = timeout; - msg.data[1] = invert ? 1 : 0; - send(msg); -} - -void MetaWatch::updateDisplay(Mode mode, bool copy) -{ - Message msg(UpdateDisplay, QByteArray(), - (copy ? 0x10 : 0) | (mode & 0xF)); - send(msg); -} - -void MetaWatch::loadTemplate(Mode mode, int templ) -{ - Message msg(LoadTemplate, QByteArray(1, templ), mode & 0xF); - send(msg); -} - -void MetaWatch::handleStatusChange(const Message &msg) -{ - qDebug() << "watch status changed" << msg.data.size(); -} - -void MetaWatch::handleButtonEvent(const Message &msg) -{ - if (msg.data.size() < 1) return; - quint8 button = msg.data[0]; - - emit buttonPressed(button); // TODO This is completely broken -} - -void MetaWatch::socketConnected() -{ - qDebug() << "connected"; - _partialReceived.type = NoMessage; - _partialReceived.data.clear(); - _buttonState = 0; - setDateTime(QDateTime::currentDateTime()); - configureWatchMode(ApplicationMode); - emit connected(); -} - -void MetaWatch::socketDisconnected() -{ - _toSend.clear(); - _sendTimer->stop(); - emit disconnected(); -} - -void MetaWatch::socketData() -{ - qint64 dataRead; - - if (_partialReceived.type == 0) { - if (_socket->bytesAvailable() < 4) return; /* Wait for more. */ - char header[4]; - - dataRead = _socket->read(header, 4); - if (dataRead < 4 || header[0] != 0x01) { - qWarning() << "TODO: Resync/Handle Garbage"; - return; - } - - _partialReceived.type = static_cast(header[2]); - _partialReceived.data.resize(header[1] - 6); - _partialReceived.options = header[3]; - } - if (_socket->bytesAvailable() < _partialReceived.data.size() + 2) { - return; /* Wait for more. */ - } - dataRead = _socket->read(_partialReceived.data.data(), _partialReceived.data.size()); - if (dataRead < _partialReceived.data.size()) { - qWarning() << "Short read"; - return; - } - - char tail[2]; - dataRead = _socket->read(tail, 2); - if (dataRead < 2) { - qWarning() << "Short read"; - return; - } - - quint16 realCrc = calcCrc(_partialReceived); - quint16 expectedCrc = tail[1] << 8 | (tail[0] & 0xFFU); - if (realCrc == expectedCrc) { - handleMessage(_partialReceived); - } else { - qWarning() << "CRC error?"; - } - - _partialReceived.data.clear(); - _partialReceived.type = NoMessage; -} - -void MetaWatch::socketError(QBluetoothSocket::SocketError error) -{ - qWarning() << "Socket error:" << error; -} - -void MetaWatch::socketState(QBluetoothSocket::SocketState error) -{ - qDebug() << "socket is in" << error; -} - -void MetaWatch::timedSend() -{ - if (_toSend.count() > 0) { - realSend(_toSend.dequeue()); - } - if (_toSend.count() == 0) { - _sendTimer->stop(); - } -} - -void MetaWatch::realSend(const Message &msg) -{ - const int msgSize = msg.data.size(); - QByteArray data; - quint16 crc; - - data.resize(msgSize + 6); - data[0] = 0x01; - data[1] = msgSize + 6; - data[2] = msg.type; - data[3] = msg.options; - data.replace(4, msgSize, msg.data); - crc = calcCrc(data, msgSize + 4); - data[msgSize+4] = crc & 0xFF; - data[msgSize+5] = crc >> 8; - - //qDebug() << "Sending" << data.toHex(); - - _socket->write(data); -} diff --git a/metawatch.h b/metawatch.h deleted file mode 100644 index 80a1894..0000000 --- a/metawatch.h +++ /dev/null @@ -1,122 +0,0 @@ -#ifndef METAWATCH_H -#define METAWATCH_H - -#include -#include -#include -#include -#include "watch.h" - -using QTM_PREPEND_NAMESPACE(QBluetoothSocket); -using QTM_PREPEND_NAMESPACE(QBluetoothAddress); - -namespace sowatch -{ - -class MetaWatch : public Watch -{ - Q_OBJECT - Q_ENUMS(MessageType Mode) - -public: - explicit MetaWatch(const QBluetoothAddress& address, QObject *parent = 0); - - QPaintEngine* paintEngine() const; - - QString model() const; - bool isConnected() const; - bool busy() const; - void update(const QList& rects); - void clear(bool white = false); - void vibrate(bool on); - - void setDateTime(const QDateTime& dateTime); - - enum MessageType { - NoMessage = 0, - GetDeviceType = 0x01, - GetDeviceTypeResponse = 0x02, - GetInformationString = 0x03, - GetInformationStringResponse = 0x04, - AdvanceWatchHands = 0x20, - SetVibrateMode = 0x23, - SetRealTimeClock = 0x26, - GetRealTimeClock = 0x27, - GetRealTimeClockResponse = 0x28, - StatusChangeEvent = 0x33, - ButtonEvent = 0x34, - WriteBuffer = 0x40, - ConfigureMode = 0x41, - ConfigureIdleBufferSize = 0x42, - UpdateDisplay = 0x43, - LoadTemplate = 0x44, - EnableButton = 0x46, - DisableButton = 0x47, - ReadButtonConfiguration = 0x48, - ReadButtonConfigurationResponse = 0x49, - BatteryConfiguration = 0x53, - LowBatteryWarning = 0x54, - LowBatteryBluetoothOff = 0x55, - ReadBatteryVoltage = 0x56, - ReadBatteryVoltageResponse = 0x57, - Accelerometer = 0xea - }; - - enum Mode { - IdleMode = 0, - ApplicationMode = 1 - }; - -protected: - QBluetoothSocket* _socket; - - struct Message { - MessageType type; - quint8 options; - QByteArray data; - Message(MessageType ntype = NoMessage, QByteArray ndata = QByteArray(), quint8 noptions = 0) : - type(ntype), options(noptions), data(ndata) - { - - } - }; - - QQueue _toSend; - QTimer* _sendTimer; - Message _partialReceived; - - quint8 _buttonState; - - static const quint8 bitRevTable[16]; - static const quint16 crcTable[256]; - quint16 calcCrc(const QByteArray& data, int size); - quint16 calcCrc(const Message& msg); - - void send(const Message& msg); - void handleMessage(const Message& msg); - - void updateLine(Mode mode, const QImage& image, int line); - void updateLines(Mode mode, const QImage& image, int lineA, int lineB); - void updateLines(Mode mode, const QImage& image, const QVector& lines); - void configureWatchMode(Mode mode, int timeout = 10, bool invert = false); - void updateDisplay(Mode mode, bool copy = true); - void loadTemplate(Mode mode, int templ); - - void handleStatusChange(const Message& msg); - void handleButtonEvent(const Message& msg); - -protected slots: - void socketConnected(); - void socketDisconnected(); - void socketData(); - void socketError(QBluetoothSocket::SocketError error); - void socketState(QBluetoothSocket::SocketState error); - void timedSend(); - -private: - void realSend(const Message& msg); -}; - -} - -#endif // METAWATCH_H diff --git a/metawatchpaintengine.cpp b/metawatchpaintengine.cpp deleted file mode 100644 index 71ad452..0000000 --- a/metawatchpaintengine.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "metawatch.h" -#include "metawatchpaintengine.h" - -using namespace sowatch; - -MetaWatchPaintEngine::MetaWatchPaintEngine(MetaWatch* watch, QImage* image) : - WatchPaintEngine(watch, image), _watch(watch), - _imageRect(image->rect()) -{ -} - -void MetaWatchPaintEngine::drawRects(const QRectF *rects, int rectCount) -{ - int i; - for (i = 0; i < rectCount; i++) { - const QRectF& r = rects[i]; - if (_hasBrush && fillsEntireImage(r.toRect()) && (_isBrushBlack | _isBrushWhite)) { - _watch->clear(_isBrushWhite); - _damaged = QRegion(); - continue; - } - if (_hasBrush) { - damageRect(r); - } - if (_hasPen) { - damagePenStroke(QLineF(r.left(), r.top(), r.right(), r.top())); - damagePenStroke(QLineF(r.right(), r.top(), r.right(), r.bottom())); - damagePenStroke(QLineF(r.left(), r.bottom(), r.right(), r.bottom())); - damagePenStroke(QLineF(r.left(), r.top(), r.left(), r.bottom())); - } - } - _painter.drawRects(rects, rectCount); -} - -void MetaWatchPaintEngine::drawRects(const QRect *rects, int rectCount) -{ - int i; - for (i = 0; i < rectCount; i++) { - const QRect& r = rects[i]; - if (_hasBrush && fillsEntireImage(r) && (_isBrushBlack | _isBrushWhite)) { - _watch->clear(_isBrushWhite); - _damaged = QRegion(); - continue; - } - if (_hasBrush) { - damageRect(r); - } - if (_hasPen) { - damagePenStroke(QLine(r.left(), r.top(), r.right(), r.top())); - damagePenStroke(QLine(r.right(), r.top(), r.right(), r.bottom())); - damagePenStroke(QLine(r.left(), r.bottom(), r.right(), r.bottom())); - damagePenStroke(QLine(r.left(), r.top(), r.left(), r.bottom())); - } - } - - _painter.drawRects(rects, rectCount); -} - -void MetaWatchPaintEngine::updateState(const QPaintEngineState &state) -{ - WatchPaintEngine::updateState(state); - if (state.state() & QPaintEngine::DirtyBrush) { - QBrush brush = state.brush(); - _isBrushBlack = false; - _isBrushWhite = false; - if (brush.style() == Qt::SolidPattern) { - const QColor color = brush.color(); - if (color == Qt::black) { - _isBrushBlack = true; - } else if (color == Qt::white) { - _isBrushWhite = true; - } - } - } -} - -bool MetaWatchPaintEngine::fillsEntireImage(const QRect& rect) -{ - return rect == _imageRect && - (!_clipEnabled || - (_clipRegion.numRects() == 1 && _clipRegion.rects().at(0) == _imageRect)); -} diff --git a/metawatchpaintengine.h b/metawatchpaintengine.h deleted file mode 100644 index efc3d6e..0000000 --- a/metawatchpaintengine.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef METAWATCHPAINTENGINE_H -#define METAWATCHPAINTENGINE_H - -#include -#include "watchpaintengine.h" - -namespace sowatch -{ - -class MetaWatch; - -/** This WatchPaintEngine accelerates fillRects by using the MetaWatch's template command. */ -class MetaWatchPaintEngine : public WatchPaintEngine -{ -public: - explicit MetaWatchPaintEngine(MetaWatch* watch, QImage* image); - - void drawRects(const QRectF *rects, int rectCount); - void drawRects(const QRect *rects, int rectCount); - - void updateState(const QPaintEngineState &state); - -protected: - bool fillsEntireImage(const QRect& rect); - - MetaWatch* _watch; - QRect _imageRect; - bool _isBrushBlack; - bool _isBrushWhite; -}; - -} - -#endif // METAWATCHPAINTENGINE_H diff --git a/metawatchsimulator.cpp b/metawatchsimulator.cpp deleted file mode 100644 index 11b938a..0000000 --- a/metawatchsimulator.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include - -#include "metawatchsimulator.h" - -#define SIMULATE_DAMAGES 1 -#define SIMULATE_FRAMERATE 1 - -using namespace sowatch; - -MetaWatchSimulator::MetaWatchSimulator(QObject *parent) : - WatchSimulator(QImage(96, 96, QImage::Format_Mono), parent), - _screen(96, 96), - _form(new MetaWatchSimulatorForm), - _nextFrame(QTime::currentTime()) -{ - _form->showNormal(); - connect(_form, SIGNAL(destroyed()), SIGNAL(disconnected())); - connect(_form, SIGNAL(buttonPressed(int)), SIGNAL(buttonPressed(int))); - connect(_form, SIGNAL(buttonReleased(int)), SIGNAL(buttonReleased(int))); -} - -MetaWatchSimulator::~MetaWatchSimulator() -{ - delete _form; -} - -QString MetaWatchSimulator::model() const -{ - return "metawatch-digital"; -} - -bool MetaWatchSimulator::isConnected() const -{ - return true; -} - -bool MetaWatchSimulator::busy() const -{ -#if SIMULATE_FRAMERATE - return _nextFrame > QTime::currentTime(); -#else - return false; -#endif -} - -void MetaWatchSimulator::update(const QList &rects) -{ -#if SIMULATE_DAMAGES - const QRect imageRect = _image.rect(); - QPainter p; - QVector rows(96, false); - unsigned total = 0, totalRows; - - p.begin(&_screen); - foreach (const QRect& rect, rects) { - QRect r = rect.intersect(imageRect); - for (int i = r.top(); i <= r.bottom(); i++) { - rows[i] = true; - } - total += r.width() * r.height(); - - p.drawImage(r, _image, r); - } - p.end(); - - totalRows = rows.count(true); - - _form->refreshScreen(_screen); - - qDebug() << "updated " << total << " pixels " << totalRows << " lines"; - _nextFrame = QTime::currentTime().addMSecs(((totalRows / 2) + 1) * 30); -#else - _form->refreshScreen(QPixmap::fromImage(_image)); - _nextFrame = QTime::currentTime().addMSecs(30); -#endif -} - -void MetaWatchSimulator::vibrate(bool on) -{ - qDebug() << "vibrate" << on; -} diff --git a/metawatchsimulator.h b/metawatchsimulator.h deleted file mode 100644 index 674c3c6..0000000 --- a/metawatchsimulator.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef METAWATCHSIMULATOR_H -#define METAWATCHSIMULATOR_H - -#include -#include "watchsimulator.h" -#include "metawatchsimulatorform.h" - -namespace sowatch { - -class MetaWatchSimulator : public WatchSimulator -{ - Q_OBJECT -public: - explicit MetaWatchSimulator(QObject *parent = 0); - ~MetaWatchSimulator(); - - QString model() const; - bool isConnected() const; - bool busy() const; - - void update(const QList &rects); - void vibrate(bool on); - -protected: - QPixmap _screen; - MetaWatchSimulatorForm* _form; - QTime _nextFrame; -}; - -} - -#endif // METAWATCHSIMULATOR_H diff --git a/metawatchsimulatorform.cpp b/metawatchsimulatorform.cpp deleted file mode 100644 index f2323bd..0000000 --- a/metawatchsimulatorform.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "metawatchsimulatorform.h" -#include "ui_metawatchsimulatorform.h" - -using namespace sowatch; - -MetaWatchSimulatorForm::MetaWatchSimulatorForm(QWidget* parent) : - QWidget(parent), - ui(new Ui::MetaWatchSimulatorForm) -{ - ui->setupUi(this); -} - -MetaWatchSimulatorForm::~MetaWatchSimulatorForm() -{ - delete ui; -} - -void MetaWatchSimulatorForm::refreshScreen(const QPixmap& pixmap) -{ - ui->lblDisplay->setPixmap(pixmap); - ui->lblDisplay->update(); -} - -void MetaWatchSimulatorForm::btnAPressed() -{ - emit buttonPressed(0); -} - -void MetaWatchSimulatorForm::btnAReleased() -{ - emit buttonReleased(0); -} - -void MetaWatchSimulatorForm::btnBPressed() -{ - emit buttonPressed(1); -} - -void MetaWatchSimulatorForm::btnBReleased() -{ - emit buttonReleased(1); -} - -void MetaWatchSimulatorForm::btnCPressed() -{ - emit buttonPressed(2); -} - -void MetaWatchSimulatorForm::btnCReleased() -{ - emit buttonReleased(2); -} - -void MetaWatchSimulatorForm::btnDPressed() -{ - emit buttonPressed(3); -} - -void MetaWatchSimulatorForm::btnDReleased() -{ - emit buttonReleased(3); -} - -void MetaWatchSimulatorForm::btnEPressed() -{ - emit buttonPressed(4); -} - -void MetaWatchSimulatorForm::btnEReleased() -{ - emit buttonReleased(4); -} - -void MetaWatchSimulatorForm::btnFPressed() -{ - emit buttonPressed(5); -} - -void MetaWatchSimulatorForm::btnFReleased() -{ - emit buttonReleased(5); -} diff --git a/metawatchsimulatorform.h b/metawatchsimulatorform.h deleted file mode 100644 index 0b45746..0000000 --- a/metawatchsimulatorform.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef METAWATCHSIMULATORFORM_H -#define METAWATCHSIMULATORFORM_H - -#include - -namespace Ui { - class MetaWatchSimulatorForm; -} - -namespace sowatch { - -class MetaWatchSimulatorForm : public QWidget -{ - Q_OBJECT - -public: - explicit MetaWatchSimulatorForm(QWidget *parent = 0); - ~MetaWatchSimulatorForm(); - - void refreshScreen(const QPixmap& screen); - -signals: - void buttonPressed(int button); - void buttonReleased(int button); - -protected slots: - void btnAPressed(); - void btnAReleased(); - void btnBPressed(); - void btnBReleased(); - void btnCPressed(); - void btnCReleased(); - void btnDPressed(); - void btnDReleased(); - void btnEPressed(); - void btnEReleased(); - void btnFPressed(); - void btnFReleased(); - -private: - Ui::MetaWatchSimulatorForm *ui; -}; - -} - -#endif // METAWATCHSIMULATORFORM_H diff --git a/metawatchsimulatorform.ui b/metawatchsimulatorform.ui deleted file mode 100644 index 39280b3..0000000 --- a/metawatchsimulatorform.ui +++ /dev/null @@ -1,294 +0,0 @@ - - - MetaWatchSimulatorForm - - - - 0 - 0 - 262 - 113 - - - - MetaWatch-Digital Simulator - - - - - - - - A - - - - - - - B - - - - - - - C - - - - - - - - - - 0 - 0 - - - - - - - Qt::AlignCenter - - - - - - - - - D - - - - - - - E - - - - - - - F - - - - - - - - - - - btnA - pressed() - MetaWatchSimulatorForm - btnAPressed() - - - 44 - 20 - - - 105 - 4 - - - - - btnA - released() - MetaWatchSimulatorForm - btnAReleased() - - - 71 - 21 - - - 4 - 10 - - - - - btnB - pressed() - MetaWatchSimulatorForm - btnBPressed() - - - 68 - 57 - - - 98 - 75 - - - - - btnB - released() - MetaWatchSimulatorForm - btnBReleased() - - - 86 - 56 - - - 98 - 58 - - - - - btnC - pressed() - MetaWatchSimulatorForm - btnCPressed() - - - 37 - 90 - - - 73 - 108 - - - - - btnC - released() - MetaWatchSimulatorForm - btnCReleased() - - - 21 - 89 - - - 19 - 105 - - - - - btnD - pressed() - MetaWatchSimulatorForm - btnDPressed() - - - 203 - 18 - - - 205 - 5 - - - - - btnD - released() - MetaWatchSimulatorForm - btnDReleased() - - - 244 - 22 - - - 258 - 21 - - - - - btnE - pressed() - MetaWatchSimulatorForm - btnEPressed() - - - 237 - 50 - - - 256 - 51 - - - - - btnE - released() - MetaWatchSimulatorForm - btnEReleased() - - - 174 - 46 - - - 164 - 40 - - - - - btnF - pressed() - MetaWatchSimulatorForm - btnFPressed() - - - 236 - 89 - - - 258 - 87 - - - - - btnF - released() - MetaWatchSimulatorForm - btnFReleased() - - - 185 - 90 - - - 187 - 108 - - - - - - btnAPressed() - btnAReleased() - btnBPressed() - btnBReleased() - btnCPressed() - btnCReleased() - btnDPressed() - btnDReleased() - btnEPressed() - btnEReleased() - btnFPressed() - btnFReleased() - - diff --git a/qt.png b/qt.png deleted file mode 100644 index eaedc3d..0000000 Binary files a/qt.png and /dev/null differ diff --git a/qtc_packaging/debian_harmattan/README b/qtc_packaging/debian_harmattan/README deleted file mode 100644 index be8bc96..0000000 --- a/qtc_packaging/debian_harmattan/README +++ /dev/null @@ -1,6 +0,0 @@ -The Debian Package sowatch ----------------------------- - -Comments regarding the Package - - -- Javier Fri, 16 Sep 2011 03:19:28 +0200 diff --git a/qtc_packaging/debian_harmattan/changelog b/qtc_packaging/debian_harmattan/changelog deleted file mode 100644 index 4ce001f..0000000 --- a/qtc_packaging/debian_harmattan/changelog +++ /dev/null @@ -1,5 +0,0 @@ -sowatch (0.0.1) unstable; urgency=low - - * Initial Release. - - -- Javier Fri, 16 Sep 2011 03:19:28 +0200 diff --git a/qtc_packaging/debian_harmattan/compat b/qtc_packaging/debian_harmattan/compat deleted file mode 100644 index 7f8f011..0000000 --- a/qtc_packaging/debian_harmattan/compat +++ /dev/null @@ -1 +0,0 @@ -7 diff --git a/qtc_packaging/debian_harmattan/control b/qtc_packaging/debian_harmattan/control deleted file mode 100644 index b43216c..0000000 --- a/qtc_packaging/debian_harmattan/control +++ /dev/null @@ -1,14 +0,0 @@ -Source: sowatch -Section: user/other -Priority: optional -Maintainer: Javier -Build-Depends: debhelper (>= 5), libqt4-dev -Standards-Version: 3.7.3 -Homepage: - -Package: sowatch -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: - -XSBC-Maemo-Display-Name: sowatch diff --git a/qtc_packaging/debian_harmattan/copyright b/qtc_packaging/debian_harmattan/copyright deleted file mode 100644 index 5a99d4d..0000000 --- a/qtc_packaging/debian_harmattan/copyright +++ /dev/null @@ -1,40 +0,0 @@ -This package was debianized by Javier on -Fri, 16 Sep 2011 03:19:28 +0200. - -It was downloaded from - -Upstream Author(s): - - - - -Copyright: - - - - -License: - - This package is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This package is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this package; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -On Debian systems, the complete text of the GNU General -Public License can be found in `/usr/share/common-licenses/GPL'. - -The Debian packaging is (C) 2011, Javier and -is licensed under the GPL, see above. - - -# Please also look if there are files or directories which have a -# different copyright/license attached and list them here. diff --git a/qtc_packaging/debian_harmattan/rules b/qtc_packaging/debian_harmattan/rules deleted file mode 100755 index da02eb9..0000000 --- a/qtc_packaging/debian_harmattan/rules +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/make -f -# -*- makefile -*- -# Sample debian/rules that uses debhelper. -# This file was originally written by Joey Hess and Craig Small. -# As a special exception, when this file is copied by dh-make into a -# dh-make output file, you may use that output file without restriction. -# This special exception was added by Craig Small in version 0.37 of dh-make. - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - - - - - -configure: configure-stamp -configure-stamp: - dh_testdir - # qmake PREFIX=/usr# Uncomment this line for use without Qt Creator - - touch configure-stamp - - -build: build-stamp - -build-stamp: configure-stamp - dh_testdir - - # Add here commands to compile the package. - # $(MAKE) # Uncomment this line for use without Qt Creator - #docbook-to-man debian/sowatch.sgml > sowatch.1 - - touch $@ - -clean: - dh_testdir - dh_testroot - rm -f build-stamp configure-stamp - - # Add here commands to clean up after the build process. - $(MAKE) clean - - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - - # Add here commands to install the package into debian/sowatch. - $(MAKE) INSTALL_ROOT="$(CURDIR)"/debian/sowatch install - - -# Build architecture-independent files here. -binary-indep: build install -# We have nothing to do by default. - -# Build architecture-dependent files here. -binary-arch: build install - dh_testdir - dh_testroot - dh_installchangelogs - dh_installdocs - dh_installexamples -# dh_install -# dh_installmenu -# dh_installdebconf -# dh_installlogrotate -# dh_installemacsen -# dh_installpam -# dh_installmime -# dh_python -# dh_installinit -# dh_installcron -# dh_installinfo - dh_installman - dh_link - dh_strip - dh_compress - dh_fixperms -# dh_perl -# dh_makeshlibs - dh_installdeb - # dh_shlibdeps # Uncomment this line for use without Qt Creator - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/sowatch.h b/sowatch.h deleted file mode 100644 index 79c631c..0000000 --- a/sowatch.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef SOWATCH_H -#define SOWATCH_H - -#include "watch.h" -#include "watchlet.h" -#include "graphicswatchlet.h" -#include "declarativewatchlet.h" -#include "watchserver.h" -#include "watchsimulator.h" - -#endif // SOWATCH_H diff --git a/sowatch.pro b/sowatch.pro deleted file mode 100644 index 402a17f..0000000 --- a/sowatch.pro +++ /dev/null @@ -1,76 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2011-09-12T20:48:51 -# -#------------------------------------------------- - -QT += core gui declarative - -CONFIG += mobility -MOBILITY += connectivity - -TARGET = sowatch -TEMPLATE = app - - -SOURCES += main.cpp\ - watchmanager.cpp \ - watchserver.cpp \ - watch.cpp \ - watchsimulator.cpp \ - metawatchsimulatorform.cpp \ - metawatchsimulator.cpp \ - watchlet.cpp \ - testwatchlet.cpp \ - watchpaintengine.cpp \ - graphicswatchlet.cpp \ - declarativewatchlet.cpp \ - testdeclarativewatchlet.cpp \ - declarativewatchwrapper.cpp \ - metawatch.cpp \ - metawatchpaintengine.cpp - -HEADERS += \ - watchmanager.h \ - watchserver.h \ - watch.h \ - watchsimulator.h \ - metawatchsimulatorform.h \ - metawatchsimulator.h \ - watchlet.h \ - testwatchlet.h \ - watchpaintengine.h \ - graphicswatchlet.h \ - declarativewatchlet.h \ - testdeclarativewatchlet.h \ - declarativewatchwrapper.h \ - metawatch.h \ - sowatch.h \ - metawatchpaintengine.h - -FORMS += \ - metawatchsimulatorform.ui - -OTHER_FILES += \ - testdeclarativewatchlet.qml \ - qtc_packaging/debian_harmattan/rules \ - qtc_packaging/debian_harmattan/README \ - qtc_packaging/debian_harmattan/copyright \ - qtc_packaging/debian_harmattan/control \ - qtc_packaging/debian_harmattan/compat \ - qtc_packaging/debian_harmattan/changelog \ - qt.png - -RESOURCES += \ - tests.qrc - -contains(MEEGO_EDITION,harmattan) { - target.path = /opt/sowatch/bin - INSTALLS += target -} - - - - - - diff --git a/testdeclarativewatchlet.cpp b/testdeclarativewatchlet.cpp deleted file mode 100644 index 432d525..0000000 --- a/testdeclarativewatchlet.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "testdeclarativewatchlet.h" - -using namespace sowatch; - -TestDeclarativeWatchlet::TestDeclarativeWatchlet(WatchServer* server) : - DeclarativeWatchlet(server, "com.javispedro.sowatch.testdeclarativewatchlet") -{ - setSource(QUrl("qrc:/testdeclarativewatchlet.qml")); -} diff --git a/testdeclarativewatchlet.h b/testdeclarativewatchlet.h deleted file mode 100644 index b7b6dcd..0000000 --- a/testdeclarativewatchlet.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef TESTDECLARATIVEWATCHLET_H -#define TESTDECLARATIVEWATCHLET_H - -#include "declarativewatchlet.h" - -namespace sowatch -{ - -class TestDeclarativeWatchlet : public DeclarativeWatchlet -{ - Q_OBJECT -public: - explicit TestDeclarativeWatchlet(WatchServer* server); - -}; - -} - -#endif // TESTDECLARATIVEWATCHLET_H diff --git a/testdeclarativewatchlet.qml b/testdeclarativewatchlet.qml deleted file mode 100644 index 20b66d5..0000000 --- a/testdeclarativewatchlet.qml +++ /dev/null @@ -1,28 +0,0 @@ -import QtQuick 1.0 -import com.javispedro.sowatch 1.0 - -Rectangle { - width: 96 - height: 96 - - Text { - text: watch.model - } - - Image { - anchors.centerIn: parent - source: "qt.png" - - transform: Rotation { - axis { x : 0; y : 1; z: 0 } - origin { x: width / 4; y: 0; } - RotationAnimation on angle { - loops: Animation.Infinite - running: watch.active - duration: 10000 - from: 0 - to: 360 - } - } - } -} diff --git a/tests.qrc b/tests.qrc deleted file mode 100644 index c86f361..0000000 --- a/tests.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - testdeclarativewatchlet.qml - qt.png - - diff --git a/testwatchlet.cpp b/testwatchlet.cpp deleted file mode 100644 index ffc4097..0000000 --- a/testwatchlet.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include - -#include "testwatchlet.h" -#include "watch.h" - -using namespace sowatch; - -TestWatchlet::TestWatchlet(WatchServer* server) : - Watchlet(server, "com.javispedro.sowatch.testwatchlet"), _timer(new QTimer(this)), _y(0) -{ - _timer->setInterval(50); - connect(_timer, SIGNAL(timeout()), SLOT(interv())); - connect(this, SIGNAL(activated()), SLOT(handleActivated())); - connect(this, SIGNAL(deactivated()), SLOT(handleDeactivated())); -} - -void TestWatchlet::interv() -{ - QPainter p(watch()); - //p.fillRect(8, _y, 8, 1, Qt::black); - _y = (_y + 1) % watch()->height(); - p.fillRect(0, _y, _y, 2, Qt::black); - //p.fillRect(0, 0, watch()->width(), watch()->height(), Qt::black); -} - - -void TestWatchlet::handleActivated() -{ - qDebug() << "test watchlet activated"; - QPainter p(watch()); - p.fillRect(0, 0, watch()->width(), watch()->height(), Qt::white); - _timer->start(); -} - -void TestWatchlet::handleDeactivated() -{ - _timer->stop(); - qDebug() << "test watchlet deactivated"; -} diff --git a/testwatchlet.h b/testwatchlet.h deleted file mode 100644 index caa68da..0000000 --- a/testwatchlet.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TESTWATCHLET_H -#define TESTWATCHLET_H - -#include -#include "watchlet.h" - -namespace sowatch -{ - -class TestWatchlet : public Watchlet -{ - Q_OBJECT -public: - explicit TestWatchlet(WatchServer* server); - -protected slots: - void interv(); - void handleActivated(); - void handleDeactivated(); - -private: - QTimer *_timer; - int _y; - -}; - -} - -#endif // TESTWATCHLET_H diff --git a/watch.cpp b/watch.cpp deleted file mode 100644 index e8da790..0000000 --- a/watch.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "watch.h" -#include "watchpaintengine.h" - -using namespace sowatch; - -Watch::Watch(const QImage& image, QObject* parent) : - QObject(parent), _image(image), _paintEngine(0) -{ - -} - -Watch::~Watch() -{ - if (_paintEngine) { - delete _paintEngine; - } -} - -QPaintEngine* Watch::paintEngine() const -{ - if (!_paintEngine) { - _paintEngine = new WatchPaintEngine(const_cast(this), - const_cast(&_image)); - } - - return _paintEngine; -} - -int Watch::metric(PaintDeviceMetric metric) const -{ - switch (metric) { - case PdmWidth: - return _image.width(); - case PdmHeight: - return _image.height(); - case PdmWidthMM: - return _image.widthMM(); - case PdmHeightMM: - return _image.heightMM(); - case PdmNumColors: - return _image.numColors(); - case PdmDepth: - return _image.depth(); - case PdmDpiX: - return _image.logicalDpiX(); - case PdmDpiY: - return _image.logicalDpiY(); - case PdmPhysicalDpiX: - return _image.physicalDpiX(); - case PdmPhysicalDpiY: - return _image.physicalDpiY(); - } - - return -1; -} - -void Watch::update(const QRect &rect) -{ - QList rects; - rects << rect; - update(rects); -} diff --git a/watch.h b/watch.h deleted file mode 100644 index 3581ada..0000000 --- a/watch.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef WATCH_H -#define WATCH_H - -#include -#include -#include - -namespace sowatch -{ - -class Watch : public QObject, public QPaintDevice -{ - Q_OBJECT - Q_PROPERTY(QString model READ model) - Q_PROPERTY(bool connected READ isConnected) -public: - explicit Watch(const QImage& image, QObject* parent = 0); - ~Watch(); - - QPaintEngine* paintEngine() const; - int metric(PaintDeviceMetric metric) const; - - Q_INVOKABLE virtual QString model() const = 0; - Q_INVOKABLE virtual bool isConnected() const = 0; - - /** Indicates if watch is too busy atm and we should limit frame rate. */ - Q_INVOKABLE virtual bool busy() const = 0; - -signals: - void connected(); - void disconnected(); - void buttonPressed(int button); - void buttonReleased(int button); - -public slots: - virtual void update(const QList& rects) = 0; - virtual void update(const QRect& rect); - virtual void vibrate(bool on) = 0; - -protected: - QImage _image; - mutable QPaintEngine* _paintEngine; - -friend class WatchPaintEngine; -}; - -} - -#endif // WATCH_H diff --git a/watchlet.cpp b/watchlet.cpp deleted file mode 100644 index 6d7fe68..0000000 --- a/watchlet.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "watchlet.h" -#include "watchserver.h" - -using namespace sowatch; - -Watchlet::Watchlet(WatchServer *server, const QString& id) : - QObject(server), _id(id), _active(false), _server(server) -{ - _server->registerWatchlet(this); -} - -WatchServer* Watchlet::server() -{ - return _server; -} - -Watch* Watchlet::watch() -{ - return _server->watch(); -} - -QString Watchlet::id() const -{ - return _id; -} - -bool Watchlet::isActive() const -{ - return _active; -} - -void Watchlet::activate() -{ - _active = true; - emit activeChanged(); - emit activated(); -} - -void Watchlet::deactivate() -{ - _active = false; - emit activeChanged(); - emit deactivated(); -} diff --git a/watchlet.h b/watchlet.h deleted file mode 100644 index f018fa1..0000000 --- a/watchlet.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef WATCHLET_H -#define WATCHLET_H - -#include - -namespace sowatch -{ - -class Watch; -class WatchServer; - -class Watchlet : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString id READ id CONSTANT) - Q_PROPERTY(bool isActive READ isActive NOTIFY activeChanged) - -public: - explicit Watchlet(WatchServer *server, const QString& id); - - WatchServer* server(); - Watch* watch(); - - Q_INVOKABLE QString id() const; - Q_INVOKABLE bool isActive() const; - -signals: - void activeChanged(); - void activated(); - void deactivated(); - -protected: - virtual void activate(); - virtual void deactivate(); - - const QString _id; - bool _active; - -private: - WatchServer* _server; - -friend class WatchServer; -}; - -} - -#endif // WATCHLET_H diff --git a/watchmanager.cpp b/watchmanager.cpp deleted file mode 100644 index b511a31..0000000 --- a/watchmanager.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "watchmanager.h" - -using namespace sowatch; - -WatchManager::WatchManager(QObject *parent) : - QObject(parent) -{ -} diff --git a/watchmanager.h b/watchmanager.h deleted file mode 100644 index 6d945ff..0000000 --- a/watchmanager.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef WATCHMANAGER_H -#define WATCHMANAGER_H - -#include - -namespace sowatch -{ - -class WatchManager : public QObject -{ - Q_OBJECT -public: - explicit WatchManager(QObject *parent = 0); - -signals: - -public slots: - -}; - -} - -#endif // WATCHMANAGER_H diff --git a/watchpaintengine.cpp b/watchpaintengine.cpp deleted file mode 100644 index 18cfb60..0000000 --- a/watchpaintengine.cpp +++ /dev/null @@ -1,305 +0,0 @@ -#include -#include - -#include "watch.h" -#include "watchpaintengine.h" - -using namespace sowatch; - -WatchPaintEngine::WatchPaintEngine(Watch* watch, QImage* image) - : QPaintEngine(QPaintEngine::AllFeatures), - _watch(watch), _painter(), - _hasPen(false), _hasBrush(false), _clipEnabled(false) -{ - Q_UNUSED(image); -} - -bool WatchPaintEngine::begin(QPaintDevice *pdev) -{ - _damaged = QRegion(); - _watch = static_cast(pdev); - - return _painter.begin(&_watch->_image); -} - -bool WatchPaintEngine::end() -{ - bool ret = _painter.end(); - if (ret) { - _watch->update(_damaged.rects().toList()); - } - return ret; -} - -void WatchPaintEngine::damageMappedRect(const QRect &r) -{ - if (_clipEnabled) { - _damaged += _clipRegion.intersected(r); - } else { - _damaged += r; - } -} - -void WatchPaintEngine::damageRect(const QRect &r) -{ - damageMappedRect(_transform.mapRect(r)); -} - -void WatchPaintEngine::damageRect(const QRectF &r) -{ - damageMappedRect(_transform.mapRect(r).toRect()); -} - -void WatchPaintEngine::damagePenStroke(const QLineF &line) -{ - if (!_hasPen) return; - - const qreal a = line.angle(); - const qreal sn = sinf(a); - const qreal cs = cosf(a); - const qreal w = _penWidth = 0.0 ? 1.0 : _penWidth; - const qreal x1 = line.x1(); - const qreal x2 = line.x2(); - const qreal y1 = line.x1(); - const qreal y2 = line.y2(); - - damageRect(QRectF(x1-(w*sn/2.0f), y1+(w*cs/2.0f), x2+(w*sn/2.0f), y2-(w*cs/2.0f)).normalized()); -} - -void WatchPaintEngine::updateClipRegion(const QRegion& region, Qt::ClipOperation op) -{ - switch(op) { - case Qt::NoClip: - _clipEnabled = false; - _clipRegion = QRegion(0, 0, _watch->width(), _watch->height()); - break; - case Qt::ReplaceClip: - _clipEnabled = true; - _clipRegion = region; - break; - case Qt::IntersectClip: - _clipEnabled = true; - _clipRegion &= region; - break; - case Qt::UniteClip: - _clipEnabled = true; - _clipRegion |= region; - break; - } -} - -void WatchPaintEngine::drawEllipse(const QRectF &r) -{ - damageRect(r); - _painter.drawEllipse(r); -} - -void WatchPaintEngine::drawEllipse(const QRect &r) -{ - damageRect(r); - _painter.drawEllipse(r); -} - -void WatchPaintEngine::drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags) -{ - damageRect(r); - _painter.drawImage(r, pm, sr, flags); -} - -void WatchPaintEngine::drawLines(const QLineF *lines, int lineCount) -{ - int i; - for (i = 0; i < lineCount; i++) { - const QLineF& line = lines[i]; - damagePenStroke(line); - } - _painter.drawLines(lines, lineCount); -} - -void WatchPaintEngine::drawLines(const QLine *lines, int lineCount) -{ - int i; - for (i = 0; i < lineCount; i++) { - const QLine& line = lines[i]; - damagePenStroke(line); - } - _painter.drawLines(lines, lineCount); -} - -void WatchPaintEngine::drawPath(const QPainterPath &path) -{ - damageRect(path.boundingRect()); - _painter.drawPath(path); -} - -void WatchPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) -{ - damageRect(r); - _painter.drawPixmap(r, pm, sr); -} - -void WatchPaintEngine::drawPoints(const QPointF *points, int pointCount) -{ - const qreal penWidth = _painter.pen().widthF(); - int i; - for (i = 0; i < pointCount; i++) { - const QPointF& p = points[i]; - damageRect(QRect(p.x() - penWidth/2, p.y() - penWidth/2, - p.x() + penWidth/2, p.y() + penWidth/2)); - } - _painter.drawPoints(points, pointCount); -} - -void WatchPaintEngine::drawPoints(const QPoint *points, int pointCount) -{ - const qreal penWidth = _painter.pen().widthF(); - int i; - for (i = 0; i < pointCount; i++) { - const QPoint& p = points[i]; - damageRect(QRect(p.x() - penWidth/2, p.y() - penWidth/2, - p.x() + penWidth/2, p.y() + penWidth/2)); - } - _painter.drawPoints(points, pointCount); -} - -void WatchPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) -{ - QPolygonF p(pointCount); - int i; - for (i = 0; i < pointCount; i++) { - p[i] = points[i]; - } - damageRect(p.boundingRect()); - _painter.drawPolygon(points, pointCount, - mode == WindingMode ? Qt::WindingFill : Qt::OddEvenFill); -} - -void WatchPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode) -{ - QPolygon p(pointCount); - int i; - for (i = 0; i < pointCount; i++) { - p[i] = points[i]; - } - damageRect(p.boundingRect()); - _painter.drawPolygon(points, pointCount, - mode == WindingMode ? Qt::WindingFill : Qt::OddEvenFill); -} - -void WatchPaintEngine::drawRects(const QRectF *rects, int rectCount) -{ - int i; - for (i = 0; i < rectCount; i++) { - const QRectF& r = rects[i]; - if (_hasBrush) { - damageRect(r); - } - if (_hasPen) { - damagePenStroke(QLineF(r.left(), r.top(), r.right(), r.top())); - damagePenStroke(QLineF(r.right(), r.top(), r.right(), r.bottom())); - damagePenStroke(QLineF(r.left(), r.bottom(), r.right(), r.bottom())); - damagePenStroke(QLineF(r.left(), r.top(), r.left(), r.bottom())); - } - } - _painter.drawRects(rects, rectCount); -} - -void WatchPaintEngine::drawRects(const QRect *rects, int rectCount) -{ - int i; - for (i = 0; i < rectCount; i++) { - const QRect& r = rects[i]; - if (_hasBrush) { - damageRect(r); - } - if (_hasPen) { - damagePenStroke(QLine(r.left(), r.top(), r.right(), r.top())); - damagePenStroke(QLine(r.right(), r.top(), r.right(), r.bottom())); - damagePenStroke(QLine(r.left(), r.bottom(), r.right(), r.bottom())); - damagePenStroke(QLine(r.left(), r.top(), r.left(), r.bottom())); - } - } - - _painter.drawRects(rects, rectCount); -} - -void WatchPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) -{ - const qreal height = textItem.ascent() + textItem.descent(); - damageRect(QRect(p.x(), p.y(), p.x() + textItem.width(), p.y() + height)); - _painter.drawTextItem(p, textItem); -} - -void WatchPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s) -{ - damageRect(r); - _painter.drawTiledPixmap(r, pixmap, s); -} - -QPaintEngine::Type WatchPaintEngine::type() const -{ - return QPaintEngine::Raster; -} - -void WatchPaintEngine::updateState(const QPaintEngineState &state) -{ - const QPaintEngine::DirtyFlags flags = state.state(); - if (flags & QPaintEngine::DirtyBackground) - { - _painter.setBackground(state.backgroundBrush()); - } - if (flags & QPaintEngine::DirtyBackgroundMode) - { - _painter.setBackgroundMode(state.backgroundMode()); - } - if (flags & QPaintEngine::DirtyBrush) - { - QBrush brush = state.brush(); - _hasBrush = brush.style() != Qt::NoBrush; - _painter.setBrush(brush); - } - if (flags & QPaintEngine::DirtyBrushOrigin) - { - _painter.setBrushOrigin(state.brushOrigin()); - } - if (flags & QPaintEngine::DirtyClipEnabled) - { - _clipEnabled = state.isClipEnabled(); - _painter.setClipping(_clipEnabled); - } - if (flags & QPaintEngine::DirtyClipPath) - { - QRegion region = state.clipPath().boundingRect().toRect(); - updateClipRegion(region, state.clipOperation()); - _painter.setClipPath(state.clipPath(), state.clipOperation()); - } - if (flags & QPaintEngine::DirtyClipRegion) - { - updateClipRegion(state.clipRegion(), state.clipOperation()); - _painter.setClipRegion(state.clipRegion(), state.clipOperation()); - } - if (flags & QPaintEngine::DirtyCompositionMode) - { - _painter.setCompositionMode(state.compositionMode()); - } - if (flags & QPaintEngine::DirtyFont) - { - _painter.setFont(state.font()); - } - if (flags & QPaintEngine::DirtyHints) - { - _painter.setRenderHints(state.renderHints()); - } - if (flags & QPaintEngine::DirtyPen) - { - QPen pen = state.pen(); - _hasPen = pen.style() != Qt::NoPen; - _penWidth = pen.widthF(); - _painter.setPen(pen); - } - if (flags & QPaintEngine::DirtyTransform) - { - _transform = state.transform(); - _painter.setTransform(_transform); - } -} diff --git a/watchpaintengine.h b/watchpaintengine.h deleted file mode 100644 index 14181fa..0000000 --- a/watchpaintengine.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef WATCHPAINTENGINE_H -#define WATCHPAINTENGINE_H - -#include - -namespace sowatch -{ - -class Watch; - -class WatchPaintEngine : public QPaintEngine -{ -public: - WatchPaintEngine(Watch* watch, QImage* image); - - bool begin(QPaintDevice *pdev); - bool end(); - - void drawEllipse(const QRectF &r); - void drawEllipse(const QRect &r); - void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags); - void drawLines(const QLineF *lines, int lineCount); - void drawLines(const QLine *lines, int lineCount); - void drawPath(const QPainterPath &path); - void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr); - void drawPoints(const QPointF *points, int pointCount); - void drawPoints(const QPoint *points, int pointCount); - void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode); - void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode); - void drawRects(const QRectF *rects, int rectCount); - void drawRects(const QRect *rects, int rectCount); - void drawTextItem(const QPointF &p, const QTextItem &textItem); - void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s); - - Type type() const; - void updateState(const QPaintEngineState &state); - -protected: - void damageMappedRect(const QRect& r); - void damageRect(const QRect& r); - void damageRect(const QRectF& r); - void damagePenStroke(const QLineF& line); - void updateClipRegion(const QRegion& region, Qt::ClipOperation op); - - Watch* _watch; - QPainter _painter; - QRegion _damaged; - - bool _hasPen; - qreal _penWidth; - - bool _hasBrush; - - bool _clipEnabled; - QRegion _clipRegion; - - QTransform _transform; -}; - -} - -#endif // WATCHPAINTENGINE_H diff --git a/watchserver.cpp b/watchserver.cpp deleted file mode 100644 index ad49995..0000000 --- a/watchserver.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "watch.h" -#include "watchlet.h" -#include "watchserver.h" - -using namespace sowatch; - -WatchServer::WatchServer(Watch* watch, QObject* parent) : - QObject(parent), _watch(watch), _currentWatchlet(0) -{ - connect(_watch, SIGNAL(connected()), SLOT(watchConnected())); - connect(_watch, SIGNAL(disconnected()), SLOT(watchDisconnected())); -} - -Watch* WatchServer::watch() -{ - return _watch; -} - -void WatchServer::runWatchlet(const QString& id) -{ - if (_currentWatchlet) { - closeWatchlet(); - } - _currentWatchlet = watchlets[id]; - if (_watch->isConnected()) { - _currentWatchlet->activate(); - } -} - -void WatchServer::closeWatchlet() -{ - Q_ASSERT(_currentWatchlet != 0); - if (_watch->isConnected()) { - _currentWatchlet->deactivate(); - } - _currentWatchlet = 0; -} - -void WatchServer::registerWatchlet(Watchlet *watchlet) -{ - Q_ASSERT(watchlet->_server == this); - watchlets[watchlet->id()] = watchlet; -} - -void WatchServer::watchConnected() -{ - if (_currentWatchlet) { - _currentWatchlet->activate(); - } -} - -void WatchServer::watchDisconnected() -{ - if (_currentWatchlet) { - _currentWatchlet->deactivate(); - } -} diff --git a/watchserver.h b/watchserver.h deleted file mode 100644 index 78454d4..0000000 --- a/watchserver.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef WATCHSERVER_H -#define WATCHSERVER_H - -#include -#include - -namespace sowatch -{ - -class Watch; -class Watchlet; - -class WatchServer : public QObject -{ - Q_OBJECT - Q_PROPERTY(Watch* watch READ watch) -public: - explicit WatchServer(Watch* watch, QObject* parent = 0); - - Watch* watch(); - - void runWatchlet(const QString& id); - void closeWatchlet(); - -signals: - -public slots: - -protected: - Watch* _watch; - Watchlet* _currentWatchlet; - - QMap watchlets; - - void registerWatchlet(Watchlet *watchlet); - -protected slots: - void watchConnected(); - void watchDisconnected(); - -friend class Watchlet; -}; - -} - -#endif // WATCHSERVER_H diff --git a/watchsimulator.cpp b/watchsimulator.cpp deleted file mode 100644 index 464f3a5..0000000 --- a/watchsimulator.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include - -#include "watchsimulator.h" - -using namespace sowatch; - -WatchSimulator::WatchSimulator(const QImage& image, QObject* parent) : - Watch(image, parent) -{ - -} diff --git a/watchsimulator.h b/watchsimulator.h deleted file mode 100644 index 564118c..0000000 --- a/watchsimulator.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef WATCHSIMULATOR_H -#define WATCHSIMULATOR_H - -#include - -#include "watch.h" - -namespace sowatch -{ - -class WatchSimulator : public Watch -{ - Q_OBJECT -public: - explicit WatchSimulator(const QImage& image, QObject *parent = 0); -}; - -} - -#endif // WATCHSIMULATOR_H -- cgit v1.2.3