AntiClipSettings/qml/MessageDialog.qml

132 lines
4.5 KiB
QML

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
Dialog {
id: control
width: 320
padding: 30
parent: Overlay.overlay
anchors.centerIn: Overlay.overlay
modal: true
property alias titleText: titleLabel.text
property alias text: textLabel.text
property alias textFontSize: textLabel.font.pixelSize
property int type: MessageDialog.Type.Successful
property var callback
closePolicy: Popup.CloseOnEscap | Popup.NoAutoClose
background: Rectangle {
radius: 8
}
enum Type {
Ok,
Successful,
Warning,
Failed
}
contentItem: ColumnLayout {
id: layout
IconButton {
Layout.leftMargin: 30
Layout.rightMargin: 6
Layout.alignment: Qt.AlignRight
source: "../resources/popup_close.svg"
onClicked: control.close()
}
RowLayout {
Layout.leftMargin: 30
Image {
id: image
Layout.rightMargin: 6
width: 18
height: 18
source: "qrc:/qt/qml/AntiClipSettings/resources/successfull.svg"
}
Text {
id: titleLabel
font.family: control.font.family
font.pixelSize: 16
color: "#0A1F44"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
Label {
id: textLabel
Layout.leftMargin: 30 + image.width+image.Layout.rightMargin+layout.spacing
Layout.maximumWidth: control.width-Layout.leftMargin-control.rightPadding-control.rightInset-50
font.family: control.font.family
font.pixelSize: 14
color: "#53627C"
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
}
Row {
Layout.alignment: Qt.AlignRight
Layout.rightMargin: 6
spacing: 10
Button {
id: okButton
width: 72
height: 40
font.family: control.font.family
text: "好的"
font.pixelSize: 14
contentItem: Text {
text: parent.text
font: parent.font
color: parent.down ? "#FFFFFF" : "#53627C"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
border.color: "#E1E4E8"
border.width: 1
color: parent.down ? "#F25959" : "#FFFFFF"
radius: 2
}
onClicked: {
if(callback !== undefined){
callback()
}
control.accept()
}
}
Button {
id: cancelButton
visible: callback !== undefined
width: 72
height: 40
font.family: control.font.family
text: "取消"
font.pixelSize: 14
contentItem: Text {
text: parent.text
font: parent.font
color: parent.down ? "#FFFFFF" : "#53627C"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
border.color: "#E1E4E8"
border.width: 1
color: parent.down ? "#F25959" : "#FFFFFF"
radius: 2
}
onClicked: control.reject()
}
}
}
onTypeChanged: {
if (type === MessageDialog.Type.Successful || type === MessageDialog.Type.Ok) {
image.source = "qrc:/qt/qml/AntiClipSettings/resources/successfull.svg"
} else if (type === MessageDialog.Type.Warning) {
image.source = "qrc:/qt/qml/AntiClipSettings/resources/warning.svg"
} else if (type === MessageDialog.Type.Failed) {
image.source = "qrc:/qt/qml/AntiClipSettings/resources/prompt_delete.svg"
}
}
}