Skip to content

Commit bb02c60

Browse files
committed
Introduce catch all mouse area
To be able to handle clicks outside the search box, we now have a catch-all mouse area. This area does not accept any events but always focuses the comment table. It also overrides all mouse cursors in the main view. The split view drag handle is the only other area where the user expects a different mouse handle. Since listening to the hovered state change is not officially supported, we introduce a workaround that emits a signal whenever the mouse enters or leaves a split view drag handle.
1 parent 6b59e3b commit bb02c60

File tree

5 files changed

+126
-1
lines changed

5 files changed

+126
-1
lines changed

qml/app/MpvqcApplication.qml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ ApplicationWindow {
8181
mpvqcApplication: root
8282
focus: true
8383
anchors.fill: parent
84-
anchors.margins: root.windowBorder // root.windowBorder
84+
anchors.margins: root.windowBorder
85+
86+
onSplitViewHandleHovered: (hovered) => _catchAllMouseArea.splitViewHandleHovered(hovered)
8587
}
8688
}
8789

@@ -109,6 +111,17 @@ ApplicationWindow {
109111
}
110112
}
111113

114+
MpvqcCatchAllMouseArea {
115+
id: _catchAllMouseArea
116+
117+
mpvqcApplication: root
118+
anchors.fill: parent
119+
120+
onAfterPressed: {
121+
mpvqcCommentTable.forceActiveFocus()
122+
}
123+
}
124+
112125
MpvqcQuitHandler {
113126
id: closeHandler
114127

qml/app/MpvqcCatchAllMouseArea.qml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
mpvQC
3+
4+
Copyright (C) 2022 mpvQC developers
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
import QtQuick
21+
22+
23+
MouseArea {
24+
id: root
25+
26+
required property var mpvqcApplication
27+
28+
readonly property var mpvqcSettings: mpvqcApplication.mpvqcSettings
29+
30+
propagateComposedEvents: true
31+
32+
signal afterPressed()
33+
34+
function splitViewHandleHovered(state: bool): void {
35+
if (!state) {
36+
cursorShape = Qt.ArrowCursor
37+
} else if (mpvqcSettings.layoutOrientation === Qt.Vertical) {
38+
cursorShape = Qt.SizeVerCursor
39+
} else {
40+
cursorShape = Qt.SizeHorCursor
41+
}
42+
}
43+
44+
onPressed: (event) => {
45+
event.accepted = false
46+
root.afterPressed()
47+
}
48+
49+
}

qml/app/MpvqcContent.qml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ FocusScope {
3333

3434
readonly property alias mpvqcCommentTable: _contentSplitView.mpvqcCommentTable
3535

36+
signal splitViewHandleHovered(bool hovered)
37+
3638
MpvqcResizeToOriginalResolutionHandler {
3739
id: _videoResizer
3840

@@ -60,6 +62,8 @@ FocusScope {
6062
focus: true
6163
anchors.fill: _page.contentItem
6264

65+
onSplitViewHandleHovered: (hovered) => root.splitViewHandleHovered(hovered)
66+
6367
MpvqcDragAndDropHandler {
6468
anchors.fill: parent
6569
supportedSubtitleFileExtensions: root.supportedSubtitleFileExtensions

qml/app/MpvqcContentSplitView.qml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ FocusScope {
4242
readonly property int draggerWidth: _splitView.width - _playerContainer.width - tableContainerWidth
4343
readonly property int orientation: _splitView.orientation
4444

45+
signal splitViewHandleHovered(bool hovered)
46+
4547
states: [
4648
State { name: "fullscreen"; ParentChange { target: _player; parent: root } },
4749
State { name: "normal"; ParentChange { target: _player; parent: _playerContainer } }
@@ -65,6 +67,12 @@ FocusScope {
6567
anchors.fill: root
6668
orientation: root.mpvqcSettings.layoutOrientation
6769

70+
handle: MpvqcSplitViewHandle {
71+
control: _splitView
72+
73+
onHoveredChanged: root.splitViewHandleHovered(hovered)
74+
}
75+
6876
Item {
6977
id: _playerContainer
7078

qml/app/MpvqcSplitViewHandle.qml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (C) 2018 The Qt Company Ltd.
2+
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3+
4+
// Adapted from qtdeclarative/qml/QtQuick/Controls/Material/SplitView.qml
5+
// SplitHandles should be purely visual but we need to detect when the mouse hovers the handle
6+
7+
import QtQuick
8+
import QtQuick.Templates as T
9+
import QtQuick.Controls.impl
10+
import QtQuick.Controls.Material
11+
12+
Rectangle {
13+
id: root
14+
15+
required property var control
16+
17+
implicitWidth: control.orientation === Qt.Horizontal ? 6 : control.width
18+
implicitHeight: control.orientation === Qt.Horizontal ? control.height : 6
19+
color: T.SplitHandle.pressed ? control.Material.background
20+
: Qt.lighter(control.Material.background, T.SplitHandle.hovered ? 1.2 : 1.1)
21+
22+
Rectangle {
23+
color: control.Material.secondaryTextColor
24+
width: control.orientation === Qt.Horizontal ? thickness : length
25+
height: control.orientation === Qt.Horizontal ? length : thickness
26+
radius: thickness
27+
x: (parent.width - width) / 2
28+
y: (parent.height - height) / 2
29+
30+
property int length: parent.T.SplitHandle.pressed ? 3 : 8
31+
readonly property int thickness: parent.T.SplitHandle.pressed ? 3 : 1
32+
33+
Behavior on length {
34+
NumberAnimation {
35+
duration: 100
36+
}
37+
}
38+
39+
// Begin: Listen to hover changes
40+
property var hoveredd: parent.T.SplitHandle.hovered
41+
42+
onHovereddChanged: {
43+
root.hovered = hoveredd
44+
}
45+
// End: Listen to hover changes
46+
}
47+
48+
// Begin: Listen to hover changes
49+
property var hovered: false
50+
// End: Listen to hover changes
51+
}

0 commit comments

Comments
 (0)