VirtualBox

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

Last change on this file was 104358, checked in by vboxsync, 5 weeks 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
RevLine 
[26719]1/* $Id: VBoxAboutDlg.cpp 104358 2024-04-18 05:33:40Z vboxsync $ */
[12582]2/** @file
[52722]3 * VBox Qt GUI - VBoxAboutDlg class implementation.
[12582]4 */
5
6/*
[98103]7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
[12582]8 *
[96407]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
[12582]26 */
27
[57551]28/* Qt includes: */
[76606]29#include <QEvent>
30#include <QLabel>
31#include <QPainter>
32#include <QPushButton>
33#include <QVBoxLayout>
[101560]34#include <QWindow>
[12582]35
[57551]36/* GUI includes: */
[100070]37#include "QIDialogButtonBox.h"
[76606]38#include "UIIconPool.h"
[104358]39#include "UITranslationEventListener.h"
[103793]40#include "UIVersion.h"
[76606]41#include "VBoxAboutDlg.h"
[100070]42#ifdef VBOX_WS_MAC
43# include "UIDesktopWidgetWatchdog.h"
44#endif
[52722]45
[57551]46/* Other VBox includes: */
[100070]47#include <iprt/path.h> /* RTPathExecDir */
[76606]48#include <VBox/version.h> /* VBOX_VENDOR */
[57551]49
[12582]50
[34781]51VBoxAboutDlg::VBoxAboutDlg(QWidget *pParent, const QString &strVersion)
[68441]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.
[104358]57 : QDialog(0)
[68441]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.
[104358]63 : QDialog(pParent)
[68441]64 , m_pPseudoParent(0)
65#endif
[100070]66 , m_fPolished(false)
[34781]67 , m_strVersion(strVersion)
[71553]68 , m_pMainLayout(0)
[57608]69 , m_pLabel(0)
[12582]70{
[57551]71 prepare();
[12582]72}
73
[100070]74void VBoxAboutDlg::showEvent(QShowEvent *pEvent)
[12582]75{
[100070]76 /* Call to base-class: */
77 QDialog::showEvent(pEvent);
78
79 /* Polish once: */
80 if (!m_fPolished)
[96815]81 {
[100070]82 m_fPolished = true;
[51474]83 setFixedSize(m_size);
[100070]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
[96815]90 }
[12582]91}
92
[71553]93void VBoxAboutDlg::paintEvent(QPaintEvent *)
[12582]94{
[71553]95 /* Draw About-VirtualBox background image: */
[34781]96 QPainter painter(this);
[51474]97 painter.drawPixmap(0, 0, m_pixmap);
[12582]98}
99
[104358]100void VBoxAboutDlg::sltRetranslateUI()
[34781]101{
102 setWindowTitle(tr("VirtualBox - About"));
[100070]103
104 if (m_pLabel)
105 {
106 const QString strAboutText = tr("VirtualBox Graphical User Interface");
[34781]107#ifdef VBOX_BLEEDING_EDGE
[100070]108 const QString strVersionText = "EXPERIMENTAL build %1 - " + QString(VBOX_BLEEDING_EDGE);
[63307]109#else
[100070]110 const QString strVersionText = tr("Version %1");
[63307]111#endif
112#ifdef VBOX_OSE
[100070]113 m_strAboutText = strAboutText + " " + strVersionText.arg(m_strVersion) + "\n"
114 + QString("%1 2004-" VBOX_C_YEAR " " VBOX_VENDOR).arg(QChar(0xa9));
[63307]115#else
[100070]116 m_strAboutText = strAboutText + "\n" + strVersionText.arg(m_strVersion);
[63307]117#endif
[100070]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 }
[12582]123}
124
[57551]125void VBoxAboutDlg::prepare()
126{
127 /* Delete dialog on close: */
128 setAttribute(Qt::WA_DeleteOnClose);
[100070]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);
[57551]132
[68441]133 /* Make sure the dialog is deleted on pseudo-parent destruction: */
[68443]134 if (m_pPseudoParent)
135 connect(m_pPseudoParent, &QObject::destroyed, this, &VBoxAboutDlg::close);
[68441]136
[57551]137 /* Choose default image: */
138 QString strPath(":/about.png");
139
140 /* Branding: Use a custom about splash picture if set: */
[103793]141 const QString strSplash = UIVersionInfo::brandingGetKey("UI/AboutSplash");
142 if (UIVersionInfo::brandingIsActive() && !strSplash.isEmpty())
[57551]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: */
[57608]152 const QIcon icon = UIIconPool::iconSet(strPath);
[100070]153 m_size = QSize(640, 480);
[100075]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);
[57551]157
[57716]158 /* Prepare main-layout: */
[57551]159 prepareMainLayout();
160
161 /* Translate: */
[104358]162 sltRetranslateUI();
163 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
164 this, &VBoxAboutDlg::sltRetranslateUI);
[57551]165}
166
167void VBoxAboutDlg::prepareMainLayout()
168{
169 /* Create main-layout: */
[57640]170 m_pMainLayout = new QVBoxLayout(this);
[71553]171 if (m_pMainLayout)
[57551]172 {
[100070]173 /* Prepare stuff: */
[57640]174 prepareLabel();
175 prepareCloseButton();
176 }
177}
178
179void VBoxAboutDlg::prepareLabel()
180{
181 /* Create label for version text: */
[100070]182 m_pLabel = new QLabel(this);
[71553]183 if (m_pLabel)
[57640]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: */
[103793]189 const QString strColor = UIVersionInfo::brandingGetKey("UI/AboutTextColor");
[57640]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: */
[100070]199 if (m_pMainLayout)
200 {
201 m_pMainLayout->addWidget(m_pLabel);
202 m_pMainLayout->setAlignment(m_pLabel, Qt::AlignRight | Qt::AlignBottom);
203 }
[57640]204 }
205}
206
207void VBoxAboutDlg::prepareCloseButton()
208{
209 /* Create button-box: */
[100070]210 QIDialogButtonBox *pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this);
[71553]211 if (pButtonBox)
[57640]212 {
[57716]213 /* Prepare close-button: */
[100070]214 connect(pButtonBox, &QDialogButtonBox::rejected, this, &VBoxAboutDlg::close);
[57716]215
216 /* Add button-box to the main-layout: */
[100070]217 if (m_pMainLayout)
218 m_pMainLayout->addWidget(pButtonBox);
[57551]219 }
220}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use