add a setting to display the snore backend nitification in a different screen corner

This commit is contained in:
Patrick von Reth 2015-01-22 12:58:21 +01:00
parent 82ebb45b2c
commit 44bd51c3f5
4 changed files with 30 additions and 6 deletions

View File

@ -23,13 +23,26 @@ Rectangle {
if (!isUpdate) {
var corner = window.corner
var id = window.id
var space = (id + 1) * height * 0.025
window.y = space + (space + height) * id
animation.target = window
window.y = space + (space + height) * id
if (corner == Qt.TopRightCorner || corner == Qt.BottomRightCorner) {
animation.from = Screen.desktopAvailableWidth
animation.to = Screen.desktopAvailableWidth - width
} else if(corner == Qt.TopLeftCorner || corner == Qt.BottomLeftCorner) {
animation.from = -width
animation.to = 0
}
if (corner == Qt.TopRightCorner || corner == Qt.TopLeftCorner) {
window.y = space + (space + height) * id
} else {
window.y = Screen.desktopAvailableHeight - (space + (space + height) * (id + 1))
}
animation.start()
window.visible = true
}

View File

@ -26,9 +26,10 @@
#include <QSize>
using namespace Snore;
NotifyWidget::NotifyWidget(int pos, QWindow *parent) :
NotifyWidget::NotifyWidget(int pos, Qt::Corner corner, QWindow *parent) :
QQuickView(QUrl("qrc:/notification.qml"),parent),
m_id(pos),
m_corner(corner),
m_mem(QString("SnoreNotifyWidget_rev%1_id%2").arg(QString::number(SHARED_MEM_TYPE_REV()), QString::number(m_id))),
m_ready(true)
{
@ -147,6 +148,11 @@ int NotifyWidget::id()
return m_id;
}
Qt::Corner NotifyWidget::corner()
{
return m_corner;
}
void NotifyWidget::slotDismissed()
{
emit dismissed();

View File

@ -44,7 +44,8 @@ class NotifyWidget : public QQuickView
public:
Q_PROPERTY(int id READ id)
explicit NotifyWidget(int pos, QWindow *parent = 0);
Q_PROPERTY(Qt::Corner corner READ corner)
explicit NotifyWidget(int pos, Qt::Corner corner, QWindow *parent = 0);
~NotifyWidget();
void display(const Snore::Notification &notification);
@ -55,6 +56,7 @@ public:
Snore::Notification &notification();
int id();
Qt::Corner corner();
signals:
void invoked();
@ -71,6 +73,7 @@ private:
Snore::Notification m_notification;
QObject *m_qmlNotification;
int m_id;
Qt::Corner m_corner;
QSharedMemory m_mem;
bool m_ready;
};

View File

@ -123,8 +123,9 @@ void SnoreNotifier::slotProcessQueue()
void SnoreNotifier::setup()
{
Qt::Corner displayPos = static_cast<Qt::Corner>(value("Position").toInt());
for (int i = 0; i < m_widgets.size(); ++i) {
NotifyWidget *w = new NotifyWidget(i);
NotifyWidget *w = new NotifyWidget(i,displayPos);
m_widgets[i] = w;
connect(w, SIGNAL(dismissed()), this, SLOT(slotDismissed()));
connect(w, SIGNAL(invoked()), this, SLOT(slotInvoked()));
@ -138,6 +139,7 @@ void SnoreNotifier::setup()
bool SnoreNotifier::initialize(SnoreCore *snore)
{
if (SnoreBackend::initialize(snore)) {
setDefaultValue("Position", Qt::TopRightCorner, "The position for the notification.");
return metaObject()->invokeMethod(this, "setup", Qt::QueuedConnection);
}
return false;