Skip to content

Commit

Permalink
Introduce catch all mouse area
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
trin94 committed Feb 4, 2024
1 parent 6b59e3b commit bb02c60
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 1 deletion.
15 changes: 14 additions & 1 deletion qml/app/MpvqcApplication.qml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ ApplicationWindow {
mpvqcApplication: root
focus: true
anchors.fill: parent
anchors.margins: root.windowBorder // root.windowBorder
anchors.margins: root.windowBorder

onSplitViewHandleHovered: (hovered) => _catchAllMouseArea.splitViewHandleHovered(hovered)
}
}

Expand Down Expand Up @@ -109,6 +111,17 @@ ApplicationWindow {
}
}

MpvqcCatchAllMouseArea {
id: _catchAllMouseArea

mpvqcApplication: root
anchors.fill: parent

onAfterPressed: {
mpvqcCommentTable.forceActiveFocus()
}
}

MpvqcQuitHandler {
id: closeHandler

Expand Down
49 changes: 49 additions & 0 deletions qml/app/MpvqcCatchAllMouseArea.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
mpvQC
Copyright (C) 2022 mpvQC developers
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick


MouseArea {
id: root

required property var mpvqcApplication

readonly property var mpvqcSettings: mpvqcApplication.mpvqcSettings

propagateComposedEvents: true

signal afterPressed()

function splitViewHandleHovered(state: bool): void {
if (!state) {
cursorShape = Qt.ArrowCursor
} else if (mpvqcSettings.layoutOrientation === Qt.Vertical) {
cursorShape = Qt.SizeVerCursor
} else {
cursorShape = Qt.SizeHorCursor
}
}

onPressed: (event) => {
event.accepted = false
root.afterPressed()
}

}
4 changes: 4 additions & 0 deletions qml/app/MpvqcContent.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ FocusScope {

readonly property alias mpvqcCommentTable: _contentSplitView.mpvqcCommentTable

signal splitViewHandleHovered(bool hovered)

MpvqcResizeToOriginalResolutionHandler {
id: _videoResizer

Expand Down Expand Up @@ -60,6 +62,8 @@ FocusScope {
focus: true
anchors.fill: _page.contentItem

onSplitViewHandleHovered: (hovered) => root.splitViewHandleHovered(hovered)

MpvqcDragAndDropHandler {
anchors.fill: parent
supportedSubtitleFileExtensions: root.supportedSubtitleFileExtensions
Expand Down
8 changes: 8 additions & 0 deletions qml/app/MpvqcContentSplitView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ FocusScope {
readonly property int draggerWidth: _splitView.width - _playerContainer.width - tableContainerWidth
readonly property int orientation: _splitView.orientation

signal splitViewHandleHovered(bool hovered)

states: [
State { name: "fullscreen"; ParentChange { target: _player; parent: root } },
State { name: "normal"; ParentChange { target: _player; parent: _playerContainer } }
Expand All @@ -65,6 +67,12 @@ FocusScope {
anchors.fill: root
orientation: root.mpvqcSettings.layoutOrientation

handle: MpvqcSplitViewHandle {
control: _splitView

onHoveredChanged: root.splitViewHandleHovered(hovered)
}

Item {
id: _playerContainer

Expand Down
51 changes: 51 additions & 0 deletions qml/app/MpvqcSplitViewHandle.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

// Adapted from qtdeclarative/qml/QtQuick/Controls/Material/SplitView.qml
// SplitHandles should be purely visual but we need to detect when the mouse hovers the handle

import QtQuick
import QtQuick.Templates as T
import QtQuick.Controls.impl
import QtQuick.Controls.Material

Rectangle {
id: root

required property var control

implicitWidth: control.orientation === Qt.Horizontal ? 6 : control.width
implicitHeight: control.orientation === Qt.Horizontal ? control.height : 6
color: T.SplitHandle.pressed ? control.Material.background
: Qt.lighter(control.Material.background, T.SplitHandle.hovered ? 1.2 : 1.1)

Rectangle {
color: control.Material.secondaryTextColor
width: control.orientation === Qt.Horizontal ? thickness : length
height: control.orientation === Qt.Horizontal ? length : thickness
radius: thickness
x: (parent.width - width) / 2
y: (parent.height - height) / 2

property int length: parent.T.SplitHandle.pressed ? 3 : 8
readonly property int thickness: parent.T.SplitHandle.pressed ? 3 : 1

Behavior on length {
NumberAnimation {
duration: 100
}
}

// Begin: Listen to hover changes
property var hoveredd: parent.T.SplitHandle.hovered

onHovereddChanged: {
root.hovered = hoveredd
}
// End: Listen to hover changes
}

// Begin: Listen to hover changes
property var hovered: false
// End: Listen to hover changes
}

0 comments on commit bb02c60

Please sign in to comment.