VirtualBox

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

Last change on this file since 100347 was 100075, checked in by vboxsync, 18 months ago

FE/Qt: bugref:10450: Qt6 compatibility bits for QIcon; Good old QIcon::pixmap taking QWindow is deprecated in Qt6; Reworking a lot of calls to use devicePixelRatio acquired beforehand.

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