VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/VBoxAboutDlg.cpp

Last change on this file was 106351, checked in by vboxsync, 4 months ago

FE/Qt: bugref:10407. Add platform name next toQt version string on about dialog

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1/* $Id: VBoxAboutDlg.cpp 106351 2024-10-16 10:45:04Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - VBoxAboutDlg class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-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 <QGuiApplication>
30#include <QEvent>
31#include <QLabel>
32#include <QPainter>
33#include <QPushButton>
34#include <QVBoxLayout>
35#include <QWindow>
36
37/* GUI includes: */
38#include "QIDialogButtonBox.h"
39#include "UIIconPool.h"
40#include "UIDesktopWidgetWatchdog.h"
41#include "UITranslationEventListener.h"
42#include "UIVersion.h"
43#include "VBoxAboutDlg.h"
44
45/* Other VBox includes: */
46#include <iprt/path.h> /* RTPathExecDir */
47#include <VBox/version.h> /* VBOX_VENDOR */
48
49
50VBoxAboutDlg::VBoxAboutDlg(QWidget *pParent, const QString &strVersion)
51#ifdef VBOX_WS_MAC
52 // No need for About dialog parent on macOS.
53 // First of all, non of other native apps (Safari, App Store, iTunes) centers About dialog according the app itself, they do
54 // it according to screen instead, we should do it as well. Besides that since About dialog is not modal, it will be in
55 // conflict with modal dialogs if there will be a parent passed, because the dialog will not have own event-loop in that case.
56 : QDialog(0)
57 , m_pPseudoParent(pParent)
58#else
59 // On other hosts we will keep the current behavior for now.
60 // First of all it's quite difficult to find native (Metro UI) Windows app which have About dialog at all. But non-native
61 // cross-platform apps (Qt Creator, VLC) centers About dialog according the app exactly.
62 : QDialog(pParent)
63 , m_pPseudoParent(0)
64#endif
65 , m_fPolished(false)
66 , m_strVersion(strVersion)
67 , m_pMainLayout(0)
68 , m_pLabel(0)
69{
70 prepare();
71}
72
73void VBoxAboutDlg::showEvent(QShowEvent *pEvent)
74{
75 /* Call to base-class: */
76 QDialog::showEvent(pEvent);
77
78 /* Polish once: */
79 if (!m_fPolished)
80 {
81 m_fPolished = true;
82 setFixedSize(m_size);
83
84 QRect geo = geometry();
85#ifdef VBOX_WS_MAC
86 /* Center according to parent screen: */
87 geo.moveCenter(gpDesktop->screenGeometry(m_pPseudoParent).center());
88#else
89 /* Center according to parent widget: */
90 geo.moveCenter(parentWidget()->geometry().center());
91#endif
92 setGeometry(geo);
93 }
94}
95
96void VBoxAboutDlg::paintEvent(QPaintEvent *)
97{
98 /* Draw About-VirtualBox background image: */
99 QPainter painter(this);
100 painter.drawPixmap(0, 0, m_pixmap);
101}
102
103void VBoxAboutDlg::sltRetranslateUI()
104{
105 setWindowTitle(tr("VirtualBox - About"));
106
107 if (m_pLabel)
108 {
109 const QString strAboutText = tr("VirtualBox Graphical User Interface");
110#ifdef VBOX_BLEEDING_EDGE
111 const QString strVersionText = "EXPERIMENTAL build %1 - " + QString(VBOX_BLEEDING_EDGE);
112#else
113 const QString strVersionText = tr("Version %1");
114#endif
115#ifdef VBOX_OSE
116 m_strAboutText = strAboutText + " " + strVersionText.arg(m_strVersion) + "\n"
117 + QString("%1 2004-" VBOX_C_YEAR " " VBOX_VENDOR).arg(QChar(0xa9));
118#else
119 m_strAboutText = strAboutText + "\n" + strVersionText.arg(m_strVersion);
120#endif
121 QString strPlatformName = QGuiApplication::platformName();
122 if (strPlatformName.isEmpty())
123 m_strAboutText = m_strAboutText + QString(" (Qt%1)").arg(qVersion());
124 else
125 m_strAboutText = m_strAboutText + QString(" (Qt%1 on %2)").arg(qVersion()).arg(strPlatformName);
126 m_strAboutText = m_strAboutText + "\n" + QString("Copyright %1 %2 %3.")
127 .arg(QChar(0xa9)).arg(VBOX_C_YEAR).arg(VBOX_VENDOR);
128 m_pLabel->setText(m_strAboutText);
129 }
130}
131
132void VBoxAboutDlg::prepare()
133{
134 /* Delete dialog on close: */
135 setAttribute(Qt::WA_DeleteOnClose);
136 /* Do not count that window as important for application,
137 * it will NOT be taken into account when other top-level windows will be closed: */
138 setAttribute(Qt::WA_QuitOnClose, false);
139
140 /* Make sure the dialog is deleted on pseudo-parent destruction: */
141 if (m_pPseudoParent)
142 connect(m_pPseudoParent, &QObject::destroyed, this, &VBoxAboutDlg::close);
143
144 /* Choose default image: */
145 QString strPath(":/about.png");
146
147 /* Branding: Use a custom about splash picture if set: */
148 const QString strSplash = UIVersionInfo::brandingGetKey("UI/AboutSplash");
149 if (UIVersionInfo::brandingIsActive() && !strSplash.isEmpty())
150 {
151 char szExecPath[1024];
152 RTPathExecDir(szExecPath, 1024);
153 QString strTmpPath = QString("%1/%2").arg(szExecPath).arg(strSplash);
154 if (QFile::exists(strTmpPath))
155 strPath = strTmpPath;
156 }
157
158 /* Load image: */
159 const QIcon icon = UIIconPool::iconSet(strPath);
160 m_size = QSize(640, 480);
161 QWidget *pParent = m_pPseudoParent ? m_pPseudoParent : parentWidget();
162 const qreal fDevicePixelRatio = pParent ? pParent->windowHandle()->devicePixelRatio() : 1;
163 m_pixmap = icon.pixmap(m_size, fDevicePixelRatio);
164
165 /* Prepare main-layout: */
166 prepareMainLayout();
167
168 /* Translate: */
169 sltRetranslateUI();
170 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
171 this, &VBoxAboutDlg::sltRetranslateUI);
172}
173
174void VBoxAboutDlg::prepareMainLayout()
175{
176 /* Create main-layout: */
177 m_pMainLayout = new QVBoxLayout(this);
178 if (m_pMainLayout)
179 {
180 /* Prepare stuff: */
181 prepareLabel();
182 prepareCloseButton();
183 }
184}
185
186void VBoxAboutDlg::prepareLabel()
187{
188 /* Create label for version text: */
189 m_pLabel = new QLabel(this);
190 if (m_pLabel)
191 {
192 /* Prepare label for version text: */
193 QPalette palette;
194 /* Branding: Set a different text color (because splash also could be white),
195 * otherwise use white as default color: */
196 const QString strColor = UIVersionInfo::brandingGetKey("UI/AboutTextColor");
197 if (!strColor.isEmpty())
198 palette.setColor(QPalette::WindowText, QColor(strColor).name());
199 else
200 palette.setColor(QPalette::WindowText, Qt::white);
201 m_pLabel->setPalette(palette);
202 m_pLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
203 m_pLabel->setFont(font());
204
205 /* Add label to the main-layout: */
206 if (m_pMainLayout)
207 {
208 m_pMainLayout->addWidget(m_pLabel);
209 m_pMainLayout->setAlignment(m_pLabel, Qt::AlignRight | Qt::AlignBottom);
210 }
211 }
212}
213
214void VBoxAboutDlg::prepareCloseButton()
215{
216 /* Create button-box: */
217 QIDialogButtonBox *pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this);
218 if (pButtonBox)
219 {
220 /* Prepare close-button: */
221 connect(pButtonBox, &QDialogButtonBox::rejected, this, &VBoxAboutDlg::close);
222
223 /* Add button-box to the main-layout: */
224 if (m_pMainLayout)
225 m_pMainLayout->addWidget(pButtonBox);
226 }
227}
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