From c1e6d7d25f8682a6fd491693674ddcc736c0d979 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 15 Nov 2016 15:54:02 +0100 Subject: [PATCH] unstable --- tests/src/app/App.cpp | 33 +++++++-------- .../components/notification/Notification.cpp | 41 ++++--------------- .../components/notification/Notification.hpp | 6 --- .../ui/modules/Common/Popup/DesktopPopup.qml | 39 +++++++++++++++++- 4 files changed, 59 insertions(+), 60 deletions(-) diff --git a/tests/src/app/App.cpp b/tests/src/app/App.cpp index 18e8df2d0..e44353a4a 100644 --- a/tests/src/app/App.cpp +++ b/tests/src/app/App.cpp @@ -139,25 +139,20 @@ void App::setTrayIcon () { } void App::setNotificationAttributes () { - QDesktopWidget *desktop = QApplication::desktop(); - - // The primary screen is the default given by Qt or the screen of - // system tray icon. - int primary_screen = desktop->primaryScreen(); - if (m_system_tray_icon) { - // primary_screen = QDesktopWidget::screenNumber(m_system_tray_icon); - - QRect icon_rect = m_system_tray_icon->geometry(); - QRect screen_rect = desktop->screenGeometry(primary_screen); - - int x = icon_rect.x() + icon_rect.width() / 2; - int y = icon_rect.y() + 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; - - m_notification->setEdge(edge); + if (!m_system_tray_icon) { + return; } - m_notification->setScreenNumber(primary_screen); + QDesktopWidget *desktop = QApplication::desktop(); + + 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; + + Qt::Edges edge = (x < screen_rect.width() / 2) ? Qt::LeftEdge : Qt::RightEdge; + edge |= (y < screen_rect.height() / 2) ? Qt::TopEdge : Qt::BottomEdge; + + m_notification->setEdge(edge); } diff --git a/tests/src/components/notification/Notification.cpp b/tests/src/components/notification/Notification.cpp index 27b74299f..c286fe453 100644 --- a/tests/src/components/notification/Notification.cpp +++ b/tests/src/components/notification/Notification.cpp @@ -1,18 +1,15 @@ -#include #include #include #include "../../app/App.hpp" #include "Notification.hpp" -#define NOTIFICATION_X_PROPERTY "popupX" -#define NOTIFICATION_Y_PROPERTY "popupY" +#define NOTIFICATION_SHOW_METHOD_NAME "show" +#define NOTIFICATION_EDGE_PROPERTY_NAME "edge" #define NOTIFICATION_HEIGHT_PROPERTY "popupHeight" #define NOTIFICATION_WIDTH_PROPERTY "popupWidth" -#define NOTIFICATION_SHOW_METHOD_NAME "show" - #define N_MAX_NOTIFICATIONS 3 // =================================================================== @@ -47,8 +44,8 @@ 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); + int size = variant.toInt(&so_far_so_good); if (!so_far_so_good || size < 0) { qWarning() << "Unable to get notification size."; return -1; @@ -57,13 +54,11 @@ inline int getNotificationSize (const QObject &object, const char *size_property return size; } -inline bool setNotificationPosition ( - QObject &object, const char *position_property, int value -) { - QVariant position(value); +inline bool setNotificationEdge (QObject &object, int value) { + QVariant edge(value); - if (!object.setProperty(position_property, position)) { - qWarning() << "Unable to set notification position."; + if (!object.setProperty("edge", edge)) { + qWarning() << "Unable to set notification edge."; return false; } @@ -78,32 +73,12 @@ void Notification::showCallMessage ( sip_address << ")"; QObject *object = m_components[Notification::Call]->create(); - int width, height; - if ( - (width = getNotificationSize(*object, NOTIFICATION_WIDTH_PROPERTY)) == -1 || - (height = getNotificationSize(*object, NOTIFICATION_HEIGHT_PROPERTY)) == -1 - ) { + if (!setNotificationEdge(*object, m_edge)) { delete object; return; } - QRect screen_rect = QApplication::desktop()->screenGeometry(m_screen_number); - - int x = (m_edge & Qt::LeftEdge) ? 5 : screen_rect.width() - 5 - width; - int y = (m_edge & Qt::TopEdge) ? 5 : screen_rect.height() - 5 - height; - - if ( - !setNotificationPosition(*object, NOTIFICATION_X_PROPERTY, x) || - !setNotificationPosition(*object, NOTIFICATION_Y_PROPERTY, y) - ) { - delete object; - return; - } - - - - QMetaObject::invokeMethod(object, "show", Qt::DirectConnection); QTimer::singleShot(timeout, object, [object]() { delete object; diff --git a/tests/src/components/notification/Notification.hpp b/tests/src/components/notification/Notification.hpp index 7c8c9cac5..0333b8dfd 100644 --- a/tests/src/components/notification/Notification.hpp +++ b/tests/src/components/notification/Notification.hpp @@ -24,10 +24,6 @@ public: m_edge = edge; } - void setScreenNumber (int screen_number) { - m_screen_number = screen_number; - } - public slots: void showCallMessage (int timeout, const QString &sip_address); @@ -35,8 +31,6 @@ private: Qt::Edges m_edge = Qt::RightEdge | Qt::TopEdge; QQmlComponent *m_components[MaxNbTypes]; - int m_screen_number = 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 c11efea80..87b160cf2 100644 --- a/tests/ui/modules/Common/Popup/DesktopPopup.qml +++ b/tests/ui/modules/Common/Popup/DesktopPopup.qml @@ -8,8 +8,10 @@ import Common.Styles 1.0 Item { id: wrapper - property alias popupX: popup.x - property alias popupY: popup.y + property int popupX: 0 + property int popupY: 0 + + property int edge: 0 readonly property alias popupWidth: popup.width readonly property alias popupHeight: popup.height @@ -25,6 +27,36 @@ Item { _isOpen = false } + function _applyXEdge (edge) { + var screen = popup.Screen + + if (screen == null) { + return popupX + } + + if (edge & Qt.LeftEdge) { + return 0 + } + + return screen.width - popup.width + } + + function _applyYEdge (edge) { + var screen = popup.Screen + + if (screen == null) { + return popupY + } + + if (edge & Qt.TopEdge) { + return 0 + } + + return screen.height - popup.height + } + + // ----------------------------------------------------------------- + // DO NOT TOUCH THIS PROPERTIES. // No visible. @@ -44,6 +76,9 @@ 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