Qt: Fix saving settings enabling camera when camera name changes (fixes #2125)

This commit is contained in:
Vicki Pfau 2021-04-14 20:49:32 -07:00
parent 094fe8fec0
commit fcdf6c53eb
4 changed files with 32 additions and 16 deletions

View File

@ -15,6 +15,7 @@ Other fixes:
- Qt: Fix crash when switching from high-resolution OpenGL renderer to software - Qt: Fix crash when switching from high-resolution OpenGL renderer to software
- Qt: Fix OpenGL renderer lagging behind when fast-forwarding (fixes mgba.io/i/2094) - Qt: Fix OpenGL renderer lagging behind when fast-forwarding (fixes mgba.io/i/2094)
- Qt: Fix smudged window icon on Windows - Qt: Fix smudged window icon on Windows
- Qt: Fix saving settings enabling camera when camera name changes (fixes mgba.io/i/2125)
Misc: Misc:
- Core: Truncate preloading ROMs that slightly exceed max size (fixes mgba.io/i/2093) - Core: Truncate preloading ROMs that slightly exceed max size (fixes mgba.io/i/2093)
- GBA: Default-enable VBA bug compat for Ruby and Emerald ROM hacks - GBA: Default-enable VBA bug compat for Ruby and Emerald ROM hacks

View File

@ -94,23 +94,23 @@ InputController::InputController(int playerId, QWidget* topLevel, QObject* paren
InputControllerImage* image = static_cast<InputControllerImage*>(context); InputControllerImage* image = static_cast<InputControllerImage*>(context);
image->w = w; image->w = w;
image->h = h; image->h = h;
image->p->m_cameraActive = true;
if (image->image.isNull()) { if (image->image.isNull()) {
image->image.load(":/res/no-cam.png"); image->image.load(":/res/no-cam.png");
} }
#ifdef BUILD_QT_MULTIMEDIA #ifdef BUILD_QT_MULTIMEDIA
if (image->p->m_config->getQtOption("cameraDriver").toInt() == static_cast<int>(CameraDriver::QT_MULTIMEDIA)) {
QByteArray camera = image->p->m_config->getQtOption("camera").toByteArray(); QByteArray camera = image->p->m_config->getQtOption("camera").toByteArray();
if (!camera.isNull()) { if (!camera.isNull()) {
QMetaObject::invokeMethod(image->p, "setCamera", Q_ARG(QByteArray, camera)); image->p->m_cameraDevice = camera;
} }
QMetaObject::invokeMethod(image->p, "setupCam"); QMetaObject::invokeMethod(image->p, "setupCam");
}
#endif #endif
}; };
m_image.stopRequestImage = [](mImageSource* context) { m_image.stopRequestImage = [](mImageSource* context) {
InputControllerImage* image = static_cast<InputControllerImage*>(context); InputControllerImage* image = static_cast<InputControllerImage*>(context);
#ifdef BUILD_QT_MULTIMEDIA #ifdef BUILD_QT_MULTIMEDIA
image->p->m_cameraActive = false;
QMetaObject::invokeMethod(image->p, "teardownCam"); QMetaObject::invokeMethod(image->p, "teardownCam");
#endif #endif
}; };
@ -766,10 +766,18 @@ void InputController::setLuminanceValue(uint8_t value) {
void InputController::setupCam() { void InputController::setupCam() {
#ifdef BUILD_QT_MULTIMEDIA #ifdef BUILD_QT_MULTIMEDIA
if (m_config->getQtOption("cameraDriver").toInt() != static_cast<int>(CameraDriver::QT_MULTIMEDIA)) {
return;
}
if (!m_camera) { if (!m_camera) {
m_camera = std::make_unique<QCamera>(); m_camera = std::make_unique<QCamera>(m_cameraDevice);
connect(m_camera.get(), &QCamera::statusChanged, this, &InputController::prepareCamSettings, Qt::QueuedConnection); connect(m_camera.get(), &QCamera::statusChanged, this, &InputController::prepareCamSettings, Qt::QueuedConnection);
} }
if (m_camera->status() == QCamera::UnavailableStatus) {
m_camera.reset();
return;
}
m_camera->setCaptureMode(QCamera::CaptureVideo); m_camera->setCaptureMode(QCamera::CaptureVideo);
m_camera->setViewfinder(&m_videoDumper); m_camera->setViewfinder(&m_videoDumper);
m_camera->load(); m_camera->load();
@ -820,20 +828,22 @@ void InputController::prepareCamSettings(QCamera::Status status) {
void InputController::teardownCam() { void InputController::teardownCam() {
#ifdef BUILD_QT_MULTIMEDIA #ifdef BUILD_QT_MULTIMEDIA
if (m_camera) { if (m_camera) {
m_camera->stop(); m_camera->unload();
m_camera.reset();
} }
#endif #endif
} }
void InputController::setCamera(const QByteArray& name) { void InputController::setCamera(const QByteArray& name) {
#ifdef BUILD_QT_MULTIMEDIA #ifdef BUILD_QT_MULTIMEDIA
bool needsRestart = false; if (m_cameraDevice == name) {
if (m_camera) { return;
needsRestart = m_camera->state() == QCamera::ActiveState;
} }
m_camera = std::make_unique<QCamera>(name); m_cameraDevice = name;
connect(m_camera.get(), &QCamera::statusChanged, this, &InputController::prepareCamSettings, Qt::QueuedConnection); if (m_camera && m_camera->state() == QCamera::ActiveState) {
if (needsRestart) { teardownCam();
}
if (m_cameraActive) {
setupCam(); setupCam();
} }
#endif #endif

View File

@ -158,6 +158,8 @@ private:
} m_image; } m_image;
#ifdef BUILD_QT_MULTIMEDIA #ifdef BUILD_QT_MULTIMEDIA
bool m_cameraActive = false;
QByteArray m_cameraDevice;
std::unique_ptr<QCamera> m_camera; std::unique_ptr<QCamera> m_camera;
VideoDumper m_videoDumper; VideoDumper m_videoDumper;
#endif #endif

View File

@ -503,10 +503,13 @@ void SettingsView::updateConfig() {
} }
QVariant camera = m_ui.camera->itemData(m_ui.camera->currentIndex()); QVariant camera = m_ui.camera->itemData(m_ui.camera->currentIndex());
if (camera != m_controller->getQtOption("camera")) { QVariant oldCamera = m_controller->getQtOption("camera");
if (camera != oldCamera) {
m_controller->setQtOption("camera", camera); m_controller->setQtOption("camera", camera);
if (!oldCamera.isNull()) {
emit cameraChanged(camera.toByteArray()); emit cameraChanged(camera.toByteArray());
} }
}
QLocale language = m_ui.languages->itemData(m_ui.languages->currentIndex()).toLocale(); QLocale language = m_ui.languages->itemData(m_ui.languages->currentIndex()).toLocale();
if (language != m_controller->getQtOption("language").toLocale() && !(language.bcp47Name() == QLocale::system().bcp47Name() && m_controller->getQtOption("language").isNull())) { if (language != m_controller->getQtOption("language").toLocale() && !(language.bcp47Name() == QLocale::system().bcp47Name() && m_controller->getQtOption("language").isNull())) {