VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsView.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
File size: 6.2 KB
Line 
1/* $Id: UIToolsView.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIToolsView 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 <QApplication>
31#include <QScrollBar>
32
33/* GUI includes: */
34#include "UITools.h"
35#include "UIToolsItem.h"
36#include "UIToolsModel.h"
37#include "UIToolsView.h"
38
39/* Other VBox includes: */
40#include <iprt/assert.h>
41
42
43/** QAccessibleWidget extension used as an accessibility interface for Tools-view. */
44class UIAccessibilityInterfaceForUIToolsView : public QAccessibleWidget
45{
46public:
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 Tools-view accessibility interface: */
52 if (pObject && strClassname == QLatin1String("UIToolsView"))
53 return new UIAccessibilityInterfaceForUIToolsView(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 UIAccessibilityInterfaceForUIToolsView(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 /* Return the number of children: */
71 return view()->tools()->model()->items().size();
72 }
73
74 /** Returns the child with the passed @a iIndex. */
75 virtual QAccessibleInterface *child(int iIndex) const RT_OVERRIDE
76 {
77 /* Make sure view still alive: */
78 AssertPtrReturn(view(), 0);
79 /* Make sure index is valid: */
80 AssertReturn(iIndex >= 0 && iIndex < childCount(), 0);
81
82 /* Return the child with the passed iIndex: */
83 return QAccessible::queryAccessibleInterface(view()->tools()->model()->items().at(iIndex));
84 }
85
86 /** Returns the index of passed @a pChild. */
87 virtual int indexOfChild(const QAccessibleInterface *pChild) const RT_OVERRIDE
88 {
89 /* Make sure view still alive: */
90 AssertPtrReturn(view(), -1);
91 /* Make sure child is valid: */
92 AssertReturn(pChild, -1);
93
94 /* Return the index of passed model child: */
95 return view()->tools()->model()->items().indexOf(qobject_cast<UIToolsItem*>(pChild->object()));
96 }
97
98 /** Returns a text for the passed @a enmTextRole. */
99 virtual QString text(QAccessible::Text enmTextRole) const RT_OVERRIDE
100 {
101 /* Make sure view still alive: */
102 AssertPtrReturn(view(), QString());
103
104 /* Return view tool-tip: */
105 Q_UNUSED(enmTextRole);
106 return view()->toolTip();
107 }
108
109private:
110
111 /** Returns corresponding Tools-view. */
112 UIToolsView *view() const { return qobject_cast<UIToolsView*>(widget()); }
113};
114
115
116UIToolsView::UIToolsView(UITools *pParent)
117 : QIWithRetranslateUI<QIGraphicsView>(pParent)
118 , m_pTools(pParent)
119 , m_iMinimumWidthHint(0)
120 , m_iMinimumHeightHint(0)
121{
122 /* Prepare: */
123 prepare();
124}
125
126void UIToolsView::sltFocusChanged()
127{
128 /* Make sure focus-item set: */
129 const UIToolsItem *pFocusItem = tools() && tools()->model()
130 ? tools()->model()->focusItem()
131 : 0;
132 if (!pFocusItem)
133 return;
134
135 const QSize viewSize = viewport()->size();
136 QRectF geo = pFocusItem->geometry();
137 geo &= QRectF(geo.topLeft(), viewSize);
138 ensureVisible(geo, 0, 0);
139}
140
141void UIToolsView::sltMinimumWidthHintChanged(int iHint)
142{
143 /* Is there something changed? */
144 if (m_iMinimumWidthHint == iHint)
145 return;
146
147 /* Remember new value: */
148 m_iMinimumWidthHint = iHint;
149
150 /* Set minimum view width according passed width-hint: */
151 setMinimumWidth(2 * frameWidth() + m_iMinimumWidthHint);
152
153 /* Update scene-rect: */
154 updateSceneRect();
155}
156
157void UIToolsView::sltMinimumHeightHintChanged(int iHint)
158{
159 /* Is there something changed? */
160 if (m_iMinimumHeightHint == iHint)
161 return;
162
163 /* Remember new value: */
164 m_iMinimumHeightHint = iHint;
165
166 /* Set minimum view height according passed height-hint: */
167 setMinimumHeight(2 * frameWidth() + m_iMinimumHeightHint);
168
169 /* Update scene-rect: */
170 updateSceneRect();
171}
172
173void UIToolsView::retranslateUi()
174{
175 /* Translate this: */
176 setWhatsThis(tr("Contains a list of VirtualBox tools."));
177}
178
179void UIToolsView::prepare()
180{
181 /* Install Tools-view accessibility interface factory: */
182 QAccessible::installFactory(UIAccessibilityInterfaceForUIToolsView::pFactory);
183
184 /* Prepare palette: */
185 preparePalette();
186
187 /* Setup frame: */
188 setFrameShape(QFrame::NoFrame);
189 setFrameShadow(QFrame::Plain);
190 setAlignment(Qt::AlignLeft | Qt::AlignTop);
191
192 /* Setup scroll-bars policy: */
193 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
194
195 /* Update scene-rect: */
196 updateSceneRect();
197
198 /* Apply language settings: */
199 retranslateUi();
200}
201
202void UIToolsView::preparePalette()
203{
204 /* Setup palette: */
205 QPalette pal = qApp->palette();
206 pal.setColor(QPalette::Active, QPalette::Base, pal.color(QPalette::Active, QPalette::Window));
207 setPalette(pal);
208}
209
210void UIToolsView::resizeEvent(QResizeEvent *pEvent)
211{
212 /* Call to base-class: */
213 QIWithRetranslateUI<QIGraphicsView>::resizeEvent(pEvent);
214 /* Notify listeners: */
215 emit sigResized();
216}
217
218void UIToolsView::updateSceneRect()
219{
220 setSceneRect(0, 0, m_iMinimumWidthHint, m_iMinimumHeightHint);
221}
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