1 | /* $Id: QITreeView.h 104513 2024-05-03 16:09:10Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QITreeView class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_extensions_QITreeView_h
|
---|
29 | #define FEQT_INCLUDED_SRC_extensions_QITreeView_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QTreeView>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "UILibraryDefs.h"
|
---|
39 |
|
---|
40 | /* Forward declarations: */
|
---|
41 | class QITreeViewItem;
|
---|
42 | class QITreeView;
|
---|
43 |
|
---|
44 |
|
---|
45 | /** OObject subclass used as item for the QITreeView. */
|
---|
46 | class SHARED_LIBRARY_STUFF QITreeViewItem : public QObject
|
---|
47 | {
|
---|
48 | Q_OBJECT;
|
---|
49 |
|
---|
50 | public:
|
---|
51 |
|
---|
52 | /** Constructs tree-view item for passed @a pParent. */
|
---|
53 | QITreeViewItem(QITreeView *pParent)
|
---|
54 | : m_pParentTree(pParent)
|
---|
55 | , m_pParentItem(0)
|
---|
56 | {}
|
---|
57 |
|
---|
58 | /** Constructs tree-view item for passed @a pParent. */
|
---|
59 | QITreeViewItem(QITreeViewItem *pParentItem)
|
---|
60 | : m_pParentTree(pParentItem ? pParentItem->parentTree() : 0)
|
---|
61 | , m_pParentItem(pParentItem)
|
---|
62 | {}
|
---|
63 |
|
---|
64 | /** Returns the parent tree-view. */
|
---|
65 | QITreeView *parentTree() const { return m_pParentTree; }
|
---|
66 | /** Returns the parent tree-view item. */
|
---|
67 | QITreeViewItem *parentItem() const { return m_pParentItem; }
|
---|
68 |
|
---|
69 | /** Returns the number of children. */
|
---|
70 | virtual int childCount() const = 0;
|
---|
71 | /** Returns the child item with @a iIndex. */
|
---|
72 | virtual QITreeViewItem *childItem(int iIndex) const = 0;
|
---|
73 |
|
---|
74 | /** Returns the item text. */
|
---|
75 | virtual QString text() const = 0;
|
---|
76 |
|
---|
77 | /** Returns the rectangle. */
|
---|
78 | QRect rect() const;
|
---|
79 |
|
---|
80 | /** Returns the model-index: */
|
---|
81 | QModelIndex modelIndex() const;
|
---|
82 |
|
---|
83 | private:
|
---|
84 |
|
---|
85 | /** Holds the parent tree reference. */
|
---|
86 | QITreeView *m_pParentTree;
|
---|
87 | /** Holds the parent item reference. */
|
---|
88 | QITreeViewItem *m_pParentItem;
|
---|
89 | };
|
---|
90 |
|
---|
91 |
|
---|
92 | /** QTreeView subclass extending standard functionality. */
|
---|
93 | class SHARED_LIBRARY_STUFF QITreeView : public QTreeView
|
---|
94 | {
|
---|
95 | Q_OBJECT;
|
---|
96 |
|
---|
97 | signals:
|
---|
98 |
|
---|
99 | /** Notifies listeners about index changed from @a previous to @a current.*/
|
---|
100 | void currentItemChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
---|
101 |
|
---|
102 | /** Notifies listeners about painting of item branches.
|
---|
103 | * @param pPainter Brings the painter to draw branches.
|
---|
104 | * @param rect Brings the rectangle embedding branches.
|
---|
105 | * @param index Brings the index of the item for which branches will be painted. */
|
---|
106 | void drawItemBranches(QPainter *pPainter, const QRect &rect, const QModelIndex &index) const;
|
---|
107 |
|
---|
108 | /** Notifies listeners about mouse moved @a pEvent. */
|
---|
109 | void mouseMoved(QMouseEvent *pEvent);
|
---|
110 | /** Notifies listeners about mouse pressed @a pEvent. */
|
---|
111 | void mousePressed(QMouseEvent *pEvent);
|
---|
112 | /** Notifies listeners about mouse released @a pEvent. */
|
---|
113 | void mouseReleased(QMouseEvent *pEvent);
|
---|
114 | /** Notifies listeners about mouse double-clicked @a pEvent. */
|
---|
115 | void mouseDoubleClicked(QMouseEvent *pEvent);
|
---|
116 |
|
---|
117 | /** Notifies listeners about mouse drag entered @a pEvent. */
|
---|
118 | void dragEntered(QDragEnterEvent *pEvent);
|
---|
119 | /** Notifies listeners about mouse drag moved @a pEvent. */
|
---|
120 | void dragMoved(QDragMoveEvent *pEvent);
|
---|
121 | /** Notifies listeners about mouse drag left @a pEvent. */
|
---|
122 | void dragLeft(QDragLeaveEvent *pEvent);
|
---|
123 | /** Notifies listeners about mouse drag dropped @a pEvent. */
|
---|
124 | void dragDropped(QDropEvent *pEvent);
|
---|
125 |
|
---|
126 | public:
|
---|
127 |
|
---|
128 | /** Constructs tree-view passing @a pParent to the base-class. */
|
---|
129 | QITreeView(QWidget *pParent = 0);
|
---|
130 |
|
---|
131 | /** Returns the number of children. */
|
---|
132 | virtual int childCount() const { return 0; }
|
---|
133 | /** Returns the child item with @a iIndex. */
|
---|
134 | virtual QITreeViewItem *childItem(int /* iIndex */) const { return 0; }
|
---|
135 |
|
---|
136 | protected slots:
|
---|
137 |
|
---|
138 | /** Handles index changed from @a previous to @a current.*/
|
---|
139 | void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) RT_OVERRIDE;
|
---|
140 |
|
---|
141 | protected:
|
---|
142 |
|
---|
143 | /** Handles painting of item branches.
|
---|
144 | * @param pPainter Brings the painter to draw branches.
|
---|
145 | * @param rect Brings the rectangle embedding branches.
|
---|
146 | * @param index Brings the index of the item for which branches will be painted. */
|
---|
147 | virtual void drawBranches(QPainter *pPainter, const QRect &rect, const QModelIndex &index) const RT_OVERRIDE;
|
---|
148 |
|
---|
149 | /** Handles mouse move @a pEvent. */
|
---|
150 | virtual void mouseMoveEvent(QMouseEvent *pEvent) RT_OVERRIDE;
|
---|
151 | /** Handles mouse press @a pEvent. */
|
---|
152 | virtual void mousePressEvent(QMouseEvent *pEvent) RT_OVERRIDE;
|
---|
153 | /** Handles mouse release @a pEvent. */
|
---|
154 | virtual void mouseReleaseEvent(QMouseEvent *pEvent) RT_OVERRIDE;
|
---|
155 | /** Handles mouse double-click @a pEvent. */
|
---|
156 | virtual void mouseDoubleClickEvent(QMouseEvent *pEvent) RT_OVERRIDE;
|
---|
157 |
|
---|
158 | /** Handles mouse drag enter @a pEvent. */
|
---|
159 | virtual void dragEnterEvent(QDragEnterEvent *pEvent) RT_OVERRIDE;
|
---|
160 | /** Handles mouse drag move @a pEvent. */
|
---|
161 | virtual void dragMoveEvent(QDragMoveEvent *pEvent) RT_OVERRIDE;
|
---|
162 | /** Handles mouse drag leave @a pEvent. */
|
---|
163 | virtual void dragLeaveEvent(QDragLeaveEvent *pEvent) RT_OVERRIDE;
|
---|
164 | /** Handles mouse drop @a pEvent. */
|
---|
165 | virtual void dropEvent(QDropEvent *pEvent) RT_OVERRIDE;
|
---|
166 |
|
---|
167 | private:
|
---|
168 |
|
---|
169 | /** Prepares all. */
|
---|
170 | void prepare();
|
---|
171 | };
|
---|
172 |
|
---|
173 |
|
---|
174 | #endif /* !FEQT_INCLUDED_SRC_extensions_QITreeView_h */
|
---|