VirtualBox

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

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

Copyright year updates by scm.

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