all repos — mgba @ 422e2e2f62fb536ab8c9a2155999287cef5454ea

mGBA Game Boy Advance Emulator

Move screen widget to its own class, allowing for a size hint
Jeffrey Pfau jeffrey@endrift.com
Fri, 24 Oct 2014 01:47:12 -0700
commit

422e2e2f62fb536ab8c9a2155999287cef5454ea

parent

6041bf422aa7c952b53e73f64202510b5c6bbf48

2 files changed, 37 insertions(+), 10 deletions(-)

jump to
M src/platform/qt/Window.cppsrc/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 @@ QGLFormat format(QGLFormat(QGL::Rgba | QGL::DoubleBuffer));

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::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; +}
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -18,6 +18,7 @@

class GameController; class GDBController; class LogView; +class WindowBackground; class Window : public QMainWindow { Q_OBJECT

@@ -70,12 +71,25 @@ Display* m_display;

QList<QAction*> m_gameActions; LogView* m_logView; LoadSaveState* m_stateWindow; - QLabel* m_screenWidget; + WindowBackground* m_screenWidget; QPixmap m_logo; #ifdef USE_GDB_STUB GDBController* m_gdbController; #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; }; }