VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/extensions/QITreeView.h

Last change on this file was 103977, checked in by vboxsync, 2 months ago

Apply RT_OVERRIDE/NS_OVERRIDE where required to shut up clang.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* $Id: QITreeView.h 103977 2024-03-21 02:04:52Z 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: */
41class QITreeViewItem;
42class QITreeView;
43
44
45/** OObject subclass used as item for the QITreeView. */
46class SHARED_LIBRARY_STUFF QITreeViewItem : public QObject
47{
48 Q_OBJECT;
49
50public:
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
83private:
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. */
93class SHARED_LIBRARY_STUFF QITreeView : public QTreeView
94{
95 Q_OBJECT;
96
97signals:
98
99 /** Notifies listeners about index changed from @a previous to @a current.*/
100 void currentItemChanged(const QModelIndex &current, 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
126public:
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 /** Returns child rectangle. */
137 QRect visualRect(const QModelIndex &index) const RT_OVERRIDE { return QTreeView::visualRect(index); }
138
139protected slots:
140
141 /** Handles index changed from @a previous to @a current.*/
142 void currentChanged(const QModelIndex &current, const QModelIndex &previous) RT_OVERRIDE;
143
144protected:
145
146 /** Handles painting of item branches.
147 * @param pPainter Brings the painter to draw branches.
148 * @param rect Brings the rectangle embedding branches.
149 * @param index Brings the index of the item for which branches will be painted. */
150 virtual void drawBranches(QPainter *pPainter, const QRect &rect, const QModelIndex &index) const RT_OVERRIDE;
151
152 /** Handles mouse move @a pEvent. */
153 virtual void mouseMoveEvent(QMouseEvent *pEvent) RT_OVERRIDE;
154 /** Handles mouse press @a pEvent. */
155 virtual void mousePressEvent(QMouseEvent *pEvent) RT_OVERRIDE;
156 /** Handles mouse release @a pEvent. */
157 virtual void mouseReleaseEvent(QMouseEvent *pEvent) RT_OVERRIDE;
158 /** Handles mouse double-click @a pEvent. */
159 virtual void mouseDoubleClickEvent(QMouseEvent *pEvent) RT_OVERRIDE;
160
161 /** Handles mouse drag enter @a pEvent. */
162 virtual void dragEnterEvent(QDragEnterEvent *pEvent) RT_OVERRIDE;
163 /** Handles mouse drag move @a pEvent. */
164 virtual void dragMoveEvent(QDragMoveEvent *pEvent) RT_OVERRIDE;
165 /** Handles mouse drag leave @a pEvent. */
166 virtual void dragLeaveEvent(QDragLeaveEvent *pEvent) RT_OVERRIDE;
167 /** Handles mouse drop @a pEvent. */
168 virtual void dropEvent(QDropEvent *pEvent) RT_OVERRIDE;
169
170private:
171
172 /** Prepares all. */
173 void prepare();
174};
175
176
177#endif /* !FEQT_INCLUDED_SRC_extensions_QITreeView_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use