From 46148435f2687809716c84efdfea74921b891468 Mon Sep 17 00:00:00 2001 From: Mentalflow <312902918@qq.com> Date: Wed, 31 Jan 2024 19:22:53 +0800 Subject: [PATCH] RibbonTitleBar and framelesshelper: restore titlebar, prepare to deprecate helper. --- .gitmodules | 2 +- 3rdparty/framelesshelper | 2 +- lib_source/qml/RibbonTitleBar.qml | 113 ++++++++++++++---------------- 3 files changed, 55 insertions(+), 62 deletions(-) diff --git a/.gitmodules b/.gitmodules index d85aefa..f4ad0f9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "3rdparty/framelesshelper"] path = 3rdparty/framelesshelper - url = git@github.com:wangwenx190/framelesshelper.git + url = git@github.com:mentalfl0w/framelesshelper.git diff --git a/3rdparty/framelesshelper b/3rdparty/framelesshelper index 43f632f..206cd79 160000 --- a/3rdparty/framelesshelper +++ b/3rdparty/framelesshelper @@ -1 +1 @@ -Subproject commit 43f632f2617bd8748fdca605e2fe0b4b67649324 +Subproject commit 206cd7953eb37618bee14f7c3eae73f0bb863cad diff --git a/lib_source/qml/RibbonTitleBar.qml b/lib_source/qml/RibbonTitleBar.qml index bc88f50..0d5b4fc 100644 --- a/lib_source/qml/RibbonTitleBar.qml +++ b/lib_source/qml/RibbonTitleBar.qml @@ -11,12 +11,14 @@ Item { property bool show_darkmode_btn: true property bool dark_mode: RibbonTheme.dark_mode property bool modern_style: RibbonTheme.modern_style - property bool show_buildin_title_btn: Qt.platform.os !== "osx" || RibbonUI.qt_version > 624 property string title_color: modern_style ? "transparent" : dark_mode ? "#282828" : "#2C59B7" property string title_text_color: modern_style ? dark_mode ? "white" : "black" : "white" default property alias content: left_container.data property alias left_content: left_container.data property alias right_content: right_container.data + property alias maximizeBtn: maximizeBtn + property alias minimizeBtn: minimizeBtn + property alias closeBtn: closeBtn anchors { top: parent.top left: parent.left @@ -40,7 +42,7 @@ Item { id: title_text anchors.centerIn: parent text: control.title - font.family: show_buildin_title_btn ? "PingFang SC" : "Microsoft YaHei UI" + font.family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI" color: title_text_color Behavior on color { ColorAnimation { @@ -57,13 +59,9 @@ Item { top: parent.top left: parent.left bottom: parent.bottom - leftMargin: !show_buildin_title_btn ? 65 : 10 + leftMargin: Qt.platform.os === "osx" ? 65 : 10 } Layout.maximumWidth: (parent.width - title_text.contentWidth) / 2 - Loader{ - active: Qt.platform.os === "osx" - sourceComponent: title_btns - } } RowLayout{ @@ -77,9 +75,54 @@ Item { } Layout.maximumWidth: (parent.width - title_text.contentWidth) / 2 layoutDirection: Qt.RightToLeft - Loader{ - active: Qt.platform.os !== "osx" - sourceComponent: title_btns + RowLayout{ + visible: Qt.platform.os !== "osx" + layoutDirection: Qt.RightToLeft + spacing: 0 + Layout.rightMargin: Qt.platform.os === "osx" ? -5 : 0 + RibbonButton{ + id: closeBtn + show_bg:false + icon_source: RibbonIcons.Dismiss + icon_source_filled: RibbonIcons_Filled.Dismiss + text_color: titleBar.title_text_color + hover_color: "#ED6B5E" + pressed_color: "#B55149" + text_color_reverse: false + tip_text: qsTr("Close") + onClicked: Window.window.close() + } + + RibbonButton{ + id: minimizeBtn + show_bg:false + icon_source: RibbonIcons.Subtract + icon_source_filled: RibbonIcons_Filled.Subtract + text_color: titleBar.title_text_color + hover_color: "#F4BE4F" + pressed_color: "#B78F3B" + text_color_reverse: false + tip_text: qsTr("Minimize") + font.bold: pressed || checked + onClicked: Window.window.visibility = Window.Minimized + } + + RibbonButton{ + id: maximizeBtn + show_bg:false + icon_source: Window.window.visibility === Window.Maximized ? RibbonIcons.ArrowMinimize : RibbonIcons.ArrowMaximize + text_color: titleBar.title_text_color + hover_color: "#61C554" + pressed_color: "#48953F" + text_color_reverse: false + tip_text: Window.window.visibility === Window.Maximized ? qsTr("Restore") : qsTr("Maximize") + onClicked: { + if (Window.window.visibility === Window.Maximized) + Window.window.visibility = Window.Windowed + else + Window.window.visibility = Window.Maximized + } + } } RibbonSwitchButton{ text: qsTr("Style") @@ -111,54 +154,4 @@ Item { visible: show_darkmode_btn } } - - Component{ - id: title_btns - RowLayout{ - visible: show_buildin_title_btn - layoutDirection: Qt.platform.os === "osx" ? Qt.LeftToRight : Qt.RightToLeft - spacing: 0 - Layout.rightMargin: show_buildin_title_btn ? -5 : 0 - RibbonButton{ - show_bg:false - icon_source: RibbonIcons.Dismiss - icon_source_filled: RibbonIcons_Filled.Dismiss - text_color: titleBar.title_text_color - hover_color: "#ED6B5E" - pressed_color: "#B55149" - text_color_reverse: false - tip_text: qsTr("Close") - onClicked: Window.window.close() - } - - RibbonButton{ - show_bg:false - icon_source: RibbonIcons.Subtract - icon_source_filled: RibbonIcons_Filled.Subtract - text_color: titleBar.title_text_color - hover_color: "#F4BE4F" - pressed_color: "#B78F3B" - text_color_reverse: false - tip_text: qsTr("Minimize") - font.bold: pressed || checked - onClicked: Window.window.visibility = Window.Minimized - } - - RibbonButton{ - show_bg:false - icon_source: Window.window.visibility === Window.Maximized ? RibbonIcons.ArrowMinimize : RibbonIcons.ArrowMaximize - text_color: titleBar.title_text_color - hover_color: "#61C554" - pressed_color: "#48953F" - text_color_reverse: false - tip_text: Window.window.visibility === Window.Maximized ? qsTr("Restore") : qsTr("Maximize") - onClicked: { - if (Window.window.visibility === Window.Maximized) - Window.window.visibility = Window.Windowed - else - Window.window.visibility = Window.Maximized - } - } - } - } }