Add feature : changeAreaSize
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>
Fri, 30 Nov 2018 10:20:22 +0000 (19:20 +0900)
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>
Fri, 30 Nov 2018 10:20:22 +0000 (19:20 +0900)
homescreen/homescreen.pro
homescreen/qml/images/images.qrc
homescreen/qml/images/menubar_full_background.png
homescreen/qml/images/menubar_normal_background.png
homescreen/qml/images/split_switch.png [new file with mode: 0644]
homescreen/qml/images/split_switch_disable.png [new file with mode: 0644]
homescreen/qml/main.qml
homescreen/src/homescreenhandler.cpp
homescreen/src/homescreenhandler.h
homescreen/src/main.cpp

index e0a038e..e3f1e27 100644 (file)
@@ -18,9 +18,9 @@ TARGET = HomeScreen
 QT = qml quick dbus websockets
 CONFIG += c++11 link_pkgconfig
 DESTDIR = $${OUT_PWD}/../package/root/bin
-PKGCONFIG += qlibwindowmanager qtappfw
+PKGCONFIG += libwindowmanager qtappfw
 
-LIBS += -lhomescreen
+LIBS += -lhomescreen -lwindowmanager
 
 include(../interfaces/interfaces.pri)
 
index e72f697..0715215 100644 (file)
@@ -5,5 +5,7 @@
         <file>menubar_full_background.png</file>
         <file>fullscreen.png</file>
         <file>normal.png</file>
+        <file>split_switch.png</file>
+        <file>split_switch_disable.png</file>
     </qresource>
 </RCC>
index 16a7e77..6db3a9e 100644 (file)
Binary files a/homescreen/qml/images/menubar_full_background.png and b/homescreen/qml/images/menubar_full_background.png differ
index bfffc55..dadafcf 100644 (file)
Binary files a/homescreen/qml/images/menubar_normal_background.png and b/homescreen/qml/images/menubar_normal_background.png differ
diff --git a/homescreen/qml/images/split_switch.png b/homescreen/qml/images/split_switch.png
new file mode 100644 (file)
index 0000000..751b2fa
Binary files /dev/null and b/homescreen/qml/images/split_switch.png differ
diff --git a/homescreen/qml/images/split_switch_disable.png b/homescreen/qml/images/split_switch_disable.png
new file mode 100644 (file)
index 0000000..c4bfa67
Binary files /dev/null and b/homescreen/qml/images/split_switch_disable.png differ
index 10509fd..f523339 100644 (file)
@@ -128,25 +128,20 @@ Window {
         }
     }
 
-
-
-
-
     Item {
         id: switchBtn
-        width: 110
-        height: 110
+        width: 61
+        height: 61
         anchors.right: parent.right
+        anchors.rightMargin: 17
         anchors.top: parent.top
+        anchors.topMargin: 2
         z: 1
         Image {
             id: image
             width: 55
             height: 55
-            anchors.right: parent.right
-            anchors.rightMargin: 20
-            anchors.top: parent.top
-            anchors.topMargin: 5
+            anchors.centerIn: parent
             source: './images/normal.png'
         }
 
@@ -162,16 +157,68 @@ Window {
             }
         }
     }
+
+    Item {
+        id: splitSwitchBtn
+        width: 61
+        height: 61
+        anchors.right: switchBtn.left
+        anchors.top: parent.top
+        anchors.topMargin: 2
+        z: 1
+        property bool enableSplitSwitchBtn: false
+        Image {
+            id: splitSwitchImage
+            width: 55
+            height: 55
+            anchors.centerIn: parent
+            source: './images/split_switch_disable.png'
+        }
+
+        MouseArea {
+            property bool changed : false
+            anchors.fill: parent
+            onClicked: {
+                if (splitSwitchBtn.enableSplitSwitchBtn) {
+                    if(changed) {
+                        switchSplitArea(0)
+                        changed = false
+                    }
+                    else {
+                        switchSplitArea(1)
+                        changed = true
+                    }
+                }
+            }
+        }
+    }
+
+
     function turnToFullscreen() {
         image.source = './images/fullscreen.png'
         container.state = 'fullscreen'
         container.opacity = 0.0
         touchArea.switchArea(1)
     }
+
     function turnToNormal() {
         image.source = './images/normal.png'
         container.state = 'normal'
         container.opacity = 1.0
         touchArea.switchArea(0)
     }
+
+    function enableSplitSwitchBtn() {
+        splitSwitchImage.source = './images/split_switch.png'
+        splitSwitchBtn.enableSplitSwitchBtn = true
+    }
+
+    function disableSplitSwitchBtn() {
+        splitSwitchImage.source = './images/split_switch_disable.png'
+        splitSwitchBtn.enableSplitSwitchBtn = false;
+    }
+
+    function switchSplitArea(val) {
+        homescreenHandler.changeLayout(val);
+    }
 }
index a655a5e..9125ecf 100644 (file)
 
 #include "homescreenhandler.h"
 #include <functional>
+#include <QQmlApplicationEngine>
+#include <QtQuick/QQuickWindow>
 #include "hmi-debug.h"
 
 void* HomescreenHandler::myThis = 0;
 
 HomescreenHandler::HomescreenHandler(QObject *parent) :
     QObject(parent),
-    mp_hs(NULL)
+    mp_hs(NULL), mp_wm(NULL), m_role()
 {
 
 }
@@ -32,10 +34,29 @@ HomescreenHandler::~HomescreenHandler()
     if (mp_hs != NULL) {
         delete mp_hs;
     }
+    if (mp_wm != NULL) {
+        delete mp_wm;
+    }
 }
 
-void HomescreenHandler::init(int port, const char *token)
+void HomescreenHandler::init(const char* role, int port, const char *token)
 {
+    this->m_role = role;
+
+    // LibWindowManager initialize
+    mp_wm = new LibWindowmanager();
+    if(mp_wm->init(port,token) != 0){
+        exit(EXIT_FAILURE);
+    }
+
+    int surface = mp_wm->requestSurface(m_role.c_str());
+    if (surface < 0) {
+        exit(EXIT_FAILURE);
+    }
+    std::string ivi_id = std::to_string(surface);
+    setenv("QT_IVI_SURFACE_ID", ivi_id.c_str(), true);
+
+    // LibHomeScreen initialize
     mp_hs = new LibHomeScreen();
     mp_hs->init(port, token);
 
@@ -50,6 +71,52 @@ void HomescreenHandler::init(int port, const char *token)
     });
 }
 
+void HomescreenHandler::setWMHandler(WMHandler& h) {
+    h.on_sync_draw = [&](const char* role, const char* area, Rect r) {
+        this->mp_wm->endDraw(this->m_role.c_str());
+    };
+    mp_wm->setEventHandler(h);
+}
+
+void HomescreenHandler::disconnect_frame_swapped(void)
+{
+    qDebug("Let's start homescreen");
+    QObject::disconnect(this->loading);
+    mp_wm->activateWindow(m_role.c_str(), "fullscreen");
+}
+
+void HomescreenHandler::attach(QQmlApplicationEngine* engine)
+{
+    QQuickWindow *window = qobject_cast<QQuickWindow *>(engine->rootObjects().first());
+    this->loading = QObject::connect(window, SIGNAL(frameSwapped()), this, SLOT(disconnect_frame_swapped()));
+}
+
+void HomescreenHandler::changeLayout(int pattern)
+{
+    HMI_NOTICE("HomeScreen", "Pressed %d, %s", pattern,
+        (pattern == P_LEFT_METER_RIGHT_MAP) ? "left:meter, right:map": "left:map, right:meter");
+    ChangeAreaReq req;
+    std::unordered_map<std::string, Rect> map_list;
+    switch(pattern) {
+        case P_LEFT_METER_RIGHT_MAP:
+            map_list["split.main"] = Rect(0, 0, 1280, 720);
+            map_list["split.sub"] = Rect(1280, 0, 640, 720);
+            break;
+        case P_LEFT_MAP_RIGHT_METER:
+            map_list["split.main"] = Rect(640, 0, 1280, 720);
+            map_list["split.sub"] = Rect(0, 0, 640, 720);
+            break;
+        default:
+            break;
+    }
+    if(map_list.size() != 0)
+    {
+        req.setAreaReq(map_list);
+        HMI_NOTICE("Homescreen", "Change layout");
+        mp_wm->changeAreaSize(req);
+    }
+}
+
 void HomescreenHandler::tapShortcut(QString application_name)
 {
     HMI_DEBUG("HomeScreen","tapShortcut %s", application_name.toStdString().c_str());
index 99367d5..c32e6cc 100644 (file)
 
 #include <QObject>
 #include <libhomescreen.hpp>
+#include <libwindowmanager.h>
 #include <string>
 
 using namespace std;
 
+class QQmlApplicationEngine;
+
 class HomescreenHandler : public QObject
 {
     Q_OBJECT
 public:
+    enum CHANGE_LAYOUT_PATTERN {
+        P_LEFT_METER_RIGHT_MAP = 0,
+        P_LEFT_MAP_RIGHT_METER
+    };
+    Q_ENUMS(CHANGE_LAYOUT_PATTERN)
     explicit HomescreenHandler(QObject *parent = 0);
     ~HomescreenHandler();
 
-    void init(int port, const char* token);
+    void init(const char* role, int port, const char* token);
+    void attach(QQmlApplicationEngine* engine);
+    void setWMHandler(WMHandler &handler);
 
     Q_INVOKABLE void tapShortcut(QString application_name);
+    Q_INVOKABLE void changeLayout(int pattern);
 
     void onRep(struct json_object* reply_contents);
     void onEv(const string& event, struct json_object* event_contents);
@@ -45,8 +56,14 @@ signals:
     void notification(QString id, QString icon, QString text);
     void information(QString text);
 
+private Q_SLOTS:
+    void disconnect_frame_swapped(void);
+
 private:
     LibHomeScreen *mp_hs;
+    LibWindowmanager *mp_wm;
+    std::string m_role;
+    QMetaObject::Connection loading;
 };
 
 #endif // HOMESCREENHANDLER_H
index 08f83a8..6479cd9 100644 (file)
@@ -24,7 +24,6 @@
 #include <QQuickWindow>
 #include <QThread>
 
-#include <qlibwindowmanager.h>
 #include <weather.h>
 #include <bluetooth.h>
 #include "applicationlauncher.h"
@@ -57,6 +56,7 @@ void noOutput(QtMsgType, const QMessageLogContext &, const QString &)
 int main(int argc, char *argv[])
 {
     QGuiApplication a(argc, argv);
+    const char* graphic_role = "homescreen";
 
     // use launch process
     QScopedPointer<org::AGL::afm::user, Cleanup> afm_user_daemon_proxy(new org::AGL::afm::user("org.AGL.afm.user",
@@ -94,16 +94,7 @@ int main(int argc, char *argv[])
 
     ApplicationLauncher *launcher = new ApplicationLauncher();
     HomescreenHandler* homescreenHandler = new HomescreenHandler();
-    homescreenHandler->init(port, token.toStdString().c_str());
-
-    QLibWindowmanager* layoutHandler = new QLibWindowmanager();
-    if(layoutHandler->init(port,token) != 0){
-        exit(EXIT_FAILURE);
-    }
-
-    if (layoutHandler->requestSurface(QString("homescreen")) != 0) {
-        exit(EXIT_FAILURE);
-    }
+    homescreenHandler->init(graphic_role, port, token.toStdString().c_str());
 
     QUrl bindingAddress;
     bindingAddress.setScheme(QStringLiteral("ws"));
@@ -119,7 +110,6 @@ int main(int argc, char *argv[])
 
     // mail.qml loading
     QQmlApplicationEngine engine;
-//    engine.rootContext()->setContextProperty("layoutHandler", layoutHandler);
     engine.rootContext()->setContextProperty("homescreenHandler", homescreenHandler);
     engine.rootContext()->setContextProperty("touchArea", touchArea);
     engine.rootContext()->setContextProperty("launcher", launcher);
@@ -129,27 +119,32 @@ int main(int argc, char *argv[])
 
     QObject *root = engine.rootObjects().first();
 
-    layoutHandler->set_event_handler(QLibWindowmanager::Event_SyncDraw, [layoutHandler](json_object *object) {
-        layoutHandler->endDraw(QString("homescreen"));
-    });
-
-    layoutHandler->set_event_handler(QLibWindowmanager::Event_ScreenUpdated, [layoutHandler, launcher, root](json_object *object) {
-        json_object *jarray = json_object_object_get(object, "ids");
-        int arrLen = json_object_array_length(jarray);
+    WMHandler wmh;
+    wmh.on_screen_updated = [launcher, root](std::vector<std::string> list) {
+        for(const auto& i : list) {
+            HMI_DEBUG("HomeScreen", "ids=%s", i.c_str());
+        }
+        int arrLen = list.size();
+        QString label = QString("");
         for( int idx = 0; idx < arrLen; idx++)
         {
-            QString label = QString(json_object_get_string(    json_object_array_get_idx(jarray, idx) ));
+            label = list[idx].c_str();
             HMI_DEBUG("HomeScreen","Event_ScreenUpdated application: %s.", label.toStdString().c_str());
             QMetaObject::invokeMethod(launcher, "setCurrent", Qt::QueuedConnection, Q_ARG(QString, label));
             if(label == "launcher") {
                 QMetaObject::invokeMethod(root, "turnToNormal");
-//                homescreenHandler->emitTurnToFullscreen(false);
             } else {
                 QMetaObject::invokeMethod(root, "turnToFullscreen");
-//                homescreenHandler->emitTurnToFullscreen(true);
+            }
+            if((arrLen == 1) && (QString("restriction") != label)) {
+                QMetaObject::invokeMethod(root, "disableSplitSwitchBtn");
+            } else {
+                QMetaObject::invokeMethod(root, "enableSplitSwitchBtn");
             }
         }
-    });
+    };
+    homescreenHandler->setWMHandler(wmh);
+    homescreenHandler->attach(&engine);
 
     QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
 
@@ -164,7 +159,5 @@ int main(int argc, char *argv[])
     StatusBarModel *statusBar = sobjs.first()->findChild<StatusBarModel *>("statusBar");
     statusBar->init(bindingAddress, engine.rootContext());
 
-    QObject::connect(window, SIGNAL(frameSwapped()), layoutHandler, SLOT(slotActivateSurface()));
-
     return a.exec();
 }