-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.cpp
executable file
·64 lines (54 loc) · 2.1 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <QtWidgets/QApplication>
#include <QtCore/QDebug>
#include <QtQml/QQmlContext>
#include <QtQuick/QQuickItem>
#include <QtCore/QStandardPaths>
#include "qtquick2applicationviewer.h"
#include "filereader.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QUrl fileName;
qreal volume = 0.5;
QStringList args = app.arguments();
for (int i=1; i<args.count(); ++i) {
const QString &arg = args.at(i);
if (arg.startsWith('-')) {
if ("-volume" == arg) {
if (i+1 < args.count())
volume = 0.01 * args.at(++i).toInt();
else
qWarning() << "Option \"-volume\" takes a value";
}
else {
qWarning() << "Option" << arg << "ignored";
}
} else {
if (fileName.isEmpty())
fileName = QUrl(arg);
else
qWarning() << "Argument" << arg << "ignored";
}
}
QtQuick2ApplicationViewer viewer;
viewer.rootContext()->setContextProperty("fileName", fileName);
viewer.rootContext()->setContextProperty("startingVolume", volume);
viewer.rootContext()->setContextProperty("viewer", &viewer);
viewer.setMainQmlFile(QStringLiteral("qml/CuteTime/main.qml"));
viewer.setResizeMode(QQuickView::SizeRootObjectToView);
FileReader fileReader;
viewer.rootContext()->setContextProperty("fileReader", &fileReader);
QString imagePath = "../../images";
const QStringList picturesLocation = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
if (!picturesLocation.isEmpty())
imagePath = picturesLocation.first();
viewer.rootContext()->setContextProperty("imagePath", imagePath);
QString videoPath;
const QStringList moviesLocation = QStandardPaths::standardLocations(QStandardPaths::MoviesLocation);
if (!moviesLocation.isEmpty())
videoPath = moviesLocation.first();
viewer.rootContext()->setContextProperty("videoPath", videoPath);
viewer.setTitle("CuteTime");
viewer.showExpanded();
return app.exec();
}