From 12159a44f266ebaa76d72e3263a0f151f09a027e Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Fri, 15 Feb 2019 16:00:56 +0900 Subject: add sizeChange signal --- src/aglextras/hmi/aglapplication.cpp | 2 ++ src/aglextras/hmi/aglapplication.h | 17 ++++++++++++++++- src/aglextras/hmi/aglwmclient.cpp | 34 +++++++++++++++++++++++++++++----- src/aglextras/hmi/aglwmclient.h | 5 +++++ src/aglextras/hmi/aglwmclient_p.h | 2 ++ 5 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/aglextras/hmi/aglapplication.cpp b/src/aglextras/hmi/aglapplication.cpp index 320aa17..c2204d5 100644 --- a/src/aglextras/hmi/aglapplication.cpp +++ b/src/aglextras/hmi/aglapplication.cpp @@ -110,6 +110,8 @@ void AGLApplication::setupApplicationRole (const QString &role) d_ptr->screen_info = new AGLScreenInfo(this, d_ptr->wmclient->get_scale_factor()); d_ptr->engine->rootContext()->setContextProperty(QStringLiteral("screenInfo"), d_ptr->screen_info); + QObject::connect(d_ptr->wmclient, SIGNAL(sizeChanged(int, int)), + d_ptr->screen_info, SLOT(setSize(int, int))); } QT_END_NAMESPACE diff --git a/src/aglextras/hmi/aglapplication.h b/src/aglextras/hmi/aglapplication.h index f9d17a0..3356b1f 100644 --- a/src/aglextras/hmi/aglapplication.h +++ b/src/aglextras/hmi/aglapplication.h @@ -49,12 +49,27 @@ class AGLScreenInfo : public QObject Q_OBJECT public: - AGLScreenInfo(QObject* parent = 0, double scale = 1.0) : QObject(parent), _scale_factor(scale) {}; + // AGLScreenInfo(QObject* parent = 0, double scale = 1.0) : QObject(parent), _scale_factor(scale) {}; + AGLScreenInfo(QObject* parent = 0, double scale = 1.0, int width = 1080, int height = 1488): + QObject(parent), + _scale_factor(scale), + _width(width), + _height(height) {}; Q_INVOKABLE double scale_factor() const { return _scale_factor; }; + Q_INVOKABLE double width() const { return _width; }; + Q_INVOKABLE double height() const { return _height; }; + +signals: + void sizeChanged(); + +public slots: + void setSize(int width, int height){ _width = width; _height = height; emit sizeChanged(); }; private: double _scale_factor; + int _width; + int _height; }; QT_END_NAMESPACE diff --git a/src/aglextras/hmi/aglwmclient.cpp b/src/aglextras/hmi/aglwmclient.cpp index 59518a3..32734a0 100644 --- a/src/aglextras/hmi/aglwmclient.cpp +++ b/src/aglextras/hmi/aglwmclient.cpp @@ -68,6 +68,16 @@ double AGLWmClient::get_scale_factor (void) return d_ptr->scale_factor; } +int AGLWmClient::get_width (void) +{ + return d_ptr->width; +} + +int AGLWmClient::get_height (void) +{ + return d_ptr->height; +} + #ifdef USE_AGL_HMI_LOWLEVEL_API void AGLWmClient::attach (QQmlApplicationEngine* engine) { @@ -141,12 +151,27 @@ AGLWmClient::AGLWmClient (const QString&, int port, QString) setenv("QT_IVI_SURFACE_ID", ivi_id.c_str(), true); } - // Create an event callback against an event type. Here a lambda is called when SyncDraw event occurs w_ptr->set_event_handler ( LibWindowmanager::Event_SyncDraw, - [this](json_object*) { - qDebug("Surface got syncDraw!\n"); + // [this](json_object*) { + [this](json_object* object) { + json_object *j_rect, *j_val; + int width, height; + json_object_object_get_ex(object, w_ptr->kKeyDrawingRect, &j_rect); + json_object_object_get_ex(j_rect, "width", &j_val); + width = json_object_get_int(j_val); + json_object_object_get_ex(j_rect, "height", &j_val); + height = json_object_get_int(j_val); + + fprintf(stderr, "Surface got syncDraw Size(%d, %d)!\n", width, height); + if (width != d_ptr->width || height != d_ptr->height){ + d_ptr->width = width; + d_ptr->height = height; + emit sizeChanged(width, height); + } + + // Application should call LibWindowmanager::endDraw() in SyncDraw handler json_object *obj = json_object_new_object(); std::string target = QString(d_ptr->layout).toStdString(); json_object_object_add(obj, w_ptr->kKeyDrawingName, json_object_new_string(target.c_str())); @@ -158,14 +183,13 @@ AGLWmClient::AGLWmClient (const QString&, int port, QString) h_ptr->set_event_handler ( LibHomeScreen::Event_TapShortcut, [this](json_object* object) { - qDebug("Surface got tapShortcut\n"); struct json_object *obj_param = nullptr, *obj_area = nullptr; if(json_object_object_get_ex(object, "parameter", &obj_param) && json_object_object_get_ex(obj_param, "area", &obj_area)) { w_ptr->activateWindow(d_ptr->layout.toStdString().c_str(), json_object_get_string(obj_area)); } else { - w_ptr->activateWindow(d_ptr->layout.toStdString().c_str(), "normal"); + w_ptr->activateWindow(d_ptr->layout.toStdString().c_str(), "normal.full"); } } ); diff --git a/src/aglextras/hmi/aglwmclient.h b/src/aglextras/hmi/aglwmclient.h index ccfc86e..a9bc643 100644 --- a/src/aglextras/hmi/aglwmclient.h +++ b/src/aglextras/hmi/aglwmclient.h @@ -34,6 +34,11 @@ public: AGLWmClient (const QString& layout, int port, QString secret); void attach (QQmlApplicationEngine* engine); double get_scale_factor (void); + int get_width (void); + int get_height (void); + +signals: + void sizeChanged(int width, int height); private Q_SLOTS: void disconnect_frame_swapped (void); diff --git a/src/aglextras/hmi/aglwmclient_p.h b/src/aglextras/hmi/aglwmclient_p.h index ff5cd1f..2dfdc54 100644 --- a/src/aglextras/hmi/aglwmclient_p.h +++ b/src/aglextras/hmi/aglwmclient_p.h @@ -30,6 +30,8 @@ class AGLWmClientPrivate QMetaObject::Connection loading; bool binding = false; double scale_factor = 1.0; + int width = 1080; + int height = 1488; friend class AGLWmClient; }; QT_END_NAMESPACE -- cgit 1.2.3-korg