From 919624dfcf9f467b426927488d4784ebde488e59 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 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/widgets/fancytabwidget.cpp b/src/widgets/fancytabwidget.cpp index cf06e87e2a..a13e4d792c 100644 --- a/src/widgets/fancytabwidget.cpp +++ b/src/widgets/fancytabwidget.cpp @@ -31,6 +31,7 @@ #include #include #include +#include const QSize FancyTabWidget::IconSize_LargeSidebar = QSize(24,24); const QSize FancyTabWidget::IconSize_SmallSidebar = QSize(22,22); @@ -42,6 +43,7 @@ class FancyTabBar: public QTabBar { private: int mouseHoverTabIndex = -1; QMap labelCache; + QMap spacers; public: explicit FancyTabBar(QWidget* parent=0) : QTabBar(parent) { @@ -102,6 +104,26 @@ 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++) {