Dialog.qml 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright (C) 2017 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. // Qt-Security score:significant reason:default
  4. import QtQuick
  5. import QtQuick.Templates as T
  6. import QtQuick.Controls.impl
  7. import QtQuick.Controls.Material
  8. import QtQuick.Controls.Material.impl
  9. T.Dialog {
  10. id: control
  11. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  12. implicitContentWidth + leftPadding + rightPadding,
  13. implicitHeaderWidth,
  14. implicitFooterWidth)
  15. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  16. implicitContentHeight + topPadding + bottomPadding
  17. + (implicitHeaderHeight > 0 ? implicitHeaderHeight + spacing : 0)
  18. + (implicitFooterHeight > 0 ? implicitFooterHeight + spacing : 0))
  19. // https://m3.material.io/components/dialogs/specs#7dbad5e0-f001-4eae-a536-694aeca90ba6
  20. padding: 24
  21. topPadding: 16
  22. // https://m3.material.io/components/dialogs/guidelines#812cedf1-5c45-453f-97fc-7fd9bba7522b
  23. modal: true
  24. // https://m3.material.io/components/dialogs/specs#401a48c3-f50c-4fa9-b798-701f5adcf155
  25. // Specs say level 3 (6 dp) is the default, yet the screenshots there show 0. Native Android defaults to non-zero.
  26. Material.elevation: 6
  27. Material.roundedScale: Material.dialogRoundedScale
  28. enter: Transition {
  29. // grow_fade_in
  30. NumberAnimation { property: "scale"; from: 0.9; to: 1.0; easing.type: Easing.OutQuint; duration: 220 }
  31. NumberAnimation { property: "opacity"; from: 0.0; to: 1.0; easing.type: Easing.OutCubic; duration: 150 }
  32. }
  33. exit: Transition {
  34. // shrink_fade_out
  35. NumberAnimation { property: "scale"; from: 1.0; to: 0.9; easing.type: Easing.OutQuint; duration: 220 }
  36. NumberAnimation { property: "opacity"; from: 1.0; to: 0.0; easing.type: Easing.OutCubic; duration: 150 }
  37. }
  38. background: Rectangle {
  39. // FullScale doesn't make sense for Dialog.
  40. radius: parent?.parent === Overlay.overlay ? control.Material.roundedScale : 0
  41. color: control.Material.dialogColor
  42. layer.enabled: control.Material.elevation > 0
  43. layer.effect: RoundedElevationEffect {
  44. elevation: control.Material.elevation
  45. roundedScale: control.background.radius
  46. }
  47. }
  48. header: Label {
  49. text: control.title
  50. visible: parent?.parent === Overlay.overlay && control.title
  51. elide: Label.ElideRight
  52. padding: 24
  53. bottomPadding: 0
  54. // TODO: QPlatformTheme::TitleBarFont
  55. // https://m3.material.io/components/dialogs/specs#401a48c3-f50c-4fa9-b798-701f5adcf155
  56. font.pixelSize: Material.dialogTitleFontPixelSize
  57. background: PaddedRectangle {
  58. radius: control.background.radius
  59. color: control.Material.dialogColor
  60. bottomPadding: -radius
  61. clip: true
  62. }
  63. }
  64. footer: DialogButtonBox {
  65. visible: count > 0
  66. }
  67. T.Overlay.modal: Rectangle {
  68. color: control.Material.backgroundDimColor
  69. Behavior on opacity { NumberAnimation { duration: 150 } }
  70. }
  71. T.Overlay.modeless: Rectangle {
  72. color: control.Material.backgroundDimColor
  73. Behavior on opacity { NumberAnimation { duration: 150 } }
  74. }
  75. }