2021-11-06 13:00:11 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020-2021 Alex Spataru <https://github.com/alex-spataru>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import QtQuick.Window 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
|
|
|
|
import "../Widgets" as Widgets
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: root
|
|
|
|
|
2021-11-09 14:30:59 -06:00
|
|
|
//
|
|
|
|
// Custom signals
|
|
|
|
//
|
|
|
|
signal closed()
|
|
|
|
signal minimized()
|
|
|
|
signal maximized()
|
|
|
|
signal unmaximized()
|
|
|
|
|
2021-11-06 13:00:11 -06:00
|
|
|
//
|
|
|
|
// Window controls
|
|
|
|
//
|
|
|
|
property Window window
|
|
|
|
property bool fullScreen: false
|
|
|
|
property bool closeEnabled: true
|
|
|
|
property bool minimizeEnabled: true
|
|
|
|
property bool maximizeEnabled: true
|
2021-11-09 14:30:59 -06:00
|
|
|
property bool displayIcon: true
|
2021-11-06 13:00:11 -06:00
|
|
|
property bool titlebarBorderEnabled: true
|
|
|
|
property color textColor: palette.text
|
2021-11-09 14:30:59 -06:00
|
|
|
readonly property bool showMacControls: Cpp_IsMac
|
2021-11-06 13:00:11 -06:00
|
|
|
|
|
|
|
//
|
|
|
|
// Toggle maximized
|
|
|
|
//
|
|
|
|
function toggleMaximized() {
|
2021-11-09 14:30:59 -06:00
|
|
|
if (window.visibility === Window.Maximized) {
|
2021-11-06 13:00:11 -06:00
|
|
|
window.showNormal()
|
2021-11-09 14:30:59 -06:00
|
|
|
root.unmaximized()
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2021-11-06 13:00:11 -06:00
|
|
|
window.showMaximized()
|
2021-11-09 14:30:59 -06:00
|
|
|
root.maximized()
|
|
|
|
}
|
2021-11-06 13:00:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Toggle fullscreen state
|
|
|
|
//
|
|
|
|
function toggleFullscreen() {
|
|
|
|
root.fullScreen = !root.fullScreen
|
|
|
|
if (window.fullScreen)
|
|
|
|
window.showFullScreen()
|
|
|
|
else
|
|
|
|
window.showNormal()
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Height calculation
|
|
|
|
//
|
2021-11-09 14:30:59 -06:00
|
|
|
height: !showMacControls ? 38 : 32
|
2021-11-06 13:00:11 -06:00
|
|
|
|
|
|
|
//
|
|
|
|
// Radius compensator rectangle
|
|
|
|
//
|
|
|
|
Rectangle {
|
|
|
|
color: parent.color
|
|
|
|
height: parent.radius
|
|
|
|
anchors {
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
bottom: parent.bottom
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Bottom titlebar border
|
|
|
|
//
|
|
|
|
Rectangle {
|
|
|
|
height: 1
|
|
|
|
visible: root.titlebarBorderEnabled
|
|
|
|
color: Qt.darker(parent.color, 1.5)
|
|
|
|
|
|
|
|
anchors {
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
bottom: parent.bottom
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Window drag handler
|
|
|
|
//
|
|
|
|
Item {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
DragHandler {
|
|
|
|
grabPermissions: TapHandler.CanTakeOverFromAnything
|
|
|
|
onActiveChanged: {
|
|
|
|
if (active)
|
|
|
|
window.startSystemMove()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-09 14:30:59 -06:00
|
|
|
//
|
|
|
|
// Window maximize by double click
|
|
|
|
//
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
acceptedButtons: Qt.LeftButton
|
|
|
|
onDoubleClicked: {
|
|
|
|
if (root.maximizeEnabled)
|
|
|
|
root.toggleMaximized()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-06 13:00:11 -06:00
|
|
|
//
|
|
|
|
// macOS layout
|
|
|
|
//
|
|
|
|
Item {
|
|
|
|
anchors.fill: parent
|
2021-11-09 14:30:59 -06:00
|
|
|
visible: showMacControls
|
|
|
|
enabled: showMacControls
|
2021-11-06 13:00:11 -06:00
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
spacing: 0
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
Item {
|
|
|
|
width: 4
|
|
|
|
}
|
|
|
|
|
2021-11-07 03:49:50 -06:00
|
|
|
WindowButtonMacOS {
|
2021-11-06 13:00:11 -06:00
|
|
|
name: "close"
|
|
|
|
enabled: root.closeEnabled
|
|
|
|
visible: root.closeEnabled
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
2021-11-09 14:30:59 -06:00
|
|
|
onClicked: {
|
|
|
|
window.close()
|
|
|
|
root.closed()
|
|
|
|
}
|
|
|
|
|
2021-11-06 13:00:11 -06:00
|
|
|
}
|
|
|
|
|
2021-11-07 03:49:50 -06:00
|
|
|
WindowButtonMacOS {
|
2021-11-06 13:00:11 -06:00
|
|
|
name: "minimize"
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
enabled: root.minimizeEnabled && !root.fullScreen
|
|
|
|
visible: root.minimizeEnabled && !root.fullScreen
|
2021-11-09 14:30:59 -06:00
|
|
|
onClicked: {
|
|
|
|
window.showMinimized()
|
|
|
|
root.minimized()
|
|
|
|
}
|
2021-11-06 13:00:11 -06:00
|
|
|
}
|
|
|
|
|
2021-11-07 03:49:50 -06:00
|
|
|
WindowButtonMacOS {
|
2021-11-06 13:00:11 -06:00
|
|
|
name: "maximize"
|
|
|
|
onClicked: root.toggleMaximized()
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
enabled: root.maximizeEnabled && !root.fullScreen
|
|
|
|
visible: root.maximizeEnabled && !root.fullScreen
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
2021-11-07 03:49:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Windows & Linux layout
|
|
|
|
//
|
|
|
|
Item {
|
|
|
|
anchors.fill: parent
|
2021-11-09 14:30:59 -06:00
|
|
|
visible: !showMacControls
|
|
|
|
enabled: !showMacControls
|
2021-11-06 13:00:11 -06:00
|
|
|
|
2021-11-07 03:49:50 -06:00
|
|
|
RowLayout {
|
|
|
|
spacing: 0
|
|
|
|
anchors.fill: parent
|
2021-11-06 13:00:11 -06:00
|
|
|
|
|
|
|
Item {
|
|
|
|
width: 8
|
|
|
|
}
|
|
|
|
|
2021-11-09 15:49:06 -06:00
|
|
|
Image {
|
|
|
|
width: 24
|
|
|
|
height: 24
|
|
|
|
opacity: 0.9
|
2021-11-09 14:30:59 -06:00
|
|
|
visible: root.displayIcon
|
|
|
|
enabled: root.displayIcon
|
2021-11-09 15:49:06 -06:00
|
|
|
sourceSize: Qt.size(24, 24)
|
2021-11-07 03:49:50 -06:00
|
|
|
Layout.alignment: Qt.AlignVCenter
|
2021-11-09 15:49:06 -06:00
|
|
|
source: "qrc:/images/icon-window.svg"
|
2021-11-07 03:49:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowButton {
|
|
|
|
name: "minimize"
|
|
|
|
textColor: root.textColor
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
highlightColor: Cpp_ThemeManager.highlight
|
|
|
|
enabled: root.minimizeEnabled && !root.fullScreen
|
|
|
|
visible: root.minimizeEnabled && !root.fullScreen
|
2021-11-09 14:30:59 -06:00
|
|
|
onClicked: {
|
|
|
|
window.showMinimized()
|
|
|
|
root.minimized()
|
|
|
|
}
|
2021-11-07 03:49:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
WindowButton {
|
|
|
|
textColor: root.textColor
|
|
|
|
onClicked: root.toggleMaximized()
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
highlightColor: Cpp_ThemeManager.highlight
|
|
|
|
enabled: root.maximizeEnabled && !root.fullScreen
|
|
|
|
visible: root.maximizeEnabled && !root.fullScreen
|
|
|
|
name: window.visibility === Window.Maximized ? "unmaximize" : "maximize"
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowButton {
|
|
|
|
name: "close"
|
|
|
|
highlightColor: "#f00"
|
|
|
|
textColor: root.textColor
|
|
|
|
enabled: root.closeEnabled
|
|
|
|
visible: root.closeEnabled
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
2021-11-09 14:30:59 -06:00
|
|
|
onClicked: {
|
|
|
|
window.close()
|
|
|
|
root.closed()
|
|
|
|
}
|
|
|
|
|
2021-11-07 03:49:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
width: 8
|
|
|
|
}
|
2021-11-06 13:00:11 -06:00
|
|
|
}
|
|
|
|
}
|
2021-11-07 03:49:50 -06:00
|
|
|
|
|
|
|
Label {
|
|
|
|
font.bold: true
|
|
|
|
font.pixelSize: 14
|
|
|
|
text: window.title
|
|
|
|
color: root.textColor
|
|
|
|
anchors.centerIn: parent
|
|
|
|
}
|
2021-11-06 13:00:11 -06:00
|
|
|
}
|