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