1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Mobility Components.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL21$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** $QT_END_LICENSE$
31 **
32 ****************************************************************************/
33
34 #include <QtCore/QStandardPaths>
35 #include <QtCore/QStringList>
36 #include <QtQml/QQmlContext>
37 #include <QtGui/QGuiApplication>
38 #include <QtQuick/QQuickItem>
39 #include <QtQuick/QQuickView>
40 #include "filereader.h"
41 #include "trace.h"
42
43 #ifdef PERFORMANCEMONITOR_SUPPORT
44 #include "performancemonitordeclarative.h"
45 #endif
46
main(int argc,char * argv[])47 int main(int argc, char *argv[])
48 {
49 QGuiApplication app(argc, argv);
50
51 #ifdef PERFORMANCEMONITOR_SUPPORT
52 PerformanceMonitor::qmlRegisterTypes();
53 #endif
54
55 QUrl fileName;
56 qreal volume = 0.5;
57 QStringList args = app.arguments();
58 #ifdef PERFORMANCEMONITOR_SUPPORT
59 PerformanceMonitor::State performanceMonitorState;
60 #endif
61 for (int i = 1; i < args.size(); ++i) {
62 const QByteArray arg = args.at(i).toUtf8();
63 if (arg.startsWith('-')) {
64 if ("-volume" == arg) {
65 if (i + 1 < args.size())
66 volume = 0.01 * args.at(++i).toInt();
67 else
68 qtTrace() << "Option \"-volume\" takes a value";
69 }
70 #ifdef PERFORMANCEMONITOR_SUPPORT
71 else if (performanceMonitorState.parseArgument(arg)) {
72 // Do nothing
73 }
74 #endif
75 else {
76 qtTrace() << "Option" << arg << "ignored";
77 }
78 } else {
79 if (fileName.isEmpty())
80 fileName = QUrl::fromLocalFile(arg);
81 else
82 qtTrace() << "Argument" << arg << "ignored";
83 }
84 }
85
86 QQuickView viewer;
87
88 viewer.setSource(QUrl(QLatin1String("qrc:///qml/qmlvideofx/Main.qml")));
89 QQuickItem *rootObject = viewer.rootObject();
90 rootObject->setProperty("fileName", fileName);
91 viewer.rootObject()->setProperty("volume", volume);
92
93 #ifdef PERFORMANCEMONITOR_SUPPORT
94 if (performanceMonitorState.valid) {
95 rootObject->setProperty("perfMonitorsLogging", performanceMonitorState.logging);
96 rootObject->setProperty("perfMonitorsVisible", performanceMonitorState.visible);
97 }
98 QObject::connect(&viewer, SIGNAL(afterRendering()),
99 rootObject, SLOT(qmlFramePainted()));
100 #endif
101
102 FileReader fileReader;
103 viewer.rootContext()->setContextProperty("fileReader", &fileReader);
104
105 const QUrl appPath(QUrl::fromLocalFile(app.applicationDirPath()));
106 const QStringList picturesLocation = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
107 const QUrl imagePath = picturesLocation.isEmpty() ? appPath : QUrl::fromLocalFile(picturesLocation.first());
108 viewer.rootContext()->setContextProperty("imagePath", imagePath);
109
110 const QStringList moviesLocation = QStandardPaths::standardLocations(QStandardPaths::MoviesLocation);
111 const QUrl videoPath = moviesLocation.isEmpty() ? appPath : QUrl::fromLocalFile(moviesLocation.first());
112 viewer.rootContext()->setContextProperty("videoPath", videoPath);
113
114 viewer.setTitle("qmlvideofx");
115 viewer.setFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowTitleHint |
116 Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
117 viewer.setMinimumSize(QSize(1024, 600));
118 viewer.setResizeMode(QQuickView::SizeRootObjectToView);
119 viewer.showMaximized();
120 //viewer.show();
121
122 // Delay invocation of init until the event loop has started, to work around
123 // a GL context issue on Harmattan: without this, we get the following error
124 // when the first ShaderEffectItem is created:
125 // "QGLShaderProgram::addShader: Program and shader are not associated with same context"
126 QMetaObject::invokeMethod(viewer.rootObject(), "init", Qt::QueuedConnection);
127
128 return app.exec();
129 }
130
131