From f0495d7713dc4aba1a6ab0692f45ca1478e90612 Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Mon, 27 Dec 2021 11:58:03 +0100 Subject: [PATCH] Add custom window navigation drawing --- ScreenPlay/app.h | 2 + ScreenPlay/main.qml | 307 +++++++++++++++-------- ScreenPlay/qml/Navigation/Navigation.qml | 24 +- 3 files changed, 221 insertions(+), 112 deletions(-) diff --git a/ScreenPlay/app.h b/ScreenPlay/app.h index 1fd86d1d..876d93ee 100644 --- a/ScreenPlay/app.h +++ b/ScreenPlay/app.h @@ -117,6 +117,8 @@ public slots: QString version() const; void exit(); + QPointF cursorPos() { return QCursor::pos(); } + void setGlobalVariables(GlobalVariables* globalVariables) { if (m_globalVariables.get() == globalVariables) diff --git a/ScreenPlay/main.qml b/ScreenPlay/main.qml index 5c3473e2..98c44b95 100644 --- a/ScreenPlay/main.qml +++ b/ScreenPlay/main.qml @@ -55,6 +55,8 @@ ApplicationWindow { title: "ScreenPlay Alpha - " + ScreenPlay.version() minimumHeight: 450 minimumWidth: 1050 + flags: Qt.FramelessWindowHint |Qt.Window + // Partial workaround for // https://bugreports.qt.io/browse/QTBUG-86047 Material.accent: Material.color(Material.Orange) @@ -79,145 +81,228 @@ ApplicationWindow { } - Connections { - function onThemeChanged(theme) { - setTheme(theme); - } + Item { + anchors.fill: parent + anchors.margins: 1 - target: ScreenPlay.settings - } - Connections { - function onRequestNavigation(nav) { - switchPage(nav); - } - target: ScreenPlay.util - } - - Connections { - function onRequestRaise() { - root.show(); - } - - target: ScreenPlay.screenPlayManager - } - - Dialogs.SteamNotAvailable { - id: dialogSteam - } - - Dialogs.MonitorConfiguration { - } - - Dialogs.CriticalError { - window: root - } - - Common.TrayIcon { - window: root - } - - StackView { - id: stackView - objectName: "stackView" - property int duration: 300 - - anchors { - top: nav.bottom - right: parent.right - bottom: parent.bottom - left: parent.left - } - - replaceEnter: Transition { - OpacityAnimator { - from: 0 - to: 1 - duration: stackView.duration - easing.type: Easing.InOutQuart + Connections { + function onThemeChanged(theme) { + setTheme(theme); } - ScaleAnimator { - from: 0.8 - to: 1 - duration: stackView.duration - easing.type: Easing.InOutQuart + target: ScreenPlay.settings + } + + Connections { + function onRequestNavigation(nav) { + switchPage(nav); + } + + target: ScreenPlay.util + } + + Connections { + function onRequestRaise() { + root.show(); + } + + target: ScreenPlay.screenPlayManager + } + + Dialogs.SteamNotAvailable { + id: dialogSteam + } + + Dialogs.MonitorConfiguration { + } + + Dialogs.CriticalError { + window: root + } + + Common.TrayIcon { + window: root + } + + StackView { + id: stackView + objectName: "stackView" + property int duration: 300 + + anchors { + top: nav.bottom + right: parent.right + bottom: parent.bottom + left: parent.left + } + + replaceEnter: Transition { + OpacityAnimator { + from: 0 + to: 1 + duration: stackView.duration + easing.type: Easing.InOutQuart + } + + ScaleAnimator { + from: 0.8 + to: 1 + duration: stackView.duration + easing.type: Easing.InOutQuart + } + + } + + replaceExit: Transition { + OpacityAnimator { + from: 1 + to: 0 + duration: stackView.duration + easing.type: Easing.InOutQuart + } + + ScaleAnimator { + from: 1 + to: 0.8 + duration: stackView.duration + easing.type: Easing.InOutQuart + } + } } - replaceExit: Transition { - OpacityAnimator { - from: 1 - to: 0 - duration: stackView.duration - easing.type: Easing.InOutQuart + Connections { + function onSetSidebarActive(active) { + if (active) + sidebar.state = "active"; + else + sidebar.state = "inactive"; } - ScaleAnimator { - from: 1 - to: 0.8 - duration: stackView.duration - easing.type: Easing.InOutQuart + function onSetNavigationItem(pos) { + if (pos === 0) + nav.onPageChanged("Create"); + else + nav.onPageChanged("Workshop"); + } + + target: stackView.currentItem + ignoreUnknownSignals: true + } + + Installed.Sidebar { + id: sidebar + objectName: "installedSidebar" + navHeight: nav.height + + anchors { + top: parent.top + right: parent.right + bottom: parent.bottom } } - } + Navigation.Navigation { + id: nav + window: root + width:parent.width + anchors { + top: parent.top + right: parent.right + left: parent.left + } + + onChangePage: (name)=> { + monitors.close(); + switchPage(name); + } + - Connections { - function onSetSidebarActive(active) { - if (active) - sidebar.state = "active"; - else - sidebar.state = "inactive"; } - function onSetNavigationItem(pos) { - if (pos === 0) - nav.onPageChanged("Create"); - else - nav.onPageChanged("Workshop"); + Monitors.Monitors { + id: monitors } - target: stackView.currentItem - ignoreUnknownSignals: true - } - Installed.Sidebar { - id: sidebar - objectName: "installedSidebar" - - navHeight: nav.height - - anchors { - top: parent.top - right: parent.right - bottom: parent.bottom - } } - Navigation.Navigation { - id: nav - window: root - - onChangePage: (name)=> { - monitors.close(); - switchPage(name); + Rectangle { + height: 1 + color:"#222" + anchors{ + top:parent.top + right:parent.right + left:parent.left } - - anchors { - top: parent.top - right: parent.right - left: parent.left + } + Rectangle { + height: 1 + color:"#222" + anchors{ + bottom:parent.bottom + right:parent.right + left:parent.left + } + } + Rectangle { + width: 1 + color:"#222" + anchors{ + left:parent.left + bottom:parent.bottom + top:parent.top + } + } + Rectangle { + width: 1 + color:"#222" + anchors{ + right:parent.right + bottom:parent.bottom + top:parent.top } - } - Monitors.Monitors { - id: monitors + Rectangle { + width: 15 + height:width + color:"#555" + anchors{ + right:parent.right + bottom:parent.bottom + margins: 1 + } + MouseArea { + id: maResize + anchors.fill: parent + cursorShape: Qt.SizeFDiagCursor + property point clickPosition + property size originalSize + onPressed: { + maResize.clickPosition = Qt.point(maResize.mouseX, maResize.mouseY); + maResize.clickPosition = maResize.mapToGlobal(maResize.clickPosition.x , maResize.clickPosition.y ) + maResize.originalSize = Qt.size(root.width, root.height) + } + onPositionChanged: { + if (maResize.pressed){ + let newPos = maResize.mapToGlobal(maResize.mouseX, maResize.mouseY) + let newPosX = newPos.x - maResize.clickPosition.x + let newPosY = newPos.y - maResize.clickPosition.y + + root.setGeometry(root.x,root.y, maResize.originalSize.width + newPosX, + maResize.originalSize.height + newPosY) + + } + + + } + } } } diff --git a/ScreenPlay/qml/Navigation/Navigation.qml b/ScreenPlay/qml/Navigation/Navigation.qml index c8e1757c..0bba540c 100644 --- a/ScreenPlay/qml/Navigation/Navigation.qml +++ b/ScreenPlay/qml/Navigation/Navigation.qml @@ -54,7 +54,28 @@ Rectangle { color: Material.theme === Material.Light ? "white" : Material.background layer.enabled: true - MouseHoverBlocker {} + MouseArea { + id: mouseArea + + property var clickPos + + anchors.fill: parent + hoverEnabled: true + onPressed: (mouse)=>{ + clickPos = { + "x": mouse.x, + "y": mouse.y + }; + } + onPositionChanged: { + if (mouseArea.pressed){ + let pos = ScreenPlay.cursorPos(); + window.setX(pos.x - clickPos.x) + window.setY(pos.y - clickPos.y) + } + + } + } Connections { function onRequestNavigationActive(isActive) { @@ -267,6 +288,7 @@ Rectangle { title: qsTr("Are you sure you want to exit ScreenPlay? \nThis will shut down all Wallpaper and Widgets.") standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: Qt.quit() + modal: true }