1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

VerticalTabs: Hide pinned tabs view when empty

This commit is contained in:
David Rosca 2018-02-03 18:16:18 +01:00
parent f3d5f27cdf
commit e981f638de
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
3 changed files with 41 additions and 2 deletions

View File

@ -23,6 +23,7 @@
#include "webtab.h"
#include "tabcontextmenu.h"
#include <QTimer>
#include <QToolTip>
#include <QHoverEvent>
@ -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);
}

View File

@ -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 &current, const QModelIndex &previous) override;
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) 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;
};

View File

@ -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);