OnScreenApp
Functions | Variables
main.cpp File Reference
#include <QGuiApplication>
#include <QCommandLineParser>
#include <QtGui/QBitmap>
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
#include <QtQml/QQmlContext>
#include <QtQml/qqml.h>
#include <QQuickWindow>
#include <QtQuickControls2/QQuickStyle>
#include <QPixmap>
#include <QBitmap>
#include "eventhandler.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

static EventHandlereventHandler
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 35 of file main.cpp.

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 
77  eventHandler->setQuickWindow(window);
78 
79 // QBitmap bitmap = QPixmap(":/images/HMI_Phone_Back.svg").createHeuristicMask();
80 // window->setMask(QRegion(bitmap));
81 
82 // QImage img(":/images/star.png");
83 // QPixmap pixmap = QPixmap::fromImage(img);
84 // QBitmap mask = pixmap.createHeuristicMask();
85 
86 // if (mask.hasAlphaChannel()) {
87 // qDebug("has alpha");
88 // }
89 
90 // window->setMask(QRegion(mask));
91 
92 // QBitmap bitmap = QPixmap(":/images/HMI_Phone_Back_Heart.svg").createHeuristicMask();
93 // window->setMask(QRegion(bitmap));
94 
95  QObject::connect(eventHandler, SIGNAL(signalOnScreenMessage(QVariant)), window, SLOT(qmlOnScreenMessage(QVariant)));
96  QObject::connect(eventHandler, SIGNAL(signalLoader(QVariant)), window, SLOT(qmlLoader(QVariant)));
97  QObject::connect(eventHandler, SIGNAL(signalSetClearBackgroud()), window, SLOT(qmlSetClearBackgroud()));
98  QObject::connect(eventHandler, SIGNAL(signalSetDefaultBackgroud(QVariant)), window, SLOT(qmlSetDefaultBackground(QVariant)));
99 
100 #if USE_TEST_DISPLAY
101  QObject::connect(window, SIGNAL(frameSwapped()), eventHandler, SLOT(slotActivateSurface()));
102 #endif
103  HMI_DEBUG("onscreenapp", "Launched!");
104 
105  return app.exec();
106 }
#define HMI_DEBUG(prefix, args,...)
Definition: hmi-debug.h:42
static EventHandler * eventHandler
Definition: main.cpp:33

Variable Documentation

◆ eventHandler

EventHandler* eventHandler
static

Definition at line 33 of file main.cpp.