dynamically show or hide left corner tab list widget

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2016-12-07 22:53:02 +08:00
parent 6c72267788
commit a3b83b7f81
2 changed files with 36 additions and 0 deletions

View File

@ -18,6 +18,8 @@ VEditWindow::VEditWindow(VNote *vnote, QWidget *parent)
setMovable(true); setMovable(true);
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
tabBar()->installEventFilter(this);
connect(this, &VEditWindow::tabCloseRequested, connect(this, &VEditWindow::tabCloseRequested,
this, &VEditWindow::handleTabCloseRequest); this, &VEditWindow::handleTabCloseRequest);
connect(this, &VEditWindow::tabBarClicked, connect(this, &VEditWindow::tabBarClicked,
@ -520,3 +522,33 @@ void VEditWindow::updateNotebookInfo(const VNotebook *p_notebook)
} }
} }
} }
bool VEditWindow::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::Resize) {
setLeftCornerWidgetVisible(scrollerVisible());
}
return QTabWidget::eventFilter(watched, event);
}
bool VEditWindow::scrollerVisible() const
{
QTabBar *bar = tabBar();
int barWidth = bar->width();
int nrTab = count();
int tabsWidth = 0;
for (int i = 0; i < nrTab; ++i) {
tabsWidth += bar->tabRect(i).width();
}
return tabsWidth > barWidth;
}
void VEditWindow::setLeftCornerWidgetVisible(bool p_visible)
{
if (p_visible) {
setCornerWidget(leftBtn, Qt::TopLeftCorner);
leftBtn->setVisible(true);
} else {
setCornerWidget(NULL, Qt::TopLeftCorner);
}
}

View File

@ -42,6 +42,7 @@ public:
protected: protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
signals: signals:
void tabStatusChanged(const VFile *p_file, bool p_editMode); void tabStatusChanged(const VFile *p_file, bool p_editMode);
@ -77,6 +78,9 @@ private:
inline QString generateTooltip(const VFile *p_file) const; inline QString generateTooltip(const VFile *p_file) const;
inline QString generateTabText(const QString &p_name, bool p_modified) const; inline QString generateTabText(const QString &p_name, bool p_modified) const;
bool canRemoveSplit(); bool canRemoveSplit();
// If the scroller of the tabBar() is visible.
bool scrollerVisible() const;
void setLeftCornerWidgetVisible(bool p_visible);
VNote *vnote; VNote *vnote;
// Button in the right corner // Button in the right corner