1 | /* $Id: UIDetailsView.cpp 102477 2023-12-05 13:54:50Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIDetailsView class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-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 | /* Qt includes: */
|
---|
29 | #include <QAccessibleWidget>
|
---|
30 | #include <QScrollBar>
|
---|
31 |
|
---|
32 | /* GUI includes: */
|
---|
33 | #include "UICommon.h"
|
---|
34 | #include "UIDetails.h"
|
---|
35 | #include "UIDetailsItem.h"
|
---|
36 | #include "UIDetailsModel.h"
|
---|
37 | #include "UIDetailsView.h"
|
---|
38 |
|
---|
39 | /* Other VBox includes: */
|
---|
40 | #include <iprt/assert.h>
|
---|
41 |
|
---|
42 |
|
---|
43 | /** QAccessibleWidget extension used as an accessibility interface for Details-view. */
|
---|
44 | class UIAccessibilityInterfaceForUIDetailsView : public QAccessibleWidget
|
---|
45 | {
|
---|
46 | public:
|
---|
47 |
|
---|
48 | /** Returns an accessibility interface for passed @a strClassname and @a pObject. */
|
---|
49 | static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)
|
---|
50 | {
|
---|
51 | /* Creating Details-view accessibility interface: */
|
---|
52 | if (pObject && strClassname == QLatin1String("UIDetailsView"))
|
---|
53 | return new UIAccessibilityInterfaceForUIDetailsView(qobject_cast<QWidget*>(pObject));
|
---|
54 |
|
---|
55 | /* Null by default: */
|
---|
56 | return 0;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /** Constructs an accessibility interface passing @a pWidget to the base-class. */
|
---|
60 | UIAccessibilityInterfaceForUIDetailsView(QWidget *pWidget)
|
---|
61 | : QAccessibleWidget(pWidget, QAccessible::List)
|
---|
62 | {}
|
---|
63 |
|
---|
64 | /** Returns the number of children. */
|
---|
65 | virtual int childCount() const RT_OVERRIDE
|
---|
66 | {
|
---|
67 | /* Make sure view still alive: */
|
---|
68 | AssertPtrReturn(view(), 0);
|
---|
69 |
|
---|
70 | /* What amount of children root has? */
|
---|
71 | const int cChildCount = view()->details()->model()->root()->items().size();
|
---|
72 |
|
---|
73 | /* Return amount of children root has (if there are many of children): */
|
---|
74 | if (cChildCount > 1)
|
---|
75 | return cChildCount;
|
---|
76 |
|
---|
77 | /* Return the number of children lone root child has (otherwise): */
|
---|
78 | return view()->details()->model()->root()->items().first()->items().size();
|
---|
79 | }
|
---|
80 |
|
---|
81 | /** Returns the child with the passed @a iIndex. */
|
---|
82 | virtual QAccessibleInterface *child(int iIndex) const RT_OVERRIDE
|
---|
83 | {
|
---|
84 | /* Make sure view still alive: */
|
---|
85 | AssertPtrReturn(view(), 0);
|
---|
86 | /* Make sure index is valid: */
|
---|
87 | AssertReturn(iIndex >= 0 && iIndex < childCount(), 0);
|
---|
88 |
|
---|
89 | /* What amount of children root has? */
|
---|
90 | const int cChildCount = view()->details()->model()->root()->items().size();
|
---|
91 |
|
---|
92 | /* Return the root child with the passed iIndex (if there are many of children): */
|
---|
93 | if (cChildCount > 1)
|
---|
94 | return QAccessible::queryAccessibleInterface(view()->details()->model()->root()->items().at(iIndex));
|
---|
95 |
|
---|
96 | /* Return the lone root child's child with the passed iIndex (otherwise): */
|
---|
97 | return QAccessible::queryAccessibleInterface(view()->details()->model()->root()->items().first()->items().at(iIndex));
|
---|
98 | }
|
---|
99 |
|
---|
100 | /** Returns the index of passed @a pChild. */
|
---|
101 | virtual int indexOfChild(const QAccessibleInterface *pChild) const RT_OVERRIDE
|
---|
102 | {
|
---|
103 | /* Make sure view still alive: */
|
---|
104 | AssertPtrReturn(view(), -1);
|
---|
105 | /* Make sure child is valid: */
|
---|
106 | AssertReturn(pChild, -1);
|
---|
107 |
|
---|
108 | /* Acquire item itself: */
|
---|
109 | UIDetailsItem *pChildItem = qobject_cast<UIDetailsItem*>(pChild->object());
|
---|
110 |
|
---|
111 | /* Return the index of item in it's parent: */
|
---|
112 | return pChildItem && pChildItem->parentItem()
|
---|
113 | ? pChildItem->parentItem()->items().indexOf(pChildItem)
|
---|
114 | : -1;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /** Returns a text for the passed @a enmTextRole. */
|
---|
118 | virtual QString text(QAccessible::Text enmTextRole) const RT_OVERRIDE
|
---|
119 | {
|
---|
120 | /* Make sure view still alive: */
|
---|
121 | AssertPtrReturn(view(), QString());
|
---|
122 |
|
---|
123 | /* Return view tool-tip: */
|
---|
124 | Q_UNUSED(enmTextRole);
|
---|
125 | return view()->whatsThis();
|
---|
126 | }
|
---|
127 |
|
---|
128 | private:
|
---|
129 |
|
---|
130 | /** Returns corresponding Details-view. */
|
---|
131 | UIDetailsView *view() const { return qobject_cast<UIDetailsView*>(widget()); }
|
---|
132 | };
|
---|
133 |
|
---|
134 |
|
---|
135 | UIDetailsView::UIDetailsView(UIDetails *pParent)
|
---|
136 | : QIWithRetranslateUI<QIGraphicsView>(pParent)
|
---|
137 | , m_pDetails(pParent)
|
---|
138 | , m_iMinimumWidthHint(0)
|
---|
139 | {
|
---|
140 | prepare();
|
---|
141 | }
|
---|
142 |
|
---|
143 | void UIDetailsView::sltMinimumWidthHintChanged(int iHint)
|
---|
144 | {
|
---|
145 | /* Is there something changed? */
|
---|
146 | if (m_iMinimumWidthHint == iHint)
|
---|
147 | return;
|
---|
148 |
|
---|
149 | /* Remember new value: */
|
---|
150 | m_iMinimumWidthHint = iHint;
|
---|
151 | if (m_iMinimumWidthHint <= 0)
|
---|
152 | m_iMinimumWidthHint = 1;
|
---|
153 |
|
---|
154 | /* Set minimum view width according passed width-hint: */
|
---|
155 | setMinimumWidth(2 * frameWidth() + m_iMinimumWidthHint + verticalScrollBar()->sizeHint().width());
|
---|
156 |
|
---|
157 | /* Update scene-rect: */
|
---|
158 | updateSceneRect();
|
---|
159 | }
|
---|
160 |
|
---|
161 | void UIDetailsView::retranslateUi()
|
---|
162 | {
|
---|
163 | /* Translate this: */
|
---|
164 | setWhatsThis(tr("Contains a list of Virtual Machine details."));
|
---|
165 | }
|
---|
166 |
|
---|
167 | void UIDetailsView::resizeEvent(QResizeEvent *pEvent)
|
---|
168 | {
|
---|
169 | /* Call to base-class: */
|
---|
170 | QIWithRetranslateUI<QIGraphicsView>::resizeEvent(pEvent);
|
---|
171 | /* Notify listeners: */
|
---|
172 | emit sigResized();
|
---|
173 |
|
---|
174 | /* Update everything: */
|
---|
175 | updateSceneRect();
|
---|
176 | }
|
---|
177 |
|
---|
178 | void UIDetailsView::prepare()
|
---|
179 | {
|
---|
180 | /* Install Details-view accessibility interface factory: */
|
---|
181 | QAccessible::installFactory(UIAccessibilityInterfaceForUIDetailsView::pFactory);
|
---|
182 |
|
---|
183 | /* Prepares everything: */
|
---|
184 | prepareThis();
|
---|
185 |
|
---|
186 | /* Update everything: */
|
---|
187 | updateSceneRect();
|
---|
188 |
|
---|
189 | /* Translate finally: */
|
---|
190 | retranslateUi();
|
---|
191 | }
|
---|
192 |
|
---|
193 | void UIDetailsView::prepareThis()
|
---|
194 | {
|
---|
195 | /* Prepare palette: */
|
---|
196 | preparePalette();
|
---|
197 |
|
---|
198 | /* Prepare frame: */
|
---|
199 | setFrameShape(QFrame::NoFrame);
|
---|
200 | setFrameShadow(QFrame::Plain);
|
---|
201 | setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
---|
202 |
|
---|
203 | /* Prepare scroll-bars policy: */
|
---|
204 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
---|
205 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
---|
206 |
|
---|
207 | /* Prepare connections: */
|
---|
208 | connect(&uiCommon(), &UICommon::sigThemeChange,
|
---|
209 | this, &UIDetailsView::sltUpdatePalette);
|
---|
210 | }
|
---|
211 |
|
---|
212 | void UIDetailsView::preparePalette()
|
---|
213 | {
|
---|
214 | QPalette pal = QApplication::palette();
|
---|
215 | pal.setColor(QPalette::Active, QPalette::Base, pal.color(QPalette::Active, QPalette::Window));
|
---|
216 | pal.setColor(QPalette::Inactive, QPalette::Base, pal.color(QPalette::Inactive, QPalette::Window));
|
---|
217 | setPalette(pal);
|
---|
218 | }
|
---|
219 |
|
---|
220 | void UIDetailsView::updateSceneRect()
|
---|
221 | {
|
---|
222 | setSceneRect(0, 0, m_iMinimumWidthHint, height());
|
---|
223 | }
|
---|