| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- import QtQuick
- import QtQuick.Controls
- import QtQuick.Layouts
- Window {
- id: infopromptbox
- visibility: Window.FullScreen;
- flags: Qt.Dialog | Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint
- modality: Qt.ApplicationModal
- color: "transparent"
- property var _buttons : [];
- property var _message : string("提示信息");
- property var _title : string("标题信息");
- Rectangle {
- anchors.centerIn: parent
- width: 640
- height: 480
- color: "#e0e0e0"
- radius: 16
- Label {
- id: infopromptbox_label_title
- anchors.top: parent.top
- anchors.margins: 0
- width: parent.width
- height: 64
- color: "#ffffff"
- background : Rectangle {
- color: "#3498db"
- }
- leftPadding: 20
- text: _title
- font.pixelSize: 25
- horizontalAlignment: Text.AlignLeft
- verticalAlignment: Text.AlignVCenter
- }
- Rectangle {
- id: infopromptbox_rect_message
- anchors.top: infopromptbox_label_title.bottom
- anchors.bottom: infopromptbox_rect_buttons.top
- anchors.margins: 0
- width: parent.width
- Label {
- anchors.fill: parent
- color: "#000000"
- background : Rectangle {
- color: "#ffffff"
- }
- text: _message
- wrapMode: Text.Wrap
- font.pixelSize: 30
- horizontalAlignment: Text.AlignHCenter
- verticalAlignment: Text.AlignVCenter
- }
- }
- Rectangle {
- id: infopromptbox_rect_buttons
- anchors.bottom: parent.bottom
- anchors.margins: 0
- width: parent.width
- height: 64
- color: "#bfbfbf"
- Row {
- anchors.right: parent.right
- anchors.verticalCenter: parent.verticalCenter
- spacing: 10
- layoutDirection: Qt.RightToLeft
- leftPadding: 20
- rightPadding: 20
- Repeater {
- id : infopromptbox_repeater_buttons
- model: _buttons
- delegate: Button {
- padding: 10
- hoverEnabled: false
- implicitWidth: Math.max(contentItem.implicitWidth + leftPadding + rightPadding, 96);
- implicitHeight: Math.max(contentItem.implicitHeight + topPadding + bottomPadding, 48);
- background: Rectangle {
- color: modelData.hasOwnProperty("color") ? modelData["color"] : "#ff0000";
- radius: 10
- }
- text: modelData.hasOwnProperty("text") ? modelData["text"] : "关闭";
- font.pixelSize: 25
- palette.buttonText: "white"
- onClicked: {
- // 本界面退出
- infopromptbox.close();
- // 判断是否存在回调函数
- if (modelData.hasOwnProperty("callback"))
- {
- // 进行回调函数校验
- if (typeof modelData["callback"] === "function")
- {
- // 如果存在用户参数
- if (modelData.hasOwnProperty("userargs"))
- {
- modelData.callback(modelData["userargs"]);
- }
- else
- {
- modelData.callback();
- }
- }
- }
- }
- }
- }
- }
- }
- }
- function title(title)
- {
- _title = title;
- }
- function message(message)
- {
- _message = message;
- }
- function buttons_reset(buttons)
- {
- if (!Array.isArray(buttons))
- {
- return;
- }
- for (var i = 0; i < bottons.length; ++i)
- {
- _buttons.push(buttons[i]);
- }
- }
- function button_clear()
- {
- _buttons = [];
- }
- function button_push(color, text, callback, userargs)
- {
- var item = {};
- if (color !== null)
- {
- item["color"] = color;
- }
- if (text !== null)
- {
- item["text"] = text;
- }
- if (callback !== null)
- {
- item["callback"] = callback;
- }
- if (userargs !== null)
- {
- item["userargs"] = userargs;
- }
- _buttons.push(item);
- }
- function show()
- {
- if (_buttons.length <= 0)
- {
- button_push("#3498db", "确定", null, null);
- }
- infopromptbox_repeater_buttons.model = _buttons;
- visible = true;
- }
- function hide()
- {
- visible = false;
- }
- }
|