VirtualBox

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

Last change on this file since 82781 was 80887, checked in by vboxsync, 5 years ago

FE/Qt: bugref:8938. Completing connect syntax migration except the widgets subfolder.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: VBoxAboutDlg.cpp 80887 2019-09-18 12:21:55Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - VBoxAboutDlg class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2019 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/* Qt includes: */
19#include <QDialogButtonBox>
20#include <QDir>
21#include <QEvent>
22#include <QLabel>
23#include <QPainter>
24#include <QPushButton>
25#include <QStyle>
26#include <QVBoxLayout>
27
28/* GUI includes: */
29#include "UIConverter.h"
30#include "UIExtraDataManager.h"
31#include "UIIconPool.h"
32#include "VBoxAboutDlg.h"
33#include "UICommon.h"
34
35/* Other VBox includes: */
36#include <iprt/path.h>
37#include <VBox/version.h> /* VBOX_VENDOR */
38
39
40VBoxAboutDlg::VBoxAboutDlg(QWidget *pParent, const QString &strVersion)
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.
52 : QIWithRetranslateUI2<QIDialog>(pParent)
53 , m_pPseudoParent(0)
54#endif
55 , m_strVersion(strVersion)
56 , m_pMainLayout(0)
57 , m_pLabel(0)
58{
59 /* Prepare: */
60 prepare();
61}
62
63bool VBoxAboutDlg::event(QEvent *pEvent)
64{
65 /* Set fixed-size for dialog: */
66 if (pEvent->type() == QEvent::Polish)
67 setFixedSize(m_size);
68
69 /* Call to base-class: */
70 return QIDialog::event(pEvent);
71}
72
73void VBoxAboutDlg::paintEvent(QPaintEvent *)
74{
75 /* Draw About-VirtualBox background image: */
76 QPainter painter(this);
77 painter.drawPixmap(0, 0, m_pixmap);
78}
79
80void VBoxAboutDlg::retranslateUi()
81{
82 setWindowTitle(tr("VirtualBox - About"));
83 const QString strAboutText = tr("VirtualBox Graphical User Interface");
84#ifdef VBOX_BLEEDING_EDGE
85 const QString strVersionText = "EXPERIMENTAL build %1 - " + QString(VBOX_BLEEDING_EDGE);
86#else
87 const QString strVersionText = tr("Version %1");
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
93 m_strAboutText = strAboutText + "\n" + strVersionText.arg(m_strVersion);
94#endif
95 m_strAboutText = m_strAboutText + QString(" (Qt%1)").arg(qVersion());
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);
98 AssertPtrReturnVoid(m_pLabel);
99 m_pLabel->setText(m_strAboutText);
100}
101
102void VBoxAboutDlg::prepare()
103{
104 /* Delete dialog on close: */
105 setAttribute(Qt::WA_DeleteOnClose);
106
107 /* Make sure the dialog is deleted on pseudo-parent destruction: */
108 if (m_pPseudoParent)
109 connect(m_pPseudoParent, &QObject::destroyed, this, &VBoxAboutDlg::close);
110
111 /* Choose default image: */
112 QString strPath(":/about.png");
113
114 /* Branding: Use a custom about splash picture if set: */
115 const QString strSplash = uiCommon().brandingGetKey("UI/AboutSplash");
116 if (uiCommon().brandingIsActive() && !strSplash.isEmpty())
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: */
126 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
127 const double dRatio = (double)iIconMetric / 32;
128 const QIcon icon = UIIconPool::iconSet(strPath);
129 m_size = icon.availableSizes().value(0, QSize(640, 480));
130 m_size *= dRatio;
131 m_pixmap = icon.pixmap(m_size);
132
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
142 /* Prepare main-layout: */
143 prepareMainLayout();
144
145 /* Translate: */
146 retranslateUi();
147}
148
149void VBoxAboutDlg::prepareMainLayout()
150{
151 /* Create main-layout: */
152 m_pMainLayout = new QVBoxLayout(this);
153 if (m_pMainLayout)
154 {
155 /* Prepare label: */
156 prepareLabel();
157
158 /* Prepare close-button: */
159 prepareCloseButton();
160 }
161}
162
163void VBoxAboutDlg::prepareLabel()
164{
165 /* Create label for version text: */
166 m_pLabel = new QLabel;
167 if (m_pLabel)
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: */
173 const QString strColor = uiCommon().brandingGetKey("UI/AboutTextColor");
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
188void VBoxAboutDlg::prepareCloseButton()
189{
190 /* Create button-box: */
191 QDialogButtonBox *pButtonBox = new QDialogButtonBox;
192 if (pButtonBox)
193 {
194 /* Create close-button: */
195 QPushButton *pCloseButton = pButtonBox->addButton(QDialogButtonBox::Close);
196 AssertPtrReturnVoid(pCloseButton);
197 /* Prepare close-button: */
198 connect(pButtonBox, &QDialogButtonBox::rejected, this, &VBoxAboutDlg::reject);
199
200 /* Add button-box to the main-layout: */
201 m_pMainLayout->addWidget(pButtonBox);
202 }
203}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use