From 6e3796963c8e707c293705df4854e10130f624c3 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sun, 24 Jan 2016 12:25:03 -0800 Subject: [PATCH] Window swallows more events, preventing them from reaching the applicaiton. --- .../resources/qml/windows/DefaultFrame.qml | 6 --- interface/resources/qml/windows/Frame.qml | 3 ++ .../resources/qml/windows/ModalFrame.qml | 13 ----- interface/resources/qml/windows/Window.qml | 50 +++++++++++++++---- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/interface/resources/qml/windows/DefaultFrame.qml b/interface/resources/qml/windows/DefaultFrame.qml index 1b8404f17b..6e26b858bc 100644 --- a/interface/resources/qml/windows/DefaultFrame.qml +++ b/interface/resources/qml/windows/DefaultFrame.qml @@ -5,11 +5,7 @@ import "../controls" Frame { id: frame - // The frame fills the parent, which should be the size of the content. - // The frame decorations use negative anchor margins to extend beyond - anchors.fill: parent - // FIXME needed? Rectangle { anchors { margins: -iconSize; topMargin: -iconSize * ((window && window.closable) ? 2 : 1); } anchors.fill: parent; @@ -18,8 +14,6 @@ Frame { // Allow dragging of the window MouseArea { - id: dragMouseArea - hoverEnabled: true anchors.fill: parent drag.target: window } diff --git a/interface/resources/qml/windows/Frame.qml b/interface/resources/qml/windows/Frame.qml index 0ada0028e4..d6d006c7f2 100644 --- a/interface/resources/qml/windows/Frame.qml +++ b/interface/resources/qml/windows/Frame.qml @@ -5,6 +5,9 @@ import "../js/Utils.js" as Utils Item { id: frame + // Frames always fill their parents, but their decorations may extend + // beyond the window via negative margin sizes + anchors.fill: parent // Convenience accessor for the window property alias window: frame.parent diff --git a/interface/resources/qml/windows/ModalFrame.qml b/interface/resources/qml/windows/ModalFrame.qml index 2601c3899f..135a27c647 100644 --- a/interface/resources/qml/windows/ModalFrame.qml +++ b/interface/resources/qml/windows/ModalFrame.qml @@ -5,10 +5,6 @@ import "../controls" Frame { id: frame - // The frame fills the parent, which should be the size of the content. - // The frame decorations use negative anchor margins to extend beyond - anchors.fill: parent - property alias window: frame.parent Rectangle { anchors.fill: parent @@ -16,15 +12,6 @@ Frame { visible: window.visible color: "#7f7f7f7f"; radius: 3; - MouseArea { - enabled: window.visible - anchors.fill: parent - acceptedButtons: Qt.AllButtons - onClicked: {} - onDoubleClicked: {} - onPressAndHold: {} - onReleased: {} - } } } diff --git a/interface/resources/qml/windows/Window.qml b/interface/resources/qml/windows/Window.qml index 8fe45f2227..dd0d358ef0 100644 --- a/interface/resources/qml/windows/Window.qml +++ b/interface/resources/qml/windows/Window.qml @@ -20,9 +20,11 @@ Fadable { implicitHeight: content.height implicitWidth: content.width x: -1; y: -1 + enabled: visible + + signal windowDestroyed(); property int modality: Qt.NonModal - readonly property bool topLevelWindow: true property string title // Should the window be closable control? @@ -37,7 +39,6 @@ Fadable { property bool resizable: false property vector2d minSize: Qt.vector2d(100, 100) property vector2d maxSize: Qt.vector2d(1280, 720) - enabled: visible // The content to place inside the window, determined by the client default property var content @@ -53,27 +54,39 @@ Fadable { propagateComposedEvents: true hoverEnabled: true acceptedButtons: Qt.AllButtons + enabled: window.visible onPressed: { //console.log("Pressed on activator area"); window.raise(); mouse.accepted = false; } - // Debugging -// onEntered: console.log("activator entered") -// onExited: console.log("activator exited") -// onContainsMouseChanged: console.log("Activator contains mouse " + containsMouse) -// onPositionChanged: console.log("Activator mouse position " + mouse.x + " x " + mouse.y) -// Rectangle { anchors.fill:parent; color: "#7f00ff00" } } - signal windowDestroyed(); + // This mouse area serves to swallow mouse events while the mouse is over the window + // to prevent things like mouse wheel events from reaching the application and changing + // the camera if the user is scrolling through a list and gets to the end. + property var swallower: MouseArea { + width: frame.decoration.width + height: frame.decoration.height + x: frame.decoration.anchors.margins + y: frame.decoration.anchors.topMargin + hoverEnabled: true + acceptedButtons: Qt.AllButtons + enabled: window.visible + onClicked: {} + onDoubleClicked: {} + onPressAndHold: {} + onReleased: {} + onWheel: {} + } + // 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: DefaultFrame { } - children: [ frame, content, activator ] + children: [ swallower, frame, content, activator ] Component.onCompleted: raise(); Component.onDestruction: windowDestroyed(); @@ -124,12 +137,27 @@ Fadable { Keys.onPressed: { switch(event.key) { + case Qt.Key_Control: + case Qt.Key_Shift: + case Qt.Key_Meta: + case Qt.Key_Alt: + break; + + case Qt.Key_W: if (window.closable && (event.modifiers === Qt.ControlModifier)) { visible = false event.accepted = true } - break + // fall through + + default: + // Consume unmodified keyboard entries while the window is focused, to prevent them + // from propagating to the application + if (event.modifiers === Qt.NoModifier) { + event.accepted = true; + } + break; } } }