From bc631e446756ba24859e9d16261523b563d3cb15 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 11 Oct 2012 10:36:36 +0200 Subject: [PATCH] try to keep current tab in the middle if possible --- declarativeimports/plasmacomponents/qml/TabBar.qml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/declarativeimports/plasmacomponents/qml/TabBar.qml b/declarativeimports/plasmacomponents/qml/TabBar.qml index 6095a5194..b65981c81 100644 --- a/declarativeimports/plasmacomponents/qml/TabBar.qml +++ b/declarativeimports/plasmacomponents/qml/TabBar.qml @@ -106,9 +106,10 @@ FocusScope { } } - onCurrentTabChanged: tabBarLayout.x = Math.min(0, -(currentTab.x + currentTab.width - tabbarScroller.width)) + onCurrentTabChanged: tabBarLayout.x = Math.max(Math.min(0, -(currentTab.x + currentTab.width/2) + tabbarScroller.width/2), -tabBarLayout.width + tabbarScroller.width) - onWidthChanged: tabBarLayout.x = Math.min(0, -(currentTab.x + currentTab.width - tabbarScroller.width)) + + onWidthChanged: tabBarLayout.x = Math.max(Math.min(0, -(currentTab.x + currentTab.width/2) + tabbarScroller.width/2), -tabBarLayout.width + tabbarScroller.width) Item { id: tabbarScroller @@ -128,12 +129,19 @@ FocusScope { top: parent.top bottom: parent.bottom } + Behavior on x { + NumberAnimation { + duration: 250 + easing: Easing.InOutQuad + } + } } } Row { id: buttonsLayout visible: tabBarLayout.width > root.width - backgroundFrame.margins.left - backgroundFrame.margins.right height: Math.min(parent.height, theme.mediumIconSize) + anchors { right: parent.right verticalCenter: parent.verticalCenter @@ -143,12 +151,14 @@ FocusScope { height: parent.height width: height iconSource: "go-previous" + enabled: tabBarLayout.x < 0 onClicked: tabBarLayout.x = Math.min(0, tabBarLayout.x + tabBarLayout.width/tabBarLayout.children.length) } ToolButton { height: parent.height width: height iconSource: "go-next" + enabled: tabBarLayout.x > -tabBarLayout.width + tabbarScroller.width onClicked: tabBarLayout.x = Math.max(-tabBarLayout.width + tabbarScroller.width, tabBarLayout.x - tabBarLayout.width/tabBarLayout.children.length) } }