DefaultMessageDialog.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the Qt Quick Dialogs module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. import QtQuick 2.2
  40. import QtQuick.Controls 1.2
  41. import QtQuick.Controls.Private 1.0
  42. import QtQuick.Dialogs 1.1
  43. import QtQuick.Window 2.1
  44. import "qml"
  45. AbstractMessageDialog {
  46. id: root
  47. Rectangle {
  48. id: content
  49. property real spacing: 6
  50. property real outerSpacing: 12
  51. property real buttonsRowImplicitWidth: Screen.pixelDensity * 50
  52. implicitHeight: contentColumn.implicitHeight + outerSpacing * 2
  53. onImplicitHeightChanged: root.height = implicitHeight
  54. implicitWidth: Math.min(root.__maximumDimension, Math.max(
  55. mainText.implicitWidth, buttonsRowImplicitWidth) + outerSpacing * 2);
  56. onImplicitWidthChanged: root.width = implicitWidth
  57. color: palette.window
  58. focus: root.visible
  59. Keys.onPressed: {
  60. event.accepted = true
  61. if (event.modifiers === Qt.ControlModifier)
  62. switch (event.key) {
  63. case Qt.Key_A:
  64. detailedText.selectAll()
  65. break
  66. case Qt.Key_C:
  67. detailedText.copy()
  68. break
  69. case Qt.Key_Period:
  70. if (Qt.platform.os === "osx")
  71. reject()
  72. break
  73. } else switch (event.key) {
  74. case Qt.Key_Escape:
  75. case Qt.Key_Back:
  76. reject()
  77. break
  78. case Qt.Key_Enter:
  79. case Qt.Key_Return:
  80. accept()
  81. break
  82. }
  83. }
  84. Column {
  85. id: contentColumn
  86. spacing: content.spacing
  87. x: content.outerSpacing
  88. y: content.outerSpacing
  89. width: content.width - content.outerSpacing * 2
  90. SystemPalette { id: palette }
  91. Item {
  92. width: parent.width
  93. height: Math.max(icon.height, mainText.height + informativeText.height + content.spacing)
  94. Image {
  95. id: icon
  96. source: root.standardIconSource
  97. }
  98. Text {
  99. id: mainText
  100. anchors {
  101. left: icon.right
  102. leftMargin: content.spacing
  103. right: parent.right
  104. }
  105. text: root.text
  106. font.weight: Font.Bold
  107. wrapMode: Text.WordWrap
  108. renderType: Settings.isMobile ? Text.QtRendering : Text.NativeRendering
  109. }
  110. Text {
  111. id: informativeText
  112. anchors {
  113. left: icon.right
  114. right: parent.right
  115. top: mainText.bottom
  116. leftMargin: content.spacing
  117. topMargin: content.spacing
  118. }
  119. text: root.informativeText
  120. wrapMode: Text.WordWrap
  121. renderType: Settings.isMobile ? Text.QtRendering : Text.NativeRendering
  122. }
  123. }
  124. Flow {
  125. id: buttons
  126. spacing: content.spacing
  127. layoutDirection: Qt.RightToLeft
  128. width: parent.width + content.outerSpacing
  129. x: -content.outerSpacing
  130. Button {
  131. id: okButton
  132. text: qsTr("OK")
  133. onClicked: root.click(StandardButton.Ok)
  134. visible: root.standardButtons & StandardButton.Ok
  135. }
  136. Button {
  137. id: openButton
  138. text: qsTr("Open")
  139. onClicked: root.click(StandardButton.Open)
  140. visible: root.standardButtons & StandardButton.Open
  141. }
  142. Button {
  143. id: saveButton
  144. text: qsTr("Save")
  145. onClicked: root.click(StandardButton.Save)
  146. visible: root.standardButtons & StandardButton.Save
  147. }
  148. Button {
  149. id: saveAllButton
  150. text: qsTr("Save All")
  151. onClicked: root.click(StandardButton.SaveAll)
  152. visible: root.standardButtons & StandardButton.SaveAll
  153. }
  154. Button {
  155. id: retryButton
  156. text: qsTr("Retry")
  157. onClicked: root.click(StandardButton.Retry)
  158. visible: root.standardButtons & StandardButton.Retry
  159. }
  160. Button {
  161. id: ignoreButton
  162. text: qsTr("Ignore")
  163. onClicked: root.click(StandardButton.Ignore)
  164. visible: root.standardButtons & StandardButton.Ignore
  165. }
  166. Button {
  167. id: applyButton
  168. text: qsTr("Apply")
  169. onClicked: root.click(StandardButton.Apply)
  170. visible: root.standardButtons & StandardButton.Apply
  171. }
  172. Button {
  173. id: yesButton
  174. text: qsTr("Yes")
  175. onClicked: root.click(StandardButton.Yes)
  176. visible: root.standardButtons & StandardButton.Yes
  177. }
  178. Button {
  179. id: yesAllButton
  180. text: qsTr("Yes to All")
  181. onClicked: root.click(StandardButton.YesToAll)
  182. visible: root.standardButtons & StandardButton.YesToAll
  183. }
  184. Button {
  185. id: noButton
  186. text: qsTr("No")
  187. onClicked: root.click(StandardButton.No)
  188. visible: root.standardButtons & StandardButton.No
  189. }
  190. Button {
  191. id: noAllButton
  192. text: qsTr("No to All")
  193. onClicked: root.click(StandardButton.NoToAll)
  194. visible: root.standardButtons & StandardButton.NoToAll
  195. }
  196. Button {
  197. id: discardButton
  198. text: qsTr("Discard")
  199. onClicked: root.click(StandardButton.Discard)
  200. visible: root.standardButtons & StandardButton.Discard
  201. }
  202. Button {
  203. id: resetButton
  204. text: qsTr("Reset")
  205. onClicked: root.click(StandardButton.Reset)
  206. visible: root.standardButtons & StandardButton.Reset
  207. }
  208. Button {
  209. id: restoreDefaultsButton
  210. text: qsTr("Restore Defaults")
  211. onClicked: root.click(StandardButton.RestoreDefaults)
  212. visible: root.standardButtons & StandardButton.RestoreDefaults
  213. }
  214. Button {
  215. id: cancelButton
  216. text: qsTr("Cancel")
  217. onClicked: root.click(StandardButton.Cancel)
  218. visible: root.standardButtons & StandardButton.Cancel
  219. }
  220. Button {
  221. id: abortButton
  222. text: qsTr("Abort")
  223. onClicked: root.click(StandardButton.Abort)
  224. visible: root.standardButtons & StandardButton.Abort
  225. }
  226. Button {
  227. id: closeButton
  228. text: qsTr("Close")
  229. onClicked: root.click(StandardButton.Close)
  230. visible: root.standardButtons & StandardButton.Close
  231. }
  232. Button {
  233. id: moreButton
  234. text: qsTr("Show Details...")
  235. onClicked: content.state = (content.state === "" ? "expanded" : "")
  236. visible: root.detailedText.length > 0
  237. }
  238. Button {
  239. id: helpButton
  240. text: qsTr("Help")
  241. onClicked: root.click(StandardButton.Help)
  242. visible: root.standardButtons & StandardButton.Help
  243. }
  244. onVisibleChildrenChanged: calculateImplicitWidth()
  245. }
  246. }
  247. Item {
  248. id: details
  249. width: parent.width
  250. implicitHeight: detailedText.implicitHeight + content.spacing
  251. height: 0
  252. clip: true
  253. anchors {
  254. left: parent.left
  255. right: parent.right
  256. top: contentColumn.bottom
  257. topMargin: content.spacing
  258. leftMargin: content.outerSpacing
  259. rightMargin: content.outerSpacing
  260. }
  261. Flickable {
  262. id: flickable
  263. contentHeight: detailedText.height
  264. anchors.fill: parent
  265. anchors.topMargin: content.spacing
  266. anchors.bottomMargin: content.outerSpacing
  267. TextEdit {
  268. id: detailedText
  269. text: root.detailedText
  270. width: details.width
  271. wrapMode: Text.WordWrap
  272. readOnly: true
  273. selectByMouse: true
  274. renderType: Settings.isMobile ? Text.QtRendering : Text.NativeRendering
  275. }
  276. }
  277. }
  278. states: [
  279. State {
  280. name: "expanded"
  281. PropertyChanges {
  282. target: details
  283. height: content.height - contentColumn.height - content.spacing - content.outerSpacing
  284. }
  285. PropertyChanges {
  286. target: content
  287. implicitHeight: contentColumn.implicitHeight + content.spacing * 2 +
  288. detailedText.implicitHeight + content.outerSpacing * 2
  289. }
  290. PropertyChanges {
  291. target: moreButton
  292. text: qsTr("Hide Details")
  293. }
  294. }
  295. ]
  296. }
  297. function calculateImplicitWidth() {
  298. if (buttons.visibleChildren.length < 2)
  299. return;
  300. var calcWidth = 0;
  301. for (var i = 0; i < buttons.visibleChildren.length; ++i)
  302. calcWidth += Math.max(100, buttons.visibleChildren[i].implicitWidth) + content.spacing
  303. content.buttonsRowImplicitWidth = content.outerSpacing + calcWidth
  304. }
  305. Component.onCompleted: calculateImplicitWidth()
  306. }