VirtualBox

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

Last change on this file since 103977 was 103094, checked in by vboxsync, 11 months ago

FE/Qt: UIWelcomePane: bugref:10513: Extending UIWelcomePane with some info regarding Experience mode; Adding one-time choice as well.

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