diff options
author | wang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com> | 2019-02-13 18:10:20 +0800 |
---|---|---|
committer | wang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com> | 2019-02-15 10:56:06 +0800 |
commit | aee1b69e8e207081a3d8b2670980671a9fbc78b8 (patch) | |
tree | 86e71a4d08908c8c6711400a810bbbb00f19f803 /sample/app | |
parent | 483c21f9d648f2cd58e00f39fcbee7b5dcbe2bc5 (diff) |
Add onscreenapp
Onscreenapp is a qt application for showing onscreens.
Applications can show/hide onscreen by calling homescreen-service's
showWindow/hideWindow verb. Applications also can customize onscreen's
title,type, display contents and buttons. Some images about onscreen
pattern had uploaded in JIRA SPEC-1967.
Bug-AGL: SPEC-1967
Change-Id: I421193f7d089584a26db629be27414d050a74337
Signed-off-by: wang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Diffstat (limited to 'sample/app')
-rw-r--r-- | sample/app/app.pro | 33 | ||||
-rw-r--r-- | sample/app/eventhandler.cpp | 117 | ||||
-rw-r--r-- | sample/app/eventhandler.h | 59 | ||||
-rw-r--r-- | sample/app/hmi-debug.h | 77 | ||||
-rw-r--r-- | sample/app/main.cpp | 70 | ||||
-rw-r--r-- | sample/app/main.qml | 349 | ||||
-rw-r--r-- | sample/app/qml.qrc | 5 |
7 files changed, 710 insertions, 0 deletions
diff --git a/sample/app/app.pro b/sample/app/app.pro new file mode 100644 index 0000000..c72fd28 --- /dev/null +++ b/sample/app/app.pro @@ -0,0 +1,33 @@ +# +# Copyright (c) 2019 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. + +TARGET = onstestapp +QT = quick quickcontrols2 qml + +CONFIG += c++11 link_pkgconfig +PKGCONFIG += qlibwindowmanager qlibhomescreen +DESTDIR = $${OUT_PWD}/../package/root/bin + +SOURCES = main.cpp \ + eventhandler.cpp + +RESOURCES += \ + qml.qrc + +HEADERS += \ + eventhandler.h + +LIBS += -ljson-c + diff --git a/sample/app/eventhandler.cpp b/sample/app/eventhandler.cpp new file mode 100644 index 0000000..4e55619 --- /dev/null +++ b/sample/app/eventhandler.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2019 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 <functional> +#include <QUrl> +#include <QJsonDocument> +#include <QJsonObject> +#include <QQuickWindow> +//#include <QtQml/QQmlContext> +#include <QQmlContext> +#include <QtQml/QQmlApplicationEngine> +#include "eventhandler.h" + +void* EventHandler::myThis = 0; + +const char _drawing_name[] = "drawing_name"; + +EventHandler::EventHandler(QObject *parent) : + QObject(parent), + mp_hs(NULL), + mp_wm(NULL), + mp_qw(NULL) +{ + +} + +EventHandler::~EventHandler() +{ + if (mp_hs != NULL) { + delete mp_hs; + } + if (mp_wm != NULL) { + delete mp_wm; + } +} + +void EventHandler::init(int port, const char *token) +{ + myThis = this; + mp_wm = new QLibWindowmanager(); + mp_wm->init(port, token); + + mp_hs = new QLibHomeScreen(); + mp_hs->init(port, token); + + mp_hs->set_event_handler(QLibHomeScreen::Event_ShowWindow, [this](json_object *object){ + this->mp_wm->activateWindow(ROLE_NAME, "normal"); + HMI_DEBUG(APP_ID, "received showWindow event, end!, line=%d", __LINE__); + }); + + mp_hs->set_event_handler(QLibHomeScreen::Event_ReplyShowWindow, [this](json_object *object){ + HMI_DEBUG(APP_ID, "got Event_ReplyShowWindow!\n"); + const char* msg = json_object_to_json_string(object); + emit this->signalOnReplyShowWindow(msg); + }); + + if (mp_wm->requestSurface(ROLE_NAME) != 0) { + HMI_DEBUG(APP_ID, "!!!!LayoutHandler requestSurface Failed!!!!!"); + exit(EXIT_FAILURE); + } + + // Create an event callback against an event type. Here a lambda is called when SyncDraw event occurs + mp_wm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [this](json_object *object) { + HMI_DEBUG(APP_ID, "Surface got syncDraw!"); + this->mp_wm->endDraw(ROLE_NAME); + }); + + mp_wm->set_event_handler(QLibWindowmanager::Event_Visible, [this](json_object *object) { + struct json_object *value; + json_object_object_get_ex(object, _drawing_name, &value); + const char *name = json_object_get_string(value); + + HMI_DEBUG(APP_ID, "Event_Active kKeyDrawingName = %s", name); + }); + + mp_wm->set_event_handler(QLibWindowmanager::Event_Invisible, [this](json_object *object) { + struct json_object *value; + json_object_object_get_ex(object, _drawing_name, &value); + const char *name = json_object_get_string(value); + + HMI_DEBUG(APP_ID, "Event_Inactive kKeyDrawingName = %s", name); + }); + + HMI_DEBUG(APP_ID, "LayoutHander::init() finished."); +} + +void EventHandler::setQuickWindow(QQuickWindow *qw) +{ + mp_qw = qw; + QObject::connect(mp_qw, SIGNAL(frameSwapped()), mp_wm, SLOT(slotActivateSurface())); +} + +void EventHandler::showWindow(QString id, QString json) +{ + if(json.isNull()) + mp_hs->tapShortcut(id); + else + mp_hs->showWindow(id.toStdString().c_str(), json_tokener_parse(json.toStdString().c_str())); +} + +void EventHandler::hideWindow(QString id) +{ + mp_hs->hideWindow(id.toStdString().c_str()); +} diff --git a/sample/app/eventhandler.h b/sample/app/eventhandler.h new file mode 100644 index 0000000..af66644 --- /dev/null +++ b/sample/app/eventhandler.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2019 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. + */ + +#ifndef EVENTHANDLER_H +#define EVENTHANDLER_H + +#include <QObject> +#include <string> +#include <QVariant> + +#include <qlibhomescreen.h> +#include <qlibwindowmanager.h> +#include "hmi-debug.h" + +#define ROLE_NAME "onstestapp" +#define APP_ID "onstestapp" + +using namespace std; + +class QQuickWindow; +class QQmlApplicationEngine; + +class EventHandler : public QObject +{ + Q_OBJECT +public: + explicit EventHandler(QObject *parent = 0); + ~EventHandler(); + + void init(int port, const char* token); + void setQuickWindow(QQuickWindow *qw); + static void* myThis; + + Q_INVOKABLE void showWindow(QString id, QString json); + Q_INVOKABLE void hideWindow(QString id); + +signals: + void signalOnReplyShowWindow(QVariant val); + +private: + QLibHomeScreen *mp_hs; + QLibWindowmanager* mp_wm; + QQuickWindow *mp_qw; +}; + +#endif // EVENTHANDLER_H diff --git a/sample/app/hmi-debug.h b/sample/app/hmi-debug.h new file mode 100644 index 0000000..5178aa5 --- /dev/null +++ b/sample/app/hmi-debug.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2017 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. + */ + +#ifndef __HMI_DEBUG_H__ +#define __HMI_DEBUG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <time.h> +#include <stdio.h> +#include <stdarg.h> +#include <string.h> +#include <stdlib.h> + +enum LOG_LEVEL{ + LOG_LEVEL_NONE = 0, + LOG_LEVEL_ERROR, + LOG_LEVEL_WARNING, + LOG_LEVEL_NOTICE, + LOG_LEVEL_INFO, + LOG_LEVEL_DEBUG, + LOG_LEVEL_MAX = LOG_LEVEL_DEBUG +}; + +#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) + +#define HMI_ERROR(prefix, args,...) _HMI_LOG(LOG_LEVEL_ERROR, __FILENAME__, __FUNCTION__, __LINE__, prefix, args, ##__VA_ARGS__) +#define HMI_WARNING(prefix, args,...) _HMI_LOG(LOG_LEVEL_WARNING, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__) +#define HMI_NOTICE(prefix, args,...) _HMI_LOG(LOG_LEVEL_NOTICE, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__) +#define HMI_INFO(prefix, args,...) _HMI_LOG(LOG_LEVEL_INFO, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__) +#define HMI_DEBUG(prefix, args,...) _HMI_LOG(LOG_LEVEL_DEBUG, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__) + +static char ERROR_FLAG[6][20] = {"NONE", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG"}; + +static void _HMI_LOG(enum LOG_LEVEL level, const char* file, const char* func, const int line, const char* prefix, const char* log, ...) +{ + const int log_level = (getenv("USE_HMI_DEBUG") == NULL)?LOG_LEVEL_ERROR:atoi(getenv("USE_HMI_DEBUG")); + if(log_level < level) + { + return; + } + + char *message; + struct timespec tp; + unsigned int time; + + clock_gettime(CLOCK_REALTIME, &tp); + time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); + + va_list args; + va_start(args, log); + if (log == NULL || vasprintf(&message, log, args) < 0) + message = NULL; + fprintf(stderr, "[%10.3f] [%s %s] [%s, %s(), Line:%d] >>> %s \n", time / 1000.0, prefix, ERROR_FLAG[level], file, func, line, message); + va_end(args); + free(message); +} + +#ifdef __cplusplus +} +#endif +#endif //__HMI_DEBUG_H__ diff --git a/sample/app/main.cpp b/sample/app/main.cpp new file mode 100644 index 0000000..c47c869 --- /dev/null +++ b/sample/app/main.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2019 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 <QQmlContext> +#include <QtCore/QCommandLineParser> +#include <QtGui/QGuiApplication> +#include <QtQml/QQmlContext> +#include <QtQml/QQmlApplicationEngine> +#include <QtQuickControls2/QQuickStyle> +#include <QtQuick/QQuickWindow> + +#include "eventhandler.h" + + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + app.setApplicationName("onstestapp"); + app.setApplicationVersion(QStringLiteral("3.99.3")); + app.setOrganizationDomain(QStringLiteral("automotivelinux.org")); + app.setOrganizationName(QStringLiteral("AutomotiveGradeLinux")); + + 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(); + + QQmlApplicationEngine engine; + int port = 0; + QString secret; + if (positionalArguments.length() == 2) { + port = positionalArguments.takeFirst().toInt(); + secret = positionalArguments.takeFirst(); + } + + EventHandler *eventHandler = new EventHandler(); + eventHandler->init(port, secret.toStdString().c_str()); + engine.rootContext()->setContextProperty("eventHandler", eventHandler); + + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + if (engine.rootObjects().isEmpty()) { + HMI_DEBUG(APP_ID, "Fatal Error, rootObject is empty!"); + return -1; + } + + QObject *root = engine.rootObjects().first(); + QQuickWindow *window = qobject_cast<QQuickWindow *>(root); + QObject::connect(eventHandler, SIGNAL(signalOnReplyShowWindow(QVariant)), window, SLOT(qmlOnReplyShowWindow(QVariant))); + eventHandler->setQuickWindow(window); + + return app.exec(); +} diff --git a/sample/app/main.qml b/sample/app/main.qml new file mode 100644 index 0000000..b9f415b --- /dev/null +++ b/sample/app/main.qml @@ -0,0 +1,349 @@ +import QtQuick 2.7 +import QtQuick.Window 2.2 +import QtQuick.Controls 2.0 +import QtQuick.Layouts 1.0 +import AGL.Demo.Controls 1.0 + +ApplicationWindow { + id: root + visible: true + width: 1080 + height: 1487 + + property string onsId: qsTr("onscreenapp") + property string onsTitle: qsTr("One Button title") + property string onsType: "critical" + property string onsContents: qsTr("An operating system is a program that manages a computer’s hardware.") + property string onsButton1: qsTr("Yes") + property string onsButton2: qsTr("") + property string onsButton3: qsTr("") + property string postmsg: qsTr("") + property string btndata: qsTr("") + + Label { + id: title + width: parent.width + height: 40 + text: "OnScreen Test App" + font.pixelSize: 40 + font.bold: true + color: "white" + } + + ColumnLayout { + spacing: 20 + anchors.top: title.bottom + anchors.topMargin: 40 + anchors.horizontalCenter: title.horizontalCenter + + // show received reply information area + Flickable { + id: flickable + width: 800 + height: 320 + Layout.alignment: Qt.AlignCenter + flickableDirection: Flickable.VerticalFlick + boundsBehavior: Flickable.StopAtBounds + + TextArea.flickable: TextArea { + id: output + text: "show received reply information area\n...\n...\n...\n...\n" + font.pixelSize: 24 + wrapMode: TextArea.Wrap + color: '#00ADDC' + } + + ScrollBar.vertical: ScrollBar { } + } + + // select onscreen type area + GroupBox { + label: Label { + text: qsTr("Please select send OnScreen Message") + font.pixelSize: 32 + font.bold: true + color: "white" + } + + width: 800 + height: 100 + Layout.alignment: Qt.AlignLeft + + RowLayout { + anchors.fill: parent + RadioButton { + text: qsTr("One Button") + font.pixelSize: 20 + checked: true + onClicked: { + selectOneButton(); + } + } + RadioButton { + text: qsTr("Two Buttons") + font.pixelSize: 20 + onClicked: { + selectTwoButtons(); + } + } + RadioButton { + text: qsTr("Three Buttons") + font.pixelSize: 20 + onClicked: { + selectThreeButtons(); + } + } + RadioButton { + text: qsTr("No Button") + font.pixelSize: 20 + onClicked: { + selectNoButton(); + } + } + } + } + + // edit post message area + GroupBox { + label: Label { + text: qsTr("Post Infomations") + font.pixelSize: 32 + font.bold: true + color: "white" + } + width: 800 + height: 400 + Layout.alignment: Qt.AlignLeft + Layout.maximumWidth: 800 + Layout.maximumHeight: 400 + + ColumnLayout { + spacing: 20 + RowLayout { + spacing: 20 + Label { + id: ons_title + anchors.left: parent.left + anchors.leftMargin: 30 + text: qsTr("ons_title:") + font.pixelSize: 20 + font.italic: true + color: '#00ADDC' + } + + Label { + id: ons_title_data + text: onsTitle + font.pixelSize: 20 + font.italic: true + anchors.left: ons_title.right + anchors.leftMargin: 20 + color: '#00ADDC' + Layout.maximumWidth: 600 + Layout.maximumHeight: 40 + maximumLineCount: 1 + wrapMode: Text.Wrap + elide: Text.ElideRight + horizontalAlignment: Label.AlignHCenter + verticalAlignment: Label.AlignVCenter + } + } + RowLayout { + spacing: 20 + Label { + id: ons_type + anchors.left: parent.left + anchors.leftMargin: 30 + text: qsTr("type:") + font.pixelSize: 20 + font.italic: true + color: '#00ADDC' + } + + Label { + id: ons_type_data + text: onsType + font.pixelSize: 20 + font.italic: true + anchors.left: ons_type.right + anchors.leftMargin: 20 + color: '#00ADDC' + } + } + RowLayout { + spacing: 20 + Label { + id: ons_contents + anchors.left: parent.left + anchors.leftMargin: 30 + text: qsTr("contents:") + font.pixelSize: 20 + font.italic: true + color: '#00ADDC' + } + Label { + id: ons_contents_data + text: onsContents + font.pixelSize: 20 + font.italic: true + anchors.left: ons_contents.right + anchors.leftMargin: 20 + color: '#00ADDC' + Layout.maximumWidth: 600 + Layout.maximumHeight: 200 + maximumLineCount: 4 + wrapMode: Text.Wrap + elide: Text.ElideRight + horizontalAlignment: Label.AlignLeft + verticalAlignment: Label.AlignVCenter + } + } + RowLayout { + spacing: 20 + Label { + id: btn1 + anchors.left: parent.left + anchors.leftMargin: 30 + text: qsTr("Button1") + font.pixelSize: 20 + font.italic: true + color: '#00ADDC' + } + + Label { + id: btn1_data + text: onsButton1 + font.pixelSize: 20 + font.italic: true + anchors.left: btn1.right + anchors.leftMargin: 20 + color: '#00ADDC' + } + } + RowLayout { + spacing: 20 + Label { + id: btn2 + anchors.left: parent.left + anchors.leftMargin: 30 + text: qsTr("Button2") + font.pixelSize: 20 + font.italic: true + color: '#00ADDC' + } + Label { + id: btn2_data + text: onsButton2 + font.pixelSize: 20 + font.italic: true + anchors.left: btn2.right + anchors.leftMargin: 20 + color: '#00ADDC' + } + } + RowLayout { + spacing: 20 + Label { + id: btn3 + anchors.left: parent.left + anchors.leftMargin: 30 + text: qsTr("Button3") + font.pixelSize: 20 + font.italic: true + color: '#00ADDC' + } + Label { + id: btn3_data + text: onsButton3 + font.pixelSize: 20 + font.italic: true + anchors.left: btn3.right + anchors.leftMargin: 20 + color: '#00ADDC' + } + } + } + } + + // post button + Button { + id: poster + text: "Post" + Layout.alignment: Qt.AlignCenter + onClicked: { + postMessage(); + } + } + } + + function selectOneButton() { + console.log("select one button!") + onsTitle = qsTr("One Button title") + onsType = qsTr("critical") + onsContents = qsTr("An operating system is a program that manages a computer’s hardware.") + onsButton1 = qsTr("Yes") + onsButton2 = qsTr("") + onsButton3 = qsTr("") + } + + function selectTwoButtons() { + console.log("select two buttons!") + onsTitle = qsTr("Two Buttons title") + onsType = qsTr("exclamation") + onsContents = qsTr("Beforewe can explore the details of computer system operation, we need to know something about system structure. We thus discuss the basic functions of system startup, I/O, and storage early in this chapter. We also describe the basic computer architecture that makes it possible to write a functional operating system.") + onsButton1 = qsTr("Yes") + onsButton2 = qsTr("No") + onsButton3 = qsTr("") + } + + function selectThreeButtons() { + console.log("select three buttons!") + onsTitle = qsTr("Three Buttons title") + onsType = qsTr("information") + onsContents = qsTr("We can also view a computer system as consisting of hardware, software,and data. The operating system provides the means for proper use of these resources in the operation of the computer system.") + onsButton1 = qsTr("Yes") + onsButton2 = qsTr("Abort") + onsButton3 = qsTr("No") + } + + function selectNoButton() { + console.log("select no button!") + onsTitle = qsTr("No Button title,very long title beyond screen wide which will show ellipsis at the end") + onsType = qsTr("question") + onsContents = qsTr("Recently, many varieties of mobile computers, such as smartphones and tablets, have come into fashion. Most mobile computers are standalone units for individual users. Quite often, they are connected to networks through cellular or other wireless technologies. Increasingly, these mobile devices are replacing desktop and laptop computers for people who are primarily interested in using computers for e-mail and web browsing. The user interface for mobile computers generally features a touch screen, where the user interacts with the system by pressing and swiping fingers across the screen rather than using a physical keyboard and mouse.") + onsButton1 = qsTr("") + onsButton2 = qsTr("") + onsButton3 = qsTr("") + } + + function postMessage() { + console.log("poster pressed") + btndata = "" + postmsg = "{\"title\": \"" + onsTitle + "\"," + "\"type\": \"" + onsType + "\"," + "\"contents\": \"" + onsContents + "\""; + if (onsButton1 != "") { + btndata = "\"" + onsButton1 + "\""; + } + if (onsButton2 != "") { + if (btndata != "") + btndata += ","; + btndata += "\"" + onsButton2 + "\""; + } + if (onsButton3 != "") { + if (btndata != "") + btndata += ","; + btndata += "\"" + onsButton3 + "\""; + } + + if(btndata != "") + postmsg += ",\"buttons\":[" + btndata + "]}" + else + postmsg += "}" + + eventHandler.showWindow(onsId, postmsg); + } + + function qmlOnReplyShowWindow(text) { + console.log("onstestapp received:",text); + output.text = text; + } +} diff --git a/sample/app/qml.qrc b/sample/app/qml.qrc new file mode 100644 index 0000000..5f6483a --- /dev/null +++ b/sample/app/qml.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + </qresource> +</RCC> |