HangPromptBox.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. Window {
  4. id: hangpromptbox
  5. visibility: Window.FullScreen;
  6. flags: Qt.Dialog | Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint
  7. modality: Qt.ApplicationModal
  8. color: "transparent"
  9. property var _message : string("");
  10. property var _urlIcon : string("");
  11. property var _cancelCallback;
  12. property var _cancelUserargs;
  13. Rectangle {
  14. anchors.centerIn : parent
  15. width: 360
  16. height: 360
  17. color: "#980e57ea"
  18. radius: 16
  19. Image {
  20. anchors.top: parent.top
  21. anchors.topMargin: 32
  22. anchors.horizontalCenter: parent.horizontalCenter
  23. width: 200
  24. height: 200
  25. opacity: 0.5
  26. source: _urlIcon
  27. }
  28. Text {
  29. anchors.bottom: parent.bottom
  30. anchors.bottomMargin: 64
  31. anchors.horizontalCenter: parent.horizontalCenter
  32. text: _message
  33. color: "#ffffff"
  34. font.pixelSize: 32
  35. font.bold: true
  36. }
  37. Text {
  38. anchors.bottom: parent.bottom
  39. anchors.bottomMargin: 16
  40. anchors.horizontalCenter: parent.horizontalCenter
  41. text: qsTr("取消")
  42. color: "#ffffff"
  43. font.pixelSize: 24
  44. font.underline: true
  45. font.bold: false
  46. MouseArea {
  47. anchors.fill: parent
  48. onClicked:
  49. {
  50. if (typeof _cancelCallback === "function")
  51. {
  52. // 如果存在用户参数
  53. if (_cancelUserargs !== null)
  54. {
  55. _cancelCallback(_cancelUserargs);
  56. }
  57. else
  58. {
  59. _cancelCallback();
  60. }
  61. }
  62. hide();
  63. }
  64. }
  65. }
  66. }
  67. // 设置取消按钮回调函数
  68. function setCancelCallBack(callback, userargs)
  69. {
  70. _cancelCallback = callback;
  71. _cancelUserargs = userargs;
  72. }
  73. // 隐藏并且执行回调
  74. function hideExecuteCallback()
  75. {
  76. if (typeof _cancelCallback === "function")
  77. {
  78. // 如果存在用户参数
  79. if (_cancelUserargs !== null)
  80. {
  81. _cancelCallback(_cancelUserargs);
  82. }
  83. else
  84. {
  85. _cancelCallback();
  86. }
  87. _cancelCallback = null;
  88. }
  89. visible = false;
  90. }
  91. // 消息
  92. function message(message)
  93. {
  94. _message = message
  95. }
  96. // 图标
  97. function urlIcon(urlIcon)
  98. {
  99. _urlIcon = urlIcon;
  100. }
  101. // 显示
  102. function show()
  103. {
  104. visible = true;
  105. }
  106. // 隐藏
  107. function hide()
  108. {
  109. _cancelCallback = null;
  110. visible = false;
  111. }
  112. }