From f13e8d762ee7d51ca33d85f249f6b025895bb214 Mon Sep 17 00:00:00 2001 From: Amish Naidu Date: Sun, 7 Oct 2018 13:36:00 +0530 Subject: [PATCH] Remove spacers in non-LargeSideBar modes for FancyTabWidget To maintain behavior with the older FancyTabWidget, spacers are now removed and stored when switching to a non-LargeSideBar mode. And subsequently restored when switching back to LargeSideBar mode. --- src/widgets/fancytabwidget.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/widgets/fancytabwidget.cpp b/src/widgets/fancytabwidget.cpp index 05db6012ca..65e3cd61f4 100644 --- a/src/widgets/fancytabwidget.cpp +++ b/src/widgets/fancytabwidget.cpp @@ -22,15 +22,16 @@ #include +#include #include #include #include +#include #include -#include #include +#include #include #include -#include const QSize FancyTabWidget::IconSize_LargeSidebar = QSize(24,24); const QSize FancyTabWidget::IconSize_SmallSidebar = QSize(22,22); @@ -42,8 +43,9 @@ class FancyTabBar: public QTabBar { private: int mouseHoverTabIndex = -1; QMap labelCache; + QMap spacers; -public: + public: explicit FancyTabBar(QWidget* parent=0) : QTabBar(parent) { setMouseTracking(true); } @@ -102,6 +104,27 @@ class FancyTabBar: public QTabBar { if(tabWidget->mode() == FancyTabWidget::Mode_SmallSidebar) verticalTextTabs = true; + // if LargeSidebar, restore spacers + if (spacers.count() > 0 && + tabWidget->mode() == FancyTabWidget::Mode_LargeSidebar) { + for (int index : spacers.keys()) { + tabWidget->insertTab(index, spacers[index], QIcon(), QString()); + tabWidget->setTabEnabled(index, false); + } + spacers.clear(); + } + if (tabWidget->mode() != FancyTabWidget::Mode_LargeSidebar) { + // traverse in the opposite order to save indices of spacers + for (int i = count() - 1; i >= 0; --i) { + // spacers are disabled tabs + if (!isTabEnabled(i) && !spacers.contains(i)) { + spacers[i] = tabWidget->widget(i); + tabWidget->removeTab(i); + --i; + } + } + } + // Restore any label text that was hidden/cached for the IconOnlyTabs mode if(labelCache.count() > 0 && tabWidget->mode() != FancyTabWidget::Mode_IconOnlyTabs) { for(int i =0; i < count(); i++) {