summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoris Verria <doris.verria@qt.io>2021-02-15 14:35:59 +0100
committerLars Knoll <lars.knoll@qt.io>2021-03-02 14:50:56 +0000
commit19b2ff9c232448588918e2fe59f457f21f44e49b (patch)
tree6273b41f59f9975fdd9c970e8cd8b2ace0eabcc7
parent4a6b7816b1f11e00063ee6080141be4d77bca9ac (diff)
Set metadata when recording to the camera example
Change-Id: I5a914591f9fe9f09c04da4a1e06b29ac0d92ae00 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--examples/multimediawidgets/camera/CMakeLists.txt1
-rw-r--r--examples/multimediawidgets/camera/camera.cpp40
-rw-r--r--examples/multimediawidgets/camera/camera.h10
-rw-r--r--examples/multimediawidgets/camera/camera.pro6
-rw-r--r--examples/multimediawidgets/camera/camera.ui10
-rw-r--r--examples/multimediawidgets/camera/metadatadialog.cpp127
-rw-r--r--examples/multimediawidgets/camera/metadatadialog.h78
7 files changed, 270 insertions, 2 deletions
diff --git a/examples/multimediawidgets/camera/CMakeLists.txt b/examples/multimediawidgets/camera/CMakeLists.txt
index aa9d42436..de647c647 100644
--- a/examples/multimediawidgets/camera/CMakeLists.txt
+++ b/examples/multimediawidgets/camera/CMakeLists.txt
@@ -26,6 +26,7 @@ qt_add_executable(camera
imagesettings.cpp imagesettings.h imagesettings.ui
main.cpp
videosettings.cpp videosettings.h videosettings.ui
+ metadatadialog.cpp metadatadialog.h
)
set_target_properties(camera PROPERTIES
WIN32_EXECUTABLE TRUE
diff --git a/examples/multimediawidgets/camera/camera.cpp b/examples/multimediawidgets/camera/camera.cpp
index 52e4b9b86..a06391c8f 100644
--- a/examples/multimediawidgets/camera/camera.cpp
+++ b/examples/multimediawidgets/camera/camera.cpp
@@ -52,6 +52,7 @@
#include "ui_camera.h"
#include "videosettings.h"
#include "imagesettings.h"
+#include "metadatadialog.h"
#include <QMediaRecorder>
#include <QVideoWidget>
@@ -60,6 +61,7 @@
#include <QMessageBox>
#include <QPalette>
+#include <QImage>
#include <QtWidgets>
#include <QMediaDeviceManager>
@@ -79,6 +81,8 @@ Camera::Camera() : ui(new Ui::Camera)
connect(videoDevicesGroup, &QActionGroup::triggered, this, &Camera::updateCameraDevice);
connect(ui->captureWidget, &QTabWidget::currentChanged, this, &Camera::updateCaptureMode);
+ connect(ui->metaDataButton, &QPushButton::clicked, this, &Camera::showMetaDataDialog);
+
setCamera(QMediaDeviceManager::defaultVideoInput());
qDebug() << "Supported Containers:";
@@ -295,16 +299,19 @@ void Camera::updateRecorderState(QMediaRecorder::State state)
ui->recordButton->setEnabled(true);
ui->pauseButton->setEnabled(true);
ui->stopButton->setEnabled(false);
+ ui->metaDataButton->setEnabled(false);
break;
case QMediaRecorder::PausedState:
ui->recordButton->setEnabled(true);
ui->pauseButton->setEnabled(false);
ui->stopButton->setEnabled(true);
+ ui->metaDataButton->setEnabled(true);
break;
case QMediaRecorder::RecordingState:
ui->recordButton->setEnabled(false);
ui->pauseButton->setEnabled(true);
ui->stopButton->setEnabled(true);
+ ui->metaDataButton->setEnabled(true);
break;
}
}
@@ -379,3 +386,36 @@ void Camera::updateCameras()
ui->menuDevices->addAction(videoDeviceAction);
}
}
+
+void Camera::showMetaDataDialog()
+{
+ if (!m_metaDataDialog)
+ m_metaDataDialog = new MetaDataDialog(this);
+ m_metaDataDialog->setAttribute(Qt::WA_DeleteOnClose, false);
+ if (m_metaDataDialog->exec() == QDialog::Accepted)
+ saveMetaData();
+}
+
+void Camera::saveMetaData()
+{
+ QMediaMetaData data;
+ for (int i = 0; i < QMediaMetaData::NumMetaData; i++) {
+ QString val = m_metaDataDialog->m_metaDataFields[i]->text();
+ if (!val.isEmpty()) {
+ auto key = static_cast<QMediaMetaData::Key>(i);
+ if (i == QMediaMetaData::CoverArtImage) {
+ QImage coverArt(val);
+ data.insert(key, coverArt);
+ }
+ else if (i == QMediaMetaData::ThumbnailImage) {
+ QImage thumbnail(val);
+ data.insert(key, thumbnail);
+ }
+ else {
+ data.insert(key, val);
+ }
+ }
+ }
+ m_mediaRecorder->setMetaData(data);
+}
+
diff --git a/examples/multimediawidgets/camera/camera.h b/examples/multimediawidgets/camera/camera.h
index 66cc6eee3..7f7aae9a4 100644
--- a/examples/multimediawidgets/camera/camera.h
+++ b/examples/multimediawidgets/camera/camera.h
@@ -55,6 +55,7 @@
#include <QCameraImageCapture>
#include <QMediaRecorder>
#include <QScopedPointer>
+#include <QMediaMetaData>
#include <QMainWindow>
@@ -63,6 +64,8 @@ namespace Ui { class Camera; }
class QActionGroup;
QT_END_NAMESPACE
+class MetaDataDialog;
+
class Camera : public QMainWindow
{
Q_OBJECT
@@ -70,6 +73,9 @@ class Camera : public QMainWindow
public:
Camera();
+public slots:
+ void saveMetaData();
+
private slots:
void setCamera(const QCameraInfo &cameraInfo);
@@ -110,6 +116,8 @@ private slots:
void updateCameras();
+ void showMetaDataDialog();
+
protected:
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
@@ -129,6 +137,8 @@ private:
bool m_isCapturingImage = false;
bool m_applicationExiting = false;
bool m_doImageCapture = true;
+
+ MetaDataDialog *m_metaDataDialog = nullptr;
};
#endif
diff --git a/examples/multimediawidgets/camera/camera.pro b/examples/multimediawidgets/camera/camera.pro
index 52c511acb..edf40ed9d 100644
--- a/examples/multimediawidgets/camera/camera.pro
+++ b/examples/multimediawidgets/camera/camera.pro
@@ -6,13 +6,15 @@ QT += multimedia multimediawidgets
HEADERS = \
camera.h \
imagesettings.h \
- videosettings.h
+ videosettings.h \
+ metadatadialog.h
SOURCES = \
main.cpp \
camera.cpp \
imagesettings.cpp \
- videosettings.cpp
+ videosettings.cpp \
+ metadatadialog.cpp
FORMS += \
camera.ui \
diff --git a/examples/multimediawidgets/camera/camera.ui b/examples/multimediawidgets/camera/camera.ui
index ba82ba623..e00e9d843 100644
--- a/examples/multimediawidgets/camera/camera.ui
+++ b/examples/multimediawidgets/camera/camera.ui
@@ -129,6 +129,16 @@
</property>
</widget>
</item>
+ <item row="5" column="0">
+ <widget class="QPushButton" name="metaDataButton">
+ <property name="text">
+ <string>Set metadata</string>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</widget>
diff --git a/examples/multimediawidgets/camera/metadatadialog.cpp b/examples/multimediawidgets/camera/metadatadialog.cpp
new file mode 100644
index 000000000..e0df6ba57
--- /dev/null
+++ b/examples/multimediawidgets/camera/metadatadialog.cpp
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "metadatadialog.h"
+#include "camera.h"
+
+#include <QtWidgets>
+#include <QFormLayout>
+#include <QMediaMetaData>
+
+MetaDataDialog::MetaDataDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ QFormLayout *metaDataLayout = new QFormLayout;
+ for (int key = 0; key < QMediaMetaData::NumMetaData; key++) {
+ QString label = QMediaMetaData::metaDataKeyToString(static_cast<QMediaMetaData::Key>(key));
+ m_metaDataFields[key] = new QLineEdit;
+ if (key == QMediaMetaData::ThumbnailImage) {
+ QPushButton *openThumbnail = new QPushButton(tr("Open"));
+ connect(openThumbnail, &QPushButton::clicked, this, &MetaDataDialog::openThumbnailImage);
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(m_metaDataFields[key]);
+ layout->addWidget(openThumbnail);
+ metaDataLayout->addRow(label, layout);
+ }
+ else if (key == QMediaMetaData::CoverArtImage) {
+ QPushButton *openCoverArt = new QPushButton(tr("Open"));
+ connect(openCoverArt, &QPushButton::clicked, this, &MetaDataDialog::openCoverArtImage);
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(m_metaDataFields[key]);
+ layout->addWidget(openCoverArt);
+ metaDataLayout->addRow(label, layout);
+ }
+ else {
+ if (key == QMediaMetaData::Title)
+ m_metaDataFields[key]->setText(tr("Qt Camera Example"));
+ else if (key == QMediaMetaData::Author)
+ m_metaDataFields[key]->setText(tr("The Qt Company"));
+ else if (key == QMediaMetaData::Year)
+ m_metaDataFields[key]->setText("2020");
+ else if (key == QMediaMetaData::Date)
+ m_metaDataFields[key]->setText(QDate::currentDate().toString());
+ metaDataLayout->addRow(label, m_metaDataFields[key]);
+ }
+ }
+
+ QWidget *viewport = new QWidget;
+ viewport->setLayout(metaDataLayout);
+ QScrollArea *scrollArea = new QScrollArea;
+ scrollArea->setWidget(viewport);
+ QVBoxLayout *dialogLayout = new QVBoxLayout();
+ this->setLayout(dialogLayout);
+ this->layout()->addWidget(scrollArea);
+
+ auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel);
+ this->layout()->addWidget(buttonBox);
+
+ this->setWindowTitle(tr("Set Metadata"));
+ this->resize(400, 300);
+
+ connect(buttonBox, &QDialogButtonBox::accepted, this, &MetaDataDialog::accept);
+ connect(buttonBox, &QDialogButtonBox::rejected, this, &MetaDataDialog::reject);
+}
+
+void MetaDataDialog::openThumbnailImage()
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Image"), QDir::currentPath(), tr("Image Files (*.png *.jpg *.bmp)"));
+ if (!fileName.isEmpty())
+ m_metaDataFields[QMediaMetaData::ThumbnailImage]->setText(fileName);
+}
+
+void MetaDataDialog::openCoverArtImage()
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Image"), QDir::currentPath(), tr("Image Files (*.png *.jpg *.bmp)"));
+ if (!fileName.isEmpty())
+ m_metaDataFields[QMediaMetaData::CoverArtImage]->setText(fileName);
+}
diff --git a/examples/multimediawidgets/camera/metadatadialog.h b/examples/multimediawidgets/camera/metadatadialog.h
new file mode 100644
index 000000000..0269e3479
--- /dev/null
+++ b/examples/multimediawidgets/camera/metadatadialog.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QDialog>
+#include <QMediaMetaData>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QLineEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class MetaDataDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit MetaDataDialog(QWidget *parent = nullptr);
+
+ QLineEdit *m_metaDataFields[QMediaMetaData::NumMetaData] = {};
+
+private slots:
+ void openThumbnailImage();
+ void openCoverArtImage();
+};
+//! [0]
+
+#endif