ApplicationWindow.qml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 Controls 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 QtQml 2.14 as Qml
  40. import QtQuick.Window 2.2
  41. import QtQuick 2.2
  42. import QtQuick.Controls 1.2
  43. import QtQuick.Layouts 1.0
  44. import QtQuick.Controls.Private 1.0
  45. /*!
  46. \qmltype ApplicationWindow
  47. \since 5.1
  48. \inqmlmodule QtQuick.Controls
  49. \ingroup applicationwindow
  50. \ingroup controls
  51. \brief Provides a top-level application window.
  52. \image applicationwindow.png
  53. ApplicationWindow is a \l Window that adds convenience for positioning items,
  54. such as \l MenuBar, \l ToolBar, and \l StatusBar in a platform independent
  55. manner.
  56. \code
  57. ApplicationWindow {
  58. id: window
  59. visible: true
  60. menuBar: MenuBar {
  61. Menu { MenuItem {...} }
  62. Menu { MenuItem {...} }
  63. }
  64. toolBar: ToolBar {
  65. RowLayout {
  66. anchors.fill: parent
  67. ToolButton {...}
  68. }
  69. }
  70. TabView {
  71. id: myContent
  72. anchors.fill: parent
  73. ...
  74. }
  75. }
  76. \endcode
  77. \note By default, an ApplicationWindow is not visible.
  78. The \l{Qt Quick Controls 1 - Gallery} example is a good starting
  79. point to explore this type.
  80. */
  81. Window {
  82. id: root
  83. /*!
  84. \qmlproperty MenuBar ApplicationWindow::menuBar
  85. This property holds the \l MenuBar.
  86. By default, this value is not set.
  87. */
  88. property MenuBar menuBar: null
  89. /*!
  90. \qmlproperty Item ApplicationWindow::toolBar
  91. This property holds the toolbar \l Item.
  92. It can be set to any Item type, but is generally used with \l ToolBar.
  93. By default, this value is not set. When you set the toolbar item, it will
  94. be anchored automatically into the application window.
  95. */
  96. property Item toolBar
  97. /*!
  98. \qmlproperty Item ApplicationWindow::statusBar
  99. This property holds the status bar \l Item.
  100. It can be set to any Item type, but is generally used with \l StatusBar.
  101. By default, this value is not set. When you set the status bar item, it
  102. will be anchored automatically into the application window.
  103. */
  104. property Item statusBar
  105. // The below documentation was supposed to be written as a grouped property, but qdoc would
  106. // not render it correctly due to a bug (QTBUG-34206)
  107. /*!
  108. \qmlproperty ContentItem ApplicationWindow::contentItem
  109. This group holds the size constraints of the content item. This is the area between the
  110. \l ToolBar and the \l StatusBar.
  111. The \l ApplicationWindow will use this as input when calculating the effective size
  112. constraints of the actual window.
  113. It holds these 6 properties for describing the minimum, implicit and maximum sizes:
  114. \table
  115. \header \li Grouped property \li Description
  116. \row \li contentItem.minimumWidth \li The minimum width of the content item.
  117. \row \li contentItem.minimumHeight \li The minimum height of the content item.
  118. \row \li contentItem.implicitWidth \li The implicit width of the content item.
  119. \row \li contentItem.implicitHeight \li The implicit height of the content item.
  120. \row \li contentItem.maximumWidth \li The maximum width of the content item.
  121. \row \li contentItem.maximumHeight \li The maximum height of the content item.
  122. \endtable
  123. */
  124. property alias contentItem : contentArea
  125. /*! The style Component for the window.
  126. \sa {Qt Quick Controls 1 Styles QML Types}
  127. */
  128. property Component style: Settings.styleComponent(Settings.style, "ApplicationWindowStyle.qml", root)
  129. /*! \internal */
  130. property alias __style: styleLoader.item
  131. /*! \internal */
  132. property alias __panel: panelLoader.item
  133. /*! \internal */
  134. property real __topBottomMargins: __panel.contentArea.y + __panel.statusBarArea.height
  135. /*! \internal
  136. There is a similar macro QWINDOWSIZE_MAX in qwindow_p.h that is used to limit the
  137. range of QWindow::maximum{Width,Height}
  138. However, in case we have a very big number (> 2^31) conversion will fail, and it will be
  139. converted to 0, resulting in that we will call setMaximumWidth(0)....
  140. We therefore need to enforce the limit at a level where we are still operating on
  141. floating point values.
  142. */
  143. readonly property real __qwindowsize_max: (1 << 24) - 1
  144. /*! \internal */
  145. property real __width: 0
  146. Qml.Binding {
  147. target: root
  148. property: "__width"
  149. when: (root.minimumWidth <= root.maximumWidth) && !contentArea.__noImplicitWidthGiven
  150. value: Math.max(Math.min(root.maximumWidth, contentArea.implicitWidth), root.minimumWidth)
  151. restoreMode: Binding.RestoreBinding
  152. }
  153. /*! \internal */
  154. property real __height: 0
  155. Qml.Binding {
  156. target: root
  157. property: "__height"
  158. when: (root.minimumHeight <= root.maximumHeight) && !contentArea.__noImplicitHeightGiven
  159. value: Math.max(Math.min(root.maximumHeight, contentArea.implicitHeight + __topBottomMargins), root.minimumHeight)
  160. restoreMode: Binding.RestoreBinding
  161. }
  162. /* As soon as an application developer writes
  163. width: 200
  164. this binding will be broken. This is the reason for this indirection
  165. via __width (and __height)
  166. */
  167. width: __width
  168. height: __height
  169. minimumWidth: contentArea.__noMinimumWidthGiven ? 0 : contentArea.minimumWidth
  170. minimumHeight: contentArea.__noMinimumHeightGiven ? 0 : (contentArea.minimumHeight + __topBottomMargins)
  171. maximumWidth: Math.min(__qwindowsize_max, contentArea.maximumWidth)
  172. maximumHeight: Math.min(__qwindowsize_max, contentArea.maximumHeight + __topBottomMargins)
  173. /*! \internal */
  174. default property alias data: contentArea.data
  175. flags: Qt.Window | Qt.WindowFullscreenButtonHint |
  176. Qt.WindowTitleHint | Qt.WindowSystemMenuHint | Qt.WindowMinMaxButtonsHint |
  177. Qt.WindowCloseButtonHint | Qt.WindowFullscreenButtonHint
  178. // QTBUG-35049: Windows is removing features we didn't ask for, even though Qt::CustomizeWindowHint is not set
  179. // Otherwise Qt.Window | Qt.WindowFullscreenButtonHint would be enough
  180. Loader {
  181. id: panelLoader
  182. anchors.fill: parent
  183. sourceComponent: __style ? __style.panel : null
  184. onStatusChanged: if (status === Loader.Error) console.error("Failed to load Style for", root)
  185. focus: true
  186. Loader {
  187. id: styleLoader
  188. sourceComponent: style
  189. property var __control: root
  190. property QtObject styleData: QtObject {
  191. readonly property bool hasColor: root.color != "#ffffff"
  192. }
  193. onStatusChanged: if (status === Loader.Error) console.error("Failed to load Style for", root)
  194. }
  195. Qml.Binding {
  196. target: toolBar
  197. property: "parent"
  198. value: __panel.toolBarArea
  199. restoreMode: Binding.RestoreBinding
  200. }
  201. Qml.Binding {
  202. target: statusBar
  203. property: "parent"
  204. value: __panel.statusBarArea
  205. restoreMode: Binding.RestoreBinding
  206. }
  207. Qml.Binding {
  208. property: "parent"
  209. target: menuBar ? menuBar.__contentItem : null
  210. when: menuBar && !menuBar.__isNative
  211. value: __panel.menuBarArea
  212. restoreMode: Binding.RestoreBinding
  213. }
  214. Qml.Binding {
  215. target: menuBar
  216. property: "__parentWindow"
  217. value: root
  218. restoreMode: Binding.RestoreBinding
  219. }
  220. Keys.forwardTo: menuBar ? [menuBar.__contentItem, __panel] : []
  221. ContentItem {
  222. id: contentArea
  223. anchors.fill: parent
  224. parent: __panel.contentArea
  225. }
  226. }
  227. }