VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsView.cpp

Last change on this file was 104251, checked in by vboxsync, 8 weeks ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in the manager UI classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1/* $Id: UIToolsView.cpp 104251 2024-04-09 12:36:47Z 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#include "UITranslationEventListener.h"
39
40/* Other VBox includes: */
41#include <iprt/assert.h>
42
43
44/** QAccessibleWidget extension used as an accessibility interface for Tools-view. */
45class UIAccessibilityInterfaceForUIToolsView : public QAccessibleWidget
46{
47public:
48
49 /** Returns an accessibility interface for passed @a strClassname and @a pObject. */
50 static QAccessibleInterface *pFactory(const QString &strClassname, QObject *pObject)
51 {
52 /* Creating Tools-view accessibility interface: */
53 if (pObject && strClassname == QLatin1String("UIToolsView"))
54 return new UIAccessibilityInterfaceForUIToolsView(qobject_cast<QWidget*>(pObject));
55
56 /* Null by default: */
57 return 0;
58 }
59
60 /** Constructs an accessibility interface passing @a pWidget to the base-class. */
61 UIAccessibilityInterfaceForUIToolsView(QWidget *pWidget)
62 : QAccessibleWidget(pWidget, QAccessible::List)
63 {}
64
65 /** Returns the number of children. */
66 virtual int childCount() const RT_OVERRIDE
67 {
68 /* Make sure view still alive: */
69 AssertPtrReturn(view(), 0);
70
71 /* Return the number of children: */
72 return view()->tools()->model()->items().size();
73 }
74
75 /** Returns the child with the passed @a iIndex. */
76 virtual QAccessibleInterface *child(int iIndex) const RT_OVERRIDE
77 {
78 /* Make sure view still alive: */
79 AssertPtrReturn(view(), 0);
80 /* Make sure index is valid: */
81 AssertReturn(iIndex >= 0 && iIndex < childCount(), 0);
82
83 /* Return the child with the passed iIndex: */
84 return QAccessible::queryAccessibleInterface(view()->tools()->model()->items().at(iIndex));
85 }
86
87 /** Returns the index of passed @a pChild. */
88 virtual int indexOfChild(const QAccessibleInterface *pChild) const RT_OVERRIDE
89 {
90 /* Make sure view still alive: */
91 AssertPtrReturn(view(), -1);
92 /* Make sure child is valid: */
93 AssertReturn(pChild, -1);
94
95 /* Return the index of passed model child: */
96 return view()->tools()->model()->items().indexOf(qobject_cast<UIToolsItem*>(pChild->object()));
97 }
98
99 /** Returns a text for the passed @a enmTextRole. */
100 virtual QString text(QAccessible::Text enmTextRole) const RT_OVERRIDE
101 {
102 /* Make sure view still alive: */
103 AssertPtrReturn(view(), QString());
104
105 /* Return view tool-tip: */
106 Q_UNUSED(enmTextRole);
107 return view()->toolTip();
108 }
109
110private:
111
112 /** Returns corresponding Tools-view. */
113 UIToolsView *view() const { return qobject_cast<UIToolsView*>(widget()); }
114};
115
116
117UIToolsView::UIToolsView(UITools *pParent)
118 : QIGraphicsView(pParent)
119 , m_pTools(pParent)
120 , m_iMinimumWidthHint(0)
121 , m_iMinimumHeightHint(0)
122{
123 /* Prepare: */
124 prepare();
125}
126
127void UIToolsView::sltFocusChanged()
128{
129 /* Make sure focus-item set: */
130 const UIToolsItem *pFocusItem = tools() && tools()->model()
131 ? tools()->model()->focusItem()
132 : 0;
133 if (!pFocusItem)
134 return;
135
136 const QSize viewSize = viewport()->size();
137 QRectF geo = pFocusItem->geometry();
138 geo &= QRectF(geo.topLeft(), viewSize);
139 ensureVisible(geo, 0, 0);
140}
141
142void UIToolsView::sltMinimumWidthHintChanged(int iHint)
143{
144 /* Is there something changed? */
145 if (m_iMinimumWidthHint == iHint)
146 return;
147
148 /* Remember new value: */
149 m_iMinimumWidthHint = iHint;
150
151 /* Set minimum view width according passed width-hint: */
152 setMinimumWidth(2 * frameWidth() + m_iMinimumWidthHint);
153
154 /* Update scene-rect: */
155 updateSceneRect();
156}
157
158void UIToolsView::sltMinimumHeightHintChanged(int iHint)
159{
160 /* Is there something changed? */
161 if (m_iMinimumHeightHint == iHint)
162 return;
163
164 /* Remember new value: */
165 m_iMinimumHeightHint = iHint;
166
167 /* Set minimum view height according passed height-hint: */
168 setMinimumHeight(2 * frameWidth() + m_iMinimumHeightHint);
169
170 /* Update scene-rect: */
171 updateSceneRect();
172}
173
174void UIToolsView::sltRetranslateUI()
175{
176 /* Translate this: */
177 setWhatsThis(tr("Contains a list of VirtualBox tools."));
178}
179
180void UIToolsView::prepare()
181{
182 /* Install Tools-view accessibility interface factory: */
183 QAccessible::installFactory(UIAccessibilityInterfaceForUIToolsView::pFactory);
184
185 /* Prepare palette: */
186 preparePalette();
187
188 /* Setup frame: */
189 setFrameShape(QFrame::NoFrame);
190 setFrameShadow(QFrame::Plain);
191 setAlignment(Qt::AlignLeft | Qt::AlignTop);
192
193 /* Setup scroll-bars policy: */
194 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
195
196 /* Update scene-rect: */
197 updateSceneRect();
198
199 /* Apply language settings: */
200 sltRetranslateUI();
201 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
202 this, &UIToolsView::sltRetranslateUI);
203}
204
205void UIToolsView::preparePalette()
206{
207 /* Setup palette: */
208 QPalette pal = qApp->palette();
209 pal.setColor(QPalette::Active, QPalette::Base, pal.color(QPalette::Active, QPalette::Window));
210 setPalette(pal);
211}
212
213void UIToolsView::resizeEvent(QResizeEvent *pEvent)
214{
215 /* Call to base-class: */
216 QIGraphicsView::resizeEvent(pEvent);
217 /* Notify listeners: */
218 emit sigResized();
219}
220
221void UIToolsView::updateSceneRect()
222{
223 setSceneRect(0, 0, m_iMinimumWidthHint, m_iMinimumHeightHint);
224}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use