Falkon Develop
Cross-platform Qt-based web browser
tabtreeview.h
Go to the documentation of this file.
1/* ============================================================
2* VerticalTabs plugin for Falkon
3* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#pragma once
19
20#include <QTreeView>
21
22class QMenu;
23
24class BrowserWindow;
25
26class TabTreeDelegate;
27
28class TabTreeView : public QTreeView
29{
30 Q_OBJECT
32
33public:
34 explicit TabTreeView(BrowserWindow *window, QWidget *parent = nullptr);
35
36 int backgroundIndentation() const;
37 void setBackgroundIndentation(int indentation);
38
39 // In TabBar order
40 bool areTabsInOrder() const;
41 void setTabsInOrder(bool enable);
42
43 bool haveTreeModel() const;
44 void setHaveTreeModel(bool enable);
45
46 void setModel(QAbstractItemModel *model) override;
47
48 void updateIndex(const QModelIndex &index);
49 void adjustStyleOption(QStyleOptionViewItem *option);
50
51private:
52 void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const override;
53 void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;
54 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
55 void rowsInserted(const QModelIndex &parent, int start, int end) override;
56 bool viewportEvent(QEvent *event) override;
57
58 enum DelegateButton {
59 NoButton,
60 ExpandButton,
61 AudioButton,
63 };
64
65 void initView();
66 DelegateButton buttonAt(const QPoint &pos, const QModelIndex &index) const;
67 void addMenuActions(QMenu *menu, const QModelIndex &index);
68 void reverseTraverse(const QModelIndex &root, const std::function<void(const QModelIndex&)> &callback) const;
69
70 void closeTree(const QModelIndex &root);
71 void unloadTree(const QModelIndex &root);
72
73 BrowserWindow *m_window;
74 TabTreeDelegate *m_delegate;
75 DelegateButton m_pressedButton = NoButton;
76 QPersistentModelIndex m_pressedIndex;
77 QPersistentModelIndex m_hoveredIndex;
78 bool m_tabsInOrder = false;
79 bool m_haveTreeModel = false;
80 int m_backgroundIndentation = 0;
81 QString m_expandedSessionKey;
82 bool m_initializing = false;
83};
int backgroundIndentation
Definition: tabtreeview.h:31
void setModel(QAbstractItemModel *model) override
void setHaveTreeModel(bool enable)
Definition: tabtreeview.cpp:96
bool areTabsInOrder() const
Definition: tabtreeview.cpp:81
TabTreeView(BrowserWindow *window, QWidget *parent=nullptr)
Definition: tabtreeview.cpp:31
bool haveTreeModel() const
Definition: tabtreeview.cpp:91
void updateIndex(const QModelIndex &index)
void setBackgroundIndentation(int indentation)
Definition: tabtreeview.cpp:76
void setTabsInOrder(bool enable)
Definition: tabtreeview.cpp:86
void adjustStyleOption(QStyleOptionViewItem *option)