RibbonPopup and RibbonWindow: Use a new method to use custom Component.

This commit is contained in:
Mentalflow 2024-04-04 22:39:42 +08:00
parent 79a17c3fb1
commit 7e48832312
Signed by: Mentalflow
GPG Key ID: 5AE68D4401A2EE71
4 changed files with 64 additions and 33 deletions

View File

@ -7,18 +7,6 @@ Item {
id: root
implicitHeight: layout.height + layout.anchors.margins * 2
implicitWidth: 500
RibbonButton{
anchors{
top:parent.top
topMargin: 8
right: parent.right
rightMargin: anchors.topMargin
}
show_bg: false
show_hovered_bg: false
icon_source: RibbonIcons.Dismiss
onClicked: close_popup()
}
ColumnLayout{
id: layout
width: parent.width - anchors.margins * 2

View File

@ -432,7 +432,9 @@ RibbonWindow {
RibbonButton{
text: qsTr('Open Message List View')
icon_source: RibbonIcons.Open
onClicked: root.show_popup("qrc:/qt/qml/RibbonUIAPP/components/RibbonMessageListViewExample.qml")
onClicked: {
Window.window.popup.show_content("qrc:/qt/qml/RibbonUIAPP/components/RibbonMessageListViewExample.qml")
}
}
}
}

View File

@ -16,6 +16,10 @@ Popup {
property alias target: blur.target
property alias target_rect: blur.target_rect
property alias radius: blur.radius
property string content_source: ""
property var content_items: undefined
property bool destroy_after_close: true
enter: Transition {
NumberAnimation {
properties: "scale"
@ -71,19 +75,43 @@ Popup {
}
}
contentItem: Item{
id: control
implicitHeight: container.height
implicitWidth: container.width
property var args
RibbonButton{
anchors{
top:parent.top
topMargin: 8
right:parent.right
rightMargin: topMargin
rightMargin: anchors.topMargin
}
show_bg: false
show_hovered_bg: false
icon_source: RibbonIcons.Dismiss
onClicked: close()
onClicked: popup.close_content()
visible: show_close_btn
}
Loader{
id: container
anchors.centerIn: parent
width: item ? item.implicitWidth : 0
height: item ? item.implicitHeight : 0
sourceComponent: content_source ? undefined : content_items
source: content_source
onLoaded: {
if (!control.args)
return
else if(Object.keys(control.args).length){
for (let arg in control.args){
item[arg] = control.args[arg]
}
}
else{
console.error("RibbonPopup: Arguments error, please check.")
}
}
}
}
Overlay.modal:Rectangle{
color:"transparent"
@ -91,4 +119,29 @@ Popup {
Overlay.modeless:Rectangle{
color:"transparent"
}
onClosed: free_content()
function show_content(content, args){
popup.contentItem.args = args
if (content instanceof Component)
{
content_items = content
content.parent = popup
}
else
{
content_source = content
}
open()
}
function close_content(){
free_content()
close()
}
function free_content(){
if (destroy_after_close)
{
content_source = ""
content_items = undefined
}
}
}

View File

@ -84,7 +84,6 @@ Window {
target: window_items
target_rect: Qt.rect(window_items.x + x, window_items.y + y, width, height)
blur_enabled: true
onClosed: contentItem.destroy()
}
RibbonPopupDialog{
id: dialog
@ -110,26 +109,15 @@ Window {
dialog.open()
}
function show_popup(content_url, argument)
function show_popup(content_url, arguments)
{
let component = Qt.createComponent(content_url,pop)
if (component.status === Component.Error) {
console.log(qsTr("Error loading component:"), component.errorString());
return
}
else
{
if (typeof(argument)!='undefined')
pop.contentItem = component.createObject(pop,argument)
else
pop.contentItem = component.createObject(pop)
}
pop.open()
console.warn("RibbonWindow: This \"show_popup()\" function deprecated, please use RibbonPopup.open_content()")
popup.show_content(content_url, arguments)
}
function close_popup()
{
pop.close()
console.warn("RibbonWindow: This \"close_popup()\" function deprecated, please use RibbonPopup.close_content()")
pop.close_content()
}
}