From 91ef7469d0ace7c42ce96177b18d5825d941ca9c Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 16 Nov 2016 12:23:10 +0100 Subject: [PATCH] feat(app): add `Notification` component, restore `DesktopPopup` component without notification deps --- tests/resources.qrc | 2 + tests/src/components/notifier/Notifier.cpp | 15 +++---- tests/src/components/notifier/Notifier.hpp | 2 - .../ui/modules/Common/Popup/DesktopPopup.qml | 40 ++--------------- tests/ui/modules/Common/SearchBox.qml | 1 - tests/ui/modules/Common/Styles/PopupStyle.qml | 4 -- .../Notifications/CallNotification.qml | 4 +- .../Linphone/Notifications/Notification.qml | 43 +++++++++++++++++++ .../Linphone/Styles/NotificationStyle.qml | 8 ++++ tests/ui/modules/Linphone/Styles/qmldir | 2 + tests/ui/modules/Linphone/qmldir | 3 -- tests/ui/scripts/Utils/utils.spec.qml | 4 ++ 12 files changed, 69 insertions(+), 59 deletions(-) create mode 100644 tests/ui/modules/Linphone/Notifications/Notification.qml create mode 100644 tests/ui/modules/Linphone/Styles/NotificationStyle.qml diff --git a/tests/resources.qrc b/tests/resources.qrc index d851e1f3e..afb1ca09d 100644 --- a/tests/resources.qrc +++ b/tests/resources.qrc @@ -118,6 +118,7 @@ ui/modules/Linphone/Contact/ContactDescription.qml ui/modules/Linphone/Contact/Contact.qml ui/modules/Linphone/Notifications/CallNotification.qml + ui/modules/Linphone/Notifications/Notification.qml ui/modules/Linphone/Presence/PresenceLevel.qml ui/modules/Linphone/Presence/PresenceString.qml ui/modules/Linphone/qmldir @@ -127,6 +128,7 @@ ui/modules/Linphone/Styles/Contact/AvatarStyle.qml ui/modules/Linphone/Styles/Contact/ContactDescriptionStyle.qml ui/modules/Linphone/Styles/Contact/ContactStyle.qml + ui/modules/Linphone/Styles/NotificationStyle.qml ui/modules/Linphone/Styles/Presence/PresenceStringStyle.qml ui/modules/Linphone/Styles/qmldir ui/modules/Linphone/Styles/TimelineStyle.qml diff --git a/tests/src/components/notifier/Notifier.cpp b/tests/src/components/notifier/Notifier.cpp index 0caccfe3a..df360bb6f 100644 --- a/tests/src/components/notifier/Notifier.cpp +++ b/tests/src/components/notifier/Notifier.cpp @@ -7,14 +7,12 @@ // Notifications QML properties/methods. #define NOTIFICATION_SHOW_METHOD_NAME "show" -#define NOTIFICATION_EDGE_PROPERTY_NAME "edge" -#define NOTIFICATION_HEIGHT_PROPERTY "popupHeight" -#define NOTIFICATION_OFFSET_PROPERTY_NAME "edgeOffset" +#define NOTIFICATION_HEIGHT_PROPERTY "notificationHeight" +#define NOTIFICATION_OFFSET_PROPERTY_NAME "notificationOffset" // Arbitrary hardcoded values. #define NOTIFICATION_SPACING 10 -#define NOTIFICATION_START_OFFSET 30 -#define N_MAX_NOTIFICATIONS 3 +#define N_MAX_NOTIFICATIONS 15 // =================================================================== @@ -47,7 +45,7 @@ bool setProperty (QObject &object, const char *property, const T &value) { // ------------------------------------------------------------------- Notifier::Notifier (QObject *parent) : - QObject(parent), m_offset(NOTIFICATION_START_OFFSET) { + QObject(parent) { QQmlEngine *engine = App::getInstance()->getEngine(); // Build components. @@ -95,7 +93,6 @@ void Notifier::showCallMessage ( if ( offset == -1 || - !::setProperty(*object, NOTIFICATION_EDGE_PROPERTY_NAME, Qt::TopEdge | Qt::RightEdge) || !::setProperty(*object, NOTIFICATION_OFFSET_PROPERTY_NAME, m_offset) ) { delete object; @@ -108,7 +105,7 @@ void Notifier::showCallMessage ( m_mutex.unlock(); - // Display popup. + // Display notification. QMetaObject::invokeMethod(object, "show", Qt::DirectConnection); // Destroy it after timeout. @@ -119,7 +116,7 @@ void Notifier::showCallMessage ( m_n_instances--; if (m_n_instances == 0) - m_offset = NOTIFICATION_START_OFFSET; + m_offset = 0; m_mutex.unlock(); }); diff --git a/tests/src/components/notifier/Notifier.hpp b/tests/src/components/notifier/Notifier.hpp index 25830b9ce..df7a17a6e 100644 --- a/tests/src/components/notifier/Notifier.hpp +++ b/tests/src/components/notifier/Notifier.hpp @@ -24,8 +24,6 @@ public slots: void showCallMessage (int timeout, const QString &sip_address); private: - void computePositions (); - QQmlComponent *m_components[MaxNbTypes]; int m_offset = 0; diff --git a/tests/ui/modules/Common/Popup/DesktopPopup.qml b/tests/ui/modules/Common/Popup/DesktopPopup.qml index a2e06036d..21031f9d1 100644 --- a/tests/ui/modules/Common/Popup/DesktopPopup.qml +++ b/tests/ui/modules/Common/Popup/DesktopPopup.qml @@ -8,13 +8,10 @@ import Common.Styles 1.0 Item { id: wrapper - property int popupX: 0 - property int popupY: 0 + property alias popupX: popup.x + property alias popupY: popup.y - property int edge: 0 - property int edgeOffset: 0 - - property int flags: Qt.Popup + property int flags: Qt.SplashScreen readonly property alias popupWidth: popup.width readonly property alias popupHeight: popup.height @@ -30,34 +27,6 @@ Item { _isOpen = false } - function _applyXEdge () { - var screen = popup.Screen - - if (screen == null) { - return popupX - } - - if (edge & Qt.LeftEdge) { - return PopupStyle.desktop.edgeMargin - } - - return screen.width - popup.width - PopupStyle.desktop.edgeMargin - } - - function _applyYEdge () { - var screen = popup.Screen - - if (screen == null) { - return popupY - } - - if (edge & Qt.TopEdge) { - return edgeOffset + PopupStyle.desktop.edgeMargin - } - - return screen.height - popup.height - edgeOffset - PopupStyle.desktop.edgeMargin - } - // ----------------------------------------------------------------- // DO NOT TOUCH THIS PROPERTIES. @@ -79,9 +48,6 @@ Item { height: _content[0] != null ? _content[0].height : 0 width: _content[0] != null ? _content[0].width : 0 - x: edge ? _applyXEdge() : popupX - y: edge ? _applyYEdge() : popupY - Item { id: content diff --git a/tests/ui/modules/Common/SearchBox.qml b/tests/ui/modules/Common/SearchBox.qml index 330226948..54778523a 100644 --- a/tests/ui/modules/Common/SearchBox.qml +++ b/tests/ui/modules/Common/SearchBox.qml @@ -90,7 +90,6 @@ 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 c7b8e32d4..6a8d7b0e0 100644 --- a/tests/ui/modules/Common/Styles/PopupStyle.qml +++ b/tests/ui/modules/Common/Styles/PopupStyle.qml @@ -13,10 +13,6 @@ 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 4cba8cecd..c9a4ef3e0 100644 --- a/tests/ui/modules/Linphone/Notifications/CallNotification.qml +++ b/tests/ui/modules/Linphone/Notifications/CallNotification.qml @@ -1,8 +1,6 @@ import QtQuick 2.7 -import Common 1.0 - -DesktopPopup { +Notification { Rectangle { color: 'red' diff --git a/tests/ui/modules/Linphone/Notifications/Notification.qml b/tests/ui/modules/Linphone/Notifications/Notification.qml new file mode 100644 index 000000000..a0de0c015 --- /dev/null +++ b/tests/ui/modules/Linphone/Notifications/Notification.qml @@ -0,0 +1,43 @@ +import QtQuick 2.7 + +// Warning: This import is necessary to use the attached property `Screen`. +// See: https://doc-snapshots.qt.io/qt5-5.7/qml-qtquick-window-screen.html +import QtQuick.Window 2.2 + +import Common 1.0 +import Linphone.Styles 1.0 +import Utils 1.0 + +// =================================================================== + +DesktopPopup { + id: notification + + property int notificationOffset: 0 + property alias notificationHeight: notification.popupHeight + + flags: Qt.Popup + + Component.onCompleted: { + var window = data[0] + + Utils.assert( + Utils.qmlTypeof(window, 'QQuickWindowQmlImpl'), true, + 'Unable to found `Window` object in `DesktopPopup`.' + ) + + window.x = Qt.binding(function () { + var screen = window.Screen + return screen != null + ? screen.width - window.width - NotificationStyle.margin + : 0 + }) + + window.y = Qt.binding(function () { + var screen = window.Screen + return screen != null + ? screen.desktopAvailableHeight - window.height - notificationOffset + : 0 + }) + } +} diff --git a/tests/ui/modules/Linphone/Styles/NotificationStyle.qml b/tests/ui/modules/Linphone/Styles/NotificationStyle.qml new file mode 100644 index 000000000..847d0370d --- /dev/null +++ b/tests/ui/modules/Linphone/Styles/NotificationStyle.qml @@ -0,0 +1,8 @@ +pragma Singleton +import QtQuick 2.7 + +// =================================================================== + +QtObject { + property int margin: 10 +} diff --git a/tests/ui/modules/Linphone/Styles/qmldir b/tests/ui/modules/Linphone/Styles/qmldir index de0bb8764..6a261c06b 100644 --- a/tests/ui/modules/Linphone/Styles/qmldir +++ b/tests/ui/modules/Linphone/Styles/qmldir @@ -12,6 +12,8 @@ singleton AvatarStyle 1.0 Contact/AvatarStyle.qml singleton ContactDescriptionStyle 1.0 Contact/ContactDescriptionStyle.qml singleton ContactStyle 1.0 Contact/ContactStyle.qml +singleton NotificationStyle 1.0 NotificationStyle.qml + singleton PresenceStringStyle 1.0 Presence/PresenceStringStyle.qml singleton TimelineStyle 1.0 TimelineStyle.qml diff --git a/tests/ui/modules/Linphone/qmldir b/tests/ui/modules/Linphone/qmldir index b75b3aa1c..84540b032 100644 --- a/tests/ui/modules/Linphone/qmldir +++ b/tests/ui/modules/Linphone/qmldir @@ -20,9 +20,6 @@ Avatar 1.0 Contact/Avatar.qml Contact 1.0 Contact/Contact.qml ContactDescription 1.0 Contact/ContactDescription.qml -# Notifications -CallNotification 1.0 Notifications/CallNotification.qml - # Presence PresenceLevel 1.0 Presence/PresenceLevel.qml PresenceString 1.0 Presence/PresenceString.qml diff --git a/tests/ui/scripts/Utils/utils.spec.qml b/tests/ui/scripts/Utils/utils.spec.qml index 2714a3ce6..624bf8a79 100644 --- a/tests/ui/scripts/Utils/utils.spec.qml +++ b/tests/ui/scripts/Utils/utils.spec.qml @@ -78,6 +78,10 @@ TestCase { component: 'import QtQuick 2.7; MouseArea {}', result: true, type: 'QQuickMouseArea' + }, { + component: 'import QtQuick 2.7; import QtQuick.Window 2.2; Window {}', + result: true, + type: 'QQuickWindowQmlImpl' } ] }