From 9bf2bbe9bb14425ef228c8e1689bbd14935cac48 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 26 Nov 2012 17:20:15 +0100 Subject: Fix tabs moves when some of them are pinned --- src/tabwindow/tabbar.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'src/tabwindow/tabbar.cpp') diff --git a/src/tabwindow/tabbar.cpp b/src/tabwindow/tabbar.cpp index 70dcd3b1..aaf18dc7 100644 --- a/src/tabwindow/tabbar.cpp +++ b/src/tabwindow/tabbar.cpp @@ -333,10 +333,35 @@ void TabBar::removeAnimation(int index) } +void TabBar::tabInserted(int index) +{ + // Find the available index to move + int availableIndex = index; + for (int i = index; i < count(); i++) + { + if (tabData(i).toBool()) + { + availableIndex++; + break; + } + } + + if (index < availableIndex) + { + TabWindow *w = qobject_cast(parent()); + w->moveTab(index, availableIndex); + } + + KTabBar::tabInserted(index); +} + + void TabBar::tabRemoved(int index) { hideTabPreview(); removeAnimation(index); + + KTabBar::tabRemoved(index); } @@ -396,6 +421,41 @@ void TabBar::mousePressEvent(QMouseEvent *event) } +void TabBar::mouseReleaseEvent(QMouseEvent *event) +{ + // count pinned tabs + int pinnedTabs = 0; + for(int i = 0; i < count(); i++) + { + if (tabData(i).toBool()) + pinnedTabs++; + } + + // fix unpinned ones + for(int i = 0; i < pinnedTabs; i++) + { + if (!tabData(i).toBool()) + { + TabWindow *w = qobject_cast(parent()); + w->moveTab(i, pinnedTabs); + w->setCurrentIndex(pinnedTabs); + } + } + + // fix pinned ones + for (int i = pinnedTabs; i < count(); i++) + { + if (tabData(i).toBool()) + { + TabWindow *w = qobject_cast(parent()); + w->moveTab(i, pinnedTabs - 1); + w->setCurrentIndex(pinnedTabs - 1); + } + } + KTabBar::mouseReleaseEvent(event); +} + + void TabBar::tabLayoutChange() { KTabBar::tabLayoutChange(); -- cgit v1.2.1