VirtualBox

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

Last change on this file since 103793 was 103793, checked in by vboxsync, 2 months ago

FE/Qt: UICommon: Move versioning related functionality to UIVersion / UIVersionInfo; Rework user cases accordingly.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1/* $Id: VBoxAboutDlg.cpp 103793 2024-03-11 19:17:31Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - VBoxAboutDlg class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-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 <QEvent>
30#include <QLabel>
31#include <QPainter>
32#include <QPushButton>
33#include <QVBoxLayout>
34#include <QWindow>
35
36/* GUI includes: */
37#include "QIDialogButtonBox.h"
38#include "UIIconPool.h"
39#include "UIVersion.h"
40#include "VBoxAboutDlg.h"
41#ifdef VBOX_WS_MAC
42# include "UIDesktopWidgetWatchdog.h"
43#endif
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 : QIWithRetranslateUI2<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 : QIWithRetranslateUI2<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#ifdef VBOX_WS_MAC
84 /* Center according to parent's screen: */
85 QRect geo = geometry();
86 geo.moveCenter(gpDesktop->screenGeometry(m_pPseudoParent).center());
87 setGeometry(geo);
88#endif
89 }
90}
91
92void VBoxAboutDlg::paintEvent(QPaintEvent *)
93{
94 /* Draw About-VirtualBox background image: */
95 QPainter painter(this);
96 painter.drawPixmap(0, 0, m_pixmap);
97}
98
99void VBoxAboutDlg::retranslateUi()
100{
101 setWindowTitle(tr("VirtualBox - About"));
102
103 if (m_pLabel)
104 {
105 const QString strAboutText = tr("VirtualBox Graphical User Interface");
106#ifdef VBOX_BLEEDING_EDGE
107 const QString strVersionText = "EXPERIMENTAL build %1 - " + QString(VBOX_BLEEDING_EDGE);
108#else
109 const QString strVersionText = tr("Version %1");
110#endif
111#ifdef VBOX_OSE
112 m_strAboutText = strAboutText + " " + strVersionText.arg(m_strVersion) + "\n"
113 + QString("%1 2004-" VBOX_C_YEAR " " VBOX_VENDOR).arg(QChar(0xa9));
114#else
115 m_strAboutText = strAboutText + "\n" + strVersionText.arg(m_strVersion);
116#endif
117 m_strAboutText = m_strAboutText + QString(" (Qt%1)").arg(qVersion());
118 m_strAboutText = m_strAboutText + "\n" + QString("Copyright %1 %2 %3.")
119 .arg(QChar(0xa9)).arg(VBOX_C_YEAR).arg(VBOX_VENDOR);
120 m_pLabel->setText(m_strAboutText);
121 }
122}
123
124void VBoxAboutDlg::prepare()
125{
126 /* Delete dialog on close: */
127 setAttribute(Qt::WA_DeleteOnClose);
128 /* Do not count that window as important for application,
129 * it will NOT be taken into account when other top-level windows will be closed: */
130 setAttribute(Qt::WA_QuitOnClose, false);
131
132 /* Make sure the dialog is deleted on pseudo-parent destruction: */
133 if (m_pPseudoParent)
134 connect(m_pPseudoParent, &QObject::destroyed, this, &VBoxAboutDlg::close);
135
136 /* Choose default image: */
137 QString strPath(":/about.png");
138
139 /* Branding: Use a custom about splash picture if set: */
140 const QString strSplash = UIVersionInfo::brandingGetKey("UI/AboutSplash");
141 if (UIVersionInfo::brandingIsActive() && !strSplash.isEmpty())
142 {
143 char szExecPath[1024];
144 RTPathExecDir(szExecPath, 1024);
145 QString strTmpPath = QString("%1/%2").arg(szExecPath).arg(strSplash);
146 if (QFile::exists(strTmpPath))
147 strPath = strTmpPath;
148 }
149
150 /* Load image: */
151 const QIcon icon = UIIconPool::iconSet(strPath);
152 m_size = QSize(640, 480);
153 QWidget *pParent = m_pPseudoParent ? m_pPseudoParent : parentWidget();
154 const qreal fDevicePixelRatio = pParent ? pParent->windowHandle()->devicePixelRatio() : 1;
155 m_pixmap = icon.pixmap(m_size, fDevicePixelRatio);
156
157 /* Prepare main-layout: */
158 prepareMainLayout();
159
160 /* Translate: */
161 retranslateUi();
162}
163
164void VBoxAboutDlg::prepareMainLayout()
165{
166 /* Create main-layout: */
167 m_pMainLayout = new QVBoxLayout(this);
168 if (m_pMainLayout)
169 {
170 /* Prepare stuff: */
171 prepareLabel();
172 prepareCloseButton();
173 }
174}
175
176void VBoxAboutDlg::prepareLabel()
177{
178 /* Create label for version text: */
179 m_pLabel = new QLabel(this);
180 if (m_pLabel)
181 {
182 /* Prepare label for version text: */
183 QPalette palette;
184 /* Branding: Set a different text color (because splash also could be white),
185 * otherwise use white as default color: */
186 const QString strColor = UIVersionInfo::brandingGetKey("UI/AboutTextColor");
187 if (!strColor.isEmpty())
188 palette.setColor(QPalette::WindowText, QColor(strColor).name());
189 else
190 palette.setColor(QPalette::WindowText, Qt::black);
191 m_pLabel->setPalette(palette);
192 m_pLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
193 m_pLabel->setFont(font());
194
195 /* Add label to the main-layout: */
196 if (m_pMainLayout)
197 {
198 m_pMainLayout->addWidget(m_pLabel);
199 m_pMainLayout->setAlignment(m_pLabel, Qt::AlignRight | Qt::AlignBottom);
200 }
201 }
202}
203
204void VBoxAboutDlg::prepareCloseButton()
205{
206 /* Create button-box: */
207 QIDialogButtonBox *pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this);
208 if (pButtonBox)
209 {
210 /* Prepare close-button: */
211 connect(pButtonBox, &QDialogButtonBox::rejected, this, &VBoxAboutDlg::close);
212
213 /* Add button-box to the main-layout: */
214 if (m_pMainLayout)
215 m_pMainLayout->addWidget(pButtonBox);
216 }
217}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use