diff --git a/nymea-app/ui/components/SelectionTabs.qml b/nymea-app/ui/components/SelectionTabs.qml index 559ece71..f4dcc0c8 100644 --- a/nymea-app/ui/components/SelectionTabs.qml +++ b/nymea-app/ui/components/SelectionTabs.qml @@ -1,6 +1,6 @@ -import QtQuick 2.15 -import QtQuick.Layouts 1.15 -import QtQuick.Controls 2.15 +import QtQuick 2.9 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.9 import Nymea 1.0 Rectangle { diff --git a/nymea-app/ui/mainviews/dashboard/Dashboard.qml b/nymea-app/ui/mainviews/dashboard/Dashboard.qml index 86b9c59a..b7b10c1c 100644 --- a/nymea-app/ui/mainviews/dashboard/Dashboard.qml +++ b/nymea-app/ui/mainviews/dashboard/Dashboard.qml @@ -48,6 +48,9 @@ Item { index = root.model.count } var addComponent = Qt.createComponent(Qt.resolvedUrl("DashboardAddWizard.qml")) + if (addComponent.status === Component.Error) { + console.warn(addComponent.errorString()) + } var popup = addComponent.createObject(root, {dashboardModel: root.model, index: index}) popup.open() } diff --git a/nymea-app/ui/mainviews/dashboard/DashboardAddWizard.qml b/nymea-app/ui/mainviews/dashboard/DashboardAddWizard.qml index 91328e1f..c7518d6d 100644 --- a/nymea-app/ui/mainviews/dashboard/DashboardAddWizard.qml +++ b/nymea-app/ui/mainviews/dashboard/DashboardAddWizard.qml @@ -42,6 +42,8 @@ MeaDialog { title: qsTr("Add item") standardButtons: Dialog.NoButton + width: Math.min(parent.width, 400) + closePolicy: Popup.CloseOnEscape property DashboardModel dashboardModel: null property int index: 0 @@ -92,7 +94,6 @@ MeaDialog { Layout.fillWidth: true text: qsTr("Web view") iconName: "stock_website" - visible: Qt.platform.os != "android" onClicked: { internalPageStack.push(addWebViewComponent) } @@ -104,6 +105,8 @@ MeaDialog { id: addThingSelectionComponent ColumnLayout { RowLayout { + Layout.leftMargin: Style.margins + Layout.rightMargin: Style.margins ColorIcon { name: "/ui/images/find.svg" } @@ -197,6 +200,8 @@ MeaDialog { id: addGraphSelectThingComponent ColumnLayout { RowLayout { + Layout.leftMargin: Style.margins + Layout.rightMargin: Style.margins ColorIcon { name: "/ui/images/find.svg" } @@ -293,78 +298,87 @@ MeaDialog { Component { id: addWebViewComponent - ColumnLayout { + Flickable { property bool needsOkButton: true property bool okButtonEnabled: urlTextField.displayText.length > 0 + implicitHeight: webViewColumn.implicitHeight + contentHeight: webViewColumn.height - Connections { - target: okButton - onClicked: { - root.dashboardModel.addWebViewItem(urlTextField.text, columnsTabs.currentValue, rowsTabs.currentValue, interactiveSwitch.checked, root.index) - root.close(); + ColumnLayout { + id: webViewColumn + width: parent.width + + Connections { + target: okButton + onClicked: { + root.dashboardModel.addWebViewItem(urlTextField.text, columnsTabs.currentValue, rowsTabs.currentValue, interactiveSwitch.checked, root.index) + root.close(); + } } - } - SettingsPageSectionHeader { - Layout.fillWidth: true - text: qsTr("Location") - } - - TextField { - id: urlTextField - Layout.fillWidth: true - Layout.leftMargin: Style.margins - Layout.rightMargin: Style.margins - placeholderText: qsTr("Enter a URL") - text: "https://" - } - - SettingsPageSectionHeader { - Layout.fillWidth: true - text: qsTr("Size") - } - - GridLayout { - columns: width > 300 ? 2 : 1 - Layout.fillWidth: true - Layout.leftMargin: Style.margins - Layout.rightMargin: Style.margins - columnSpacing: Style.smallMargins - rowSpacing: Style.smallMargins - Label { - text: qsTr("Columns") - } - SelectionTabs { - id: columnsTabs + SettingsPageSectionHeader { Layout.fillWidth: true - model: [1, 2, 3, 4, 5, 6] - currentIndex: root.item.columnSpan - 1 + text: qsTr("Location") } - Label { - text: qsTr("Rows") - } - SelectionTabs { - id: rowsTabs + + TextField { + id: urlTextField Layout.fillWidth: true - model: [1, 2, 3, 4, 5, 6] - currentIndex: root.item.rowSpan - 1 + Layout.leftMargin: Style.margins + Layout.rightMargin: Style.margins + placeholderText: qsTr("Enter a URL") + text: "https://" + inputMethodHints: Qt.ImhNoAutoUppercase } - } - SettingsPageSectionHeader { - Layout.fillWidth: true - text: qsTr("Behavior") - visible: ["android", "ios"].indexOf(Qt.platform.os) < 0 - } + SettingsPageSectionHeader { + Layout.fillWidth: true + text: qsTr("Size") + } - SwitchDelegate { - id: interactiveSwitch - Layout.fillWidth: true - checked: root.item.interactive - text: qsTr("Interactive") - visible: ["android", "ios"].indexOf(Qt.platform.os) < 0 + GridLayout { + columns: width > 300 ? 2 : 1 + Layout.fillWidth: true + Layout.leftMargin: Style.margins + Layout.rightMargin: Style.margins + columnSpacing: Style.smallMargins + rowSpacing: Style.smallMargins + Label { + text: qsTr("Columns") + } + SelectionTabs { + id: columnsTabs + Layout.fillWidth: true + model: [1, 2, 3, 4, 5, 6] + currentIndex: root.item.columnSpan - 1 + } + Label { + text: qsTr("Rows") + } + SelectionTabs { + id: rowsTabs + Layout.fillWidth: true + model: [1, 2, 3, 4, 5, 6] + currentIndex: root.item.rowSpan - 1 + } + } + + SettingsPageSectionHeader { + Layout.fillWidth: true + text: qsTr("Behavior") + visible: ["android", "ios"].indexOf(Qt.platform.os) < 0 + } + + SwitchDelegate { + id: interactiveSwitch + Layout.fillWidth: true + checked: root.item.interactive + text: qsTr("Interactive") + visible: ["android", "ios"].indexOf(Qt.platform.os) < 0 + } } } + } } diff --git a/nymea-app/ui/mainviews/dashboard/DashboardWebViewDelegate.qml b/nymea-app/ui/mainviews/dashboard/DashboardWebViewDelegate.qml index 924b1ae5..fd30d39f 100644 --- a/nymea-app/ui/mainviews/dashboard/DashboardWebViewDelegate.qml +++ b/nymea-app/ui/mainviews/dashboard/DashboardWebViewDelegate.qml @@ -55,9 +55,19 @@ DashboardDelegateBase { Component.onCompleted: { // This might fail if qml-module-qtwebview isn't around - var webView = Qt.createQmlObject(webViewString, webViewContainer); - print("created webView", webView) + try { + var webView = Qt.createQmlObject(webViewString, webViewContainer); + print("created webView", webView) + } catch(e) { + console.warn("Error creating webview") + errorLabel.visible = true + } } + + property bool needsHack: ["android", "ios"].indexOf(Qt.platform.os) >= 0 + property bool webViewVisible: !needsHack || + (!app.mainMenu.visible && !root.editMode && root.topClip < root.height && root.bottomClip < height && !pageStack.busy) + property string webViewString: ' import QtQuick 2.8; @@ -67,18 +77,29 @@ DashboardDelegateBase { WebView { id: webView anchors.fill: parent -anchors.bottomMargin: root.bottomClip + Style.smallMargins -anchors.topMargin: root.topClip + Style.smallMargins - anchors.margins: Style.smallMargins + anchors.bottomMargin: root.bottomClip + Style.smallMargins + anchors.topMargin: root.topClip + Style.smallMargins url: root.item.url enabled: root.item.interactive - visible: !app.mainMenu.visible && !root.editMode && root.topClip < root.height && root.bottomClip < height + visible: delegateRoot.webViewVisible } ' Item { id: webViewContainer anchors.fill: parent + anchors.margins: Style.smallMargins + + Label { + id: errorLabel + visible: false + anchors.centerIn: parent + width: parent.width - Style.margins * 2 + horizontalAlignment: Text.AlignHCenter + + text: qsTr("Web view is not supported on this platform.") + wrapMode: Text.WordWrap + } } Rectangle { @@ -86,6 +107,7 @@ anchors.topMargin: root.topClip + Style.smallMargins anchors.fill: parent anchors.margins: Style.smallMargins radius: Style.cornerRadius + color: Style.tileBackgroundColor } OpacityMask { @@ -98,6 +120,30 @@ anchors.topMargin: root.topClip + Style.smallMargins } maskSource: mask } + + ColumnLayout { + anchors.centerIn: parent + width: delegateRoot.width - Style.margins * 2 + spacing: Style.margins + visible: !parent.webViewVisible + + ColorIcon { + anchors.horizontalCenter: parent.horizontalCenter + size: Style.largeIconSize + name: "stock_website" + color: Style.accentColor + } + + Label { + Layout.fillWidth: true + text: root.item.url + wrapMode: Text.WrapAtWordBoundaryOrAnywhere + font.pixelSize: app.smallFont + horizontalAlignment: Text.AlignHCenter + maximumLineCount: 5 + elide: Text.ElideRight + } + } } Component {