Qt: Remember scale option independent of core dimensions

This commit is contained in:
Jeffrey Pfau 2016-10-04 11:24:56 -07:00
parent 0b2f8bb4dc
commit c8db38f93b
3 changed files with 28 additions and 9 deletions

View File

@ -37,6 +37,7 @@ Misc:
- All: Split out install locations for Libretro and OpenEmu - All: Split out install locations for Libretro and OpenEmu
- GBA Video: Clean up unused timers - GBA Video: Clean up unused timers
- Qt: Manage window sizes slightly better - Qt: Manage window sizes slightly better
- Qt: Remember scale option independent of core dimensions
0.5.0: (2016-09-19) 0.5.0: (2016-09-19)
Features: Features:

View File

@ -89,8 +89,14 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
m_screenWidget->setMinimumSize(m_display->minimumSize()); m_screenWidget->setMinimumSize(m_display->minimumSize());
m_screenWidget->setSizePolicy(m_display->sizePolicy()); m_screenWidget->setSizePolicy(m_display->sizePolicy());
int i = 2;
QVariant multiplier = m_config->getOption("scaleMultiplier");
if (!multiplier.isNull()) {
m_savedScale = multiplier.toInt();
i = m_savedScale;
}
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
m_screenWidget->setSizeHint(QSize(VIDEO_HORIZONTAL_PIXELS * 2, VIDEO_VERTICAL_PIXELS * 2)); m_screenWidget->setSizeHint(QSize(VIDEO_HORIZONTAL_PIXELS * i, VIDEO_VERTICAL_PIXELS * i));
#endif #endif
m_screenWidget->setPixmap(m_logo); m_screenWidget->setPixmap(m_logo);
m_screenWidget->setLockAspectRatio(m_logo.width(), m_logo.height()); m_screenWidget->setLockAspectRatio(m_logo.width(), m_logo.height());
@ -569,17 +575,15 @@ void Window::resizeEvent(QResizeEvent* event) {
if (m_controller->isLoaded()) { if (m_controller->isLoaded()) {
size = m_controller->screenDimensions(); size = m_controller->screenDimensions();
} }
if (event->size().width() % size.width() == 0 && event->size().height() % size.height() == 0 && if (m_screenWidget->width() % size.width() == 0 && m_screenWidget->height() % size.height() == 0 &&
event->size().width() / size.width() == event->size().height() / size.height()) { m_screenWidget->width() / size.width() == m_screenWidget->height() / size.height()) {
factor = event->size().width() / size.width(); factor = m_screenWidget->width() / size.width();
} else {
m_savedScale = 0;
} }
for (QMap<int, QAction*>::iterator iter = m_frameSizes.begin(); iter != m_frameSizes.end(); ++iter) { for (QMap<int, QAction*>::iterator iter = m_frameSizes.begin(); iter != m_frameSizes.end(); ++iter) {
bool enableSignals = iter.value()->blockSignals(true); bool enableSignals = iter.value()->blockSignals(true);
if (iter.key() == factor) { iter.value()->setChecked(iter.key() == factor);
iter.value()->setChecked(true);
} else {
iter.value()->setChecked(false);
}
iter.value()->blockSignals(enableSignals); iter.value()->blockSignals(enableSignals);
} }
@ -605,6 +609,11 @@ void Window::showEvent(QShowEvent* event) {
void Window::closeEvent(QCloseEvent* event) { void Window::closeEvent(QCloseEvent* event) {
emit shutdown(); emit shutdown();
m_config->setQtOption("windowPos", pos()); m_config->setQtOption("windowPos", pos());
if (m_savedScale > 0) {
m_config->setOption("height", VIDEO_VERTICAL_PIXELS * m_savedScale);
m_config->setOption("width", VIDEO_HORIZONTAL_PIXELS * m_savedScale);
}
saveConfig(); saveConfig();
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
} }
@ -708,6 +717,9 @@ void Window::gameStarted(mCoreThread* context, const QString& fname) {
context->core->desiredVideoDimensions(context->core, &width, &height); context->core->desiredVideoDimensions(context->core, &width, &height);
m_display->setMinimumSize(width, height); m_display->setMinimumSize(width, height);
m_screenWidget->setMinimumSize(m_display->minimumSize()); m_screenWidget->setMinimumSize(m_display->minimumSize());
if (m_savedScale > 0) {
resizeFrame(QSize(width, height) * m_savedScale);
}
attachWidget(m_display); attachWidget(m_display);
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
@ -1174,6 +1186,9 @@ void Window::setupMenu(QMenuBar* menubar) {
for (int i = 1; i <= 6; ++i) { for (int i = 1; i <= 6; ++i) {
QAction* setSize = new QAction(tr("%1x").arg(QString::number(i)), avMenu); QAction* setSize = new QAction(tr("%1x").arg(QString::number(i)), avMenu);
setSize->setCheckable(true); setSize->setCheckable(true);
if (m_savedScale == i) {
setSize->setChecked(true);
}
connect(setSize, &QAction::triggered, [this, i, setSize]() { connect(setSize, &QAction::triggered, [this, i, setSize]() {
showNormal(); showNormal();
QSize size(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS); QSize size(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
@ -1181,6 +1196,8 @@ void Window::setupMenu(QMenuBar* menubar) {
size = m_controller->screenDimensions(); size = m_controller->screenDimensions();
} }
size *= i; size *= i;
m_savedScale = i;
m_config->setOption("scaleMultiplier", i); // TODO: Port to other
resizeFrame(size); resizeFrame(size);
bool enableSignals = setSize->blockSignals(true); bool enableSignals = setSize->blockSignals(true);
setSize->setChecked(true); setSize->setChecked(true);

View File

@ -153,6 +153,7 @@ private:
GameController* m_controller; GameController* m_controller;
Display* m_display; Display* m_display;
int m_savedScale;
// TODO: Move these to a new class // TODO: Move these to a new class
QList<QAction*> m_gameActions; QList<QAction*> m_gameActions;
QList<QAction*> m_nonMpActions; QList<QAction*> m_nonMpActions;