From 73604020d7477ed1868135c23e8e40a74a3102d0 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 31 Mar 2019 17:24:25 -0700 Subject: [PATCH] Rewrite dialog code to use Quick Controls 2 --- app/gui/AppView.qml | 6 +-- app/gui/CliQuitStreamSegue.qml | 1 - app/gui/CliStartStreamSegue.qml | 7 +-- app/gui/ErrorMessageDialog.qml | 14 +----- app/gui/NavigableDialog.qml | 26 +++++++++++ app/gui/NavigableMessageDialog.qml | 58 +++++++++++++++++++------ app/gui/PcView.qml | 10 +---- app/gui/QuitSegue.qml | 1 - app/gui/StreamSegue.qml | 1 - app/gui/main.qml | 31 +++++-------- app/main.cpp | 12 ----- app/qml.qrc | 1 + app/res/baseline-error_outline-24px.svg | 1 + app/res/baseline-help_outline-24px.svg | 1 + app/resources.qrc | 2 + 15 files changed, 92 insertions(+), 80 deletions(-) create mode 100644 app/gui/NavigableDialog.qml create mode 100644 app/res/baseline-error_outline-24px.svg create mode 100644 app/res/baseline-help_outline-24px.svg diff --git a/app/gui/AppView.qml b/app/gui/AppView.qml index c590fc29..04f87e92 100644 --- a/app/gui/AppView.qml +++ b/app/gui/AppView.qml @@ -1,5 +1,4 @@ import QtQuick 2.9 -import QtQuick.Dialogs 1.2 import QtQuick.Controls 2.2 import AppModel 1.0 @@ -221,7 +220,7 @@ GridView { property string nextAppName: "" property int nextAppIndex: 0 text:"Are you sure you want to quit " + appName +"? Any unsaved progress will be lost." - standardButtons: StandardButton.Yes | StandardButton.No + standardButtons: Dialog.Yes | Dialog.No function quitApp() { var component = Qt.createComponent("QuitSegue.qml") @@ -243,9 +242,6 @@ GridView { appModel.quitRunningApp() } - onYes: quitApp() - - // For keyboard/gamepad navigation onAccepted: quitApp() } diff --git a/app/gui/CliQuitStreamSegue.qml b/app/gui/CliQuitStreamSegue.qml index 54f4de41..f5b36f26 100644 --- a/app/gui/CliQuitStreamSegue.qml +++ b/app/gui/CliQuitStreamSegue.qml @@ -1,6 +1,5 @@ import QtQuick 2.0 import QtQuick.Controls 2.2 -import QtQuick.Dialogs 1.2 import ComputerManager 1.0 import Session 1.0 diff --git a/app/gui/CliStartStreamSegue.qml b/app/gui/CliStartStreamSegue.qml index 4b3beddc..54d8bf0f 100644 --- a/app/gui/CliStartStreamSegue.qml +++ b/app/gui/CliStartStreamSegue.qml @@ -1,7 +1,6 @@ import QtQml 2.2 import QtQuick 2.0 import QtQuick.Controls 2.2 -import QtQuick.Dialogs 1.2 import ComputerManager 1.0 @@ -76,9 +75,8 @@ Item { NavigableMessageDialog { id: quitAppDialog - modality:Qt.WindowModal text:"Are you sure you want to quit " + appName +"? Any unsaved progress will be lost." - standardButtons: StandardButton.Yes | StandardButton.No + standardButtons: Dialog.Yes | Dialog.No property string appName : "" function quitApp() { @@ -89,9 +87,6 @@ Item { launcher.quitRunningApp() } - onYes: quitApp() - - // For keyboard/gamepad navigation onAccepted: quitApp() // Exit process if app quit is rejected (reacts also to closing of the diff --git a/app/gui/ErrorMessageDialog.qml b/app/gui/ErrorMessageDialog.qml index d0ffba89..49392afc 100644 --- a/app/gui/ErrorMessageDialog.qml +++ b/app/gui/ErrorMessageDialog.qml @@ -1,18 +1,8 @@ import QtQuick 2.0 -import QtQuick.Dialogs 1.2 +import QtQuick.Controls 2.2 import SystemProperties 1.0 NavigableMessageDialog { - property string helpText - property string helpUrl : "https://github.com/moonlight-stream/moonlight-docs/wiki/Troubleshooting" - - informativeText: SystemProperties.hasBrowser ? helpText : "" - icon: StandardIcon.Critical - standardButtons: StandardButton.Ok | - (SystemProperties.hasBrowser ? StandardButton.Help : 0) - - onHelp: { - Qt.openUrlExternally(helpUrl) - } + standardButtons: Dialog.Ok | (SystemProperties.hasBrowser ? Dialog.Help : 0) } diff --git a/app/gui/NavigableDialog.qml b/app/gui/NavigableDialog.qml new file mode 100644 index 00000000..bbfe4c6a --- /dev/null +++ b/app/gui/NavigableDialog.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 +import QtQuick.Controls 2.2 + +Dialog { + property Item originalFocusItem + + x: Math.round((window.width - width) / 2) + y: Math.round((window.height - height) / 2) + + onAboutToShow: { + originalFocusItem = window.activeFocusItem + } + + onOpened: { + // Force focus on the dialog to ensure keyboard navigation works + forceActiveFocus() + } + + onClosed: { + // We must force focus back to the last item for platforms without + // support for more than one active window like Steam Link. If + // we don't, gamepad and keyboard navigation will break after a + // dialog appears. + originalFocusItem.forceActiveFocus() + } +} diff --git a/app/gui/NavigableMessageDialog.qml b/app/gui/NavigableMessageDialog.qml index a4677556..9c2773d3 100644 --- a/app/gui/NavigableMessageDialog.qml +++ b/app/gui/NavigableMessageDialog.qml @@ -1,21 +1,53 @@ import QtQuick 2.0 -import QtQuick.Dialogs 1.2 +import QtQuick.Controls 2.2 -MessageDialog { - property Item originalFocusItem +import SystemProperties 1.0 - onVisibleChanged: { - if (!isWindow) { - if (visible) { - originalFocusItem = window.activeFocusItem +NavigableDialog { + id: dialog + + property alias text: dialogTextControl.dialogText + + property string helpText + property string helpUrl : "https://github.com/moonlight-stream/moonlight-docs/wiki/Troubleshooting" + + Row { + spacing: 10 + + Image { + source: (standardButtons & Dialog.Yes) ? + "qrc:/res/baseline-help_outline-24px.svg" : + "qrc:/res/baseline-error_outline-24px.svg" + sourceSize { + // The icon should be square so use the height as the width too + width: 50 + height: 50 } - else { - // We must force focus back to the last item for platforms without - // support for more than one active window like Steam Link. If - // we don't, gamepad and keyboard navigation will break after a - // dialog appears. - originalFocusItem.forceActiveFocus() + } + + Label { + property string dialogText + + id: dialogTextControl + text: dialogText + (SystemProperties.hasBrowser ? (" " + helpText) : "") + wrapMode: Text.WordWrap + focus: true + + anchors.verticalCenter: parent.verticalCenter + + Keys.onReturnPressed: { + accept() } } } + + footer: DialogButtonBox { + id: dialogButtonBox + standardButtons: dialog.standardButtons + + onHelpRequested: { + Qt.openUrlExternally(helpUrl) + close() + } + } } diff --git a/app/gui/PcView.qml b/app/gui/PcView.qml index 737d3a73..146289d4 100644 --- a/app/gui/PcView.qml +++ b/app/gui/PcView.qml @@ -1,6 +1,5 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 -import QtQuick.Dialogs 1.2 import QtQuick.Layouts 1.3 import QtQuick.Window 2.2 @@ -240,10 +239,9 @@ GridView { NavigableMessageDialog { id: pairDialog // don't allow edits to the rest of the window while open - modality:Qt.WindowModal property string pin : "0000" text:"Please enter " + pin + " on your GameStream PC. This dialog will close when pairing is completed." - standardButtons: StandardButton.Cancel + standardButtons: Dialog.Cancel onRejected: { // FIXME: We should interrupt pairing here } @@ -252,19 +250,15 @@ GridView { NavigableMessageDialog { id: deletePcDialog // don't allow edits to the rest of the window while open - modality:Qt.WindowModal property int pcIndex : -1; text:"Are you sure you want to remove this PC?" - standardButtons: StandardButton.Yes | StandardButton.No + standardButtons: Dialog.Yes | Dialog.No function deletePc() { console.log("deleting PC pairing for PC at index: " + pcIndex) computerModel.deleteComputer(pcIndex); } - onYes: deletePc() - - // For keyboard/gamepad activation onAccepted: deletePc() } diff --git a/app/gui/QuitSegue.qml b/app/gui/QuitSegue.qml index 536f9d3a..068a5760 100644 --- a/app/gui/QuitSegue.qml +++ b/app/gui/QuitSegue.qml @@ -1,6 +1,5 @@ import QtQuick 2.0 import QtQuick.Controls 2.2 -import QtQuick.Dialogs 1.2 import ComputerManager 1.0 import Session 1.0 diff --git a/app/gui/StreamSegue.qml b/app/gui/StreamSegue.qml index e45373bf..6350290a 100644 --- a/app/gui/StreamSegue.qml +++ b/app/gui/StreamSegue.qml @@ -1,6 +1,5 @@ import QtQuick 2.0 import QtQuick.Controls 2.2 -import QtQuick.Dialogs 1.2 import QtQuick.Window 2.2 import ComputerManager 1.0 diff --git a/app/gui/main.qml b/app/gui/main.qml index a503f2f1..6869b6c9 100644 --- a/app/gui/main.qml +++ b/app/gui/main.qml @@ -1,6 +1,5 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 -import QtQuick.Dialogs 1.2 import QtQuick.Layouts 1.3 import QtQuick.Window 2.2 @@ -379,7 +378,6 @@ ApplicationWindow { ErrorMessageDialog { id: noHwDecoderDialog - icon: StandardIcon.Warning text: "No functioning hardware accelerated H.264 video decoder was detected by Moonlight. " + "Your streaming performance may be severely degraded in this configuration." helpText: "Click the Help button for more information on solving this problem." @@ -388,7 +386,6 @@ ApplicationWindow { ErrorMessageDialog { id: waylandDialog - icon: StandardIcon.Warning text: "Moonlight does not support hardware acceleration on Wayland. Continuing on Wayland may result in poor streaming performance. " + "Please switch to an X session for optimal performance." helpText: "Click the Help button for more information." @@ -397,8 +394,7 @@ ApplicationWindow { NavigableMessageDialog { id: wow64Dialog - icon: StandardIcon.Warning - standardButtons: StandardButton.Ok | StandardButton.Cancel + standardButtons: Dialog.Ok | Dialog.Cancel text: "This PC is running a 64-bit version of Windows. Please download the x64 version of Moonlight for the best streaming performance." onAccepted: { Qt.openUrlExternally("https://github.com/moonlight-stream/moonlight-qt/releases"); @@ -408,7 +404,6 @@ ApplicationWindow { ErrorMessageDialog { id: unmappedGamepadDialog property string unmappedGamepads : "" - icon: StandardIcon.Warning text: "Moonlight detected gamepads without a mapping:\n" + unmappedGamepads helpText: "Click the Help button for information on how to map your gamepads." helpUrl: "https://github.com/moonlight-stream/moonlight-docs/wiki/Gamepad-Mapping" @@ -417,21 +412,17 @@ ApplicationWindow { // This dialog appears when quitting via keyboard or gamepad button NavigableMessageDialog { id: quitConfirmationDialog - icon: StandardIcon.Warning - standardButtons: StandardButton.Yes | StandardButton.No + standardButtons: Dialog.Yes | Dialog.No text: "Are you sure you want to quit?" - - onYes: Qt.quit() - // For keyboard/gamepad navigation onAccepted: Qt.quit() } - Dialog { + NavigableDialog { id: addPcDialog property string label: "Enter the IP address of your GameStream PC:" - standardButtons: StandardButton.Ok | StandardButton.Cancel + standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { if (editText.text) { @@ -439,22 +430,20 @@ ApplicationWindow { } } - onVisibleChanged: { - if (visible) { - editText.forceActiveFocus() - } - } - ColumnLayout { - Text { + Label { text: addPcDialog.label font.bold: true } TextField { id: editText - color: "black" Layout.fillWidth: true + focus: true + + Keys.onReturnPressed: { + addPcDialog.accept() + } } } } diff --git a/app/main.cpp b/app/main.cpp index 9b1ea921..6cebfe3c 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -342,18 +342,6 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); - // Override the default palette to fix dialog rendering on Linux - // with QGnomePlatform loaded. Using setDesktopSettingsAware(false) - // also works but can cause crashes in some configurations. - // - // See the following issues: - // https://github.com/moonlight-stream/moonlight-qt/issues/161 - // https://github.com/moonlight-stream/moonlight-qt/issues/185 - // https://github.com/FedoraQt/QGnomePlatform/issues/42 -#ifdef Q_OS_LINUX - app.setPalette(QPalette(Qt::lightGray)); -#endif - #ifdef STEAM_LINK // Qt 5.9 from the Steam Link SDK is not able to load any fonts // since the Steam Link doesn't include any of the ones it looks diff --git a/app/qml.qrc b/app/qml.qrc index e9f03992..e842cfd7 100644 --- a/app/qml.qrc +++ b/app/qml.qrc @@ -16,5 +16,6 @@ gui/NavigableMenu.qml gui/ErrorMessageDialog.qml gui/NavigableMessageDialog.qml + gui/NavigableDialog.qml diff --git a/app/res/baseline-error_outline-24px.svg b/app/res/baseline-error_outline-24px.svg new file mode 100644 index 00000000..558d7054 --- /dev/null +++ b/app/res/baseline-error_outline-24px.svg @@ -0,0 +1 @@ + diff --git a/app/res/baseline-help_outline-24px.svg b/app/res/baseline-help_outline-24px.svg new file mode 100644 index 00000000..15490459 --- /dev/null +++ b/app/res/baseline-help_outline-24px.svg @@ -0,0 +1 @@ + diff --git a/app/resources.qrc b/app/resources.qrc index 31c1cfae..252a8176 100644 --- a/app/resources.qrc +++ b/app/resources.qrc @@ -15,6 +15,8 @@ res/question_mark.svg res/moonlight.svg res/update.svg + res/baseline-help_outline-24px.svg + res/baseline-error_outline-24px.svg SDL_GameControllerDB/gamecontrollerdb.txt