Commit fad08d64 authored by J-P Nurmi's avatar J-P Nurmi Committed by The Qt Project
Browse files

TabViewStyle: add support for left and right corner items


Empty corner items may be used as padding, so TabViewStyle::left/rightCorner
effectively replaces TabViewStyle::left/rightPadding.

Change-Id: I01f3a1552c3395352e8953456d3956f4f8c29aed
Reviewed-by: default avatarJens Bache-Wiig <jens.bache-wiig@digia.com>
parent efd0fed4
Branches
Tags
No related merge requests found
Showing with 36 additions and 15 deletions
...@@ -240,7 +240,6 @@ Item { ...@@ -240,7 +240,6 @@ Item {
property Component tabViewStyle: TabViewStyle { property Component tabViewStyle: TabViewStyle {
tabOverlap: 16 tabOverlap: 16
tabsLeftPadding: 12
frameOverlap: 4 frameOverlap: 4
tabsMovable: true tabsMovable: true
...@@ -269,6 +268,7 @@ Item { ...@@ -269,6 +268,7 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
} }
} }
leftCorner: Item { implicitWidth: 12 }
} }
} }
...@@ -48,8 +48,8 @@ import QtQuick.Controls 1.0 ...@@ -48,8 +48,8 @@ import QtQuick.Controls 1.0
*/ */
FocusScope { FocusScope {
id: tabbar id: tabbar
height: tabrow.height height: Math.max(tabrow.height, Math.max(leftCorner.height, rightCorner.height))
width: tabrow.width width: tabView.width
activeFocusOnTab: true activeFocusOnTab: true
...@@ -77,6 +77,8 @@ FocusScope { ...@@ -77,6 +77,8 @@ FocusScope {
property int elide: Text.ElideRight property int elide: Text.ElideRight
property real availableWidth: tabbar.width - leftCorner.width - rightCorner.width
function tab(index) { function tab(index) {
for (var i = 0; i < tabrow.children.length; ++i) { for (var i = 0; i < tabrow.children.length; ++i) {
if (tabrow.children[i].tabindex == index) { if (tabrow.children[i].tabindex == index) {
...@@ -109,7 +111,7 @@ FocusScope { ...@@ -109,7 +111,7 @@ FocusScope {
interactive: false interactive: false
focus: true focus: true
width: contentItem ? contentItem.width : 0 width: Math.min(availableWidth, count ? contentWidth : availableWidth)
height: currentItem ? currentItem.height : 0 height: currentItem ? currentItem.height : 0
displaced: Transition { displaced: Transition {
...@@ -125,7 +127,7 @@ FocusScope { ...@@ -125,7 +127,7 @@ FocusScope {
name: "left" name: "left"
when: tabsAlignment === Qt.AlignLeft when: tabsAlignment === Qt.AlignLeft
AnchorChanges { target:tabrow ; anchors.left: parent.left } AnchorChanges { target:tabrow ; anchors.left: parent.left }
PropertyChanges { target:tabrow ; anchors.leftMargin: styleItem ? styleItem.tabsLeftPadding : 0 } PropertyChanges { target:tabrow ; anchors.leftMargin: leftCorner.width }
}, },
State { State {
name: "center" name: "center"
...@@ -136,7 +138,7 @@ FocusScope { ...@@ -136,7 +138,7 @@ FocusScope {
name: "right" name: "right"
when: tabsAlignment === Qt.AlignRight when: tabsAlignment === Qt.AlignRight
AnchorChanges { target:tabrow ; anchors.right: parent.right } AnchorChanges { target:tabrow ; anchors.right: parent.right }
PropertyChanges { target:tabrow ; anchors.rightMargin: styleItem ? styleItem.tabsRightPadding : 0 } PropertyChanges { target:tabrow ; anchors.rightMargin: rightCorner.width }
} }
] ]
...@@ -161,7 +163,7 @@ FocusScope { ...@@ -161,7 +163,7 @@ FocusScope {
property bool previousSelected: tabView.currentIndex === index - 1 property bool previousSelected: tabView.currentIndex === index - 1
z: selected ? 1 : -index z: selected ? 1 : -index
implicitWidth: Math.min(tabloader.implicitWidth, tabbar.width/tabrow.count) + 1 implicitWidth: Math.min(tabloader.implicitWidth, availableWidth/tabrow.count) + 1
implicitHeight: tabloader.implicitHeight implicitHeight: tabloader.implicitHeight
onPressed: { onPressed: {
...@@ -238,6 +240,24 @@ FocusScope { ...@@ -238,6 +240,24 @@ FocusScope {
} }
} }
Loader {
id: leftCorner
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
sourceComponent: styleItem ? styleItem.leftCorner : undefined
width: item ? item.implicitWidth : 0
height: item ? item.implicitHeight : 0
}
Loader {
id: rightCorner
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
sourceComponent: styleItem ? styleItem.rightCorner : undefined
width: item ? item.implicitWidth : 0
height: item ? item.implicitHeight : 0
}
DropArea { DropArea {
anchors.fill: tabrow anchors.fill: tabrow
keys: "application/x-tabbartab" keys: "application/x-tabbartab"
......
...@@ -97,12 +97,6 @@ Style { ...@@ -97,12 +97,6 @@ Style {
*/ */
property int tabsAlignment: Qt.AlignLeft property int tabsAlignment: Qt.AlignLeft
/*! This property holds the left padding of the tab bar. */
property int tabsLeftPadding: 0
/*! This property holds the right padding of the tab bar. */
property int tabsRightPadding: 0
/*! This property holds the amount of overlap there are between /*! This property holds the amount of overlap there are between
individual tab buttons. */ individual tab buttons. */
property int tabOverlap: 1 property int tabOverlap: 1
...@@ -179,4 +173,10 @@ Style { ...@@ -179,4 +173,10 @@ Style {
color: __syspal.text color: __syspal.text
} }
} }
/*! This defines the left corner. */
property Component leftCorner: null
/*! This defines the right corner. */
property Component rightCorner: null
} }
...@@ -45,8 +45,6 @@ Style { ...@@ -45,8 +45,6 @@ Style {
id: root id: root
property bool tabsMovable: false property bool tabsMovable: false
property int tabsLeftPadding: 0
property int tabsRightPadding: 0
property int tabsAlignment: __barstyle.styleHint("tabbaralignment") === "center" ? Qt.AlignHCenter : Qt.AlignLeft; property int tabsAlignment: __barstyle.styleHint("tabbaralignment") === "center" ? Qt.AlignHCenter : Qt.AlignLeft;
property int tabOverlap: __barstyle.pixelMetric("taboverlap"); property int tabOverlap: __barstyle.pixelMetric("taboverlap");
property int frameOverlap: __barstyle.pixelMetric("tabbaseoverlap"); property int frameOverlap: __barstyle.pixelMetric("tabbaseoverlap");
...@@ -98,4 +96,7 @@ Style { ...@@ -98,4 +96,7 @@ Style {
hasFocus: tabbarItem.activeFocus && selected hasFocus: tabbarItem.activeFocus && selected
} }
} }
property Component leftCorner: null
property Component rightCorner: null
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment