1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

VerticalTabs: Automatically scroll to current tab

This commit is contained in:
David Rosca 2018-02-02 11:51:32 +01:00
parent 66023d2dba
commit ebd2b6da51
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 17 additions and 3 deletions

View File

@ -58,10 +58,22 @@ void TabTreeView::drawBranches(QPainter *, const QRect &, const QModelIndex &) c
// Disable drawing branches // Disable drawing branches
} }
void TabTreeView::currentChanged(const QModelIndex &, const QModelIndex &) void TabTreeView::currentChanged(const QModelIndex &current, const QModelIndex &previous)
{ {
// Disable current index if (current.data(TabModel::CurrentTabRole).toBool()) {
setCurrentIndex(QModelIndex()); QTreeView::currentChanged(current, previous);
} else if (previous.data(TabModel::CurrentTabRole).toBool()) {
setCurrentIndex(previous);
}
}
void TabTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{
QTreeView::dataChanged(topLeft, bottomRight, roles);
if (roles.size() == 1 && roles.at(0) == TabModel::CurrentTabRole && topLeft.data(TabModel::CurrentTabRole).toBool()) {
setCurrentIndex(topLeft);
}
} }
bool TabTreeView::viewportEvent(QEvent *event) bool TabTreeView::viewportEvent(QEvent *event)

View File

@ -35,6 +35,8 @@ public:
private: private:
void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const override; void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const override;
void currentChanged(const QModelIndex &current, const QModelIndex &previous) override; void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
bool viewportEvent(QEvent *event) override; bool viewportEvent(QEvent *event) override;
enum DelegateButton { enum DelegateButton {