252 lines
9.2 KiB
QML
252 lines
9.2 KiB
QML
import QtQuick 6.2
|
|
import QtQuick.Controls 6.2
|
|
import QtQuick.Layouts 6.2
|
|
import "components"
|
|
|
|
|
|
ApplicationWindow {
|
|
id: window
|
|
width: 1920
|
|
height: 1080
|
|
visible: true
|
|
title: "Custom Window"
|
|
flags: Qt.FramelessWindowHint | Qt.Window // 无边框但可调整大小
|
|
readonly property int titleBarHeight: 35
|
|
readonly property int titleBarButtonWidth: 50
|
|
|
|
Rectangle {//主窗口
|
|
id: mainContainer
|
|
anchors.fill: parent
|
|
color: Colors.sColor_blue // 主窗口背景色
|
|
|
|
// 顶部任务栏
|
|
Rectangle {
|
|
id: titleBar
|
|
width: parent.width
|
|
height: titleBarHeight
|
|
color: Colors.sColor_Black
|
|
anchors.left: parent.left
|
|
anchors.top: parent.top // 确保对齐顶部
|
|
// anchors.margins: 0 // 设置内容边距为 0
|
|
// border.color: "#222"
|
|
// 允许拖动窗口
|
|
MouseArea {
|
|
id: dragArea
|
|
anchors.fill: parent
|
|
|
|
onPressed: function(event) {
|
|
window.startSystemMove(); // ✅ 直接调用系统级移动(防止拖影)
|
|
}
|
|
onDoubleClicked: {
|
|
// 切换窗口为全屏 / 还原
|
|
if (window.visibility === Window.Maximized) {
|
|
window.visibility = Window.Windowed; // 如果已经是全屏则还原
|
|
} else {
|
|
window.visibility = Window.Maximized; // 否则切换为全屏
|
|
}
|
|
}
|
|
}
|
|
RowLayout {
|
|
anchors.fill: parent
|
|
anchors.margins: 0 // 设置内容边距为 0
|
|
anchors.top: parent.top // 确保对齐顶部
|
|
spacing: 0
|
|
Layout.fillWidth: true
|
|
Layout.fillHeight: true
|
|
Layout.minimumHeight: titleBarHeight
|
|
// 左侧标题
|
|
Text {
|
|
text: "WIDGET"
|
|
color: "white"
|
|
font.pixelSize: 16
|
|
Layout.leftMargin: 10
|
|
}
|
|
|
|
// 占位符,让按钮靠右
|
|
Item {
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
// 最小化按钮
|
|
ToolBarButton {
|
|
id: toolBarMinimizeButton
|
|
iconSource: "qrc:/icon/minus.png" // 设置按钮图标
|
|
buttonWidth: titleBarButtonWidth
|
|
buttonHeight: titleBarHeight
|
|
Layout.alignment: Qt.AlignTop
|
|
Layout.margins: 0 // 确保没有额外的边距
|
|
onClicked: window.showMinimized()
|
|
}
|
|
|
|
// 最大化 / 还原窗口按钮
|
|
ToolBarButton {
|
|
id: windowMaximizeButton
|
|
iconSource: window.visibility === Window.Maximized ? "qrc:/icon/fullscreen-exit.png" : "qrc:/icon/fullscreen.png"
|
|
buttonWidth: titleBarButtonWidth
|
|
buttonHeight: titleBarHeight
|
|
Layout.alignment: Qt.AlignTop
|
|
Layout.margins: 0 // 确保没有额外的边距
|
|
onClicked: {
|
|
if (window.visibility === Window.Maximized) {
|
|
window.visibility = Window.Windowed;
|
|
} else {
|
|
window.visibility = Window.Maximized;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 关闭按钮
|
|
ToolBarButton {
|
|
id: toolBarCloseButton
|
|
iconSource: "qrc:/icon/close.png" // 设置按钮图标
|
|
buttonWidth: titleBarButtonWidth
|
|
buttonHeight: titleBarHeight
|
|
Layout.alignment: Qt.AlignTop
|
|
Layout.margins: 0 // 确保没有额外的边距
|
|
onClicked: Qt.quit()
|
|
}
|
|
}
|
|
}
|
|
Rectangle {//主窗口2
|
|
id: mainContainer2
|
|
width: parent.width
|
|
height: parent.height - titleBarHeight
|
|
color: Colors.sColor_blue
|
|
anchors.left: parent.left
|
|
anchors.bottom: parent.bottom // 确保对齐顶部
|
|
Rectangle {
|
|
id: leftWidgetSwitchBar
|
|
width: titleBarButtonWidth
|
|
height: parent.height
|
|
color: Colors.sColor_Black
|
|
anchors.margins: 0 // 设置内容边距为 0
|
|
anchors.left: parent.left
|
|
anchors.top: parent.top // 确保对齐顶部
|
|
ColumnLayout {
|
|
anchors.fill: parent
|
|
anchors.margins: 0 // 设置内容边距为 0
|
|
anchors.top: parent.top // 确保对齐顶部
|
|
spacing: 0
|
|
Layout.fillWidth: true
|
|
Layout.fillHeight: true
|
|
Layout.minimumWidth: titleBarButtonWidth
|
|
// 左侧标题
|
|
// 最小化按钮
|
|
ToolBarButton {
|
|
id: toolBarMinimizeButton2
|
|
iconSource: "qrc:/icon/minus.png" // 设置按钮图标
|
|
buttonWidth: titleBarButtonWidth
|
|
buttonHeight: titleBarButtonWidth
|
|
Layout.alignment: Qt.AlignTop
|
|
Layout.margins: 0 // 确保没有额外的边距
|
|
onClicked: window.showMinimized()
|
|
}
|
|
|
|
// 最大化 / 还原窗口按钮
|
|
ToolBarButton {
|
|
id: windowMaximizeButton2
|
|
iconSource: window.visibility === Window.Maximized ? "qrc:/icon/fullscreen-exit.png" : "qrc:/icon/fullscreen.png"
|
|
buttonWidth: titleBarButtonWidth
|
|
buttonHeight: titleBarButtonWidth
|
|
Layout.alignment: Qt.AlignTop
|
|
Layout.margins: 0 // 确保没有额外的边距
|
|
onClicked: {
|
|
if (window.visibility === Window.Maximized) {
|
|
window.visibility = Window.Windowed;
|
|
} else {
|
|
window.visibility = Window.Maximized;
|
|
}
|
|
}
|
|
}
|
|
Item {
|
|
Layout.fillHeight: true
|
|
}
|
|
}
|
|
}
|
|
StackLayout {//主显示界面
|
|
id: stackLayout
|
|
width: parent.width - titleBarButtonWidth
|
|
height: parent.height
|
|
anchors.right: parent.right
|
|
anchors.top: parent.top // 确保对齐顶部
|
|
// 页面1
|
|
Rectangle {
|
|
color: "lightblue"
|
|
Text {
|
|
anchors.centerIn: parent
|
|
text: "Page 1"
|
|
font.pixelSize: 24
|
|
}
|
|
}
|
|
|
|
// 页面2
|
|
Rectangle {
|
|
color: "lightgreen"
|
|
Text {
|
|
anchors.centerIn: parent
|
|
text: "Page 2"
|
|
font.pixelSize: 24
|
|
}
|
|
}
|
|
|
|
// 页面3
|
|
Rectangle {
|
|
color: "lightcoral"
|
|
Text {
|
|
anchors.centerIn: parent
|
|
text: "Page 3"
|
|
font.pixelSize: 24
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 允许调整窗口大小
|
|
MouseArea {
|
|
id: resizeArea
|
|
anchors.right: parent.right
|
|
anchors.bottom: parent.bottom
|
|
width: 20
|
|
height: 20
|
|
cursorShape: Qt.SizeFDiagCursor
|
|
|
|
property real startX: 0
|
|
property real startY: 0
|
|
property real startWidth: 0
|
|
property real startHeight: 0
|
|
property bool resizing: false
|
|
|
|
onPressed: function(event) {
|
|
cursorShape = Qt.SizeFDiagCursor
|
|
var globalPos = resizeArea.mapToItem(null, event.x, event.y);
|
|
startX = globalPos.x;
|
|
startY = globalPos.y;
|
|
startWidth = window.width;
|
|
startHeight = window.height;
|
|
resizing = true;
|
|
}
|
|
|
|
onReleased: {
|
|
resizing = false;
|
|
}
|
|
|
|
onPositionChanged: function(event) {
|
|
if (resizing && event.buttons & Qt.LeftButton) {
|
|
var globalPos = resizeArea.mapToItem(null, event.x, event.y);
|
|
var newWidth = startWidth + (globalPos.x - startX);
|
|
var newHeight = startHeight + (globalPos.y - startY);
|
|
|
|
window.width = Math.max(400, newWidth); // 限制最小宽度
|
|
window.height = Math.max(300, newHeight); // 限制最小高度
|
|
}
|
|
}
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
console.log("窗口初始化结束")
|
|
window.visibility = Window.Maximized // 默认全屏显示
|
|
window.raise() // 确保窗口在最前
|
|
}
|
|
|
|
} |