From e981f638ded2c97a4fcb65c0eaa91767c4860fdc Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sat, 3 Feb 2018 18:16:18 +0100 Subject: [PATCH] VerticalTabs: Hide pinned tabs view when empty --- src/plugins/VerticalTabs/tablistview.cpp | 32 +++++++++++++++++++ src/plugins/VerticalTabs/tablistview.h | 10 ++++-- .../VerticalTabs/verticaltabswidget.cpp | 1 + 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/plugins/VerticalTabs/tablistview.cpp b/src/plugins/VerticalTabs/tablistview.cpp index 54d60fab5..fa3b901c2 100644 --- a/src/plugins/VerticalTabs/tablistview.cpp +++ b/src/plugins/VerticalTabs/tablistview.cpp @@ -23,6 +23,7 @@ #include "webtab.h" #include "tabcontextmenu.h" +#include #include #include @@ -46,6 +47,17 @@ TabListView::TabListView(QWidget *parent) setFixedHeight(m_delegate->sizeHint(viewOptions(), QModelIndex()).height()); } +bool TabListView::isHidingWhenEmpty() const +{ + return m_hideWhenEmpty; +} + +void TabListView::setHideWhenEmpty(bool enable) +{ + m_hideWhenEmpty = enable; + updateVisibility(); +} + void TabListView::updateIndex(const QModelIndex &index) { QRect rect = visualRect(index); @@ -100,6 +112,20 @@ void TabListView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bot } } +void TabListView::rowsInserted(const QModelIndex &parent, int start, int end) +{ + QListView::rowsInserted(parent, start, end); + + updateVisibility(); +} + +void TabListView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) +{ + QListView::rowsAboutToBeRemoved(parent, start, end); + + QTimer::singleShot(0, this, &TabListView::updateVisibility); +} + bool TabListView::viewportEvent(QEvent *event) { switch (event->type()) { @@ -182,3 +208,9 @@ TabListView::DelegateButton TabListView::buttonAt(const QPoint &pos, const QMode } return NoButton; } + +void TabListView::updateVisibility() +{ + setVisible(!m_hideWhenEmpty || model()->rowCount() > 0); +} + diff --git a/src/plugins/VerticalTabs/tablistview.h b/src/plugins/VerticalTabs/tablistview.h index 78b5e6f31..0599df444 100644 --- a/src/plugins/VerticalTabs/tablistview.h +++ b/src/plugins/VerticalTabs/tablistview.h @@ -28,23 +28,29 @@ class TabListView : public QListView public: explicit TabListView(QWidget *parent = nullptr); + bool isHidingWhenEmpty() const; + void setHideWhenEmpty(bool enable); + void updateIndex(const QModelIndex &index); void adjustStyleOption(QStyleOptionViewItem *option); private: void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override; void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()) override; + void rowsInserted(const QModelIndex &parent, int start, int end) override; + void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override; bool viewportEvent(QEvent *event) override; - TabListDelegate *m_delegate; - enum DelegateButton { NoButton, AudioButton }; DelegateButton buttonAt(const QPoint &pos, const QModelIndex &index) const; + void updateVisibility(); + TabListDelegate *m_delegate; DelegateButton m_pressedButton = NoButton; QModelIndex m_pressedIndex; + bool m_hideWhenEmpty = false; }; diff --git a/src/plugins/VerticalTabs/verticaltabswidget.cpp b/src/plugins/VerticalTabs/verticaltabswidget.cpp index e2c2d8a1b..31e156adf 100644 --- a/src/plugins/VerticalTabs/verticaltabswidget.cpp +++ b/src/plugins/VerticalTabs/verticaltabswidget.cpp @@ -41,6 +41,7 @@ VerticalTabsWidget::VerticalTabsWidget(BrowserWindow *window) model->setFilterPinnedTabs(false); model->setSourceModel(m_window->tabModel()); m_pinnedView->setModel(model); + m_pinnedView->setHideWhenEmpty(true); m_normalView = new TabTreeView(this); m_pinnedView->setFocusProxy(m_normalView);