camera: Add camera flip config

This commit is contained in:
zhupengfei 2018-05-20 09:07:37 +08:00
parent 8e02c70e82
commit 5ebd466869
No known key found for this signature in database
GPG key ID: 85B82A3E62174206
16 changed files with 416 additions and 282 deletions

View file

@ -128,14 +128,19 @@ void Config::ReadValues() {
qt_config->value("camera_outer_right_name", "blank").toString().toStdString();
Settings::values.camera_config[OuterRightCamera] =
qt_config->value("camera_outer_right_config", "").toString().toStdString();
Settings::values.camera_flip[OuterRightCamera] =
qt_config->value("camera_outer_right_flip", "0").toInt();
Settings::values.camera_name[InnerCamera] =
qt_config->value("camera_inner_name", "blank").toString().toStdString();
Settings::values.camera_config[InnerCamera] =
qt_config->value("camera_inner_config", "").toString().toStdString();
Settings::values.camera_flip[InnerCamera] = qt_config->value("camera_inner_flip", "").toInt();
Settings::values.camera_name[OuterLeftCamera] =
qt_config->value("camera_outer_left_name", "blank").toString().toStdString();
Settings::values.camera_config[OuterLeftCamera] =
qt_config->value("camera_outer_left_config", "").toString().toStdString();
Settings::values.camera_flip[OuterLeftCamera] =
qt_config->value("camera_outer_left_flip", "").toInt();
qt_config->endGroup();
qt_config->beginGroup("Data Storage");
@ -317,14 +322,17 @@ void Config::SaveValues() {
QString::fromStdString(Settings::values.camera_name[OuterRightCamera]));
qt_config->setValue("camera_outer_right_config",
QString::fromStdString(Settings::values.camera_config[OuterRightCamera]));
qt_config->setValue("camera_outer_right_flip", Settings::values.camera_flip[OuterRightCamera]);
qt_config->setValue("camera_inner_name",
QString::fromStdString(Settings::values.camera_name[InnerCamera]));
qt_config->setValue("camera_inner_config",
QString::fromStdString(Settings::values.camera_config[InnerCamera]));
qt_config->setValue("camera_inner_flip", Settings::values.camera_flip[InnerCamera]);
qt_config->setValue("camera_outer_left_name",
QString::fromStdString(Settings::values.camera_name[OuterLeftCamera]));
qt_config->setValue("camera_outer_left_config",
QString::fromStdString(Settings::values.camera_config[OuterLeftCamera]));
qt_config->setValue("camera_outer_left_flip", Settings::values.camera_flip[OuterLeftCamera]);
qt_config->endGroup();
qt_config->beginGroup("Data Storage");

View file

@ -27,14 +27,7 @@ ConfigureCamera::ConfigureCamera(QWidget* parent)
// Load settings
camera_name = Settings::values.camera_name;
camera_config = Settings::values.camera_config;
for (auto&& item : camera_name) {
if (item == "opencv") {
QMessageBox::critical(this, tr("Error"),
tr("Sorry, Citra has removed support for OpenCV cameras.\n\nYour "
"existing OpenCV cameras have been replaced with Blank."));
item = "blank";
}
}
camera_flip = Settings::values.camera_flip;
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
for (const QCameraInfo& cameraInfo : cameras) {
ui->system_camera->addItem(cameraInfo.deviceName());
@ -98,6 +91,8 @@ void ConfigureCamera::connectEvents() {
connect(ui->system_camera,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
[=] { stopPreviewing(); });
connect(ui->camera_flip, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, [=] { stopPreviewing(); });
}
void ConfigureCamera::updateCameraMode() {
@ -148,6 +143,8 @@ void ConfigureCamera::updateImageSourceUI() {
}
ui->system_camera_label->setHidden(image_source != 2);
ui->system_camera->setHidden(image_source != 2);
ui->camera_flip_label->setHidden(image_source == 0);
ui->camera_flip->setHidden(image_source == 0);
}
void ConfigureCamera::recordConfig() {
@ -166,10 +163,12 @@ void ConfigureCamera::recordConfig() {
if (current_selected == CameraPosition::RearBoth) {
camera_name[0] = camera_name[2] = implementation;
camera_config[0] = camera_config[2] = config;
camera_flip[0] = camera_flip[2] = ui->camera_flip->currentIndex();
} else if (current_selected != CameraPosition::Null) {
int index = static_cast<int>(current_selected);
camera_name[index] = implementation;
camera_config[index] = config;
camera_flip[index] = ui->camera_flip->currentIndex();
}
current_selected = getCameraSelection();
}
@ -187,9 +186,9 @@ void ConfigureCamera::startPreviewing() {
ui->preview_box->setToolTip(tr("Resolution: ") + QString::number(preview_width) + "*" +
QString::number(preview_height));
// Load previewing camera
previewing_camera =
Camera::CreateCameraPreview(camera_name[camera_selection], camera_config[camera_selection],
preview_width, preview_height);
previewing_camera = Camera::CreateCameraPreview(
camera_name[camera_selection], camera_config[camera_selection], preview_width,
preview_height, static_cast<Service::CAM::Flip>(camera_flip[camera_selection]));
if (!previewing_camera) {
stopPreviewing();
return;
@ -262,6 +261,7 @@ void ConfigureCamera::setConfiguration() {
} else {
ui->camera_file->setText(QString::fromStdString(camera_config[index]));
}
ui->camera_flip->setCurrentIndex(camera_flip[index]);
updateImageSourceUI();
}
@ -288,6 +288,7 @@ void ConfigureCamera::applyConfiguration() {
stopPreviewing();
Settings::values.camera_name = camera_name;
Settings::values.camera_config = camera_config;
Settings::values.camera_flip = camera_flip;
Settings::Apply();
}

View file

@ -47,6 +47,7 @@ private:
std::unique_ptr<Ui::ConfigureCamera> ui;
std::array<std::string, 3> camera_name;
std::array<std::string, 3> camera_config;
std::array<int, 3> camera_flip;
int timer_id = 0;
int preview_width = 0;
int preview_height = 0;

View file

@ -1,257 +1,347 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureCamera</class>
<widget class="QWidget" name="ConfigureCamera">
<layout class="QVBoxLayout" name="verticalLayout">
<class>ConfigureCamera</class>
<widget class="QWidget" name="ConfigureCamera">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Camera</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Camera</string>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="camera_selection_label">
<property name="toolTip">
<string>Select the camera to configure</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="camera_selection_label">
<property name="toolTip">
<string>Select the camera to configure</string>
</property>
<property name="text">
<string>Camera to configure:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="camera_selection">
<property name="toolTip">
<string>Select the camera to configure</string>
</property>
<item>
<property name="text">
<string>Front</string>
</property>
</item>
<item>
<property name="text">
<string>Rear</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="camera_mode_label">
<property name="toolTip">
<string>Select the camera mode (single or double)</string>
</property>
<property name="text">
<string>Camera mode:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="camera_mode">
<property name="toolTip">
<string>Select the camera mode (single or double)</string>
</property>
<item>
<property name="text">
<string>Single (2D)</string>
</property>
</item>
<item>
<property name="text">
<string>Double (3D)</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="camera_position_label">
<property name="toolTip">
<string>Select the position of camera to configure</string>
</property>
<property name="text">
<string>Camera position:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="camera_position">
<property name="toolTip">
<string>Select the position of camera to configure</string>
</property>
<item>
<property name="text">
<string>Left</string>
</property>
</item>
<item>
<property name="text">
<string>Right</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<property name="text">
<string>Camera to configure:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="camera_selection">
<property name="toolTip">
<string>Select the camera to configure</string>
</property>
<item>
<property name="text">
<string>Front</string>
</property>
</item>
<item>
<property name="text">
<string>Rear</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="configurationBox">
<property name="title">
<string>Configuration</string>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="camera_mode_label">
<property name="toolTip">
<string>Select the camera mode (single or double)</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_configuration">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="image_source_label">
<property name="toolTip">
<string>Select where the image of the emulated camera comes from. It may be an image or a real camera.</string>
</property>
<property name="text">
<string>Camera Image Source:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="image_source">
<property name="toolTip">
<string>Select where the image of the emulated camera come from. It may be an image or a real camera.</string>
</property>
<item>
<property name="text">
<string>Blank (blank)</string>
</property>
</item>
<item>
<property name="text">
<string>Still Image (image)</string>
</property>
</item>
<item>
<property name="text">
<string>System Camera (qt)</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="camera_file_label">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="text">
<string>File:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="camera_file"/>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="system_camera_label">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="text">
<string>Camera:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="system_camera">
<item>
<property name="text">
<string>&lt;Default&gt;</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="prompt_before_load">
<property name="text">
<string>Prompt before load</string>
</property>
</widget>
</item>
</layout>
</widget>
<property name="text">
<string>Camera mode:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="camera_mode">
<property name="toolTip">
<string>Select the camera mode (single or double)</string>
</property>
<item>
<property name="text">
<string>Single (2D)</string>
</property>
</item>
<item>
<property name="text">
<string>Double (3D)</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="previewBox">
<property name="title">
<string>Preview</string>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="camera_position_label">
<property name="toolTip">
<string>Select the position of camera to configure</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="preview_box">
<property name="baseSize">
<size>
<width>512</width>
<height>384</height>
</size>
</property>
<property name="toolTip">
<string>Resolution: 512*384</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="preview_button">
<property name="text">
<string>Click to preview</string>
</property>
</widget>
</item>
</layout>
</widget>
<property name="text">
<string>Camera position:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="camera_position">
<property name="toolTip">
<string>Select the position of camera to configure</string>
</property>
<item>
<property name="text">
<string>Left</string>
</property>
</item>
<item>
<property name="text">
<string>Right</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="configurationBox">
<property name="title">
<string>Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_configuration">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="image_source_label">
<property name="toolTip">
<string>Select where the image of the emulated camera comes from. It may be an image or a real camera.</string>
</property>
<property name="text">
<string>Camera Image Source:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="image_source">
<property name="toolTip">
<string>Select where the image of the emulated camera comes from. It may be an image or a real camera.</string>
</property>
<item>
<property name="text">
<string>Blank (blank)</string>
</property>
</item>
<item>
<property name="text">
<string>Still Image (image)</string>
</property>
</item>
<item>
<property name="text">
<string>System Camera (qt)</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="camera_file_label">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
<property name="text">
<string>File:</string>
</property>
</spacer>
</widget>
</item>
<item>
<widget class="QLineEdit" name="camera_file"/>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="system_camera_label">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="toolTip">
<string>Select the system camera to use</string>
</property>
<property name="text">
<string>Camera:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="system_camera">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>250</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Select the system camera to use</string>
</property>
<item>
<property name="text">
<string>&lt;Default&gt;</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="camera_flip_label">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="toolTip">
<string>Select the image flip to apply</string>
</property>
<property name="text">
<string>Flip:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="camera_flip">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>800</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Select the image flip to apply</string>
</property>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Horizontal</string>
</property>
</item>
<item>
<property name="text">
<string>Vertical</string>
</property>
</item>
<item>
<property name="text">
<string>Reverse</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="prompt_before_load">
<property name="toolTip">
<string>Select an image file every time before the camera is loaded</string>
</property>
<property name="text">
<string>Prompt before load</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="previewBox">
<property name="title">
<string>Preview</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="preview_box">
<property name="baseSize">
<size>
<width>512</width>
<height>384</height>
</size>
</property>
<property name="toolTip">
<string>Resolution: 512*384</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="preview_button">
<property name="text">
<string>Click to preview</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>