InfoPromptBox.qml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Layouts
  4. Window {
  5. id: infopromptbox
  6. visibility: Window.FullScreen;
  7. flags: Qt.Dialog | Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint
  8. modality: Qt.ApplicationModal
  9. color: "transparent"
  10. property var _buttons : [];
  11. property var _message : string("提示信息");
  12. property var _title : string("标题信息");
  13. Rectangle {
  14. anchors.centerIn: parent
  15. width: 640
  16. height: 480
  17. color: "#e0e0e0"
  18. radius: 16
  19. Label {
  20. id: infopromptbox_label_title
  21. anchors.top: parent.top
  22. anchors.margins: 0
  23. width: parent.width
  24. height: 64
  25. color: "#ffffff"
  26. background : Rectangle {
  27. color: "#3498db"
  28. }
  29. leftPadding: 20
  30. text: _title
  31. font.pixelSize: 25
  32. horizontalAlignment: Text.AlignLeft
  33. verticalAlignment: Text.AlignVCenter
  34. }
  35. Rectangle {
  36. id: infopromptbox_rect_message
  37. anchors.top: infopromptbox_label_title.bottom
  38. anchors.bottom: infopromptbox_rect_buttons.top
  39. anchors.margins: 0
  40. width: parent.width
  41. Label {
  42. anchors.fill: parent
  43. color: "#000000"
  44. background : Rectangle {
  45. color: "#ffffff"
  46. }
  47. text: _message
  48. wrapMode: Text.Wrap
  49. font.pixelSize: 30
  50. horizontalAlignment: Text.AlignHCenter
  51. verticalAlignment: Text.AlignVCenter
  52. }
  53. }
  54. Rectangle {
  55. id: infopromptbox_rect_buttons
  56. anchors.bottom: parent.bottom
  57. anchors.margins: 0
  58. width: parent.width
  59. height: 64
  60. color: "#bfbfbf"
  61. Row {
  62. anchors.right: parent.right
  63. anchors.verticalCenter: parent.verticalCenter
  64. spacing: 10
  65. layoutDirection: Qt.RightToLeft
  66. leftPadding: 20
  67. rightPadding: 20
  68. Repeater {
  69. id : infopromptbox_repeater_buttons
  70. model: _buttons
  71. delegate: Button {
  72. padding: 10
  73. hoverEnabled: false
  74. implicitWidth: Math.max(contentItem.implicitWidth + leftPadding + rightPadding, 96);
  75. implicitHeight: Math.max(contentItem.implicitHeight + topPadding + bottomPadding, 48);
  76. background: Rectangle {
  77. color: modelData.hasOwnProperty("color") ? modelData["color"] : "#ff0000";
  78. radius: 10
  79. }
  80. text: modelData.hasOwnProperty("text") ? modelData["text"] : "关闭";
  81. font.pixelSize: 25
  82. palette.buttonText: "white"
  83. onClicked: {
  84. // 本界面退出
  85. infopromptbox.close();
  86. // 判断是否存在回调函数
  87. if (modelData.hasOwnProperty("callback"))
  88. {
  89. // 进行回调函数校验
  90. if (typeof modelData["callback"] === "function")
  91. {
  92. // 如果存在用户参数
  93. if (modelData.hasOwnProperty("userargs"))
  94. {
  95. modelData.callback(modelData["userargs"]);
  96. }
  97. else
  98. {
  99. modelData.callback();
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. function title(title)
  110. {
  111. _title = title;
  112. }
  113. function message(message)
  114. {
  115. _message = message;
  116. }
  117. function buttons_reset(buttons)
  118. {
  119. if (!Array.isArray(buttons))
  120. {
  121. return;
  122. }
  123. for (var i = 0; i < bottons.length; ++i)
  124. {
  125. _buttons.push(buttons[i]);
  126. }
  127. }
  128. function button_clear()
  129. {
  130. _buttons = [];
  131. }
  132. function button_push(color, text, callback, userargs)
  133. {
  134. var item = {};
  135. if (color !== null)
  136. {
  137. item["color"] = color;
  138. }
  139. if (text !== null)
  140. {
  141. item["text"] = text;
  142. }
  143. if (callback !== null)
  144. {
  145. item["callback"] = callback;
  146. }
  147. if (userargs !== null)
  148. {
  149. item["userargs"] = userargs;
  150. }
  151. _buttons.push(item);
  152. }
  153. function show()
  154. {
  155. if (_buttons.length <= 0)
  156. {
  157. button_push("#3498db", "确定", null, null);
  158. }
  159. infopromptbox_repeater_buttons.model = _buttons;
  160. visible = true;
  161. }
  162. function hide()
  163. {
  164. visible = false;
  165. }
  166. }