add source for ces2019 horizontal
[apps/onscreenapp.git] / app / main.cpp
1 /*
2  * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <QGuiApplication>
18 #include <QCommandLineParser>
19 #include <QtGui/QBitmap>
20 #include <QtGui/QGuiApplication>
21 #include <QtQml/QQmlApplicationEngine>
22 #include <QtQml/QQmlContext>
23 #include <QtQml/qqml.h>
24 #include <QQuickWindow>
25 #include <QtQuickControls2/QQuickStyle>
26 #include <QPixmap>
27 #include <QBitmap>
28
29 #include "eventhandler.h"
30
31 using namespace std;
32
33 static EventHandler* eventHandler;
34
35 int main(int argc, char *argv[])
36 {
37     QGuiApplication app(argc, argv);
38
39     QCoreApplication::setOrganizationDomain("LinuxFoundation");
40     QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
41     QCoreApplication::setApplicationName("OnScreenApp");
42     QCoreApplication::setApplicationVersion("0.1.0");
43
44     QQuickStyle::setStyle("AGL");
45
46     QCommandLineParser parser;
47     parser.addPositionalArgument("port", app.translate("main", "port for binding"));
48     parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
49     parser.addHelpOption();
50     parser.addVersionOption();
51     parser.process(app);
52     QStringList positionalArguments = parser.positionalArguments();
53
54     int port = 1700;
55     QString token = "wm";
56
57     if (positionalArguments.length() == 2) {
58         port = positionalArguments.takeFirst().toInt();
59         token = positionalArguments.takeFirst();
60     }
61
62     HMI_DEBUG("onscreenapp", "port = %d, token = %s", port, token.toStdString().c_str());
63
64     eventHandler = new EventHandler();
65     eventHandler->init(port, token.toStdString().c_str());
66
67     QQmlApplicationEngine engine;
68     engine.rootContext()->setContextProperty("eventHandler", eventHandler);
69     engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
70     if (engine.rootObjects().isEmpty()) {
71         return -1;
72     }
73
74     QObject *root = engine.rootObjects().first();
75     QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
76     QBitmap bitmap = QPixmap(":/images/mask_640_720.png").createHeuristicMask();
77     window->setMask(QRegion(bitmap));
78
79     eventHandler->setQuickWindow(window);
80
81     QObject::connect(eventHandler, SIGNAL(signalOnScreenMessage(QVariant)), window, SLOT(qmlOnScreenMessage(QVariant)));
82     QObject::connect(eventHandler, SIGNAL(signalLoader(QVariant)), window, SLOT(qmlLoader(QVariant)));
83     QObject::connect(eventHandler, SIGNAL(signalSetClearBackgroud()), window, SLOT(qmlSetClearBackgroud()));
84     QObject::connect(eventHandler, SIGNAL(signalSetDefaultBackgroud(QVariant)), window, SLOT(qmlSetDefaultBackground(QVariant)));
85
86 #if USE_TEST_DISPLAY
87     QObject::connect(window, SIGNAL(frameSwapped()), eventHandler, SLOT(slotActivateSurface()));
88 #endif
89     HMI_DEBUG("onscreenapp", "Launched!");
90
91     return app.exec();
92 }
93