RibbonTheme,RibbonWindow and example: Add nativeText property and bug fix.

This commit is contained in:
Mentalflow 2024-05-11 09:12:00 +08:00
parent d5101de44c
commit 974268fe9a
Signed by: Mentalflow
GPG Key ID: 5AE68D4401A2EE71
18 changed files with 33 additions and 6 deletions

View File

@ -33,8 +33,10 @@ RibbonWindow {
text: qsTr("Vertical/Horizental sliders with/without buttons."), text: qsTr("Vertical/Horizental sliders with/without buttons."),
target: slider_layout, target: slider_layout,
enter_func: ()=>{ enter_func: ()=>{
tab_bar.setPage(0)
slider_with_btn.value = 70 slider_with_btn.value = 70
slider_without_btn.value = 70 slider_without_btn.value = 70
tour.refresh(500)
}, },
exit_func: ()=>{ exit_func: ()=>{
slider_with_btn.value = 50 slider_with_btn.value = 50
@ -555,6 +557,15 @@ RibbonWindow {
text: "Test Text (Read Only)" text: "Test Text (Read Only)"
view_only: true view_only: true
} }
RibbonSwitchButton{
text: "Render"
grabber_text: RibbonTheme.nativeText ? "native" : "Qt"
checked: true
Layout.alignment: Qt.AlignHCenter
onClicked: {
RibbonTheme.nativeText = checked
}
}
} }
} }
} }

View File

@ -110,6 +110,7 @@ Button {
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
font.pixelSize: 12 font.pixelSize: 12
font.family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI" font.family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI"
renderType: RibbonTheme.nativeText ? Text.NativeRendering : Text.QtRendering
color: { color: {
if (!show_bg && (hovered || checked || pressed) && text_color_reverse) if (!show_bg && (hovered || checked || pressed) && text_color_reverse)
return Qt.lighter(text_color) return Qt.lighter(text_color)

View File

@ -82,6 +82,7 @@ Button {
pixelSize: control.text_size pixelSize: control.text_size
bold: control.text_bold bold: control.text_bold
} }
renderType: RibbonTheme.nativeText ? Text.NativeRendering : Text.QtRendering
color: text_color color: text_color
visible: text visible: text
} }

View File

@ -19,6 +19,7 @@ Text {
font.pixelSize: icon_size font.pixelSize: icon_size
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
renderType: RibbonTheme.nativeText ? Text.NativeRendering : Text.QtRendering
text: (String.fromCharCode(filled ? icon_source_filled : icon_source).toString(16)) text: (String.fromCharCode(filled ? icon_source_filled : icon_source).toString(16))
FontLoader{ FontLoader{

View File

@ -26,6 +26,7 @@ TextField{
width:150 width:150
height:20 height:20
onCommit: cursorVisible = false onCommit: cursorVisible = false
renderType: RibbonTheme.nativeText ? TextField.NativeRendering : TextField.QtRendering
background: Rectangle{ background: Rectangle{
radius: 4 radius: 4
implicitHeight: 20 implicitHeight: 20

View File

@ -92,6 +92,7 @@ MenuItem {
elide: Text.ElideRight elide: Text.ElideRight
font.family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI" font.family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI"
color: text_color color: text_color
renderType: RibbonTheme.nativeText ? Text.NativeRendering : Text.QtRendering
Layout.preferredWidth:{ Layout.preferredWidth:{
let w = 0 let w = 0
w += rib_icon.visible ? rib_icon.contentWidth : 0 w += rib_icon.visible ? rib_icon.contentWidth : 0

View File

@ -120,6 +120,7 @@ Item {
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
font.pixelSize: 12 font.pixelSize: 12
font.family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI" font.family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI"
renderType: RibbonTheme.nativeText ? Text.NativeRendering : Text.QtRendering
color: text_color color: text_color
} }

View File

@ -128,6 +128,7 @@ Button {
text: control.grabber_text text: control.grabber_text
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.margins: 4 anchors.margins: 4
renderType: RibbonTheme.nativeText ? Text.NativeRendering : Text.QtRendering
visible: control.show_grabber_text visible: control.show_grabber_text
x: control.checked ? grabber.x - anchors.margins - contentWidth : grabber.x + grabber.width + anchors.margins x: control.checked ? grabber.x - anchors.margins - contentWidth : grabber.x + grabber.width + anchors.margins
z: 0 z: 0
@ -192,6 +193,7 @@ Button {
id:label id:label
text:control.text text:control.text
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
renderType: RibbonTheme.nativeText ? Text.NativeRendering : Text.QtRendering
font{ font{
family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI" family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI"
pixelSize: control.text_size pixelSize: control.text_size

View File

@ -96,12 +96,6 @@ Item{
} }
height: bar_layout.height height: bar_layout.height
z:1 z:1
ScrollBar.horizontal: RibbonScrollBar{
anchors.bottom: bar_view.bottom
anchors.horizontalCenter: bar_view.horizontalCenter
width: bar_view.width - 10
height: 5
}
RowLayout RowLayout
{ {
id: bar_layout id: bar_layout

View File

@ -27,6 +27,7 @@ TabButton {
pixelSize: 13 pixelSize: 13
bold: checked bold: checked
} }
renderType: RibbonTheme.nativeText ? Text.NativeRendering : Text.QtRendering
color: font_color color: font_color
height: contentHeight height: contentHeight
anchors{ anchors{

View File

@ -29,6 +29,7 @@ Item {
} }
color: font_color color: font_color
height: contentHeight height: contentHeight
renderType: RibbonTheme.nativeText ? Text.NativeRendering : Text.QtRendering
anchors{ anchors{
horizontalCenter: control.horizontalCenter horizontalCenter: control.horizontalCenter
bottom: control.bottom bottom: control.bottom

View File

@ -19,6 +19,12 @@ TextEdit {
wrapMode: TextEdit.WrapAnywhere wrapMode: TextEdit.WrapAnywhere
enabled: !view_only enabled: !view_only
font.family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI" font.family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI"
renderType: RibbonTheme.nativeText ? TextEdit.NativeRendering : TextEdit.QtRendering
onRenderTypeChanged: {
selectAll()
deselect()
}
MouseArea{ MouseArea{
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.IBeamCursor cursorShape: Qt.IBeamCursor

View File

@ -42,6 +42,7 @@ Item{
selectionColor: dark_mode ? "#4F5E7F" : "#BECDE8" selectionColor: dark_mode ? "#4F5E7F" : "#BECDE8"
selectedTextColor: dark_mode ? "white" : "black" selectedTextColor: dark_mode ? "white" : "black"
wrapMode: Text.WrapAnywhere wrapMode: Text.WrapAnywhere
renderType: RibbonTheme.nativeText ? TextArea.NativeRendering : TextArea.QtRendering
opacity: enabled ? 1.0 : 0.3 opacity: enabled ? 1.0 : 0.3
signal commit() signal commit()

View File

@ -48,6 +48,7 @@ Item {
text: control.title text: control.title
font.family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI" font.family: Qt.platform.os === "osx" ? "PingFang SC" : "Microsoft YaHei UI"
color: title_text_color color: title_text_color
renderType: RibbonTheme.nativeText ? Text.NativeRendering : Text.QtRendering
Behavior on color { Behavior on color {
ColorAnimation { ColorAnimation {
duration: 60 duration: 60

View File

@ -12,6 +12,7 @@ ToolTip {
text: control.text text: control.text
font: control.font font: control.font
color: RibbonTheme.dark_mode ? "white" : "black" color: RibbonTheme.dark_mode ? "white" : "black"
renderType: RibbonTheme.nativeText ? Text.NativeRendering : Text.QtRendering
} }
background: Rectangle { background: Rectangle {

View File

@ -48,6 +48,7 @@ Window {
windowAgent.setTitleBar(titleBar) windowAgent.setTitleBar(titleBar)
window.visible = true window.visible = true
windowAgent.centralize() windowAgent.centralize()
raise()
windowAgent.setWindowAttribute("dark-mode", RibbonTheme.dark_mode) windowAgent.setWindowAttribute("dark-mode", RibbonTheme.dark_mode)
if (Qt.platform.os === 'windows') if (Qt.platform.os === 'windows')
{ {

View File

@ -19,6 +19,7 @@ RibbonTheme::RibbonTheme()
_theme_mode = RibbonThemeType::ThemeMode::System; _theme_mode = RibbonThemeType::ThemeMode::System;
_system_theme_mode = current_theme(); _system_theme_mode = current_theme();
modern_style(false); modern_style(false);
nativeText(true);
qApp->installEventFilter(this); qApp->installEventFilter(this);
} }

View File

@ -14,6 +14,7 @@ class RibbonTheme : public QQuickItem
Q_PROPERTY(bool dark_mode READ dark_mode() NOTIFY dark_modeChanged FINAL) Q_PROPERTY(bool dark_mode READ dark_mode() NOTIFY dark_modeChanged FINAL)
Q_PROPERTY_RW(RibbonThemeType::ThemeMode,theme_mode) Q_PROPERTY_RW(RibbonThemeType::ThemeMode,theme_mode)
Q_PROPERTY_RW(bool,modern_style) Q_PROPERTY_RW(bool,modern_style)
Q_PROPERTY_RW(bool,nativeText)
public: public:
static RibbonTheme* create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return instance();} static RibbonTheme* create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return instance();}
static RibbonTheme* instance(); static RibbonTheme* instance();