VirtualBox

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

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

© 2023 Oracle
ContactPrivacy policyTerms of Use