GroupBox.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (C) 2024 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.Controls.impl
  6. import QtQuick.Controls.FluentWinUI3.impl as Impl
  7. import QtQuick.Templates as T
  8. T.GroupBox {
  9. id: control
  10. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  11. implicitContentWidth + leftPadding + rightPadding,
  12. implicitLabelWidth + leftPadding + rightPadding)
  13. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  14. implicitContentHeight + topPadding + bottomPadding)
  15. readonly property real __deltaY: (__config.background.y - __config.label.y) || 0
  16. readonly property real __deltaX: (__config.background.x - __config.label.x) || 0
  17. spacing: (__deltaY - __config.label.height) || 0
  18. topPadding: (__config.topPadding || 0) + (spacing >= 0 ? (label.height + spacing) : __deltaY)
  19. bottomPadding: __config.bottomPadding || 0
  20. leftPadding: (__config.leftPadding || 0) + (__deltaX >= 0 ? __deltaX : 0)
  21. rightPadding: __config.rightPadding || 0
  22. topInset: __deltaY > 0 ? __deltaY : 0
  23. bottomInset: -__config.bottomInset || 0
  24. leftInset: __deltaX > 0 ? __deltaX : 0
  25. rightInset: -__config.rightInset || 0
  26. readonly property string __currentState: [
  27. !control.enabled && "disabled",
  28. control.enabled && control.hovered && "hovered",
  29. ].filter(Boolean).join("_") || "normal"
  30. readonly property var __config: Config.controls.groupbox[__currentState] || {}
  31. label: T.Label {
  32. x: control.__deltaX > 0 ? 0 : -__deltaX
  33. y: control.__deltaY > 0 ? 0 : -__deltaY
  34. topPadding: control.__config.label_contentItem.topPadding || 0
  35. leftPadding: control.__config.label_contentItem.leftPadding || 0
  36. rightPadding: control.__config.label_contentItem.rightPadding || 0
  37. bottomPadding: control.__config.label_contentItem.bottomPadding || 0
  38. height: Math.max(implicitHeight, __config.label.height)
  39. text: control.title
  40. font: control.font
  41. color: control.palette.windowText
  42. elide: Text.ElideRight
  43. horizontalAlignment: control.__config.label_text.textHAlignment
  44. verticalAlignment: control.__config.label_text.textVAlignment
  45. background: Impl.StyleImage {
  46. imageConfig: control.__config.label_background
  47. }
  48. }
  49. background: Rectangle {
  50. color: "transparent"
  51. border.color: Application.styleHints.accessibility.contrastPreference === Qt.HighContrast ? control.palette.text : "transparent"
  52. radius: 4
  53. Impl.StyleImage {
  54. imageConfig: control.__config.background.filePath ? control.__config.background : Config.controls.frame["normal"].background // fallback to regular frame background
  55. width: parent.width
  56. height: parent.height
  57. }
  58. }
  59. }