TabViewStyle.qml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 QtQuick 2.2
  40. import QtQuick.Controls 1.2
  41. import QtQuick.Controls.Private 1.0
  42. /*!
  43. \qmltype TabViewStyle
  44. \inqmlmodule QtQuick.Controls.Styles
  45. \since 5.1
  46. \ingroup viewsstyling
  47. \ingroup controlsstyling
  48. \brief Provides custom styling for TabView.
  49. \qml
  50. TabView {
  51. id: frame
  52. anchors.fill: parent
  53. anchors.margins: 4
  54. Tab { title: "Tab 1" }
  55. Tab { title: "Tab 2" }
  56. Tab { title: "Tab 3" }
  57. style: TabViewStyle {
  58. frameOverlap: 1
  59. tab: Rectangle {
  60. color: styleData.selected ? "steelblue" :"lightsteelblue"
  61. border.color: "steelblue"
  62. implicitWidth: Math.max(text.width + 4, 80)
  63. implicitHeight: 20
  64. radius: 2
  65. Text {
  66. id: text
  67. anchors.centerIn: parent
  68. text: styleData.title
  69. color: styleData.selected ? "white" : "black"
  70. }
  71. }
  72. frame: Rectangle { color: "steelblue" }
  73. }
  74. }
  75. \endqml
  76. */
  77. Style {
  78. /*! The \l ScrollView this style is attached to. */
  79. readonly property TabView control: __control
  80. /*! This property holds whether the user can move the tabs.
  81. Tabs are not movable by default. */
  82. property bool tabsMovable: false
  83. /*! This property holds the horizontal alignment of
  84. the tab buttons. Supported values are:
  85. \list
  86. \li Qt.AlignLeft (default)
  87. \li Qt.AlignHCenter
  88. \li Qt.AlignRight
  89. \endlist
  90. */
  91. property int tabsAlignment: Qt.AlignLeft
  92. /*! This property holds the amount of overlap there are between
  93. individual tab buttons. */
  94. property int tabOverlap: 1
  95. /*! This property holds the amount of overlap there are between
  96. individual tab buttons and the frame. */
  97. property int frameOverlap: 2
  98. /*! This defines the tab frame. */
  99. property Component frame: Rectangle {
  100. color: "#dcdcdc"
  101. border.color: "#aaa"
  102. Rectangle {
  103. anchors.fill: parent
  104. color: "transparent"
  105. border.color: "#66ffffff"
  106. anchors.margins: 1
  107. }
  108. }
  109. /*! This defines the tab. You can access the tab state through the
  110. \c styleData property, with the following properties:
  111. \table
  112. \row \li readonly property int \b styleData.index \li This is the current tab index.
  113. \row \li readonly property bool \b styleData.selected \li This is the active tab.
  114. \row \li readonly property string \b styleData.title \li Tab title text.
  115. \row \li readonly property bool \b styleData.nextSelected \li The next tab is selected.
  116. \row \li readonly property bool \b styleData.previousSelected \li The previous tab is selected.
  117. \row \li readonly property bool \b styleData.pressed \li The tab is being pressed. (since QtQuick.Controls.Styles 1.3)
  118. \row \li readonly property bool \b styleData.hovered \li The tab is being hovered.
  119. \row \li readonly property bool \b styleData.enabled \li The tab is enabled. (since QtQuick.Controls.Styles 1.2)
  120. \row \li readonly property bool \b styleData.activeFocus \li The tab button has keyboard focus.
  121. \row \li readonly property bool \b styleData.availableWidth \li The available width for the tabs.
  122. \row \li readonly property bool \b styleData.totalWidth \li The total width of the tabs. (since QtQuick.Controls.Styles 1.2)
  123. \endtable
  124. */
  125. property Component tab: Item {
  126. scale: control.tabPosition === Qt.TopEdge ? 1 : -1
  127. property int totalOverlap: tabOverlap * (control.count - 1)
  128. property real maxTabWidth: control.count > 0 ? (styleData.availableWidth + totalOverlap) / control.count : 0
  129. implicitWidth: Math.round(Math.min(maxTabWidth, textitem.implicitWidth + 20))
  130. implicitHeight: Math.round(textitem.implicitHeight + 10)
  131. Item {
  132. anchors.fill: parent
  133. anchors.bottomMargin: styleData.selected ? 0 : 2
  134. BorderImage {
  135. anchors.fill: parent
  136. source: styleData.selected ? "images/tab_selected.png" : "images/tab.png"
  137. border.top: 6
  138. border.bottom: 6
  139. border.left: 6
  140. border.right: 6
  141. anchors.topMargin: styleData.selected ? 0 : 1
  142. }
  143. }
  144. Text {
  145. id: textitem
  146. anchors.fill: parent
  147. anchors.leftMargin: 4
  148. anchors.rightMargin: 4
  149. verticalAlignment: Text.AlignVCenter
  150. horizontalAlignment: Text.AlignHCenter
  151. text: styleData.title
  152. elide: Text.ElideMiddle
  153. renderType: Settings.isMobile ? Text.QtRendering : Text.NativeRendering
  154. scale: control.tabPosition === Qt.TopEdge ? 1 : -1
  155. color: SystemPaletteSingleton.text(styleData.enabled)
  156. Rectangle {
  157. anchors.centerIn: parent
  158. width: textitem.paintedWidth + 6
  159. height: textitem.paintedHeight + 4
  160. visible: (styleData.activeFocus && styleData.selected)
  161. radius: 3
  162. color: "#224f9fef"
  163. border.color: "#47b"
  164. }
  165. }
  166. }
  167. /*! This defines the left corner. */
  168. property Component leftCorner: null
  169. /*! This defines the right corner. */
  170. property Component rightCorner: null
  171. /*! This defines the tab bar background. */
  172. property Component tabBar: null
  173. }