Skip to content

Commit

Permalink
Remove spacers in non-LargeSideBar modes for FancyTabWidget
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amhndu committed Oct 7, 2018
1 parent fb00835 commit 919624d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/widgets/fancytabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QTimer>
#include <QVBoxLayout>
#include <QSettings>
#include <QMap>

const QSize FancyTabWidget::IconSize_LargeSidebar = QSize(24,24);
const QSize FancyTabWidget::IconSize_SmallSidebar = QSize(22,22);
Expand All @@ -42,6 +43,7 @@ class FancyTabBar: public QTabBar {
private:
int mouseHoverTabIndex = -1;
QMap<QWidget*,QString> labelCache;
QMap<int, QWidget*> spacers;

public:
explicit FancyTabBar(QWidget* parent=0) : QTabBar(parent) {
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit 919624d

Please sign in to comment.