AntiClipSettings/qml/MessageBar.qml
2024-12-11 19:05:37 +08:00

102 lines
3.0 KiB
QML

import QtQuick 2.15
import QtQuick.Controls 2.15
Object {
id: control
property var root
property var screenLayout: null
property int layoutY: 75
function showSuccess(text,duration=1000){
return create("success",text,duration)
}
function create(type,text,duration){
if(screenLayout){
let last = screenLayout.getLastloader()
if(last.type === type && last.text === text){
last.duration = duration
if (duration > 0) last.restart()
return last
}
} else {
initScreenLayout()
}
return contentComponent.createObject(screenLayout,{type:type,text:text,duration:duration,})
}
function initScreenLayout() {
if(control.screenLayout == null) {
control.screenLayout = screenLayoutComponent.createObject(root)
screenLayout.y = control.layoutY
screenLayout.z = 100000
}
}
Component {
id:contentComponent
Rectangle {
id: content
property int duration: 1500
property string type
property alias text: message.text
color: "#EBF8ED"
radius: 3.2
border.width: 1
border.color: Qt.darker(content.color)
layer.enabled: true
x:(parent.width - width) / 2
width: 200
height: 32
Row {
anchors.fill: parent
Image {
width: 32
height: 32
fillMode: Image.Pad
source: "qrc:/qt/qml/AntiClipSettings/resources/successfull.svg"
anchors.verticalCenter: parent.verticalCenter
}
Label {
id: message
anchors.verticalCenter: parent.verticalCenter
}
}
Timer {
id:delayTimer
interval: duration
running: duration > 0
repeat: duration > 0
onTriggered: content.close()
}
function close(){
content.destroy()
}
}
}
Component {
id:screenLayoutComponent
Column{
parent: Overlay.overlay
z:999
spacing: 5
width: root.width
move: Transition {
NumberAnimation {
properties: "y"
easing.type: Easing.InOutQuad
duration: 167
}
}
onChildrenChanged: if(children.length === 0) destroy()
function getLastloader(){
if(children.length > 0){
return children[children.length - 1]
}
return null
}
}
}
}