VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsItem.cpp@ 103977

Last change on this file since 103977 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svn:mergeinfo set to (toggle deleted branches)
    /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.cpp58652,​70973
    /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.cpp66309,​66318
    /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.cpp70873
    /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.cpp74233
    /branches/VBox-4.2/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsItem.cpp91503-91504,​91506-91508,​91510,​91514-91515,​91521
    /branches/VBox-4.3/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsItem.cpp91223
    /branches/VBox-4.3/trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsItem.cpp91223
    /branches/dsen/gui/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.cpp79076-79078,​79089,​79109-79110,​79112-79113,​79127-79130,​79134,​79141,​79151,​79155,​79157-79159,​79193,​79197
    /branches/dsen/gui2/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsItem.cpp79562-79569,​79572-79573,​79578,​79581-79582,​79590-79591,​79598-79599,​79602-79603,​79605-79606,​79632,​79635,​79637,​79644
    /branches/dsen/gui3/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsItem.cpp79645-79692
    /trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.cpp79225,​79271
File size: 10.1 KB
Line 
1/* $Id: UIDetailsItem.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIDetailsItem class definition.
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 <QAccessibleObject>
30#include <QApplication>
31#include <QGraphicsScene>
32#include <QPainter>
33#include <QStyleOptionGraphicsItem>
34
35/* GUI includes: */
36#include "UIGraphicsTextPane.h"
37#include "UIDetails.h"
38#include "UIDetailsElement.h"
39#include "UIDetailsGroup.h"
40#include "UIDetailsModel.h"
41#include "UIDetailsSet.h"
42#include "UIDetailsView.h"
43
44
45/** QAccessibleObject extension used as an accessibility interface for Details-view items. */
46class UIAccessibilityInterfaceForUIDetailsItem : public QAccessibleObject
47{
48public:
49
50 /** Returns an accessibility interface for passed @a strClassname and @a pObject. */
51 static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)
52 {
53 /* Creating Details-view accessibility interface: */
54 if (pObject && strClassname == QLatin1String("UIDetailsItem"))
55 return new UIAccessibilityInterfaceForUIDetailsItem(pObject);
56
57 /* Null by default: */
58 return 0;
59 }
60
61 /** Constructs an accessibility interface passing @a pObject to the base-class. */
62 UIAccessibilityInterfaceForUIDetailsItem(QObject *pObject)
63 : QAccessibleObject(pObject)
64 {}
65
66 /** Returns the parent. */
67 virtual QAccessibleInterface *parent() const RT_OVERRIDE
68 {
69 /* Make sure item still alive: */
70 AssertPtrReturn(item(), 0);
71
72 /* Return the parent: */
73 switch (item()->type())
74 {
75 /* For a set: */
76 case UIDetailsItemType_Set:
77 {
78 /* Always return parent view: */
79 return QAccessible::queryAccessibleInterface(item()->model()->details()->view());
80 }
81 /* For an element: */
82 case UIDetailsItemType_Element:
83 {
84 /* What amount of children root has? */
85 const int cChildCount = item()->model()->root()->items().size();
86
87 /* Return our parent (if root has many of children): */
88 if (cChildCount > 1)
89 return QAccessible::queryAccessibleInterface(item()->parentItem());
90
91 /* Return parent view (otherwise): */
92 return QAccessible::queryAccessibleInterface(item()->model()->details()->view());
93 }
94 default:
95 break;
96 }
97
98 /* Null by default: */
99 return 0;
100 }
101
102 /** Returns the number of children. */
103 virtual int childCount() const RT_OVERRIDE
104 {
105 /* Make sure item still alive: */
106 AssertPtrReturn(item(), 0);
107
108 /* Return the number of children: */
109 switch (item()->type())
110 {
111 case UIDetailsItemType_Set: return item()->items().size();
112 case UIDetailsItemType_Element: return item()->toElement()->text().size();
113 default: break;
114 }
115
116 /* Zero by default: */
117 return 0;
118 }
119
120 /** Returns the child with the passed @a iIndex. */
121 virtual QAccessibleInterface *child(int iIndex) const RT_OVERRIDE
122 {
123 /* Make sure item still alive: */
124 AssertPtrReturn(item(), 0);
125 /* Make sure index is valid: */
126 AssertReturn(iIndex >= 0 && iIndex < childCount(), 0);
127
128 /* Return the child with the iIndex: */
129 switch (item()->type())
130 {
131 case UIDetailsItemType_Set: return QAccessible::queryAccessibleInterface(item()->items().at(iIndex));
132 case UIDetailsItemType_Element: return QAccessible::queryAccessibleInterface(&item()->toElement()->text()[iIndex]);
133 default: break;
134 }
135
136 /* Null be default: */
137 return 0;
138 }
139
140 /** Returns the index of the passed @a pChild. */
141 virtual int indexOfChild(const QAccessibleInterface *pChild) const RT_OVERRIDE
142 {
143 /* Search for corresponding child: */
144 for (int i = 0; i < childCount(); ++i)
145 if (child(i) == pChild)
146 return i;
147
148 /* -1 by default: */
149 return -1;
150 }
151
152 /** Returns the rect. */
153 virtual QRect rect() const RT_OVERRIDE
154 {
155 /* Now goes the mapping: */
156 const QSize itemSize = item()->size().toSize();
157 const QPointF itemPosInScene = item()->mapToScene(QPointF(0, 0));
158 const QPoint itemPosInView = item()->model()->details()->view()->mapFromScene(itemPosInScene);
159 const QPoint itemPosInScreen = item()->model()->details()->view()->mapToGlobal(itemPosInView);
160 const QRect itemRectInScreen = QRect(itemPosInScreen, itemSize);
161 return itemRectInScreen;
162 }
163
164 /** Returns a text for the passed @a enmTextRole. */
165 virtual QString text(QAccessible::Text enmTextRole) const RT_OVERRIDE
166 {
167 /* Make sure item still alive: */
168 AssertPtrReturn(item(), QString());
169
170 /* Return the description: */
171 if (enmTextRole == QAccessible::Description)
172 return item()->description();
173
174 /* Null-string by default: */
175 return QString();
176 }
177
178 /** Returns the role. */
179 virtual QAccessible::Role role() const RT_OVERRIDE
180 {
181 /* Return the role: */
182 return QAccessible::List;
183 }
184
185 /** Returns the state. */
186 virtual QAccessible::State state() const RT_OVERRIDE
187 {
188 /* Return the state: */
189 return QAccessible::State();
190 }
191
192private:
193
194 /** Returns corresponding Details-view item. */
195 UIDetailsItem *item() const { return qobject_cast<UIDetailsItem*>(object()); }
196};
197
198
199/*********************************************************************************************************************************
200* Class UIDetailsItem implementation. *
201*********************************************************************************************************************************/
202
203UIDetailsItem::UIDetailsItem(UIDetailsItem *pParent)
204 : QIWithRetranslateUI4<QIGraphicsWidget>(pParent)
205 , m_pParent(pParent)
206{
207 /* Install Details-view item accessibility interface factory: */
208 QAccessible::installFactory(UIAccessibilityInterfaceForUIDetailsItem::pFactory);
209
210 /* Basic item setup: */
211 setOwnedByLayout(false);
212 setFocusPolicy(Qt::NoFocus);
213 setFlag(QGraphicsItem::ItemIsSelectable, false);
214
215 /* Non-root item? */
216 if (parentItem())
217 {
218 /* Non-root item setup: */
219 setAcceptHoverEvents(true);
220 }
221
222 /* Setup connections: */
223 connect(this, &UIDetailsItem::sigBuildStep,
224 this, &UIDetailsItem::sltBuildStep,
225 Qt::QueuedConnection);
226}
227
228UIDetailsGroup *UIDetailsItem::toGroup()
229{
230 UIDetailsGroup *pItem = qgraphicsitem_cast<UIDetailsGroup*>(this);
231 AssertMsg(pItem, ("Trying to cast invalid item type to UIDetailsGroup!"));
232 return pItem;
233}
234
235UIDetailsSet *UIDetailsItem::toSet()
236{
237 UIDetailsSet *pItem = qgraphicsitem_cast<UIDetailsSet*>(this);
238 AssertMsg(pItem, ("Trying to cast invalid item type to UIDetailsSet!"));
239 return pItem;
240}
241
242UIDetailsElement *UIDetailsItem::toElement()
243{
244 UIDetailsElement *pItem = qgraphicsitem_cast<UIDetailsElement*>(this);
245 AssertMsg(pItem, ("Trying to cast invalid item type to UIDetailsElement!"));
246 return pItem;
247}
248
249UIDetailsModel *UIDetailsItem::model() const
250{
251 UIDetailsModel *pModel = qobject_cast<UIDetailsModel*>(QIGraphicsWidget::scene()->parent());
252 AssertMsg(pModel, ("Incorrect graphics scene parent set!"));
253 return pModel;
254}
255
256void UIDetailsItem::updateGeometry()
257{
258 /* Call to base-class: */
259 QIGraphicsWidget::updateGeometry();
260
261 /* Do the same for the parent: */
262 if (parentItem())
263 parentItem()->updateGeometry();
264}
265
266QSizeF UIDetailsItem::sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint /* = QSizeF() */) const
267{
268 /* If Qt::MinimumSize or Qt::PreferredSize requested: */
269 if (enmWhich == Qt::MinimumSize || enmWhich == Qt::PreferredSize)
270 /* Return wrappers: */
271 return QSizeF(minimumWidthHint(), minimumHeightHint());
272 /* Call to base-class: */
273 return QIGraphicsWidget::sizeHint(enmWhich, constraint);
274}
275
276void UIDetailsItem::sltBuildStep(const QUuid &, int)
277{
278 AssertMsgFailed(("This item doesn't support building!"));
279}
280
281
282/*********************************************************************************************************************************
283* Class UIPrepareStep implementation. *
284*********************************************************************************************************************************/
285
286UIPrepareStep::UIPrepareStep(QObject *pParent, QObject *pBuildObject, const QUuid &uStepId, int iStepNumber)
287 : QObject(pParent)
288 , m_uStepId(uStepId)
289 , m_iStepNumber(iStepNumber)
290{
291 /* Prepare connections: */
292 connect(qobject_cast<UIDetailsItem*>(pBuildObject), &UIDetailsItem::sigBuildDone,
293 this, &UIPrepareStep::sltStepDone,
294 Qt::QueuedConnection);
295
296 UIDetailsItem *pDetailsItem = qobject_cast<UIDetailsItem*>(pParent);
297 AssertPtrReturnVoid(pDetailsItem);
298 {
299 connect(this, &UIPrepareStep::sigStepDone,
300 pDetailsItem, &UIDetailsItem::sltBuildStep,
301 Qt::QueuedConnection);
302 }
303}
304
305void UIPrepareStep::sltStepDone()
306{
307 emit sigStepDone(m_uStepId, m_iStepNumber);
308}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette