summaryrefslogtreecommitdiffstats
path: root/examples/multimedia/video/qmlvideo/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/multimedia/video/qmlvideo/main.cpp')
-rw-r--r--examples/multimedia/video/qmlvideo/main.cpp126
1 files changed, 48 insertions, 78 deletions
diff --git a/examples/multimedia/video/qmlvideo/main.cpp b/examples/multimedia/video/qmlvideo/main.cpp
index e288c0ae4..94c5bfea0 100644
--- a/examples/multimedia/video/qmlvideo/main.cpp
+++ b/examples/multimedia/video/qmlvideo/main.cpp
@@ -1,65 +1,24 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $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$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtCore/QStandardPaths>
-#include <QtCore/QString>
-#include <QtCore/QStringList>
-#include <QtQml/QQmlContext>
-#include <QtQml/QQmlEngine>
-#include <QtGui/QGuiApplication>
-#include <QtQuick/QQuickItem>
-#include <QtQuick/QQuickView>
+#include "performancemonitor.h"
#include "trace.h"
-
+#include "qmlvideo/videosingleton.h"
#ifdef PERFORMANCEMONITOR_SUPPORT
-#include "performancemonitordeclarative.h"
+# include "performancemonitordeclarative.h"
+#endif
+
+#include <QGuiApplication>
+#include <QQmlContext>
+#include <QQmlEngine>
+#include <QQuickItem>
+#include <QQuickView>
+#include <QStandardPaths>
+#include <QString>
+#include <QStringList>
+
+#if QT_CONFIG(permissions)
+ #include <QPermission>
#endif
static const QString DefaultFileName1 = "";
@@ -84,7 +43,7 @@ int main(int argc, char *argv[])
const QByteArray arg = args.at(i).toUtf8();
if (arg.startsWith('-')) {
if ("-volume" == arg) {
- if (i+1 < args.count())
+ if (i + 1 < args.count())
volume = 0.01 * args.at(++i).toInt();
else
qtTrace() << "Option \"-volume\" takes a value";
@@ -120,36 +79,47 @@ int main(int argc, char *argv[])
url2 = QUrl::fromLocalFile(source2);
}
+ const QStringList moviesLocation = QStandardPaths::standardLocations(QStandardPaths::MoviesLocation);
+ const QUrl videoPath = QUrl::fromLocalFile(moviesLocation.isEmpty() ? app.applicationDirPath()
+ : moviesLocation.front());
+
QQuickView viewer;
- viewer.setSource(QUrl("qrc:///qml/qmlvideo/main.qml"));
+ VideoSingleton* singleton = viewer.engine()->singletonInstance<VideoSingleton*>("qmlvideo", "VideoSingleton");
+ singleton->setVideoPath(videoPath);
+ singleton->setSource1(source1);
+ singleton->setSource2(source2);
+ singleton->setVolume(volume);
+ viewer.loadFromModule("qmlvideo", "Main");
QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QQuickView::close);
- QQuickItem *rootObject = viewer.rootObject();
- rootObject->setProperty("source1", url1);
- rootObject->setProperty("source2", url2);
- rootObject->setProperty("volume", volume);
-
#ifdef PERFORMANCEMONITOR_SUPPORT
+ QQuickItem *rootObject = viewer.rootObject();
if (performanceMonitorState.valid) {
rootObject->setProperty("perfMonitorsLogging", performanceMonitorState.logging);
rootObject->setProperty("perfMonitorsVisible", performanceMonitorState.visible);
}
- QObject::connect(&viewer, SIGNAL(afterRendering()),
- rootObject, SLOT(qmlFramePainted()));
+ QObject::connect(&viewer, SIGNAL(afterRendering()), rootObject, SLOT(qmlFramePainted()));
#endif
- const QStringList moviesLocation = QStandardPaths::standardLocations(QStandardPaths::MoviesLocation);
- const QUrl videoPath =
- QUrl::fromLocalFile(moviesLocation.isEmpty() ?
- app.applicationDirPath() :
- moviesLocation.front());
- viewer.rootContext()->setContextProperty("videoPath", videoPath);
-
QMetaObject::invokeMethod(rootObject, "init");
- viewer.setMinimumSize(QSize(640, 360));
- viewer.show();
+ auto setupView = [&viewer]() {
+ viewer.setMinimumSize(QSize(640, 360));
+ viewer.show();
+ };
+
+#if QT_CONFIG(permissions)
+ QCameraPermission cameraPermission;
+ qApp->requestPermission(cameraPermission, [&setupView](const QPermission &permission) {
+ // Show UI in any case. If there is no permission, the UI will just
+ // be disabled.
+ if (permission.status() != Qt::PermissionStatus::Granted)
+ qWarning("Camera permission is not granted! Camera will not be available.");
+ setupView();
+ });
+#else
+ setupView();
+#endif
return app.exec();
}
-