X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=app%2Fmain.cpp;fp=app%2Fmain.cpp;h=fab22447c2b63af52778f59370ed91bdb58202b4;hb=4ccb23ff85897f668f56a2566aceaa1b59dc64f6;hp=0000000000000000000000000000000000000000;hpb=ec044f44133cad1d12311345437b13b1a953226e;p=apps%2Fonscreenapp.git diff --git a/app/main.cpp b/app/main.cpp new file mode 100644 index 0000000..fab2244 --- /dev/null +++ b/app/main.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2018 TOYOTA MOTOR CORPORATION + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "eventhandler.h" + +using namespace std; + +static EventHandler* eventHandler; + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QCoreApplication::setOrganizationDomain("LinuxFoundation"); + QCoreApplication::setOrganizationName("AutomotiveGradeLinux"); + QCoreApplication::setApplicationName("OnScreenApp"); + QCoreApplication::setApplicationVersion("0.1.0"); + + QQuickStyle::setStyle("AGL"); + + QCommandLineParser parser; + parser.addPositionalArgument("port", app.translate("main", "port for binding")); + parser.addPositionalArgument("secret", app.translate("main", "secret for binding")); + parser.addHelpOption(); + parser.addVersionOption(); + parser.process(app); + QStringList positionalArguments = parser.positionalArguments(); + + int port = 1700; + QString token = "wm"; + + if (positionalArguments.length() == 2) { + port = positionalArguments.takeFirst().toInt(); + token = positionalArguments.takeFirst(); + } + + HMI_DEBUG("onscreenapp", "port = %d, token = %s", port, token.toStdString().c_str()); + + eventHandler = new EventHandler(); + eventHandler->init(port, token.toStdString().c_str()); + + QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty("eventHandler", eventHandler); + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + if (engine.rootObjects().isEmpty()) { + return -1; + } + + QObject *root = engine.rootObjects().first(); + QQuickWindow *window = qobject_cast(root); + QBitmap bitmap = QPixmap(":/images/mask_640_720.png").createHeuristicMask(); + window->setMask(QRegion(bitmap)); + + eventHandler->setQuickWindow(window); + + QObject::connect(eventHandler, SIGNAL(signalOnScreenMessage(QVariant)), window, SLOT(qmlOnScreenMessage(QVariant))); + QObject::connect(eventHandler, SIGNAL(signalLoader(QVariant)), window, SLOT(qmlLoader(QVariant))); + QObject::connect(eventHandler, SIGNAL(signalSetClearBackgroud()), window, SLOT(qmlSetClearBackgroud())); + QObject::connect(eventHandler, SIGNAL(signalSetDefaultBackgroud(QVariant)), window, SLOT(qmlSetDefaultBackground(QVariant))); + +#if USE_TEST_DISPLAY + QObject::connect(window, SIGNAL(frameSwapped()), eventHandler, SLOT(slotActivateSurface())); +#endif + HMI_DEBUG("onscreenapp", "Launched!"); + + return app.exec(); +} +