From 67e2073ef3968d0fb3b1a9bbbe58a13329ae3b65 Mon Sep 17 00:00:00 2001 From: wang_zhiqiang Date: Fri, 8 Mar 2019 14:32:09 +0800 Subject: upload --- app/app.pri | 13 ++++++ app/app.pro | 17 ++++++++ app/images/black_normal.png | Bin 0 -> 9809 bytes app/images/black_split.png | Bin 0 -> 5011 bytes app/main.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++ app/main.qml | 67 +++++++++++++++++++++++++++++++ app/main.qrc | 7 ++++ 7 files changed, 200 insertions(+) create mode 100644 app/app.pri create mode 100644 app/app.pro create mode 100644 app/images/black_normal.png create mode 100644 app/images/black_split.png create mode 100644 app/main.cpp create mode 100644 app/main.qml create mode 100644 app/main.qrc (limited to 'app') diff --git a/app/app.pri b/app/app.pri new file mode 100644 index 0000000..c3b1fd1 --- /dev/null +++ b/app/app.pri @@ -0,0 +1,13 @@ +TEMPLATE = app +QMAKE_LFLAGS += "-Wl,--hash-style=gnu -Wl,--as-needed" + +load(configure) +qtCompileTest(libhomescreen) + +config_libhomescreen { + CONFIG += link_pkgconfig + PKGCONFIG += homescreen + DEFINES += HAVE_LIBHOMESCREEN +} + +DESTDIR = $${OUT_PWD}/../package/root/bin diff --git a/app/app.pro b/app/app.pro new file mode 100644 index 0000000..22c9b00 --- /dev/null +++ b/app/app.pro @@ -0,0 +1,17 @@ +###################################################################### +# Automatically generated by qmake (3.1) Tue Apr 24 05:31:07 2018 +###################################################################### + +TARGET = restriction +INCLUDEPATH += . + +QT = quickcontrols2 + +CONFIG += link_pkgconfig +PKGCONFIG += libhomescreen qlibwindowmanager + +# Input +SOURCES += main.cpp +RESOURCES += main.qrc + +include(app.pri) \ No newline at end of file diff --git a/app/images/black_normal.png b/app/images/black_normal.png new file mode 100644 index 0000000..378798a Binary files /dev/null and b/app/images/black_normal.png differ diff --git a/app/images/black_split.png b/app/images/black_split.png new file mode 100644 index 0000000..9ce95ed Binary files /dev/null and b/app/images/black_split.png differ diff --git a/app/main.cpp b/app/main.cpp new file mode 100644 index 0000000..30d3ced --- /dev/null +++ b/app/main.cpp @@ -0,0 +1,96 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char* argv[]) { + QString role = QString("Restriction"); + + QGuiApplication app(argc, argv); + + QQuickStyle::setStyle("AGL"); + + QQmlApplicationEngine engine; + + 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(); + + if (positionalArguments.length() == 2) { + int port = positionalArguments.takeFirst().toInt(); + QString secret = positionalArguments.takeFirst(); + QUrl bindingAddress; + bindingAddress.setScheme(QStringLiteral("ws")); + bindingAddress.setHost(QStringLiteral("localhost")); + bindingAddress.setPort(port); + bindingAddress.setPath(QStringLiteral("/api")); + QUrlQuery query; + query.addQueryItem(QStringLiteral("token"), secret); + bindingAddress.setQuery(query); + + std::string token = secret.toStdString(); + LibHomeScreen* hs = new LibHomeScreen(); + QLibWindowmanager* qwm = new QLibWindowmanager(); + + if (qwm->init(port, secret) != 0) { + exit(EXIT_FAILURE); + } + // Request a surface as described in layers.json windowmanager’s file + if (qwm->requestSurface(role) != 0) { + exit(EXIT_FAILURE); + } + + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + QObject* root = engine.rootObjects().first(); + + // Create an event callback against an event type. Here a lambda is + // called when SyncDraw event occurs + qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, + [qwm, role](json_object* object) { + fprintf(stderr, "Surface got syncDraw! object=%s\n", json_object_to_json_string(object)); + qwm->endDraw(role); + }); + + // HomeScreen + hs->init(port, token.c_str()); + // showWindow + hs->set_event_handler(LibHomeScreen::Event_ShowWindow, + [qwm, role, root](json_object* object){ + fprintf(stderr, "restiction got showWindow event! object=%s\n", json_object_to_json_string(object)); + json_object *paramJ = nullptr, *areaJ = nullptr; + if (json_object_object_get_ex(object, "parameter", ¶mJ) + && json_object_object_get_ex(paramJ, "area", &areaJ)) { + qwm->activateWindow(role, json_object_get_string(areaJ)); + } + + QString area(QLatin1String(json_object_get_string(areaJ))); + QMetaObject::invokeMethod(root, "showImage", Q_ARG(QVariant, area)); + }); + + // hideWindow + hs->set_event_handler(LibHomeScreen::Event_HideWindow, + [qwm, role, root](json_object* object){ + fprintf(stderr, "restiction got hideWindow event! object=%s\n", json_object_to_json_string(object)); + QMetaObject::invokeMethod(root, "hideImage"); + qwm->deactivateWindow(role); + }); + } + + return app.exec(); +} diff --git a/app/main.qml b/app/main.qml new file mode 100644 index 0000000..e08b935 --- /dev/null +++ b/app/main.qml @@ -0,0 +1,67 @@ +import QtQuick 2.6 +import QtQuick.Controls 2.0 + +ApplicationWindow { + id: root + + color: "#00000000" + + Label { + id: message + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.margins: 20 + font.pixelSize: 75 + wrapMode: Text.WordWrap + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + color: "white" + text: "Only the video’s sound will be available while driving." + } + + background : Image { + id: backgroundImg + anchors.fill: parent + anchors.topMargin: 0 + anchors.bottomMargin: 0 + + visible: true + fillMode: Image.Stretch + source: 'images/black_normal.png' + + state: "begin" + states: [ + State { + name: "begin" + PropertyChanges { target: backgroundImg; opacity: 0.25 } + }, + State { + name: "end" + PropertyChanges { target: backgroundImg; opacity: 0.75 } + } + ] + + transitions: [ + Transition { + from: "begin"; to: "end" + PropertyAnimation {target: backgroundImg; properties: "opacity"; duration: 2000} + } + ] + } + + function showImage(area) { + if (area === 'normal.full') { + backgroundImg.source = 'images/black_normal.png' + } else { + backgroundImg.source = 'images/black_split.png' + } + backgroundImg.state = "end" + } + + + function hideImage() { + backgroundImg.state = "begin" + } +} diff --git a/app/main.qrc b/app/main.qrc new file mode 100644 index 0000000..c9f6449 --- /dev/null +++ b/app/main.qrc @@ -0,0 +1,7 @@ + + + main.qml + images/black_normal.png + images/black_split.png + + -- cgit 1.2.3-korg