VirtualBox

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

Last change on this file was 104358, checked in by vboxsync, 4 weeks ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.0 KB
Line 
1/* $Id: UIWelcomePane.cpp 104358 2024-04-18 05:33:40Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIWelcomePane class implementation.
4 */
5
6/*
7 * Copyright (C) 2010-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 <QApplication>
30#include <QButtonGroup>
31#include <QGridLayout>
32#include <QLabel>
33#include <QPushButton>
34#include <QStyle>
35#include <QUrl>
36
37/* GUI includes */
38#include "QIRichTextLabel.h"
39#include "UICommon.h"
40#include "UIDesktopWidgetWatchdog.h"
41#include "UIExtraDataManager.h"
42#include "UIIconPool.h"
43#include "UITranslationEventListener.h"
44#include "UIWelcomePane.h"
45
46
47/*********************************************************************************************************************************
48* Class UIWelcomePane implementation. *
49*********************************************************************************************************************************/
50
51UIWelcomePane::UIWelcomePane(QWidget *pParent /* = 0 */)
52 : QWidget(pParent)
53 , m_pLabelGreetings(0)
54 , m_pLabelMode(0)
55 , m_pLabelIcon(0)
56{
57 prepare();
58}
59
60bool UIWelcomePane::event(QEvent *pEvent)
61{
62 /* Handle known event types: */
63 switch (pEvent->type())
64 {
65 case QEvent::Show:
66 case QEvent::ScreenChangeInternal:
67 {
68 /* Update pixmap: */
69 updateTextLabels();
70 updatePixmap();
71 break;
72 }
73 default:
74 break;
75 }
76
77 /* Call to base-class: */
78 return QWidget::event(pEvent);
79}
80
81void UIWelcomePane::sltRetranslateUI()
82{
83 /* Translate greetings text: */
84 if (m_pLabelGreetings)
85 m_pLabelGreetings->setText(tr("<h3>Welcome to VirtualBox!</h3>"
86 "<p>The left part of application window contains global tools and "
87 "lists all virtual machines and virtual machine groups on your computer. "
88 "You can import, add and create new VMs using corresponding toolbar buttons. "
89 "You can popup a tools of currently selected element using corresponding element "
90 "button.</p>"
91 "<p>You can press the <b>%1</b> key to get instant help, or visit "
92 "<a href=https://www.virtualbox.org>www.virtualbox.org</a> "
93 "for more information and latest news.</p>")
94 .arg(QKeySequence(QKeySequence::HelpContents).toString(QKeySequence::NativeText)));
95
96 /* Translate experience mode stuff: */
97 if (m_pLabelMode)
98 m_pLabelMode->setText(tr("<h3>Please choose Experience Mode!</h3>"
99 "By default, the VirtualBox GUI is hiding some options, tools and wizards. "
100 "<p>The <b>Basic Mode</b> is intended for a users who are not interested in advanced "
101 "functionality and prefer a simpler, cleaner interface.</p>"
102 "<p>The <b>Expert Mode</b> is intended for experienced users who wish to utilize all "
103 "VirtualBox functionality.</p>"
104 "<p>You can choose whether you are a beginner or experienced user by selecting required "
105 "option at the right. This choice can always be changed in Global Preferences or Machine "
106 "Settings windows.</p>"));
107 if (m_buttons.contains(false))
108 m_buttons.value(false)->setText(tr("Basic Mode"));
109 if (m_buttons.contains(true))
110 m_buttons.value(true)->setText(tr("Expert Mode"));
111}
112
113void UIWelcomePane::sltHandleLinkActivated(const QUrl &urlLink)
114{
115 uiCommon().openURL(urlLink.toString());
116}
117
118void UIWelcomePane::sltHandleButtonClicked(QAbstractButton *pButton)
119{
120 /* Make sure one of buttons was really pressed: */
121 AssertReturnVoid(m_buttons.contains(pButton));
122
123 /* Hide everything related to experience mode: */
124 if (m_pLabelMode)
125 m_pLabelMode->hide();
126 if (m_buttons.contains(false))
127 m_buttons.value(false)->hide();
128 if (m_buttons.contains(true))
129 m_buttons.value(true)->hide();
130
131 /* Check which button was pressed actually and save the value: */
132 const bool fExpertMode = m_buttons.key(pButton, false);
133 gEDataManager->setSettingsInExpertMode(fExpertMode);
134}
135
136void UIWelcomePane::prepare()
137{
138 /* Prepare default welcome icon: */
139 m_icon = UIIconPool::iconSet(":/tools_banner_global_200px.png");
140
141 /* Prepare main layout: */
142 QGridLayout *pMainLayout = new QGridLayout(this);
143 if (pMainLayout)
144 {
145 const int iL = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 2;
146 const int iT = qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin);
147 const int iR = qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin);
148 const int iB = qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin) / 2;
149#ifdef VBOX_WS_MAC
150 const int iSpacing = 20;
151#else
152 const int iSpacing = qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing);
153#endif
154 pMainLayout->setContentsMargins(iL, iT, iR, iB);
155 pMainLayout->setSpacing(iSpacing);
156 pMainLayout->setRowStretch(2, 1);
157
158 /* Prepare greetings label: */
159 m_pLabelGreetings = new QIRichTextLabel(this);
160 if (m_pLabelGreetings)
161 {
162 m_pLabelGreetings->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
163 connect(m_pLabelGreetings, &QIRichTextLabel::sigLinkClicked, this, &UIWelcomePane::sltHandleLinkActivated);
164 pMainLayout->addWidget(m_pLabelGreetings, 0, 0);
165 }
166
167 /* Prepare icon label: */
168 m_pLabelIcon = new QLabel(this);
169 if (m_pLabelIcon)
170 {
171 m_pLabelIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
172 pMainLayout->addWidget(m_pLabelIcon, 0, 1);
173 }
174
175 /* This block for the case if experienced mode is NOT defined yet: */
176 if (gEDataManager->extraDataString(UIExtraDataDefs::GUI_Settings_ExpertMode).isNull())
177 {
178 /* Prepare experience mode label: */
179 m_pLabelMode = new QIRichTextLabel(this);
180 if (m_pLabelMode)
181 {
182 m_pLabelMode->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
183 pMainLayout->addWidget(m_pLabelMode, 1, 0);
184 }
185
186 /* Prepare button layout: */
187 QVBoxLayout *pLayoutButton = new QVBoxLayout;
188 if (pLayoutButton)
189 {
190 pLayoutButton->setSpacing(iSpacing / 2);
191
192 /* Prepare button group: */
193 QButtonGroup *pButtonGroup = new QButtonGroup(this);
194 if (pButtonGroup)
195 {
196 /* Prepare Basic button ('false' means 'not Expert'): */
197 m_buttons[false] = new QPushButton(this);
198 QAbstractButton *pButtonBasic = m_buttons.value(false);
199 if (pButtonBasic)
200 {
201 pButtonGroup->addButton(pButtonBasic);
202 pLayoutButton->addWidget(pButtonBasic);
203 }
204
205 /* Prepare Expert button ('true' means 'is Expert'): */
206 m_buttons[true] = new QPushButton(this);
207 QAbstractButton *pButtonExpert = m_buttons[true];
208 if (pButtonExpert)
209 {
210 pButtonGroup->addButton(pButtonExpert);
211 pLayoutButton->addWidget(pButtonExpert);
212 }
213
214 connect(pButtonGroup, &QButtonGroup::buttonClicked,
215 this, &UIWelcomePane::sltHandleButtonClicked);
216 }
217
218 pLayoutButton->addStretch();
219 pMainLayout->addLayout(pLayoutButton, 1, 1);
220 }
221 }
222 }
223
224 /* Assign Help keyword: */
225 uiCommon().setHelpKeyword(this, "intro-starting");
226
227 /* Translate finally: */
228 sltRetranslateUI();
229 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
230 this, &UIWelcomePane::sltRetranslateUI);
231
232 /* Update stuff: */
233 updateTextLabels();
234 updatePixmap();
235}
236
237void UIWelcomePane::updateTextLabels()
238{
239 /* For all the text-labels: */
240 QList<QIRichTextLabel*> labels = findChildren<QIRichTextLabel*>();
241 if (!labels.isEmpty())
242 {
243 /* Make sure their minimum width is around 20% of the screen width: */
244 const QSize screenGeometry = gpDesktop->screenGeometry(this).size();
245 foreach (QIRichTextLabel *pLabel, labels)
246 {
247 pLabel->setMinimumTextWidth(screenGeometry.width() * .2);
248 pLabel->resize(pLabel->minimumSizeHint());
249 }
250 }
251}
252
253void UIWelcomePane::updatePixmap()
254{
255 /* Assign corresponding icon: */
256 if (!m_icon.isNull() && m_pLabelIcon)
257 {
258 /* Check which size goes as the default one: */
259 const QList<QSize> sizes = m_icon.availableSizes();
260 const QSize defaultSize = sizes.isEmpty() ? QSize(200, 200) : sizes.first();
261 /* Acquire device-pixel ratio: */
262 const qreal fDevicePixelRatio = gpDesktop->devicePixelRatio(this);
263 m_pLabelIcon->setPixmap(m_icon.pixmap(defaultSize, fDevicePixelRatio));
264 }
265}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use