Commit c1e6d7d2 authored by Ronan Abhamon's avatar Ronan Abhamon

unstable

parent 6a6d3752
...@@ -139,25 +139,20 @@ void App::setTrayIcon () { ...@@ -139,25 +139,20 @@ void App::setTrayIcon () {
} }
void App::setNotificationAttributes () { void App::setNotificationAttributes () {
QDesktopWidget *desktop = QApplication::desktop(); if (!m_system_tray_icon) {
return;
// 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(); QDesktopWidget *desktop = QApplication::desktop();
QRect screen_rect = desktop->screenGeometry(primary_screen);
int x = icon_rect.x() + icon_rect.width() / 2; QRect icon_rect = m_system_tray_icon->geometry();
int y = icon_rect.y() + icon_rect.height() / 2; QRect screen_rect = desktop->screenGeometry();
Qt::Edges edge = (x < screen_rect.width() / 2) ? Qt::LeftEdge : Qt::RightEdge; int x = icon_rect.x() + icon_rect.width() / 2;
edge |= (y < screen_rect.height() / 2) ? Qt::TopEdge : Qt::BottomEdge; int y = icon_rect.y() + icon_rect.height() / 2;
m_notification->setEdge(edge); Qt::Edges edge = (x < screen_rect.width() / 2) ? Qt::LeftEdge : Qt::RightEdge;
} edge |= (y < screen_rect.height() / 2) ? Qt::TopEdge : Qt::BottomEdge;
m_notification->setScreenNumber(primary_screen); m_notification->setEdge(edge);
} }
#include <QDesktopWidget>
#include <QTimer> #include <QTimer>
#include <QtDebug> #include <QtDebug>
#include "../../app/App.hpp" #include "../../app/App.hpp"
#include "Notification.hpp" #include "Notification.hpp"
#define NOTIFICATION_X_PROPERTY "popupX" #define NOTIFICATION_SHOW_METHOD_NAME "show"
#define NOTIFICATION_Y_PROPERTY "popupY" #define NOTIFICATION_EDGE_PROPERTY_NAME "edge"
#define NOTIFICATION_HEIGHT_PROPERTY "popupHeight" #define NOTIFICATION_HEIGHT_PROPERTY "popupHeight"
#define NOTIFICATION_WIDTH_PROPERTY "popupWidth" #define NOTIFICATION_WIDTH_PROPERTY "popupWidth"
#define NOTIFICATION_SHOW_METHOD_NAME "show"
#define N_MAX_NOTIFICATIONS 3 #define N_MAX_NOTIFICATIONS 3
// =================================================================== // ===================================================================
...@@ -47,8 +44,8 @@ Notification::~Notification () { ...@@ -47,8 +44,8 @@ Notification::~Notification () {
inline int getNotificationSize (const QObject &object, const char *size_property) { inline int getNotificationSize (const QObject &object, const char *size_property) {
QVariant variant = object.property(size_property); QVariant variant = object.property(size_property);
bool so_far_so_good; 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) { if (!so_far_so_good || size < 0) {
qWarning() << "Unable to get notification size."; qWarning() << "Unable to get notification size.";
return -1; return -1;
...@@ -57,13 +54,11 @@ inline int getNotificationSize (const QObject &object, const char *size_property ...@@ -57,13 +54,11 @@ inline int getNotificationSize (const QObject &object, const char *size_property
return size; return size;
} }
inline bool setNotificationPosition ( inline bool setNotificationEdge (QObject &object, int value) {
QObject &object, const char *position_property, int value QVariant edge(value);
) {
QVariant position(value);
if (!object.setProperty(position_property, position)) { if (!object.setProperty("edge", edge)) {
qWarning() << "Unable to set notification position."; qWarning() << "Unable to set notification edge.";
return false; return false;
} }
...@@ -78,32 +73,12 @@ void Notification::showCallMessage ( ...@@ -78,32 +73,12 @@ void Notification::showCallMessage (
sip_address << ")"; sip_address << ")";
QObject *object = m_components[Notification::Call]->create(); QObject *object = m_components[Notification::Call]->create();
int width, height;
if ( if (!setNotificationEdge(*object, m_edge)) {
(width = getNotificationSize(*object, NOTIFICATION_WIDTH_PROPERTY)) == -1 ||
(height = getNotificationSize(*object, NOTIFICATION_HEIGHT_PROPERTY)) == -1
) {
delete object; delete object;
return; 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); QMetaObject::invokeMethod(object, "show", Qt::DirectConnection);
QTimer::singleShot(timeout, object, [object]() { QTimer::singleShot(timeout, object, [object]() {
delete object; delete object;
......
...@@ -24,10 +24,6 @@ public: ...@@ -24,10 +24,6 @@ public:
m_edge = edge; m_edge = edge;
} }
void setScreenNumber (int screen_number) {
m_screen_number = screen_number;
}
public slots: public slots:
void showCallMessage (int timeout, const QString &sip_address); void showCallMessage (int timeout, const QString &sip_address);
...@@ -35,8 +31,6 @@ private: ...@@ -35,8 +31,6 @@ private:
Qt::Edges m_edge = Qt::RightEdge | Qt::TopEdge; Qt::Edges m_edge = Qt::RightEdge | Qt::TopEdge;
QQmlComponent *m_components[MaxNbTypes]; QQmlComponent *m_components[MaxNbTypes];
int m_screen_number = 0;
int m_n_instances = 0; int m_n_instances = 0;
QMutex m_mutex; QMutex m_mutex;
}; };
......
...@@ -8,8 +8,10 @@ import Common.Styles 1.0 ...@@ -8,8 +8,10 @@ import Common.Styles 1.0
Item { Item {
id: wrapper id: wrapper
property alias popupX: popup.x property int popupX: 0
property alias popupY: popup.y property int popupY: 0
property int edge: 0
readonly property alias popupWidth: popup.width readonly property alias popupWidth: popup.width
readonly property alias popupHeight: popup.height readonly property alias popupHeight: popup.height
...@@ -25,6 +27,36 @@ Item { ...@@ -25,6 +27,36 @@ Item {
_isOpen = false _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. // DO NOT TOUCH THIS PROPERTIES.
// No visible. // No visible.
...@@ -44,6 +76,9 @@ Item { ...@@ -44,6 +76,9 @@ Item {
height: _content[0] != null ? _content[0].height : 0 height: _content[0] != null ? _content[0].height : 0
width: _content[0] != null ? _content[0].width : 0 width: _content[0] != null ? _content[0].width : 0
x: edge ? _applyXEdge() : popupX
y: edge ? _applyYEdge() : popupY
Item { Item {
id: content id: content
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment