Commit cf6eecbd authored by Ronan Abhamon's avatar Ronan Abhamon

unstable

parent 363d03e6
......@@ -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;
......
......@@ -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<class T>
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();
});
}
......@@ -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;
};
......
......@@ -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
......
......@@ -90,6 +90,7 @@ Item {
return point
}
flags: Qt.SplashScreen
popupX: coords.x
popupY: coords.y
......
......@@ -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
......
......@@ -5,6 +5,7 @@ import Common 1.0
DesktopPopup {
Rectangle {
color: 'red'
width: 200
height: 100
}
......
......@@ -36,7 +36,7 @@ ColumnLayout {
})
}
spacing: Notification.showCallMessage(10000, "toto@toto.com") || 0
spacing: Notification.showCallMessage(5000, "toto@toto.com") || 0
// -----------------------------------------------------------------
// Search Bar & actions.
......
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