StatusBar.qml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2021 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the Qt Quick Controls module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:COMM$
  9. **
  10. ** Commercial License Usage
  11. ** Licensees holding valid commercial Qt licenses may use this file in
  12. ** accordance with the commercial license agreement provided with the
  13. ** Software or, alternatively, in accordance with the terms contained in
  14. ** a written agreement between you and The Qt Company. For licensing terms
  15. ** and conditions see https://www.qt.io/terms-conditions. For further
  16. ** information use the contact form at https://www.qt.io/contact-us.
  17. **
  18. ** $QT_END_LICENSE$
  19. **
  20. **
  21. **
  22. **
  23. **
  24. **
  25. **
  26. **
  27. **
  28. **
  29. **
  30. **
  31. **
  32. **
  33. **
  34. **
  35. **
  36. **
  37. **
  38. ****************************************************************************/
  39. import QtQuick 2.2
  40. import QtQuick.Controls 1.2
  41. import QtQuick.Controls.Private 1.0
  42. /*!
  43. \qmltype StatusBar
  44. \inqmlmodule QtQuick.Controls
  45. \since 5.1
  46. \ingroup applicationwindow
  47. \ingroup controls
  48. \brief Contains status information in your app.
  49. The common way of using StatusBar is in relation to \l ApplicationWindow.
  50. Note that the StatusBar does not provide a layout of its own, but requires
  51. you to position its contents, for instance by creating a \l RowLayout.
  52. If only a single item is used within the StatusBar, it will resize to fit the implicitHeight
  53. of its contained item. This makes it particularly suitable for use together with layouts.
  54. Otherwise the height is platform dependent.
  55. \code
  56. import QtQuick.Controls 1.2
  57. import QtQuick.Layouts 1.0
  58. ApplicationWindow {
  59. statusBar: StatusBar {
  60. RowLayout {
  61. anchors.fill: parent
  62. Label { text: "Read Only" }
  63. }
  64. }
  65. }
  66. \endcode
  67. */
  68. FocusScope {
  69. id: statusbar
  70. activeFocusOnTab: false
  71. Accessible.role: Accessible.StatusBar
  72. width: parent ? parent.width : implicitWidth
  73. implicitWidth: container.leftMargin + container.rightMargin
  74. + Math.max(container.layoutWidth, __panel ? __panel.implicitWidth : 0)
  75. implicitHeight: container.topMargin + container.bottomMargin
  76. + Math.max(container.layoutHeight, __panel ? __panel.implicitHeight : 0)
  77. /*! \qmlproperty Component StatusBar::style
  78. The style Component for this control.
  79. \sa {StatusBarStyle}
  80. */
  81. property Component style: Settings.styleComponent(Settings.style, "StatusBarStyle.qml", statusbar)
  82. /*! \internal */
  83. property alias __style: styleLoader.item
  84. /*! \internal */
  85. property Item __panel: panelLoader.item
  86. /*! \internal */
  87. default property alias __content: container.data
  88. /*!
  89. \qmlproperty Item StatusBar::contentItem
  90. This property holds the content Item of the status bar.
  91. Items declared as children of a StatusBar are automatically parented to the StatusBar's contentItem.
  92. Items created dynamically need to be explicitly parented to the contentItem:
  93. \note The implicit size of the StatusBar is calculated based on the size of its content. If you want to anchor
  94. items inside the status bar, you must specify an explicit width and height on the StatusBar itself.
  95. */
  96. readonly property alias contentItem: container
  97. data: [
  98. Loader {
  99. id: panelLoader
  100. anchors.fill: parent
  101. sourceComponent: styleLoader.item ? styleLoader.item.panel : null
  102. onLoaded: item.z = -1
  103. Loader {
  104. id: styleLoader
  105. property alias __control: statusbar
  106. sourceComponent: style
  107. }
  108. },
  109. Item {
  110. id: container
  111. z: 1
  112. focus: true
  113. anchors.fill: parent
  114. anchors.topMargin: topMargin
  115. anchors.leftMargin: leftMargin
  116. anchors.rightMargin: rightMargin
  117. anchors.bottomMargin: bottomMargin
  118. property int topMargin: __style ? __style.padding.top : 0
  119. property int bottomMargin: __style ? __style.padding.bottom : 0
  120. property int leftMargin: __style ? __style.padding.left : 0
  121. property int rightMargin: __style ? __style.padding.right : 0
  122. property Item layoutItem: container.children.length === 1 ? container.children[0] : null
  123. property real layoutWidth: layoutItem ? (layoutItem.implicitWidth || layoutItem.width) +
  124. (layoutItem.anchors.fill ? layoutItem.anchors.leftMargin +
  125. layoutItem.anchors.rightMargin : 0) : 0
  126. property real layoutHeight: layoutItem ? (layoutItem.implicitHeight || layoutItem.height) +
  127. (layoutItem.anchors.fill ? layoutItem.anchors.topMargin +
  128. layoutItem.anchors.bottomMargin : 0) : 0
  129. }]
  130. }