1 | /* $Id: VBoxAboutDlg.cpp 71553 2018-03-28 17:28:44Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - VBoxAboutDlg class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
19 | # include <precomp.h>
|
---|
20 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
21 |
|
---|
22 | /* Qt includes: */
|
---|
23 | # include <QDialogButtonBox>
|
---|
24 | # include <QDir>
|
---|
25 | # include <QEvent>
|
---|
26 | # include <QLabel>
|
---|
27 | # include <QPainter>
|
---|
28 | # include <QPushButton>
|
---|
29 | # include <QStyle>
|
---|
30 | # include <QVBoxLayout>
|
---|
31 |
|
---|
32 | /* GUI includes: */
|
---|
33 | # include "UIConverter.h"
|
---|
34 | # include "UIExtraDataManager.h"
|
---|
35 | # include "UIIconPool.h"
|
---|
36 | # include "VBoxAboutDlg.h"
|
---|
37 | # include "VBoxGlobal.h"
|
---|
38 |
|
---|
39 | /* Other VBox includes: */
|
---|
40 | # include <iprt/path.h>
|
---|
41 | # include <VBox/version.h> /* VBOX_VENDOR */
|
---|
42 |
|
---|
43 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
44 |
|
---|
45 | VBoxAboutDlg::VBoxAboutDlg(QWidget *pParent, const QString &strVersion)
|
---|
46 | #ifdef VBOX_WS_MAC
|
---|
47 | // No need for About dialog parent on macOS.
|
---|
48 | // First of all, non of other native apps (Safari, App Store, iTunes) centers About dialog according the app itself, they do
|
---|
49 | // it according to screen instead, we should do it as well. Besides that since About dialog is not modal, it will be in
|
---|
50 | // conflict with modal dialogs if there will be a parent passed, because the dialog will not have own event-loop in that case.
|
---|
51 | : QIWithRetranslateUI2<QIDialog>(0)
|
---|
52 | , m_pPseudoParent(pParent)
|
---|
53 | #else
|
---|
54 | // On other hosts we will keep the current behavior for now.
|
---|
55 | // First of all it's quite difficult to find native (Metro UI) Windows app which have About dialog at all. But non-native
|
---|
56 | // cross-platform apps (Qt Creator, VLC) centers About dialog according the app exactly.
|
---|
57 | : QIWithRetranslateUI2<QIDialog>(pParent)
|
---|
58 | , m_pPseudoParent(0)
|
---|
59 | #endif
|
---|
60 | , m_strVersion(strVersion)
|
---|
61 | , m_pMainLayout(0)
|
---|
62 | , m_pLabel(0)
|
---|
63 | {
|
---|
64 | /* Prepare: */
|
---|
65 | prepare();
|
---|
66 | }
|
---|
67 |
|
---|
68 | bool VBoxAboutDlg::event(QEvent *pEvent)
|
---|
69 | {
|
---|
70 | /* Set fixed-size for dialog: */
|
---|
71 | if (pEvent->type() == QEvent::Polish)
|
---|
72 | setFixedSize(m_size);
|
---|
73 |
|
---|
74 | /* Call to base-class: */
|
---|
75 | return QIDialog::event(pEvent);
|
---|
76 | }
|
---|
77 |
|
---|
78 | void VBoxAboutDlg::paintEvent(QPaintEvent *)
|
---|
79 | {
|
---|
80 | /* Draw About-VirtualBox background image: */
|
---|
81 | QPainter painter(this);
|
---|
82 | painter.drawPixmap(0, 0, m_pixmap);
|
---|
83 | }
|
---|
84 |
|
---|
85 | void VBoxAboutDlg::retranslateUi()
|
---|
86 | {
|
---|
87 | setWindowTitle(tr("VirtualBox - About"));
|
---|
88 | const QString strAboutText = tr("VirtualBox Graphical User Interface");
|
---|
89 | #ifdef VBOX_BLEEDING_EDGE
|
---|
90 | const QString strVersionText = "EXPERIMENTAL build %1 - " + QString(VBOX_BLEEDING_EDGE);
|
---|
91 | #else
|
---|
92 | const QString strVersionText = tr("Version %1");
|
---|
93 | #endif
|
---|
94 | #ifdef VBOX_OSE
|
---|
95 | m_strAboutText = strAboutText + " " + strVersionText.arg(m_strVersion) + "\n"
|
---|
96 | + QString("%1 2004-" VBOX_C_YEAR " " VBOX_VENDOR).arg(QChar(0xa9));
|
---|
97 | #else
|
---|
98 | m_strAboutText = strAboutText + "\n" + strVersionText.arg(m_strVersion);
|
---|
99 | #endif
|
---|
100 | m_strAboutText = m_strAboutText + QString(" (Qt%1)").arg(qVersion());
|
---|
101 | m_strAboutText = m_strAboutText + "\n" + QString("Copyright %1 %2 %3 and/or its affiliates. All rights reserved.")
|
---|
102 | .arg(QChar(0xa9)).arg(VBOX_C_YEAR).arg(VBOX_VENDOR);
|
---|
103 | AssertPtrReturnVoid(m_pLabel);
|
---|
104 | m_pLabel->setText(m_strAboutText);
|
---|
105 | }
|
---|
106 |
|
---|
107 | void VBoxAboutDlg::prepare()
|
---|
108 | {
|
---|
109 | /* Delete dialog on close: */
|
---|
110 | setAttribute(Qt::WA_DeleteOnClose);
|
---|
111 |
|
---|
112 | /* Make sure the dialog is deleted on pseudo-parent destruction: */
|
---|
113 | if (m_pPseudoParent)
|
---|
114 | connect(m_pPseudoParent, &QObject::destroyed, this, &VBoxAboutDlg::close);
|
---|
115 |
|
---|
116 | /* Choose default image: */
|
---|
117 | QString strPath(":/about.png");
|
---|
118 |
|
---|
119 | /* Branding: Use a custom about splash picture if set: */
|
---|
120 | const QString strSplash = vboxGlobal().brandingGetKey("UI/AboutSplash");
|
---|
121 | if (vboxGlobal().brandingIsActive() && !strSplash.isEmpty())
|
---|
122 | {
|
---|
123 | char szExecPath[1024];
|
---|
124 | RTPathExecDir(szExecPath, 1024);
|
---|
125 | QString strTmpPath = QString("%1/%2").arg(szExecPath).arg(strSplash);
|
---|
126 | if (QFile::exists(strTmpPath))
|
---|
127 | strPath = strTmpPath;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /* Load image: */
|
---|
131 | const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
|
---|
132 | const double dRatio = (double)iIconMetric / 32;
|
---|
133 | const QIcon icon = UIIconPool::iconSet(strPath);
|
---|
134 | m_size = icon.availableSizes().value(0, QSize(640, 480));
|
---|
135 | m_size *= dRatio;
|
---|
136 | m_pixmap = icon.pixmap(m_size);
|
---|
137 |
|
---|
138 | // WORKAROUND:
|
---|
139 | // Since we don't have x3 and x4 HiDPI icons yet,
|
---|
140 | // and we hadn't enabled automatic up-scaling for now,
|
---|
141 | // we have to make sure m_pixmap is upscaled to required size.
|
---|
142 | const QSize actualSize = m_pixmap.size() / m_pixmap.devicePixelRatio();
|
---|
143 | if ( actualSize.width() < m_size.width()
|
---|
144 | || actualSize.height() < m_size.height())
|
---|
145 | m_pixmap = m_pixmap.scaled(m_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
---|
146 |
|
---|
147 | /* Prepare main-layout: */
|
---|
148 | prepareMainLayout();
|
---|
149 |
|
---|
150 | /* Translate: */
|
---|
151 | retranslateUi();
|
---|
152 | }
|
---|
153 |
|
---|
154 | void VBoxAboutDlg::prepareMainLayout()
|
---|
155 | {
|
---|
156 | /* Create main-layout: */
|
---|
157 | m_pMainLayout = new QVBoxLayout(this);
|
---|
158 | if (m_pMainLayout)
|
---|
159 | {
|
---|
160 | /* Prepare label: */
|
---|
161 | prepareLabel();
|
---|
162 |
|
---|
163 | /* Prepare close-button: */
|
---|
164 | prepareCloseButton();
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | void VBoxAboutDlg::prepareLabel()
|
---|
169 | {
|
---|
170 | /* Create label for version text: */
|
---|
171 | m_pLabel = new QLabel;
|
---|
172 | if (m_pLabel)
|
---|
173 | {
|
---|
174 | /* Prepare label for version text: */
|
---|
175 | QPalette palette;
|
---|
176 | /* Branding: Set a different text color (because splash also could be white),
|
---|
177 | * otherwise use white as default color: */
|
---|
178 | const QString strColor = vboxGlobal().brandingGetKey("UI/AboutTextColor");
|
---|
179 | if (!strColor.isEmpty())
|
---|
180 | palette.setColor(QPalette::WindowText, QColor(strColor).name());
|
---|
181 | else
|
---|
182 | palette.setColor(QPalette::WindowText, Qt::black);
|
---|
183 | m_pLabel->setPalette(palette);
|
---|
184 | m_pLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
---|
185 | m_pLabel->setFont(font());
|
---|
186 |
|
---|
187 | /* Add label to the main-layout: */
|
---|
188 | m_pMainLayout->addWidget(m_pLabel);
|
---|
189 | m_pMainLayout->setAlignment(m_pLabel, Qt::AlignRight | Qt::AlignBottom);
|
---|
190 | }
|
---|
191 | }
|
---|
192 |
|
---|
193 | void VBoxAboutDlg::prepareCloseButton()
|
---|
194 | {
|
---|
195 | /* Create button-box: */
|
---|
196 | QDialogButtonBox *pButtonBox = new QDialogButtonBox;
|
---|
197 | if (pButtonBox)
|
---|
198 | {
|
---|
199 | /* Create close-button: */
|
---|
200 | QPushButton *pCloseButton = pButtonBox->addButton(QDialogButtonBox::Close);
|
---|
201 | AssertPtrReturnVoid(pCloseButton);
|
---|
202 | /* Prepare close-button: */
|
---|
203 | connect(pButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
---|
204 |
|
---|
205 | /* Add button-box to the main-layout: */
|
---|
206 | m_pMainLayout->addWidget(pButtonBox);
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|