Move screen widget to its own class, allowing for a size hint

This commit is contained in:
Jeffrey Pfau 2014-10-24 01:47:12 -07:00
parent 6041bf422a
commit 422e2e2f62
2 changed files with 37 additions and 10 deletions

View File

@ -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;
}

View File

@ -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<QAction*> 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