From 3d46eda165f009d05196e2f0589cefcd4822ca75 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 21 Jan 2016 13:47:23 -0800 Subject: [PATCH 1/2] Frame construction in onCompleted was messing up the browser keyboard focus --- .../resources/qml/dialogs/FileDialog.qml | 7 ++---- .../resources/qml/dialogs/MessageDialog.qml | 7 +----- .../resources/qml/windows/ModalFrame.qml | 3 ++- .../resources/qml/windows/ModalWindow.qml | 12 ++++++++++ interface/resources/qml/windows/Window.qml | 23 ++---------------- tests/ui/qml/main.qml | 24 ------------------- tests/ui/qmlscratch.pro | 3 ++- 7 files changed, 21 insertions(+), 58 deletions(-) create mode 100644 interface/resources/qml/windows/ModalWindow.qml diff --git a/interface/resources/qml/dialogs/FileDialog.qml b/interface/resources/qml/dialogs/FileDialog.qml index fcaf994b1b..4c02c94f03 100644 --- a/interface/resources/qml/dialogs/FileDialog.qml +++ b/interface/resources/qml/dialogs/FileDialog.qml @@ -8,23 +8,20 @@ import "../windows" import "../styles" // Work in progress.... -Window { +ModalWindow { id: root HifiConstants { id: hifi } signal selectedFile(var file); signal canceled(); - - anchors.centerIn: parent resizable: true width: 640 height: 480 - modality: Qt.ApplicationModal + property string settingsName: "" property alias folder: folderModel.folder property alias filterModel: selectionType.model - Rectangle { anchors.fill: parent color: "white" diff --git a/interface/resources/qml/dialogs/MessageDialog.qml b/interface/resources/qml/dialogs/MessageDialog.qml index 6f96340be6..5b9a653f2e 100644 --- a/interface/resources/qml/dialogs/MessageDialog.qml +++ b/interface/resources/qml/dialogs/MessageDialog.qml @@ -7,19 +7,14 @@ import "../styles" import "../windows" // FIXME respect default button functionality -// FIXME force active focus at all times (modal dialog) -Window { +ModalWindow { id: root HifiConstants { id: hifi } - implicitWidth: 640 implicitHeight: 320 destroyOnCloseButton: true destroyOnInvisible: true visible: true - modality: Qt.ApplicationModal - anchors.centerIn: parent - frame: ModalFrame {} signal selected(int button); diff --git a/interface/resources/qml/windows/ModalFrame.qml b/interface/resources/qml/windows/ModalFrame.qml index e0e9049828..2601c3899f 100644 --- a/interface/resources/qml/windows/ModalFrame.qml +++ b/interface/resources/qml/windows/ModalFrame.qml @@ -17,9 +17,10 @@ Frame { color: "#7f7f7f7f"; radius: 3; MouseArea { + enabled: window.visible anchors.fill: parent acceptedButtons: Qt.AllButtons - onClicked: { } + onClicked: {} onDoubleClicked: {} onPressAndHold: {} onReleased: {} diff --git a/interface/resources/qml/windows/ModalWindow.qml b/interface/resources/qml/windows/ModalWindow.qml new file mode 100644 index 0000000000..eb45273ff4 --- /dev/null +++ b/interface/resources/qml/windows/ModalWindow.qml @@ -0,0 +1,12 @@ +import QtQuick 2.5 + +import "." + +Window { + id: root + anchors.centerIn: parent + modality: Qt.ApplicationModal + frame: ModalFrame{} +} + + diff --git a/interface/resources/qml/windows/Window.qml b/interface/resources/qml/windows/Window.qml index 25bb87deab..21bd8f3dec 100644 --- a/interface/resources/qml/windows/Window.qml +++ b/interface/resources/qml/windows/Window.qml @@ -69,28 +69,9 @@ Fadable { // Default to a standard frame. Can be overriden to provide custom // frame styles, like a full desktop frame to simulate a modal window - property var frame; + property var frame: DefaultFrame { } - Component { - id: defaultFrameBuilder; - DefaultFrame { anchors.fill: parent } - } - - Component { - id: modalFrameBuilder; - ModalFrame { anchors.fill: parent } - } - - Component.onCompleted: { - if (!frame) { - if (modality === Qt.NonModal) { - frame = defaultFrameBuilder.createObject(window); - } else { - frame = modalFrameBuilder.createObject(window); - } - } - raise(); - } + Component.onCompleted: raise(); children: [ frame, content, activator ] diff --git a/tests/ui/qml/main.qml b/tests/ui/qml/main.qml index ae9d93e0a6..9bc919437f 100644 --- a/tests/ui/qml/main.qml +++ b/tests/ui/qml/main.qml @@ -132,11 +132,6 @@ ApplicationWindow { console.log(appWindow.activeFocusItem); } } - Button { - text: "Preferences" - property var preferencesComponent: Component { PreferencesDialog { } } - onClicked: preferencesComponent.createObject(desktop); - } } Window { @@ -194,25 +189,6 @@ ApplicationWindow { color: "yellow" } } - - MouseArea { - anchors.fill: parent - acceptedButtons: Qt.RightButton - - Component { - id: menuBuilder - VrMenuView { } - } - - onClicked: { - console.log("zzz") - var menuItems = menuItemsToModel(stubMenu); - var newMenu = menuBuilder.createObject(desktop, { source: stubMenu, items: menuItems }); - newMenu.x = mouseX - newMenu.y = mouseY - } - - } } /* diff --git a/tests/ui/qmlscratch.pro b/tests/ui/qmlscratch.pro index 34eca04c32..97f2b9b6f7 100644 --- a/tests/ui/qmlscratch.pro +++ b/tests/ui/qmlscratch.pro @@ -85,5 +85,6 @@ DISTFILES += \ ../../interface/resources/qml/hifi/Desktop.qml \ ../../interface/resources/qml/menus/MenuMouseHandler.qml \ ../../interface/resources/qml/menus/VrMenuItem.qml \ - ../../interface/resources/qml/menus/VrMenuView.qml + ../../interface/resources/qml/menus/VrMenuView.qml \ + ../../interface/resources/qml/windows/ModalWindow.qml From f343598d9171aa745f1772b3ef9cc03fb1151e11 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 21 Jan 2016 15:09:36 -0800 Subject: [PATCH 2/2] Focus hack for menu fix --- interface/resources/qml/desktop/Desktop.qml | 18 ++++++++----- interface/resources/qml/desktop/FocusHack.qml | 26 +++++++++++++++++++ tests/ui/qmlscratch.pro | 3 ++- 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 interface/resources/qml/desktop/FocusHack.qml diff --git a/interface/resources/qml/desktop/Desktop.qml b/interface/resources/qml/desktop/Desktop.qml index ee3277e4c4..1996834378 100644 --- a/interface/resources/qml/desktop/Desktop.qml +++ b/interface/resources/qml/desktop/Desktop.qml @@ -16,12 +16,7 @@ FocusScope { property bool desktopRoot: true // The VR version of the primary menu - property var rootMenu: Menu { - id: rootMenu; objectName: "rootMenu" - Component.onCompleted: { - console.log("ROOT_MENU " + rootMenu); - } - } + property var rootMenu: Menu { objectName: "rootMenu" } QtObject { id: d @@ -210,7 +205,13 @@ FocusScope { // Debugging help for figuring out focus issues property var offscreenWindow; - onOffscreenWindowChanged: offscreenWindow.activeFocusItemChanged.connect(onWindowFocusChanged); + onOffscreenWindowChanged: { + offscreenWindow.activeFocusItemChanged.connect(onWindowFocusChanged); + focusHack.start(); + } + + FocusHack { id: focusHack; } + function onWindowFocusChanged() { console.log("Focus item is " + offscreenWindow.activeFocusItem); var focusedItem = offscreenWindow.activeFocusItem ; @@ -223,11 +224,14 @@ FocusScope { focusDebugger.height = rect.height } } + Rectangle { id: focusDebugger; z: 9999; visible: false; color: "red" ColorAnimation on color { from: "#7fffff00"; to: "#7f0000ff"; duration: 1000; loops: 9999 } } + + } diff --git a/interface/resources/qml/desktop/FocusHack.qml b/interface/resources/qml/desktop/FocusHack.qml new file mode 100644 index 0000000000..7514705983 --- /dev/null +++ b/interface/resources/qml/desktop/FocusHack.qml @@ -0,0 +1,26 @@ +import QtQuick 2.5 + +FocusScope { + id: root + + TextInput { + id: textInput; + focus: true + width: 10; height: 10 + onActiveFocusChanged: root.destroy() + } + + Timer { + id: focusTimer + running: false + interval: 100 + onTriggered: textInput.forceActiveFocus() + } + + function start() { + focusTimer.running = true; + } +} + + + diff --git a/tests/ui/qmlscratch.pro b/tests/ui/qmlscratch.pro index 97f2b9b6f7..f6859b743a 100644 --- a/tests/ui/qmlscratch.pro +++ b/tests/ui/qmlscratch.pro @@ -86,5 +86,6 @@ DISTFILES += \ ../../interface/resources/qml/menus/MenuMouseHandler.qml \ ../../interface/resources/qml/menus/VrMenuItem.qml \ ../../interface/resources/qml/menus/VrMenuView.qml \ - ../../interface/resources/qml/windows/ModalWindow.qml + ../../interface/resources/qml/windows/ModalWindow.qml \ + ../../interface/resources/qml/desktop/FocusHack.qml