Rewrite dialog code to use Quick Controls 2

This commit is contained in:
Cameron Gutman 2019-03-31 17:24:25 -07:00
parent 060a00b9c7
commit 73604020d7
15 changed files with 92 additions and 80 deletions

View file

@ -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()
}

View file

@ -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

View file

@ -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

View file

@ -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)
}

View file

@ -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()
}
}

View file

@ -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()
}
}
}

View file

@ -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()
}

View file

@ -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

View file

@ -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

View file

@ -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()
}
}
}
}

View file

@ -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

View file

@ -16,5 +16,6 @@
<file>gui/NavigableMenu.qml</file>
<file>gui/ErrorMessageDialog.qml</file>
<file>gui/NavigableMessageDialog.qml</file>
<file>gui/NavigableDialog.qml</file>
</qresource>
</RCC>

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="#FFFFFF"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"/></svg>

After

Width:  |  Height:  |  Size: 323 B

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="#FFFFFF"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 18h2v-2h-2v2zm1-16C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm0-14c-2.21 0-4 1.79-4 4h2c0-1.1.9-2 2-2s2 .9 2 2c0 2-3 1.75-3 5h2c0-2.25 3-2.5 3-5 0-2.21-1.79-4-4-4z"/></svg>

After

Width:  |  Height:  |  Size: 397 B

View file

@ -15,6 +15,8 @@
<file>res/question_mark.svg</file>
<file>res/moonlight.svg</file>
<file>res/update.svg</file>
<file>res/baseline-help_outline-24px.svg</file>
<file>res/baseline-error_outline-24px.svg</file>
</qresource>
<qresource prefix="/data">
<file alias="gamecontrollerdb.txt">SDL_GameControllerDB/gamecontrollerdb.txt</file>