File indexing completed on 2024-05-19 04:59:22
0001 /* ============================================================ 0002 * VerticalTabs plugin for Falkon 0003 * Copyright (C) 2018 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #pragma once 0019 0020 #include <QTreeView> 0021 0022 class QMenu; 0023 0024 class BrowserWindow; 0025 0026 class TabTreeDelegate; 0027 0028 class TabTreeView : public QTreeView 0029 { 0030 Q_OBJECT 0031 Q_PROPERTY(int backgroundIndentation READ backgroundIndentation WRITE setBackgroundIndentation) 0032 0033 public: 0034 explicit TabTreeView(BrowserWindow *window, QWidget *parent = nullptr); 0035 0036 int backgroundIndentation() const; 0037 void setBackgroundIndentation(int indentation); 0038 0039 // In TabBar order 0040 bool areTabsInOrder() const; 0041 void setTabsInOrder(bool enable); 0042 0043 bool haveTreeModel() const; 0044 void setHaveTreeModel(bool enable); 0045 0046 void setModel(QAbstractItemModel *model) override; 0047 0048 void updateIndex(const QModelIndex &index); 0049 void adjustStyleOption(QStyleOptionViewItem *option); 0050 0051 private: 0052 void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const override; 0053 void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override; 0054 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override; 0055 void rowsInserted(const QModelIndex &parent, int start, int end) override; 0056 bool viewportEvent(QEvent *event) override; 0057 0058 enum DelegateButton { 0059 NoButton, 0060 ExpandButton, 0061 AudioButton, 0062 CloseButton 0063 }; 0064 0065 void initView(); 0066 DelegateButton buttonAt(const QPoint &pos, const QModelIndex &index) const; 0067 void addMenuActions(QMenu *menu, const QModelIndex &index); 0068 void reverseTraverse(const QModelIndex &root, const std::function<void(const QModelIndex&)> &callback) const; 0069 0070 void closeTree(const QModelIndex &root); 0071 void unloadTree(const QModelIndex &root); 0072 0073 BrowserWindow *m_window; 0074 TabTreeDelegate *m_delegate; 0075 DelegateButton m_pressedButton = NoButton; 0076 QPersistentModelIndex m_pressedIndex; 0077 QPersistentModelIndex m_hoveredIndex; 0078 bool m_tabsInOrder = false; 0079 bool m_haveTreeModel = false; 0080 int m_backgroundIndentation = 0; 0081 QString m_expandedSessionKey; 0082 bool m_initializing = false; 0083 };