2018-05-11 19:42:23 +02:00
|
|
|
// Copyright 2018 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QImageReader>
|
|
|
|
#include <QMessageBox>
|
2018-06-03 05:29:46 +02:00
|
|
|
#include <QThread>
|
2018-05-11 19:42:23 +02:00
|
|
|
#include "citra_qt/camera/still_image_camera.h"
|
2020-08-19 08:53:54 +02:00
|
|
|
#include "common/logging/log.h"
|
2018-05-11 19:42:23 +02:00
|
|
|
|
|
|
|
namespace Camera {
|
|
|
|
|
2018-05-20 03:07:37 +02:00
|
|
|
StillImageCamera::StillImageCamera(QImage image_, const Service::CAM::Flip& flip)
|
2018-05-26 05:26:58 +02:00
|
|
|
: QtCameraInterface(flip), image(std::move(image_)) {}
|
2018-05-11 19:42:23 +02:00
|
|
|
|
2018-06-07 08:48:52 +02:00
|
|
|
StillImageCamera::~StillImageCamera() {
|
|
|
|
StillImageCameraFactory::last_path.clear();
|
|
|
|
}
|
|
|
|
|
2018-05-11 19:42:23 +02:00
|
|
|
void StillImageCamera::StartCapture() {}
|
|
|
|
|
|
|
|
void StillImageCamera::StopCapture() {}
|
|
|
|
|
2018-05-26 05:26:58 +02:00
|
|
|
QImage StillImageCamera::QtReceiveFrame() {
|
|
|
|
return image;
|
2018-05-11 19:42:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool StillImageCamera::IsPreviewAvailable() {
|
|
|
|
return !image.isNull();
|
|
|
|
}
|
|
|
|
|
2018-06-07 08:48:52 +02:00
|
|
|
std::string StillImageCameraFactory::last_path;
|
|
|
|
|
2018-06-03 05:29:46 +02:00
|
|
|
const std::string StillImageCameraFactory::GetFilePath() const {
|
2018-06-07 08:48:52 +02:00
|
|
|
if (!last_path.empty()) {
|
|
|
|
return last_path;
|
|
|
|
}
|
2018-05-11 19:42:23 +02:00
|
|
|
QList<QByteArray> types = QImageReader::supportedImageFormats();
|
2020-02-11 13:12:09 +01:00
|
|
|
QStringList temp_filters;
|
2018-05-11 19:42:23 +02:00
|
|
|
for (QByteArray type : types) {
|
2020-02-11 13:12:09 +01:00
|
|
|
temp_filters << QStringLiteral("*.%1").arg(QString::fromUtf8(type));
|
2018-05-11 19:42:23 +02:00
|
|
|
}
|
|
|
|
|
2020-02-11 13:12:09 +01:00
|
|
|
QString filter =
|
|
|
|
QObject::tr("Supported image files (%1)").arg(temp_filters.join(QLatin1Char{' '}));
|
2018-06-07 08:48:52 +02:00
|
|
|
last_path =
|
2020-02-11 13:12:09 +01:00
|
|
|
QFileDialog::getOpenFileName(nullptr, QObject::tr("Open File"), QStringLiteral("."), filter)
|
|
|
|
.toStdString();
|
2018-06-07 08:48:52 +02:00
|
|
|
return last_path;
|
2018-05-11 19:42:23 +02:00
|
|
|
}
|
|
|
|
|
2018-06-03 05:29:46 +02:00
|
|
|
std::unique_ptr<CameraInterface> StillImageCameraFactory::Create(const std::string& config,
|
|
|
|
const Service::CAM::Flip& flip) {
|
2018-05-11 19:42:23 +02:00
|
|
|
std::string real_config = config;
|
|
|
|
if (config.empty()) {
|
2018-06-03 05:29:46 +02:00
|
|
|
// call GetFilePath() in UI thread (note: StillImageCameraFactory itself is initialized in
|
|
|
|
// UI thread, so we can just pass in "this" here)
|
|
|
|
if (thread() == QThread::currentThread()) {
|
|
|
|
real_config = GetFilePath();
|
|
|
|
} else {
|
|
|
|
QMetaObject::invokeMethod(this, "GetFilePath", Qt::BlockingQueuedConnection,
|
|
|
|
Q_RETURN_ARG(std::string, real_config));
|
|
|
|
}
|
2018-05-11 19:42:23 +02:00
|
|
|
}
|
|
|
|
QImage image(QString::fromStdString(real_config));
|
|
|
|
if (image.isNull()) {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_ERROR(Service_CAM, "Couldn't load image \"{}\"", real_config.c_str());
|
2018-05-11 19:42:23 +02:00
|
|
|
}
|
2018-05-20 03:07:37 +02:00
|
|
|
return std::make_unique<StillImageCamera>(image, flip);
|
2018-05-11 19:42:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Camera
|