From 422e2e2f62fb536ab8c9a2155999287cef5454ea Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 24 Oct 2014 01:47:12 -0700 Subject: [PATCH] Move screen widget to its own class, allowing for a size hint --- src/platform/qt/Window.cpp | 31 ++++++++++++++++++++++--------- src/platform/qt/Window.h | 16 +++++++++++++++- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 4d2c4c896..7fdfe892a 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -22,7 +22,7 @@ Window::Window(QWidget* parent) : QMainWindow(parent) , m_logView(new LogView()) , m_stateWindow(nullptr) - , m_screenWidget(new QLabel()) + , m_screenWidget(new WindowBackground()) , m_logo(":/res/mgba-1024.png") #ifdef USE_GDB_STUB , m_gdbController(nullptr) @@ -35,16 +35,9 @@ Window::Window(QWidget* parent) format.setSwapInterval(1); m_display = new Display(format); - m_screenWidget->setLayout(new QStackedLayout()); - m_screenWidget->layout()->setContentsMargins(0, 0, 0, 0); - m_screenWidget->setAlignment(Qt::AlignCenter); m_screenWidget->setMinimumSize(m_display->minimumSize()); m_screenWidget->setSizePolicy(m_display->sizePolicy()); - m_screenWidget->resize(m_display->minimumSize() * 2); - QPalette palette = m_screenWidget->palette(); - palette.setColor(m_screenWidget->backgroundRole(), Qt::black); - m_screenWidget->setPalette(palette); - m_screenWidget->setAutoFillBackground(true); + m_screenWidget->setSizeHint(m_display->minimumSize() * 2); setCentralWidget(m_screenWidget); connect(m_controller, SIGNAL(gameStarted(GBAThread*)), this, SLOT(gameStarted(GBAThread*))); @@ -446,3 +439,23 @@ void Window::attachWidget(QWidget* widget) { void Window::detachWidget(QWidget* widget) { m_screenWidget->layout()->removeWidget(widget); } + +WindowBackground::WindowBackground(QWidget* parent) + : QLabel(parent) +{ + setLayout(new QStackedLayout()); + layout()->setContentsMargins(0, 0, 0, 0); + setAlignment(Qt::AlignCenter); + QPalette p = palette(); + p.setColor(backgroundRole(), Qt::black); + setPalette(p); + setAutoFillBackground(true); +} + +void WindowBackground::setSizeHint(const QSize& hint) { + m_sizeHint = hint; +} + +QSize WindowBackground::sizeHint() const { + return m_sizeHint; +} diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index 9d6fe38d0..7b6ad7a8a 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -18,6 +18,7 @@ namespace QGBA { class GameController; class GDBController; class LogView; +class WindowBackground; class Window : public QMainWindow { Q_OBJECT @@ -70,7 +71,7 @@ private: QList m_gameActions; LogView* m_logView; LoadSaveState* m_stateWindow; - QLabel* m_screenWidget; + WindowBackground* m_screenWidget; QPixmap m_logo; #ifdef USE_GDB_STUB @@ -78,6 +79,19 @@ private: #endif }; +class WindowBackground : public QLabel { +Q_OBJECT + +public: + WindowBackground(QWidget* parent = 0); + + void setSizeHint(const QSize& size); + virtual QSize sizeHint() const override; + +private: + QSize m_sizeHint; +}; + } #endif