Commit c1e6d7d2 authored by Ronan Abhamon's avatar Ronan Abhamon

unstable

parent 6a6d3752
......@@ -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);
if (!m_system_tray_icon) {
return;
}
QRect icon_rect = m_system_tray_icon->geometry();
QRect screen_rect = desktop->screenGeometry(primary_screen);
QDesktopWidget *desktop = QApplication::desktop();
int x = icon_rect.x() + icon_rect.width() / 2;
int y = icon_rect.y() + icon_rect.height() / 2;
QRect icon_rect = m_system_tray_icon->geometry();
QRect screen_rect = desktop->screenGeometry();
Qt::Edges edge = (x < screen_rect.width() / 2) ? Qt::LeftEdge : Qt::RightEdge;
edge |= (y < screen_rect.height() / 2) ? Qt::TopEdge : Qt::BottomEdge;
int x = icon_rect.x() + icon_rect.width() / 2;
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 <QtDebug>
#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;
......
......@@ -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;
};
......
......@@ -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
......
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