Qt: Add about screen
Jeffrey Pfau jeffrey@endrift.com
Wed, 29 Jul 2015 22:13:40 -0700
7 files changed,
263 insertions(+),
5 deletions(-)
A
src/platform/qt/AboutScreen.cpp
@@ -0,0 +1,36 @@
+/* Copyright (c) 2013-2015 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "AboutScreen.h" + +#include "util/version.h" + +#include <QPixmap> + +using namespace QGBA; + +AboutScreen::AboutScreen(QWidget* parent) + : QDialog(parent) +{ + m_ui.setupUi(this); + + QPixmap logo(":/res/mgba-1024.png"); + logo = logo.scaled(m_ui.logo->minimumSize() * devicePixelRatio(), Qt::KeepAspectRatio, Qt::SmoothTransformation); + logo.setDevicePixelRatio(devicePixelRatio()); + m_ui.logo->setPixmap(logo); + + m_ui.projectName->setText(QLatin1String(projectName)); + m_ui.projectVersion->setText(QLatin1String(projectVersion)); + QString gitInfo = m_ui.gitInfo->text(); + gitInfo.replace("{gitBranch}", QLatin1String(gitBranch)); + gitInfo.replace("{gitCommit}", QLatin1String(gitCommit)); + m_ui.gitInfo->setText(gitInfo); + QString description = m_ui.description->text(); + description.replace("{projectName}", QLatin1String(projectName)); + m_ui.description->setText(description); + QString extraLinks = m_ui.extraLinks->text(); + extraLinks.replace("{gitBranch}", QLatin1String(gitBranch)); + m_ui.extraLinks->setText(extraLinks); +}
A
src/platform/qt/AboutScreen.h
@@ -0,0 +1,27 @@
+/* Copyright (c) 2013-2014 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef QGBA_ABOUT_SCREEN +#define QGBA_ABOUT_SCREEN + +#include <QDialog> + +#include "ui_AboutScreen.h" + +namespace QGBA { + +class AboutScreen : public QDialog { +Q_OBJECT + +public: + AboutScreen(QWidget* parent = nullptr); + +private: + Ui::AboutScreen m_ui; +}; + +} + +#endif
A
src/platform/qt/AboutScreen.ui
@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>AboutScreen</class> + <widget class="QWidget" name="AboutScreen"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>565</width> + <height>268</height> + </rect> + </property> + <property name="windowTitle"> + <string>About</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <property name="sizeConstraint"> + <enum>QLayout::SetFixedSize</enum> + </property> + <item row="0" column="1"> + <widget class="QLabel" name="projectName"> + <property name="font"> + <font> + <pointsize>36</pointsize> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>{projectName}</string> + </property> + <property name="alignment"> + <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set> + </property> + </widget> + </item> + <item row="6" column="0" colspan="4"> + <widget class="QLabel" name="copyright"> + <property name="font"> + <font> + <pointsize>10</pointsize> + </font> + </property> + <property name="text"> + <string>© 2013 – 2015 Jeffrey Pfau — Game Boy Advance is a registered trademark of Nintendo Co., Ltd.</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="projectVersion"> + <property name="font"> + <font> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>{projectVersion}</string> + </property> + <property name="alignment"> + <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set> + </property> + <property name="textInteractionFlags"> + <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> + </property> + </widget> + </item> + <item row="0" column="0" rowspan="6"> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="leftMargin"> + <number>8</number> + </property> + <property name="rightMargin"> + <number>16</number> + </property> + <property name="bottomMargin"> + <number>12</number> + </property> + <item> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="logo"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>256</width> + <height>192</height> + </size> + </property> + <property name="text"> + <string>{logo}</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer_3"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item row="3" column="1"> + <widget class="QLabel" name="description"> + <property name="text"> + <string>{projectName} is an open-source Game Boy Advance emulator</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QLabel" name="extraLinks"> + <property name="text"> + <string><a href="http://mgba.io/">Website</a> • <a href="https://forumsmgba.io/">Forums / Support</a> • <a href="https://github.com/mgba-emu/mgba/tree/{gitBranch}">Source</a> • <a href="https://github.com/mgba-emu/mgba/blob/{gitBranch}/LICENSE">License</a></string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="openExternalLinks"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLabel" name="gitInfo"> + <property name="font"> + <font> + <pointsize>10</pointsize> + </font> + </property> + <property name="text"> + <string>Branch: <tt>{gitBranch}</tt><br/>Revision: <tt>{gitCommit}</tt></string> + </property> + <property name="textInteractionFlags"> + <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui>
M
src/platform/qt/CMakeLists.txt
→
src/platform/qt/CMakeLists.txt
@@ -47,6 +47,7 @@ add_definitions(-DQT_STATIC)
endif() set(SOURCE_FILES + AboutScreen.cpp AudioProcessor.cpp CheatsModel.cpp CheatsView.cpp@@ -83,6 +84,7 @@ VFileDevice.cpp
VideoView.cpp) qt5_wrap_ui(UI_FILES + AboutScreen.ui CheatsView.ui GIFView.ui LoadSaveState.ui
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -13,6 +13,7 @@ #include <QMimeData>
#include <QPainter> #include <QStackedLayout> +#include "AboutScreen.h" #include "CheatsView.h" #include "ConfigController.h" #include "Display.h"@@ -344,6 +345,11 @@
void Window::openMemoryWindow() { MemoryView* memoryWindow = new MemoryView(m_controller); openView(memoryWindow); +} + +void Window::openAboutScreen() { + AboutScreen* about = new AboutScreen(); + openView(about); } #ifdef BUILD_SDL@@ -755,6 +761,14 @@ });
addControlledAction(fileMenu, multiWindow, "multiWindow"); #ifndef Q_OS_MAC + fileMenu->addSeparator(); +#endif + + QAction* about = new QAction(tr("About"), fileMenu); + connect(about, SIGNAL(triggered()), this, SLOT(openAboutScreen())); + fileMenu->addAction(about); + +#ifndef Q_OS_MAC addControlledAction(fileMenu, fileMenu->addAction(tr("E&xit"), this, SLOT(close()), QKeySequence::Quit), "quit"); #endif@@ -1216,11 +1230,11 @@ QPainter painter(this);
painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.fillRect(QRect(QPoint(), size()), Qt::black); QSize s = size(); - QSize ds = s; - if (s.width() * m_aspectHeight > s.height() * m_aspectWidth) { - ds.setWidth(s.height() * m_aspectWidth / m_aspectHeight); - } else if (s.width() * m_aspectHeight < s.height() * m_aspectWidth) { - ds.setHeight(s.width() * m_aspectHeight / m_aspectWidth); + QSize ds = s * 0.8; + if (ds.width() * m_aspectHeight > ds.height() * m_aspectWidth) { + ds.setWidth(ds.height() * m_aspectWidth / m_aspectHeight); + } else if (ds.width() * m_aspectHeight < ds.height() * m_aspectWidth) { + ds.setHeight(ds.width() * m_aspectHeight / m_aspectWidth); } QPoint origin = QPoint((s.width() - ds.width()) / 2, (s.height() - ds.height()) / 2); QRect full(origin, ds);
M
src/platform/qt/Window.h
→
src/platform/qt/Window.h
@@ -82,6 +82,8 @@
void openPaletteWindow(); void openMemoryWindow(); + void openAboutScreen(); + #ifdef BUILD_SDL void openGamepadWindow(); #endif