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 527c089f1f
commit ab7cfb9634
4 changed files with 32 additions and 16 deletions

View File

@ -17,6 +17,7 @@ Other fixes:
- 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 smudged window icon on Windows
- Qt: Fix saving settings enabling camera when camera name changes (fixes mgba.io/i/2125)
Misc:
- 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

View File

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

View File

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

View File

@ -503,10 +503,13 @@ void SettingsView::updateConfig() {
}
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);
if (!oldCamera.isNull()) {
emit cameraChanged(camera.toByteArray());
}
}
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())) {