From b3476f1c2debc23411a66b1498065ab575879e22 Mon Sep 17 00:00:00 2001 From: wang_zhiqiang Date: Tue, 13 Nov 2018 15:54:13 +0800 Subject: add fullscreen¬ification&information function Change-Id: I33b355c78d5abe6bf4a8a60350cf6e7f4f78e0f7 --- homescreen/homescreen.pro | 6 +- homescreen/qml/ShortcutArea.qml | 3 +- homescreen/qml/StatusArea.qml | 17 +- homescreen/qml/images/AGL_HMI_Full_Background.png | Bin 0 -> 8306 bytes .../qml/images/AGL_HMI_Normal_Background.png | Bin 0 -> 10012 bytes homescreen/qml/images/fullscreen.png | Bin 0 -> 1633 bytes homescreen/qml/images/images.qrc | 4 + homescreen/qml/images/normal.png | Bin 0 -> 1626 bytes homescreen/qml/main.qml | 183 +++++++++++++++++++++ homescreen/src/homescreenhandler.cpp | 53 +++++- homescreen/src/homescreenhandler.h | 10 +- homescreen/src/main.cpp | 20 ++- homescreen/src/toucharea.cpp | 36 ++++ homescreen/src/toucharea.h | 30 ++++ 14 files changed, 345 insertions(+), 17 deletions(-) create mode 100644 homescreen/qml/images/AGL_HMI_Full_Background.png create mode 100644 homescreen/qml/images/AGL_HMI_Normal_Background.png create mode 100644 homescreen/qml/images/fullscreen.png create mode 100644 homescreen/qml/images/normal.png create mode 100644 homescreen/src/toucharea.cpp create mode 100644 homescreen/src/toucharea.h diff --git a/homescreen/homescreen.pro b/homescreen/homescreen.pro index 0e5bb58..9c36660 100644 --- a/homescreen/homescreen.pro +++ b/homescreen/homescreen.pro @@ -30,14 +30,16 @@ SOURCES += \ src/statusbarserver.cpp \ src/applicationlauncher.cpp \ src/mastervolume.cpp \ - src/homescreenhandler.cpp + src/homescreenhandler.cpp \ + src/toucharea.cpp HEADERS += \ src/statusbarmodel.h \ src/statusbarserver.h \ src/applicationlauncher.h \ src/mastervolume.h \ - src/homescreenhandler.h + src/homescreenhandler.h \ + src/toucharea.h OTHER_FILES += \ README.md diff --git a/homescreen/qml/ShortcutArea.qml b/homescreen/qml/ShortcutArea.qml index d7e97f0..1790e89 100644 --- a/homescreen/qml/ShortcutArea.qml +++ b/homescreen/qml/ShortcutArea.qml @@ -24,7 +24,6 @@ Item { width: 785 height: 218 - ListModel { id: applicationModel ListElement { @@ -70,7 +69,7 @@ Item { console.warn(model.application) console.warn("app cannot be launched!") } - homescreenHandler.tapShortcut(model.appid) + homescreenHandler.tapShortcut(model.appid, false) } } } diff --git a/homescreen/qml/StatusArea.qml b/homescreen/qml/StatusArea.qml index 3f2b280..1fb4601 100644 --- a/homescreen/qml/StatusArea.qml +++ b/homescreen/qml/StatusArea.qml @@ -117,11 +117,16 @@ Item { Layout.fillHeight: true Layout.preferredWidth: 76 spacing: -10 + Rectangle { + Layout.preferredWidth: 77 + Layout.preferredHeight: 55 + opacity: 0 + } Image { id: bt_icon Layout.preferredWidth: 77 - Layout.preferredHeight: 73 + Layout.preferredHeight: 55 source: connStatus ? './images/Status/HMI_Status_Bluetooth_On-01.png' : './images/Status/HMI_Status_Bluetooth_Inactive-01.png' fillMode: Image.PreserveAspectFit property string deviceName: "none" @@ -134,9 +139,9 @@ Item { onConnectionEvent: { // console.log("bluetooth connection is:", data.Status) // console.log("onConnectionEvent bt_icon.deviceName:",bt_icon.deviceName, "bt_icon.connStatus:", bt_icon.connStatus) - if (data.Status == "connected"){ + if (data.Status === "connected"){ bt_icon.connStatus = true - } else if (data.Status == "disconnected"){ + } else if (data.Status === "disconnected"){ bt_icon.connStatus = false } } @@ -144,11 +149,11 @@ Item { onDeviceUpdatedEvent: { // console.log("bluetooth onDeviceUpdatedEvent date is:", data.Name, "Paired: ", data.Paired, "Connected: ", data.Connected) // console.log("onDeviceUpdatedEvent bt_icon.deviceName:",bt_icon.deviceName, "bt_icon.connStatus:", bt_icon.connStatus) - if ( data.Paired == "True" && data.Connected == "True" ){ + if ( data.Paired === "True" && data.Connected === "True" ){ bt_icon.deviceName = data.Name bt_icon.connStatus = true } else { - if(bt_icon.deviceName == data.Name) + if(bt_icon.deviceName === data.Name) { bt_icon.connStatus = false } @@ -160,7 +165,7 @@ Item { model: StatusBarModel { objectName: "statusBar" } delegate: Image { Layout.preferredWidth: 77 - Layout.preferredHeight: 73 + Layout.preferredHeight: 55 source: model.modelData fillMode: Image.PreserveAspectFit } diff --git a/homescreen/qml/images/AGL_HMI_Full_Background.png b/homescreen/qml/images/AGL_HMI_Full_Background.png new file mode 100644 index 0000000..8b11e20 Binary files /dev/null and b/homescreen/qml/images/AGL_HMI_Full_Background.png differ diff --git a/homescreen/qml/images/AGL_HMI_Normal_Background.png b/homescreen/qml/images/AGL_HMI_Normal_Background.png new file mode 100644 index 0000000..c686067 Binary files /dev/null and b/homescreen/qml/images/AGL_HMI_Normal_Background.png differ diff --git a/homescreen/qml/images/fullscreen.png b/homescreen/qml/images/fullscreen.png new file mode 100644 index 0000000..f56a13c Binary files /dev/null and b/homescreen/qml/images/fullscreen.png differ diff --git a/homescreen/qml/images/images.qrc b/homescreen/qml/images/images.qrc index 37ad676..87b4f1e 100644 --- a/homescreen/qml/images/images.qrc +++ b/homescreen/qml/images/images.qrc @@ -6,5 +6,9 @@ Utility_Music_Background-01.png Utility_Radio_Background-01.png AGL_HMI_Blue_Background_NoCar-01.png + AGL_HMI_Full_Background.png + AGL_HMI_Normal_Background.png + fullscreen.png + normal.png diff --git a/homescreen/qml/images/normal.png b/homescreen/qml/images/normal.png new file mode 100644 index 0000000..92dee7a Binary files /dev/null and b/homescreen/qml/images/normal.png differ diff --git a/homescreen/qml/main.qml b/homescreen/qml/main.qml index 96a1950..164cbf7 100644 --- a/homescreen/qml/main.qml +++ b/homescreen/qml/main.qml @@ -26,6 +26,7 @@ Window { width: container.width * container.scale height: container.height * container.scale title: 'HomeScreen' + color: "#00000000" Image { id: container @@ -60,5 +61,187 @@ Window { Layout.preferredHeight: 215 } } + + states: [ + State { + name: "normal" + PropertyChanges { + target: topArea + y: 0 + } + PropertyChanges { + target: applicationArea + y: 218 + } + PropertyChanges { + target: mediaArea + y: 1705 + } + }, + State { + name: "fullscreen" + PropertyChanges { + target: topArea + y: -220 + } + PropertyChanges { + target: applicationArea + y: -1490 + } + PropertyChanges { + target: mediaArea + y: 2135 + } + } + ] + transitions: Transition { + NumberAnimation { + target: topArea + property: "y" + easing.type: "OutQuad" + duration: 250 + } + NumberAnimation { + target: mediaArea + property: "y" + easing.type: "OutQuad" + duration: 250 + } + } + } + + Item { + id: switchBtn + anchors.right: parent.right + anchors.rightMargin: 20 + anchors.top: parent.top + anchors.topMargin: 25 + width: 35 + height: 35 + z: 1 + + MouseArea { + anchors.fill: parent + property string btnState: 'normal' + Image { + id: image + anchors.fill: parent + source: './images/normal.png' + } + onClicked: { + var appName = homescreenHandler.getCurrentApplication() + if (btnState === 'normal') { + image.source = './images/fullscreen.png' + btnState = 'fullscreen' + container.state = 'fullscreen' + touchArea.switchArea(1) + homescreenHandler.tapShortcut(appName, true) + if (appName === 'navigation' || appName === 'browser') { + container.opacity = 0.0 + } + } else { + image.source = './images/normal.png' + btnState = 'normal' + container.state = 'normal' + touchArea.switchArea(0) + homescreenHandler.tapShortcut(appName, false) + if (appName === 'navigation' || appName === 'browser') { + container.opacity = 1.0 + } + } + } + } + } + + Timer { + id:informationTimer + interval: 3000 + running: false + repeat: true + onTriggered: { + bottomInformation.visible = false + } + } + + Item { + id: bottomInformation + width: parent.width + height: 215 + anchors.bottom: parent.bottom + visible: false + Text { + id: bottomText + anchors.centerIn: parent + font.pixelSize: 25 + font.letterSpacing: 5 + horizontalAlignment: Text.AlignHCenter + color: "white" + text: "" + z:1 + } + } + + Connections { + target: homescreenHandler + onShowInformation: { + bottomText.text = info + bottomInformation.visible = true + informationTimer.restart() + } + } + + Timer { + id:notificationTimer + interval: 3000 + running: false + repeat: true + onTriggered: notificationItem.visible = false + } + + Item { + id: notificationItem + x: 0 + y: 0 + z: 1 + width: 1280 + height: 100 + opacity: 0.8 + visible: false + + Rectangle { + width: parent.width + height: parent.height + anchors.fill: parent + color: "gray" + Image { + id: notificationIcon + width: 70 + height: 70 + anchors.left: parent.left + anchors.leftMargin: 20 + anchors.verticalCenter: parent.verticalCenter + source: "" + } + + Text { + id: notificationtext + font.pixelSize: 25 + anchors.left: notificationIcon.right + anchors.leftMargin: 5 + anchors.verticalCenter: parent.verticalCenter + color: "white" + text: qsTr("") + } + } + } + + Connections { + target: homescreenHandler + onShowNotification: { + notificationIcon.source = icon_path + notificationtext.text = text + notificationItem.visible = true + notificationTimer.restart() + } } } diff --git a/homescreen/src/homescreenhandler.cpp b/homescreen/src/homescreenhandler.cpp index daf1b90..2d51099 100644 --- a/homescreen/src/homescreenhandler.cpp +++ b/homescreen/src/homescreenhandler.cpp @@ -49,12 +49,61 @@ void HomescreenHandler::init(int port, const char *token) HMI_DEBUG("HomeScreen","set_event_handler Event_OnScreenMessage display_message = %s", display_message); }); + mp_hs->set_event_handler(LibHomeScreen::Event_ShowNotification,[this](json_object *object){ + const char *application_id = json_object_get_string( + json_object_object_get(object, "application_id")); + + json_object *p_obj = json_object_object_get(object, "parameter"); + const char *icon = json_object_get_string( + json_object_object_get(p_obj, "icon")); + const char *text = json_object_get_string( + json_object_object_get(p_obj, "text")); + QFileInfo icon_file(icon); + QString icon_path; + if (icon_file.exists()) { + icon_path = QString(QLatin1String(icon)); + } else { + icon_path = "./images/Utility_Logo_Grey-01.svg"; + } + + emit showNotification(QString(QLatin1String(application_id)), icon_path, QString(QLatin1String(text))); + }); + + mp_hs->set_event_handler(LibHomeScreen::Event_ShowInformation,[this](json_object *object){ + json_object *p_obj = json_object_object_get(object, "parameter"); + const char *info = json_object_get_string( + json_object_object_get(p_obj, "info")); + + emit showInformation(QString(QLatin1String(info))); + }); } -void HomescreenHandler::tapShortcut(QString application_id) +void HomescreenHandler::tapShortcut(QString application_id, bool is_full) { HMI_DEBUG("HomeScreen","tapShortcut %s", application_id.toStdString().c_str()); - mp_hs->tapShortcut(application_id.toStdString().c_str()); + struct json_object* j_json = json_object_new_object(); + struct json_object* value; + if(is_full) { + value = json_object_new_string("fullscreen"); + HMI_DEBUG("HomeScreen","tapShortcut fullscreen"); + } else { + value = json_object_new_string("normal"); + HMI_DEBUG("HomeScreen","tapShortcut normal"); + } + json_object_object_add(j_json, "area", value); + mp_hs->showWindow(application_id.toStdString().c_str(), j_json); +} + +void HomescreenHandler::setCurrentApplication(QString application_id) +{ + HMI_DEBUG("HomeScreen","setCurrentApplication %s", application_id.toStdString().c_str()); + current_applciation = application_id; +} + +QString HomescreenHandler::getCurrentApplication() +{ + HMI_DEBUG("HomeScreen","getCurrentApplication %s", current_applciation.toStdString().c_str()); + return current_applciation; } void HomescreenHandler::onRep_static(struct json_object* reply_contents) diff --git a/homescreen/src/homescreenhandler.h b/homescreen/src/homescreenhandler.h index 1a9a2b5..d31d6af 100644 --- a/homescreen/src/homescreenhandler.h +++ b/homescreen/src/homescreenhandler.h @@ -20,6 +20,7 @@ #include #include #include +#include using namespace std; @@ -32,7 +33,9 @@ public: void init(int port, const char* token); - Q_INVOKABLE void tapShortcut(QString application_id); + Q_INVOKABLE void tapShortcut(QString application_id, bool is_full); + Q_INVOKABLE QString getCurrentApplication(); + void setCurrentApplication(QString application_id); void onRep(struct json_object* reply_contents); void onEv(const string& event, struct json_object* event_contents); @@ -40,8 +43,13 @@ public: static void* myThis; static void onRep_static(struct json_object* reply_contents); static void onEv_static(const string& event, struct json_object* event_contents); + +signals: + void showNotification(QString application_id, QString icon_path, QString text); + void showInformation(QString info); private: LibHomeScreen *mp_hs; + QString current_applciation; }; #endif // HOMESCREENHANDLER_H diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp index 620c869..7a7aa71 100644 --- a/homescreen/src/main.cpp +++ b/homescreen/src/main.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -32,6 +33,7 @@ #include "mastervolume.h" #include "homescreenhandler.h" #include "hmi-debug.h" +#include "toucharea.h" // XXX: We want this DBus connection to be shared across the different // QML objects, is there another way to do this, a nice way, perhaps? @@ -93,6 +95,9 @@ int main(int argc, char *argv[]) ApplicationLauncher *launcher = new ApplicationLauncher(); QLibWindowmanager* layoutHandler = new QLibWindowmanager(); + TouchArea* touchArea = new TouchArea(); + HomescreenHandler* homescreenHandler = new HomescreenHandler(); + homescreenHandler->init(port, token.toStdString().c_str()); if(layoutHandler->init(port,token) != 0){ exit(EXIT_FAILURE); } @@ -107,20 +112,18 @@ int main(int argc, char *argv[]) layoutHandler->endDraw(QString("HomeScreen")); }); - layoutHandler->set_event_handler(QLibWindowmanager::Event_ScreenUpdated, [layoutHandler, launcher](json_object *object) { + layoutHandler->set_event_handler(QLibWindowmanager::Event_ScreenUpdated, [layoutHandler, launcher, homescreenHandler](json_object *object) { json_object *jarray = json_object_object_get(object, "ids"); int arrLen = json_object_array_length(jarray); for( int idx = 0; idx < arrLen; idx++) { QString label = QString(json_object_get_string( json_object_array_get_idx(jarray, idx) )); HMI_DEBUG("HomeScreen","Event_ScreenUpdated application: %s.", label.toStdString().c_str()); + homescreenHandler->setCurrentApplication(label); QMetaObject::invokeMethod(launcher, "setCurrent", Qt::QueuedConnection, Q_ARG(QString, label)); } }); - HomescreenHandler* homescreenHandler = new HomescreenHandler(); - homescreenHandler->init(port, token.toStdString().c_str()); - QUrl bindingAddress; bindingAddress.setScheme(QStringLiteral("ws")); bindingAddress.setHost(QStringLiteral("localhost")); @@ -139,10 +142,19 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("weather", new Weather(bindingAddress)); engine.rootContext()->setContextProperty("bluetooth", new Bluetooth(bindingAddress)); engine.rootContext()->setContextProperty("screenInfo", &screenInfo); + engine.rootContext()->setContextProperty("touchArea", touchArea); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); QObject *root = engine.rootObjects().first(); QQuickWindow *window = qobject_cast(root); + + touchArea->setWindow(window); + QThread* thread = new QThread; + touchArea->moveToThread(thread); + QObject::connect(thread, &QThread::started, touchArea, &TouchArea::init); + + thread->start(); + QObject::connect(window, SIGNAL(frameSwapped()), layoutHandler, SLOT(slotActivateSurface())); QList sobjs = engine.rootObjects(); diff --git a/homescreen/src/toucharea.cpp b/homescreen/src/toucharea.cpp new file mode 100644 index 0000000..1cf4384 --- /dev/null +++ b/homescreen/src/toucharea.cpp @@ -0,0 +1,36 @@ +#include "toucharea.h" +#include "hmi-debug.h" + +TouchArea::TouchArea() +{ +} + +TouchArea::~TouchArea() +{ + +} + +void TouchArea::setWindow(QQuickWindow *window) +{ + myWindow = window; +} + +void TouchArea::init() +{ + bitmapNormal = QPixmap(":/images/AGL_HMI_Normal_Background.png").createHeuristicMask(); + bitmapFullscreen = QPixmap(":/images/AGL_HMI_Full_Background.png").createHeuristicMask(); + myWindow->setMask(QRegion(bitmapNormal)); +} + +void TouchArea::switchArea(int areaType) +{ + if(areaType == NORMAL) { + myWindow->setMask(QRegion(bitmapNormal)); + HMI_DEBUG("HomeScreen","TouchArea switchArea: %d.", areaType); + } else if (areaType == FULLSCREEN) { + HMI_DEBUG("HomeScreen","TouchArea switchArea: %d.", areaType); + myWindow->setMask(QRegion(bitmapFullscreen)); + } +} + + diff --git a/homescreen/src/toucharea.h b/homescreen/src/toucharea.h new file mode 100644 index 0000000..69c6872 --- /dev/null +++ b/homescreen/src/toucharea.h @@ -0,0 +1,30 @@ +#ifndef TOUCHAREA_H +#define TOUCHAREA_H + +#include +#include + +enum { + NORMAL=0, + FULLSCREEN +}; + +class TouchArea : public QObject +{ + Q_OBJECT +public: + explicit TouchArea(); + ~TouchArea(); + + Q_INVOKABLE void switchArea(int areaType); + void setWindow(QQuickWindow* window); + +public slots: + void init(); + +private: + QBitmap bitmapNormal, bitmapFullscreen; + QQuickWindow* myWindow; +}; + +#endif // TOUCHAREA_H -- cgit 1.2.3-korg