From cf6eecbdb503c165d94e405409ef14af083cda35 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 15 Nov 2016 17:49:14 +0100 Subject: [PATCH] unstable --- tests/src/app/App.cpp | 4 +- .../components/notification/Notification.cpp | 70 ++++++++++++------- .../components/notification/Notification.hpp | 1 + .../ui/modules/Common/Popup/DesktopPopup.qml | 17 +++-- tests/ui/modules/Common/SearchBox.qml | 1 + tests/ui/modules/Common/Styles/PopupStyle.qml | 4 ++ .../Notifications/CallNotification.qml | 1 + tests/ui/views/App/MainWindow/Contacts.qml | 2 +- 8 files changed, 63 insertions(+), 37 deletions(-) diff --git a/tests/src/app/App.cpp b/tests/src/app/App.cpp index e44353a4a..d527d4013 100644 --- a/tests/src/app/App.cpp +++ b/tests/src/app/App.cpp @@ -148,8 +148,8 @@ void App::setNotificationAttributes () { QRect icon_rect = m_system_tray_icon->geometry(); QRect screen_rect = desktop->screenGeometry(); - int x = icon_rect.x() + icon_rect.width() / 2; - int y = icon_rect.y() + icon_rect.height() / 2; + int x = icon_rect.x() / 2 + icon_rect.width() / 2; + int y = icon_rect.y() / 2 + icon_rect.height() / 2; Qt::Edges edge = (x < screen_rect.width() / 2) ? Qt::LeftEdge : Qt::RightEdge; edge |= (y < screen_rect.height() / 2) ? Qt::TopEdge : Qt::BottomEdge; diff --git a/tests/src/components/notification/Notification.cpp b/tests/src/components/notification/Notification.cpp index 87cdd065c..a9a23161f 100644 --- a/tests/src/components/notification/Notification.cpp +++ b/tests/src/components/notification/Notification.cpp @@ -8,12 +8,42 @@ #define NOTIFICATION_EDGE_PROPERTY_NAME "edge" #define NOTIFICATION_HEIGHT_PROPERTY "popupHeight" -#define NOTIFICATION_WIDTH_PROPERTY "popupWidth" +#define NOTIFICATION_OFFSET_PROPERTY_NAME "edgeOffset" + +#define NOTIFICATION_SPACING 10 #define N_MAX_NOTIFICATIONS 3 // =================================================================== +// Helpers. +inline int getNotificationSize (const QObject &object, const char *property) { + QVariant variant = object.property(property); + bool so_far_so_good; + + int size = variant.toInt(&so_far_so_good); + if (!so_far_so_good || size < 0) { + qWarning() << "Unable to get notification size."; + return -1; + } + + return size; +} + +template +bool setProperty (QObject &object, const char *property, const T &value) { + QVariant qvariant(value); + + if (!object.setProperty(property, qvariant)) { + qWarning() << "Unable to set property `" << property << "`."; + return false; + } + + return true; +} + +// ------------------------------------------------------------------- + Notification::Notification (QObject *parent) : QObject(parent) { QQmlEngine *engine = App::getInstance()->getEngine(); @@ -41,30 +71,6 @@ Notification::~Notification () { // ------------------------------------------------------------------- -inline int getNotificationSize (const QObject &object, const char *size_property) { - QVariant variant = object.property(size_property); - bool so_far_so_good; - - int size = variant.toInt(&so_far_so_good); - if (!so_far_so_good || size < 0) { - qWarning() << "Unable to get notification size."; - return -1; - } - - return size; -} - -inline bool setNotificationEdge (QObject &object, int value) { - QVariant edge(value); - - if (!object.setProperty("edge", edge)) { - qWarning() << "Unable to set notification edge."; - return false; - } - - return true; -} - void Notification::showCallMessage ( int timeout, const QString &sip_address @@ -75,7 +81,7 @@ void Notification::showCallMessage ( m_mutex.lock(); // Check existing instances. - if (m_n_instances + 1 >= N_MAX_NOTIFICATIONS) { + if (m_n_instances >= N_MAX_NOTIFICATIONS) { qWarning() << "Unable to create another notification"; m_mutex.unlock(); return; @@ -83,13 +89,19 @@ void Notification::showCallMessage ( // Create instance and set attributes. QObject *object = m_components[Notification::Call]->create(); + int offset = getNotificationSize(*object, NOTIFICATION_HEIGHT_PROPERTY); - if (!setNotificationEdge(*object, m_edge)) { + if ( + offset == -1 || + !::setProperty(*object, NOTIFICATION_EDGE_PROPERTY_NAME, m_edge) || + !::setProperty(*object, NOTIFICATION_OFFSET_PROPERTY_NAME, m_offset) + ) { delete object; m_mutex.unlock(); return; } + m_offset = (m_n_instances == 0 ? offset : offset + m_offset) + NOTIFICATION_SPACING; m_n_instances++; m_mutex.unlock(); @@ -103,6 +115,10 @@ void Notification::showCallMessage ( m_mutex.lock(); m_n_instances--; + + if (m_n_instances == 0) + m_offset = 0; + m_mutex.unlock(); }); } diff --git a/tests/src/components/notification/Notification.hpp b/tests/src/components/notification/Notification.hpp index 0333b8dfd..104e5cfd0 100644 --- a/tests/src/components/notification/Notification.hpp +++ b/tests/src/components/notification/Notification.hpp @@ -31,6 +31,7 @@ private: Qt::Edges m_edge = Qt::RightEdge | Qt::TopEdge; QQmlComponent *m_components[MaxNbTypes]; + int m_offset = 0; int m_n_instances = 0; QMutex m_mutex; }; diff --git a/tests/ui/modules/Common/Popup/DesktopPopup.qml b/tests/ui/modules/Common/Popup/DesktopPopup.qml index 87b160cf2..a2e06036d 100644 --- a/tests/ui/modules/Common/Popup/DesktopPopup.qml +++ b/tests/ui/modules/Common/Popup/DesktopPopup.qml @@ -12,6 +12,9 @@ Item { property int popupY: 0 property int edge: 0 + property int edgeOffset: 0 + + property int flags: Qt.Popup readonly property alias popupWidth: popup.width readonly property alias popupHeight: popup.height @@ -27,7 +30,7 @@ Item { _isOpen = false } - function _applyXEdge (edge) { + function _applyXEdge () { var screen = popup.Screen if (screen == null) { @@ -35,13 +38,13 @@ Item { } if (edge & Qt.LeftEdge) { - return 0 + return PopupStyle.desktop.edgeMargin } - return screen.width - popup.width + return screen.width - popup.width - PopupStyle.desktop.edgeMargin } - function _applyYEdge (edge) { + function _applyYEdge () { var screen = popup.Screen if (screen == null) { @@ -49,10 +52,10 @@ Item { } if (edge & Qt.TopEdge) { - return 0 + return edgeOffset + PopupStyle.desktop.edgeMargin } - return screen.height - popup.height + return screen.height - popup.height - edgeOffset - PopupStyle.desktop.edgeMargin } // ----------------------------------------------------------------- @@ -71,7 +74,7 @@ Item { Window { id: popup - flags: Qt.SplashScreen + flags: wrapper.flags opacity: 0 height: _content[0] != null ? _content[0].height : 0 width: _content[0] != null ? _content[0].width : 0 diff --git a/tests/ui/modules/Common/SearchBox.qml b/tests/ui/modules/Common/SearchBox.qml index 54778523a..330226948 100644 --- a/tests/ui/modules/Common/SearchBox.qml +++ b/tests/ui/modules/Common/SearchBox.qml @@ -90,6 +90,7 @@ Item { return point } + flags: Qt.SplashScreen popupX: coords.x popupY: coords.y diff --git a/tests/ui/modules/Common/Styles/PopupStyle.qml b/tests/ui/modules/Common/Styles/PopupStyle.qml index 6a8d7b0e0..c7b8e32d4 100644 --- a/tests/ui/modules/Common/Styles/PopupStyle.qml +++ b/tests/ui/modules/Common/Styles/PopupStyle.qml @@ -13,6 +13,10 @@ QtObject { property int closingDuration: 250 } + property QtObject desktop: QtObject { + property int edgeMargin: 10 + } + property QtObject shadow: QtObject { property color color: Colors.l property int horizontalOffset: 4 diff --git a/tests/ui/modules/Linphone/Notifications/CallNotification.qml b/tests/ui/modules/Linphone/Notifications/CallNotification.qml index 6f6ed17bd..4cba8cecd 100644 --- a/tests/ui/modules/Linphone/Notifications/CallNotification.qml +++ b/tests/ui/modules/Linphone/Notifications/CallNotification.qml @@ -5,6 +5,7 @@ import Common 1.0 DesktopPopup { Rectangle { color: 'red' + width: 200 height: 100 } diff --git a/tests/ui/views/App/MainWindow/Contacts.qml b/tests/ui/views/App/MainWindow/Contacts.qml index 9903fb301..13598c324 100644 --- a/tests/ui/views/App/MainWindow/Contacts.qml +++ b/tests/ui/views/App/MainWindow/Contacts.qml @@ -36,7 +36,7 @@ ColumnLayout { }) } - spacing: Notification.showCallMessage(10000, "toto@toto.com") || 0 + spacing: Notification.showCallMessage(5000, "toto@toto.com") || 0 // ----------------------------------------------------------------- // Search Bar & actions.