1 | /* $Id: VBoxAboutDlg.cpp 98103 2023-01-17 14:15:46Z 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 <QDialogButtonBox>
|
---|
30 | #include <QDir>
|
---|
31 | #include <QEvent>
|
---|
32 | #include <QLabel>
|
---|
33 | #include <QPainter>
|
---|
34 | #include <QPushButton>
|
---|
35 | #include <QStyle>
|
---|
36 | #include <QVBoxLayout>
|
---|
37 |
|
---|
38 | /* GUI includes: */
|
---|
39 | #include "UIConverter.h"
|
---|
40 | #include "UIExtraDataManager.h"
|
---|
41 | #include "UIIconPool.h"
|
---|
42 | #include "VBoxAboutDlg.h"
|
---|
43 | #include "UICommon.h"
|
---|
44 |
|
---|
45 | /* Other VBox includes: */
|
---|
46 | #include <iprt/path.h>
|
---|
47 | #include <VBox/version.h> /* VBOX_VENDOR */
|
---|
48 |
|
---|
49 |
|
---|
50 | VBoxAboutDlg::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<QIDialog>(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<QIDialog>(pParent)
|
---|
63 | , m_pPseudoParent(0)
|
---|
64 | #endif
|
---|
65 | , m_strVersion(strVersion)
|
---|
66 | , m_pMainLayout(0)
|
---|
67 | , m_pLabel(0)
|
---|
68 | , m_fFixedSizeSet(false)
|
---|
69 | {
|
---|
70 | /* Prepare: */
|
---|
71 | prepare();
|
---|
72 | }
|
---|
73 |
|
---|
74 | bool VBoxAboutDlg::event(QEvent *pEvent)
|
---|
75 | {
|
---|
76 | /* Set fixed-size for dialog: */
|
---|
77 | if (!m_fFixedSizeSet && pEvent->type() == QEvent::Show)
|
---|
78 | {
|
---|
79 | m_fFixedSizeSet = true;
|
---|
80 | setFixedSize(m_size);
|
---|
81 | }
|
---|
82 |
|
---|
83 | /* Call to base-class: */
|
---|
84 | return QIDialog::event(pEvent);
|
---|
85 | }
|
---|
86 |
|
---|
87 | void VBoxAboutDlg::paintEvent(QPaintEvent *)
|
---|
88 | {
|
---|
89 | /* Draw About-VirtualBox background image: */
|
---|
90 | QPainter painter(this);
|
---|
91 | painter.drawPixmap(0, 0, m_pixmap);
|
---|
92 | }
|
---|
93 |
|
---|
94 | void VBoxAboutDlg::retranslateUi()
|
---|
95 | {
|
---|
96 | setWindowTitle(tr("VirtualBox - About"));
|
---|
97 | const QString strAboutText = tr("VirtualBox Graphical User Interface");
|
---|
98 | #ifdef VBOX_BLEEDING_EDGE
|
---|
99 | const QString strVersionText = "EXPERIMENTAL build %1 - " + QString(VBOX_BLEEDING_EDGE);
|
---|
100 | #else
|
---|
101 | const QString strVersionText = tr("Version %1");
|
---|
102 | #endif
|
---|
103 | #ifdef VBOX_OSE
|
---|
104 | m_strAboutText = strAboutText + " " + strVersionText.arg(m_strVersion) + "\n"
|
---|
105 | + QString("%1 2004-" VBOX_C_YEAR " " VBOX_VENDOR).arg(QChar(0xa9));
|
---|
106 | #else
|
---|
107 | m_strAboutText = strAboutText + "\n" + strVersionText.arg(m_strVersion);
|
---|
108 | #endif
|
---|
109 | m_strAboutText = m_strAboutText + QString(" (Qt%1)").arg(qVersion());
|
---|
110 | m_strAboutText = m_strAboutText + "\n" + QString("Copyright %1 %2 %3.")
|
---|
111 | .arg(QChar(0xa9)).arg(VBOX_C_YEAR).arg(VBOX_VENDOR);
|
---|
112 | AssertPtrReturnVoid(m_pLabel);
|
---|
113 | m_pLabel->setText(m_strAboutText);
|
---|
114 | }
|
---|
115 |
|
---|
116 | void VBoxAboutDlg::prepare()
|
---|
117 | {
|
---|
118 | /* Delete dialog on close: */
|
---|
119 | setAttribute(Qt::WA_DeleteOnClose);
|
---|
120 |
|
---|
121 | /* Make sure the dialog is deleted on pseudo-parent destruction: */
|
---|
122 | if (m_pPseudoParent)
|
---|
123 | connect(m_pPseudoParent, &QObject::destroyed, this, &VBoxAboutDlg::close);
|
---|
124 |
|
---|
125 | /* Choose default image: */
|
---|
126 | QString strPath(":/about.png");
|
---|
127 |
|
---|
128 | /* Branding: Use a custom about splash picture if set: */
|
---|
129 | const QString strSplash = uiCommon().brandingGetKey("UI/AboutSplash");
|
---|
130 | if (uiCommon().brandingIsActive() && !strSplash.isEmpty())
|
---|
131 | {
|
---|
132 | char szExecPath[1024];
|
---|
133 | RTPathExecDir(szExecPath, 1024);
|
---|
134 | QString strTmpPath = QString("%1/%2").arg(szExecPath).arg(strSplash);
|
---|
135 | if (QFile::exists(strTmpPath))
|
---|
136 | strPath = strTmpPath;
|
---|
137 | }
|
---|
138 |
|
---|
139 | /* Load image: */
|
---|
140 | const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
|
---|
141 | const double dRatio = (double)iIconMetric / 32;
|
---|
142 | const QIcon icon = UIIconPool::iconSet(strPath);
|
---|
143 | m_size = icon.availableSizes().value(0, QSize(640, 480));
|
---|
144 | m_size *= dRatio;
|
---|
145 | m_pixmap = icon.pixmap(m_size);
|
---|
146 |
|
---|
147 | // WORKAROUND:
|
---|
148 | // Since we don't have x3 and x4 HiDPI icons yet,
|
---|
149 | // and we hadn't enabled automatic up-scaling for now,
|
---|
150 | // we have to make sure m_pixmap is upscaled to required size.
|
---|
151 | const QSize actualSize = m_pixmap.size() / m_pixmap.devicePixelRatio();
|
---|
152 | if ( actualSize.width() < m_size.width()
|
---|
153 | || actualSize.height() < m_size.height())
|
---|
154 | m_pixmap = m_pixmap.scaled(m_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
---|
155 |
|
---|
156 | /* Prepare main-layout: */
|
---|
157 | prepareMainLayout();
|
---|
158 |
|
---|
159 | /* Translate: */
|
---|
160 | retranslateUi();
|
---|
161 | }
|
---|
162 |
|
---|
163 | void VBoxAboutDlg::prepareMainLayout()
|
---|
164 | {
|
---|
165 | /* Create main-layout: */
|
---|
166 | m_pMainLayout = new QVBoxLayout(this);
|
---|
167 | if (m_pMainLayout)
|
---|
168 | {
|
---|
169 | /* Prepare label: */
|
---|
170 | prepareLabel();
|
---|
171 |
|
---|
172 | /* Prepare close-button: */
|
---|
173 | prepareCloseButton();
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | void VBoxAboutDlg::prepareLabel()
|
---|
178 | {
|
---|
179 | /* Create label for version text: */
|
---|
180 | m_pLabel = new QLabel;
|
---|
181 | if (m_pLabel)
|
---|
182 | {
|
---|
183 | /* Prepare label for version text: */
|
---|
184 | QPalette palette;
|
---|
185 | /* Branding: Set a different text color (because splash also could be white),
|
---|
186 | * otherwise use white as default color: */
|
---|
187 | const QString strColor = uiCommon().brandingGetKey("UI/AboutTextColor");
|
---|
188 | if (!strColor.isEmpty())
|
---|
189 | palette.setColor(QPalette::WindowText, QColor(strColor).name());
|
---|
190 | else
|
---|
191 | palette.setColor(QPalette::WindowText, Qt::black);
|
---|
192 | m_pLabel->setPalette(palette);
|
---|
193 | m_pLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
---|
194 | m_pLabel->setFont(font());
|
---|
195 |
|
---|
196 | /* Add label to the main-layout: */
|
---|
197 | m_pMainLayout->addWidget(m_pLabel);
|
---|
198 | m_pMainLayout->setAlignment(m_pLabel, Qt::AlignRight | Qt::AlignBottom);
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | void VBoxAboutDlg::prepareCloseButton()
|
---|
203 | {
|
---|
204 | /* Create button-box: */
|
---|
205 | QDialogButtonBox *pButtonBox = new QDialogButtonBox;
|
---|
206 | if (pButtonBox)
|
---|
207 | {
|
---|
208 | /* Create close-button: */
|
---|
209 | QPushButton *pCloseButton = pButtonBox->addButton(QDialogButtonBox::Close);
|
---|
210 | AssertPtrReturnVoid(pCloseButton);
|
---|
211 | /* Prepare close-button: */
|
---|
212 | connect(pButtonBox, &QDialogButtonBox::rejected, this, &VBoxAboutDlg::reject);
|
---|
213 |
|
---|
214 | /* Add button-box to the main-layout: */
|
---|
215 | m_pMainLayout->addWidget(pButtonBox);
|
---|
216 | }
|
---|
217 | }
|
---|