mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-25 15:58:16 +00:00
feat(app): add Notification component, restore DesktopPopup component without notification deps
This commit is contained in:
parent
80e643e82a
commit
91ef7469d0
12 changed files with 69 additions and 59 deletions
|
|
@ -118,6 +118,7 @@
|
|||
<file>ui/modules/Linphone/Contact/ContactDescription.qml</file>
|
||||
<file>ui/modules/Linphone/Contact/Contact.qml</file>
|
||||
<file>ui/modules/Linphone/Notifications/CallNotification.qml</file>
|
||||
<file>ui/modules/Linphone/Notifications/Notification.qml</file>
|
||||
<file>ui/modules/Linphone/Presence/PresenceLevel.qml</file>
|
||||
<file>ui/modules/Linphone/Presence/PresenceString.qml</file>
|
||||
<file>ui/modules/Linphone/qmldir</file>
|
||||
|
|
@ -127,6 +128,7 @@
|
|||
<file>ui/modules/Linphone/Styles/Contact/AvatarStyle.qml</file>
|
||||
<file>ui/modules/Linphone/Styles/Contact/ContactDescriptionStyle.qml</file>
|
||||
<file>ui/modules/Linphone/Styles/Contact/ContactStyle.qml</file>
|
||||
<file>ui/modules/Linphone/Styles/NotificationStyle.qml</file>
|
||||
<file>ui/modules/Linphone/Styles/Presence/PresenceStringStyle.qml</file>
|
||||
<file>ui/modules/Linphone/Styles/qmldir</file>
|
||||
<file>ui/modules/Linphone/Styles/TimelineStyle.qml</file>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,6 @@ Item {
|
|||
return point
|
||||
}
|
||||
|
||||
flags: Qt.SplashScreen
|
||||
popupX: coords.x
|
||||
popupY: coords.y
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import QtQuick 2.7
|
||||
|
||||
import Common 1.0
|
||||
|
||||
DesktopPopup {
|
||||
Notification {
|
||||
Rectangle {
|
||||
color: 'red'
|
||||
|
||||
|
|
|
|||
43
tests/ui/modules/Linphone/Notifications/Notification.qml
Normal file
43
tests/ui/modules/Linphone/Notifications/Notification.qml
Normal file
|
|
@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
8
tests/ui/modules/Linphone/Styles/NotificationStyle.qml
Normal file
8
tests/ui/modules/Linphone/Styles/NotificationStyle.qml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
pragma Singleton
|
||||
import QtQuick 2.7
|
||||
|
||||
// ===================================================================
|
||||
|
||||
QtObject {
|
||||
property int margin: 10
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue