Dirk and Jocke (especially), I can see you've done a lot over the past few weeks to make the mobile UI much more attracted. Have you considered using a custom Subsurface style (falling back to Material) to make it more efficient to theme the QML controls? It would be easier to customize the controls in one place, and have the change made consistently throughout, following the guidance in: https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#creating-a-custom-style
In the attached patch I have done that for the button controls (only used on DownloadFromDiveComputer.qml) moving the styling into SubsurfaceStyle/Button.qml, but it would not be hard to do it for the other controls. Using the Button as an example, we could then add code to make the button depress and change colour when down, and only have to add the code in one place. The big problem now, is that the only way I've been able to use the custom style is to select it from the command line (testing on desktop): ./subsurface-mobile -style /home/rick/src/subsurface/mobile-widgets/qml/SubsurfaceStyle Clearly that is useless for the mobile app. I believe we should also be able to use QQuickStyle::SetStyle to set it from within the app (see https://doc.qt.io/qt-5/qquickstyle.html), but the following doesn't work for me, either with or with setting the fallback style. Maybe the problem is that I'm using Qt5.7, but I'm not sure. diff --git a/subsurface-mobile-helper.cpp b/subsurface-mobile-helper.cpp index 68dd228b..cd1df6c6 100644 --- a/subsurface-mobile-helper.cpp +++ b/subsurface-mobile-helper.cpp @@ -14,6 +14,7 @@ #include <QQuickWindow> #include <QScreen> +#include <QQuickStyle> #include <QQmlApplicationEngine> #include <QQmlContext> #include <QSortFilterProxyModel> @@ -43,6 +44,10 @@ void run_ui() qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread"); qmlRegisterType<DiveImportedModel>("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel"); + // set style for custom constrols + QQuickStyle::setStyle(":/SubsurfaceStyle"); + QQuickStyle::setFallbackStyle("Material"); + QQmlApplicationEngine engine; KirigamiPlugin::getInstance().registerTypes(); #if __APPLE__ Cheers, Rick
From 5b517f4f036e9532406954b106b543de77ae5da3 Mon Sep 17 00:00:00 2001 From: Rick Walsh <[email protected]> Date: Wed, 19 Jul 2017 07:49:11 +1200 Subject: [PATCH] QML: Create and use new SubsurfaceStyle for button controls Signed-off-by: Rick Walsh <[email protected]> --- mobile-widgets/qml/DownloadFromDiveComputer.qml | 45 ------------------------- mobile-widgets/qml/SubsurfaceStyle/Button.qml | 29 ++++++++++++++++ 2 files changed, 29 insertions(+), 45 deletions(-) create mode 100644 mobile-widgets/qml/SubsurfaceStyle/Button.qml diff --git a/mobile-widgets/qml/DownloadFromDiveComputer.qml b/mobile-widgets/qml/DownloadFromDiveComputer.qml index 9086a2e0..96d94c06 100644 --- a/mobile-widgets/qml/DownloadFromDiveComputer.qml +++ b/mobile-widgets/qml/DownloadFromDiveComputer.qml @@ -145,16 +145,7 @@ Kirigami.Page { RowLayout { Button { id: download - background: Rectangle { - color: subsurfaceTheme.darkerPrimaryColor - antialiasing: true - radius: Kirigami.Units.smallSpacing * 2 - } text: qsTr("Download") - contentItem: Text { - text: download.text - color: subsurfaceTheme.darkerPrimaryTextColor - } onClicked: { text = qsTr("Retry") if (downloadThread.deviceData.bluetoothMode) { @@ -177,16 +168,7 @@ Kirigami.Page { } Button { id:quitbutton - background: Rectangle { - color: subsurfaceTheme.darkerPrimaryColor - antialiasing: true - radius: Kirigami.Units.smallSpacing * 2 - } text: qsTr("Quit") - contentItem: Text { - text: quitbutton.text - color: subsurfaceTheme.darkerPrimaryTextColor - } onClicked: { manager.appendTextToLog("exit DCDownload screen") stackView.pop(); @@ -230,16 +212,7 @@ Kirigami.Page { Button { id: acceptButton enabled: divesDownloaded - background: Rectangle { - color: enabled ? subsurfaceTheme.darkerPrimaryColor : "gray" - antialiasing: true - radius: Kirigami.Units.smallSpacing * 2 - } text: qsTr("Accept") - contentItem: Text { - text: acceptButton.text - color: subsurfaceTheme.darkerPrimaryTextColor - } onClicked: { manager.appendTextToLog("Save downloaded dives that were selected") importModel.recordDives() @@ -256,16 +229,7 @@ Kirigami.Page { Button { id: select enabled: divesDownloaded - background: Rectangle { - color: enabled ? subsurfaceTheme.darkerPrimaryColor : "gray" - antialiasing: true - radius: Kirigami.Units.smallSpacing * 2 - } text: qsTr("Select All") - contentItem: Text { - text: select.text - color: subsurfaceTheme.darkerPrimaryTextColor - } onClicked : { selectAll = true importModel.selectAll() @@ -274,16 +238,7 @@ Kirigami.Page { Button { id: unselect enabled: divesDownloaded - background: Rectangle { - color: enabled ? subsurfaceTheme.darkerPrimaryColor : "gray" - antialiasing: true - radius: Kirigami.Units.smallSpacing * 2 - } text: qsTr("Unselect All") - contentItem: Text { - text: unselect.text - color: subsurfaceTheme.darkerPrimaryTextColor - } onClicked : { selectAll = false importModel.selectNone() diff --git a/mobile-widgets/qml/SubsurfaceStyle/Button.qml b/mobile-widgets/qml/SubsurfaceStyle/Button.qml new file mode 100644 index 00000000..d37bfe64 --- /dev/null +++ b/mobile-widgets/qml/SubsurfaceStyle/Button.qml @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +import QtQuick 2.7 +import QtQuick.Controls 2.0 +import QtQuick.Controls.impl 2.0 +import QtQuick.Templates 2.0 as T + +T.Button { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentItem.implicitWidth + leftPadding + rightPadding) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentItem.implicitHeight + topPadding + bottomPadding) + baselineOffset: contentItem.y + contentItem.baselineOffset + + padding: 6 + leftPadding: padding + 2 + rightPadding: padding + 2 + + contentItem: Text { + text: control.text + color: subsurfaceTheme.darkerPrimaryTextColor + } + background: Rectangle { + color: enabled ? subsurfaceTheme.darkerPrimaryColor : "gray" + antialiasing: true + radius: height * 0.25 + } +} -- 2.13.3
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
