Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove spacers in non-LargeSideBar modes for FancyTabWidget #6165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/widgets/fancytabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@

#include <QDebug>

#include <QMap>
#include <QMenu>
#include <QMouseEvent>
#include <QPainter>
#include <QSettings>
#include <QSignalMapper>
#include <QTabBar>
#include <QStylePainter>
#include <QTabBar>
#include <QTimer>
#include <QVBoxLayout>
#include <QSettings>

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

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