From bc5b70046e84c6e5a33a19bd2e64e626fdf0579e Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Thu, 9 Aug 2012 18:50:23 +0200 Subject: first UI editable settings! --- libsowatch/configkey.h | 7 ++- libsowatch/declarativewatchlet.cpp | 3 ++ libsowatch/gconfkey.cpp | 10 +++++ libsowatch/gconfkey.h | 3 +- libsowatch/watchplugininterface.h | 1 + metawatch/metawatch.pro | 2 +- metawatch/metawatchplugin.cpp | 9 ++++ metawatch/metawatchplugin.h | 7 +-- metawatch/qml/metawatch-digital-config.qml | 55 +++++++++++++++++++++++ sowatchui/main.cpp | 4 ++ sowatchui/qml/GroupHeader.qml | 26 +++++++++++ sowatchui/qml/MainPage.qml | 7 ++- sowatchui/qml/WatchPage.qml | 69 ++++++++++++++++++++++++----- sowatchui/sowatch_src_inkscape.svgz | Bin 0 -> 8771 bytes sowatchui/watchesmodel.cpp | 13 ++++++ sowatchui/watchesmodel.h | 4 +- 16 files changed, 198 insertions(+), 22 deletions(-) create mode 100644 metawatch/qml/metawatch-digital-config.qml create mode 100644 sowatchui/qml/GroupHeader.qml create mode 100644 sowatchui/sowatch_src_inkscape.svgz diff --git a/libsowatch/configkey.h b/libsowatch/configkey.h index ef7665e..a30ae67 100644 --- a/libsowatch/configkey.h +++ b/libsowatch/configkey.h @@ -12,7 +12,7 @@ namespace sowatch class SOWATCH_EXPORT ConfigKey : public QObject { Q_OBJECT - Q_PROPERTY(QString key READ key CONSTANT) + Q_PROPERTY(QString key READ key WRITE setKey NOTIFY keyChanged) Q_PROPERTY(QVariant value READ value WRITE set RESET unset NOTIFY changed USER true) Q_PROPERTY(QStringList dirs READ dirs) Q_PROPERTY(QStringList keys READ keys) @@ -21,6 +21,7 @@ public: ConfigKey(QObject *parent = 0); virtual QString key() const = 0; + virtual void setKey(const QString& key) = 0; virtual QVariant value() const = 0; virtual void set(const QVariant& value) = 0; @@ -43,7 +44,11 @@ public: virtual ConfigKey* getSubkey(const QString& subkey, QObject *parent = 0) const = 0; signals: + /** Key property changed (via setKey) */ + void keyChanged(); + /** Value changed. */ void changed(); + /** A value of a subkey changed. */ void subkeyChanged(const QString& subkey); }; diff --git a/libsowatch/declarativewatchlet.cpp b/libsowatch/declarativewatchlet.cpp index 275af2a..68d6c28 100644 --- a/libsowatch/declarativewatchlet.cpp +++ b/libsowatch/declarativewatchlet.cpp @@ -1,6 +1,7 @@ #include #include #include "watchserver.h" +#include "gconfkey.h" #include "declarativewatchwrapper.h" #include "declarativewatchlet.h" @@ -20,6 +21,8 @@ DeclarativeWatchlet::DeclarativeWatchlet(WatchServer* server, const QString& id) if (!_registered) { qmlRegisterUncreatableType("com.javispedro.sowatch", 1, 0, "Watch", "Watch is only available via the 'watch' object"); + qmlRegisterType(); + qmlRegisterType("com.javispedro.sowatch", 1, 0, "GConfKey"); _registered = true; } diff --git a/libsowatch/gconfkey.cpp b/libsowatch/gconfkey.cpp index c6becc4..da6aeff 100644 --- a/libsowatch/gconfkey.cpp +++ b/libsowatch/gconfkey.cpp @@ -141,6 +141,16 @@ QString GConfKey::key() const return _key; } +void GConfKey::setKey(const QString &key) +{ + _key = key; + if (_key.endsWith("/")) { + _key.chop(1); + } + emit keyChanged(); + emit changed(); +} + QVariant GConfKey::value() const { return value(QString()); diff --git a/libsowatch/gconfkey.h b/libsowatch/gconfkey.h index c9074ea..d2bf088 100644 --- a/libsowatch/gconfkey.h +++ b/libsowatch/gconfkey.h @@ -11,10 +11,11 @@ class SOWATCH_EXPORT GConfKey : public ConfigKey Q_OBJECT public: - GConfKey(const QString& key, QObject *parent = 0); + GConfKey(const QString& key = QString(), QObject *parent = 0); ~GConfKey(); QString key() const; + void setKey(const QString &key); QVariant value() const; void set(const QVariant& value); diff --git a/libsowatch/watchplugininterface.h b/libsowatch/watchplugininterface.h index 804f7f5..0ab2c4b 100644 --- a/libsowatch/watchplugininterface.h +++ b/libsowatch/watchplugininterface.h @@ -20,6 +20,7 @@ public: virtual QStringList drivers() = 0; virtual WatchScanner* getScanner(QObject *parent = 0) = 0; + virtual QUrl getConfigQmlUrl(const QString& driver) = 0; virtual Watch* getWatch(const QString& driver, ConfigKey* settings, QObject *parent = 0) = 0; }; diff --git a/metawatch/metawatch.pro b/metawatch/metawatch.pro index 9331665..721380d 100644 --- a/metawatch/metawatch.pro +++ b/metawatch/metawatch.pro @@ -33,7 +33,7 @@ FORMS += \ metawatchsimulatorform.ui res_files.files += res/graphics res/fonts -qml_files.files += qml/com +qml_files.files += qml/com qml/metawatch-digital-config.qml LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch diff --git a/metawatch/metawatchplugin.cpp b/metawatch/metawatchplugin.cpp index 72713ec..f73c127 100644 --- a/metawatch/metawatchplugin.cpp +++ b/metawatch/metawatchplugin.cpp @@ -39,6 +39,15 @@ WatchScanner* MetaWatchPlugin::getScanner(QObject *parent) return new MetaWatchScanner(parent); } +QUrl MetaWatchPlugin::getConfigQmlUrl(const QString &driver) +{ + if (driver == "metawatch-digital") { + return QUrl::fromLocalFile(SOWATCH_QML_DIR "/metawatch-digital-config.qml"); + } else { + return QUrl(); + } +} + Watch* MetaWatchPlugin::getWatch(const QString& driver, ConfigKey* settings, QObject *parent) { if (driver == "metawatch-digital") { diff --git a/metawatch/metawatchplugin.h b/metawatch/metawatchplugin.h index 964aa04..5b729f2 100644 --- a/metawatch/metawatchplugin.h +++ b/metawatch/metawatchplugin.h @@ -14,9 +14,10 @@ public: MetaWatchPlugin(); ~MetaWatchPlugin(); - virtual QStringList drivers(); - virtual WatchScanner* getScanner(QObject *parent); - virtual Watch* getWatch(const QString& driver, ConfigKey *settings, QObject *parent); + QStringList drivers(); + WatchScanner* getScanner(QObject *parent); + QUrl getConfigQmlUrl(const QString &driver); + Watch* getWatch(const QString& driver, ConfigKey *settings, QObject *parent); private: static bool fontsLoaded; diff --git a/metawatch/qml/metawatch-digital-config.qml b/metawatch/qml/metawatch-digital-config.qml new file mode 100644 index 0000000..f0f2e91 --- /dev/null +++ b/metawatch/qml/metawatch-digital-config.qml @@ -0,0 +1,55 @@ +import QtQuick 1.1 +import com.nokia.meego 1.1 +import com.javispedro.sowatch 1.0 + +Column { + property string configKey; + + Item { + id: hourModeItem + width: parent.width + height: UiConstants.ListItemHeightDefault + + GConfKey { + id: hourModeKey + key: configKey + "/24h-mode" + value: hourModeSwitch.checked + } + Label { + text: qsTr("24-hour clock mode") + font: UiConstants.TitleFont + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + } + Switch { + id: hourModeSwitch + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + checked: hourModeKey.value + } + } + + Item { + id: dayMonthOrderItem + width: parent.width + height: UiConstants.ListItemHeightDefault + + GConfKey { + id: dayMonthOrderKey + key: configKey + "/day-month-order" + value: dayMonthOrderSwitch.checked + } + Label { + text: qsTr("Use DD/MM instead of MM/DD") + font: UiConstants.TitleFont + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + } + Switch { + id: dayMonthOrderSwitch + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + checked: dayMonthOrderKey.value + } + } +} diff --git a/sowatchui/main.cpp b/sowatchui/main.cpp index f8c58af..af2a0c0 100644 --- a/sowatchui/main.cpp +++ b/sowatchui/main.cpp @@ -1,4 +1,5 @@ #include +#include #include "qmlapplicationviewer.h" #include @@ -21,6 +22,9 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) qDebug() << "Starting" << watches << endl; + qmlRegisterType(); + qmlRegisterType("com.javispedro.sowatch", 1, 0, "GConfKey"); + viewer->rootContext()->setContextProperty("watches", watches); viewer->rootContext()->setContextProperty("watchScanner", watchScanner); diff --git a/sowatchui/qml/GroupHeader.qml b/sowatchui/qml/GroupHeader.qml new file mode 100644 index 0000000..0350ee0 --- /dev/null +++ b/sowatchui/qml/GroupHeader.qml @@ -0,0 +1,26 @@ +import QtQuick 1.1 +import com.nokia.meego 1.1 + +Item { + id: header + height: 40 + + property alias text: headerLabel.text + + Text { + id: headerLabel + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.rightMargin: 8 + anchors.bottomMargin: 2 + font: UiConstants.GroupHeaderFont + color: theme.inverted ? "#4D4D4D" : "#3C3C3C"; + } + Image { + anchors.right: headerLabel.left + anchors.left: parent.left + anchors.verticalCenter: headerLabel.verticalCenter + anchors.rightMargin: 24 + source: "image://theme/meegotouch-groupheader" + (theme.inverted ? "-inverted" : "") + "-background" + } +} diff --git a/sowatchui/qml/MainPage.qml b/sowatchui/qml/MainPage.qml index d722b3d..339b1a6 100644 --- a/sowatchui/qml/MainPage.qml +++ b/sowatchui/qml/MainPage.qml @@ -32,10 +32,9 @@ Page { anchors.verticalCenter: parent.verticalCenter } - onClicked: { - var page = Qt.createComponent("WatchPage.qml"); - pageStack.push(page); - } + onClicked: pageStack.push(Qt.resolvedUrl("WatchPage.qml"), + {configKey: model.configKey, + configQmlUrl: model.configQmlUrl}); } } ScrollDecorator { diff --git a/sowatchui/qml/WatchPage.qml b/sowatchui/qml/WatchPage.qml index 8159834..83932eb 100644 --- a/sowatchui/qml/WatchPage.qml +++ b/sowatchui/qml/WatchPage.qml @@ -1,6 +1,7 @@ import QtQuick 1.1 import com.nokia.meego 1.1 import com.nokia.extras 1.1 +import com.javispedro.sowatch 1.0 Page { id: watchPage @@ -8,6 +9,9 @@ Page { anchors.rightMargin: UiConstants.DefaultMargin orientationLock: PageOrientation.LockPortrait + property string configKey; + property url configQmlUrl; + tools: ToolBarLayout { ToolIcon { platformIconId: "toolbar-back" @@ -16,22 +20,65 @@ Page { } } - ListView { - id: emptyListView + GConfKey { + id: nameKey + key: configKey + "/name" + } + + Flickable { + id: mainFlickable anchors.fill: parent - model: ListModel { + contentHeight: mainColumn.height - } + Column { + id: mainColumn + width: parent.width + + Item { + id: enableItem + width: parent.width + height: UiConstants.ListItemHeightDefault + + Label { + text: qsTr("Enabled") + font: UiConstants.TitleFont + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + } + Switch { + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + checked: true + } + } + + GroupHeader { + width: parent.width + text: "Watch settings" + visible: configQmlLoader.status === Loader.Ready + } + + Loader { + id: configQmlLoader + source: configQmlUrl + width: parent.width + onLoaded: item.configKey = configKey; + } + + GroupHeader { + width: parent.width + text: "Watchlets" + visible: configQmlLoader.status === Loader.Ready + } - delegate: ListDelegate { - Image { - source: "image://theme/icon-m-common-drilldown-arrow" + (theme.inverted ? "-inverse" : "") - anchors.right: parent.right; - anchors.verticalCenter: parent.verticalCenter - } + GroupHeader { + width: parent.width + text: "Notification sources" + visible: configQmlLoader.status === Loader.Ready + } } } ScrollDecorator { - flickableItem: watchesListView + flickableItem: mainFlickable } } diff --git a/sowatchui/sowatch_src_inkscape.svgz b/sowatchui/sowatch_src_inkscape.svgz new file mode 100644 index 0000000..ea0ee94 Binary files /dev/null and b/sowatchui/sowatch_src_inkscape.svgz differ diff --git a/sowatchui/watchesmodel.cpp b/sowatchui/watchesmodel.cpp index 5644466..c45a229 100644 --- a/sowatchui/watchesmodel.cpp +++ b/sowatchui/watchesmodel.cpp @@ -14,6 +14,8 @@ WatchesModel::WatchesModel(QObject *parent) : roles[Qt::DisplayRole] = QByteArray("title"); roles[Qt::StatusTipRole] = QByteArray("subtitle"); roles[ObjectRole] = QByteArray("object"); + roles[ConfigKeyRole] = QByteArray("configKey"); + roles[ConfigQmlUrlRole] = QByteArray("configQmlUrl"); setRoleNames(roles); connect(_config, SIGNAL(changed()), @@ -57,6 +59,17 @@ QVariant WatchesModel::data(const QModelIndex &index, int role) const } else { return QVariant(tr("Disabled")); } + case ConfigKeyRole: + return QVariant::fromValue(key); + case ConfigQmlUrlRole: + if (config->isSet("driver")) { + QString driver = config->value("driver").toString(); + WatchPluginInterface *plugin = Registry::registry()->getWatchPlugin(driver); + if (plugin) { + return QVariant::fromValue(plugin->getConfigQmlUrl(driver)); + } + } + return QVariant::fromValue(QUrl()); } return QVariant(); } diff --git a/sowatchui/watchesmodel.h b/sowatchui/watchesmodel.h index 4962725..396fc8d 100644 --- a/sowatchui/watchesmodel.h +++ b/sowatchui/watchesmodel.h @@ -15,7 +15,9 @@ public: ~WatchesModel(); enum DataRoles { - ObjectRole = Qt::UserRole + ObjectRole = Qt::UserRole, + ConfigKeyRole, + ConfigQmlUrlRole }; int rowCount(const QModelIndex &parent) const; -- cgit v1.2.3