From 4c6033e1a258f6bfb29da03998e1e86aac75878d Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Sun, 21 Sep 2014 12:06:30 +0200 Subject: [PATCH] qml power --- src/plugins/backends/snore/notification.qml | 28 +++++++++++++++----- src/plugins/backends/snore/notifywidget.cpp | 28 +++----------------- src/plugins/backends/snore/notifywidget.h | 10 +------ src/plugins/backends/snore/snorenotifier.cpp | 3 +-- 4 files changed, 26 insertions(+), 43 deletions(-) diff --git a/src/plugins/backends/snore/notification.qml b/src/plugins/backends/snore/notification.qml index b124efe..4d1a336 100644 --- a/src/plugins/backends/snore/notification.qml +++ b/src/plugins/backends/snore/notification.qml @@ -1,15 +1,12 @@ import QtQuick 2.3 - - +import QtQuick.Window 2.2 Rectangle { - objectName: "qmlNotification" id: root - width: 365 - height: 100 + property int dpi: Screen.pixelDensity*25.4 - property int startWidth: 350 - property int startHeight: 100 + width: 3.7 * dpi + height: 1 * dpi signal dismissed() @@ -24,8 +21,25 @@ Rectangle { appIcon.source = nAppIcon image.source = nImage root.color = color + + + var id = window.id + var space = (id + 1) * dpi * 0.1 + window.y = space + (space + height) * id + console.debug("space: " + space) + animation.target = window + animation.from = Screen.desktopAvailableWidth + animation.to = Screen.desktopAvailableWidth - width + console.debug(window.x + "x" + window.y) + animation.start() + } + NumberAnimation{ + id: animation + properties: "x" + duration: 500 + } MouseArea { id: mouseArea2 anchors.fill: parent diff --git a/src/plugins/backends/snore/notifywidget.cpp b/src/plugins/backends/snore/notifywidget.cpp index 20eedc9..7838658 100644 --- a/src/plugins/backends/snore/notifywidget.cpp +++ b/src/plugins/backends/snore/notifywidget.cpp @@ -28,12 +28,12 @@ using namespace Snore; NotifyWidget::NotifyWidget(int pos, QWindow *parent) : - QQuickView(QUrl("qrc:/notification.qml"), parent), - m_animationX(new QPropertyAnimation(this, "x")), + QQuickView(QUrl("qrc:/notification.qml"),parent), m_id(pos), m_mem(QString("SnoreNotifyWidget_rev%1_id%2").arg(QString::number(SHARED_MEM_TYPE_REV()), QString::number(m_id))), m_ready(true) { + rootContext()->setContextProperty("window", this); m_qmlNotification = rootObject(); setFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowDoesNotAcceptFocus @@ -63,11 +63,10 @@ NotifyWidget::NotifyWidget(int pos, QWindow *parent) : snoreDebug(SNORE_DEBUG) << "Status" << data->free << data->date.elapsed() / 1000; } - setResizeMode(QQuickView::SizeRootObjectToView); + setResizeMode(QQuickView::SizeViewToRootObject); connect(m_qmlNotification, SIGNAL(invoked()), this, SLOT(slotInvoked())); connect(m_qmlNotification, SIGNAL(dismissed()), this, SLOT(slotDismissed())); - } NotifyWidget::~NotifyWidget() @@ -79,20 +78,6 @@ void NotifyWidget::display(const Notification ¬ification) update(notification); snoreDebug(SNORE_DEBUG) << notification.id(); show(); - - QRect desktop = QDesktopWidget().availableGeometry(); - -// snoreDebug( SNORE_DEBUG ) << computeSize() << devicePixelRatio(); - resize(computeSize()); - - int space = 10 * devicePixelRatio(); - - setY(desktop.topRight().y() + space + (space + height()) * m_id); - - m_animationX->setDuration(500); - m_animationX->setStartValue(desktop.topRight().x()); - m_animationX->setEndValue(desktop.topRight().x() - width()); - m_animationX->start(); } void NotifyWidget::update(const Notification ¬ification) @@ -196,10 +181,3 @@ QColor NotifyWidget::computeBackgrondColor(const QImage &img) return QColor(r / s, g / s, b / s); } - -QSize NotifyWidget::computeSize() -{ - int width = 365; - int height = 100; - return QSize(width * devicePixelRatio(), height * devicePixelRatio()); -} diff --git a/src/plugins/backends/snore/notifywidget.h b/src/plugins/backends/snore/notifywidget.h index e30d0a0..816b8dc 100644 --- a/src/plugins/backends/snore/notifywidget.h +++ b/src/plugins/backends/snore/notifywidget.h @@ -43,6 +43,7 @@ class NotifyWidget : public QQuickView Q_OBJECT public: + Q_PROPERTY(int id READ id) explicit NotifyWidget(int pos, QWindow *parent = 0); ~NotifyWidget(); @@ -65,18 +66,9 @@ private slots: void slotInvoked(); -protected: - QSize computeSize(); - - inline float dpisScale() - { - return 96.0; - } - private: QColor computeBackgrondColor(const QImage &img); - QPropertyAnimation *m_animationX; Snore::Notification m_notification; QObject *m_qmlNotification; int m_id; diff --git a/src/plugins/backends/snore/snorenotifier.cpp b/src/plugins/backends/snore/snorenotifier.cpp index f1aef08..819b5c6 100644 --- a/src/plugins/backends/snore/snorenotifier.cpp +++ b/src/plugins/backends/snore/snorenotifier.cpp @@ -27,7 +27,7 @@ using namespace Snore; SnoreNotifier::SnoreNotifier(): SnoreBackend("Snore", true, true, true), - m_widgets(2) + m_widgets(3) { } @@ -78,7 +78,6 @@ void SnoreNotifier::slotNotify(Snore::Notification notification) void SnoreNotifier::slotCloseNotification(Snore::Notification notification) { NotifyWidget *w = m_widgets[notification.hints().privateValue(this, "id").toInt()]; - w->hide(); w->release(); //the timer will show the next }