/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* main_window.cpp - qcam - Main application window
*/
#include "main_window.h"
#include <iomanip>
#include <string>
#include <sys/mman.h>
#include <QComboBox>
#include <QCoreApplication>
#include <QFileDialog>
#include <QImage>
#include <QImageWriter>
#include <QInputDialog>
#include <QMutexLocker>
#include <QStandardPaths>
#include <QTimer>
#include <QToolBar>
#include <QToolButton>
#include <QtDebug>
#include <libcamera/camera_manager.h>
#include <libcamera/version.h>
#include "dng_writer.h"
#ifndef QT_NO_OPENGL
#include "viewfinder_gl.h"
#endif
#include "viewfinder_qt.h"
using namespace libcamera;
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
/*
* Qt::fixed was introduced in v5.14, and ::fixed deprecated in v5.15. Allow
* usage of Qt::fixed unconditionally.
*/
namespace Qt {
constexpr auto fixed = ::fixed;
} /* namespace Qt */
#endif
/**
* \brief Custom QEvent to signal capture completion
*/
class CaptureEvent : public QEvent
{
public:
CaptureEvent()
: QEvent(type())
{
}
static Type type()
{
static int type = QEvent::registerEventType();
return static_cast<Type>(type);
}
};
/**
* \brief Custom QEvent to signal hotplug or unplug
*/
class HotplugEvent : public QEvent
{
public:
enum PlugEvent {
HotPlug,
HotUnplug
};
HotplugEvent(std::shared_ptr<Camera> camera, PlugEvent event)
: QEvent(type()), camera_(std::move(camera)), plugEvent_(event)
{
}
static Type type()
{
static int type = QEvent::registerEventType();
return static_cast<Type>(type);
}
PlugEvent hotplugEvent() const { return plugEvent_; }
Camera *camera() const { return camera_.get(); }
private:
std::shared_ptr<Camera> camera_;
PlugEvent plugEvent_;
};
MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)
: saveRaw_(nullptr), options_(options), cm_(cm), allocator_(nullptr),
isCapturing_(false), captureRaw_(false)
{
int ret;
/*
* Initialize the UI: Create the toolbar, set the window title and
* create the viewfinder widget.
*/
createToolbars();
title_ = "QCam " + QString::fromStdString(CameraManager::version());
setWindowTitle(title_);
connect(&titleTimer_, SIGNAL(timeout()), this, SLOT(updateTitle()));
/* Renderer type Qt or GLES, select Qt by default. */
|