From 091d2be1f5078e50c9bb700c17b39b6754303bdc Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Sat, 6 Sep 2014 09:47:11 +0200 Subject: [PATCH] use a qporpertyanimation instead of a qtimer... --- src/plugins/backends/snore/notifywidget.cpp | 44 +++++++-------------- src/plugins/backends/snore/notifywidget.h | 14 ++----- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/src/plugins/backends/snore/notifywidget.cpp b/src/plugins/backends/snore/notifywidget.cpp index d76d85b..2c5e5a6 100644 --- a/src/plugins/backends/snore/notifywidget.cpp +++ b/src/plugins/backends/snore/notifywidget.cpp @@ -31,7 +31,7 @@ using namespace Snore; NotifyWidget::NotifyWidget(int pos,QWidget *parent) : QDeclarativeView(QUrl("qrc:/notification.qml"), parent), - m_moveTimer(new QTimer(this)), + m_animation( new QPropertyAnimation(this, "pos")), 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) @@ -66,12 +66,9 @@ NotifyWidget::NotifyWidget(int pos,QWidget *parent) : setResizeMode(QDeclarativeView::SizeRootObjectToView); - - m_moveTimer->setInterval(1); - connect( m_moveTimer, SIGNAL(timeout()), this, SLOT(slotMove())); - connect( m_qmlNotification, SIGNAL(invoked()), this, SLOT(slotInvoked())); connect( m_qmlNotification, SIGNAL(dismissed()), this, SLOT(slotDismissed())); + } NotifyWidget::~NotifyWidget() @@ -81,27 +78,28 @@ NotifyWidget::~NotifyWidget() void NotifyWidget::display(const Notification ¬ification) { update(notification); - m_dist = 0; - m_moveTimer->start(); snoreDebug( SNORE_DEBUG ) << notification.id(); - move(m_start); show(); -} - -void NotifyWidget::update(const Notification ¬ification) -{ - snoreDebug( SNORE_DEBUG ) << m_id << notification.id(); - m_notification = notification; - + QRect desktop = QDesktopWidget().availableGeometry(); resize(computeSize()); int space = 10 * logicalDpiY() / dpisScale(); - m_dest = QPoint(desktop.topRight().x() - width(), desktop.topRight().y() + space + (space + height()) * m_id); - m_start = QPoint(desktop.topRight().x(), m_dest.y()); + QPoint dest(desktop.topRight().x() - width(), desktop.topRight().y() + space + (space + height()) * m_id); + QPoint start(desktop.topRight().x(), dest.y()); + + m_animation->setDuration(1000); + m_animation->setStartValue(start); + m_animation->setEndValue(dest); + m_animation->start(); +} +void NotifyWidget::update(const Notification ¬ification) +{ + snoreDebug( SNORE_DEBUG ) << m_id << notification.id(); + m_notification = notification; QColor color; QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor"); if(vcolor.isValid()) @@ -122,8 +120,6 @@ void NotifyWidget::update(const Notification ¬ification) Q_ARG( QVariant, QUrl::fromLocalFile(notification.application().icon().localUrl())), Q_ARG( QVariant, color), Q_ARG( QVariant, textColor)); - - } bool NotifyWidget::acquire() @@ -181,16 +177,6 @@ int NotifyWidget::id() return m_id; } -void NotifyWidget::slotMove() -{ - QPoint dest(m_start.x() - m_dist++, m_start.y()); - move(dest); - if(m_dist >= width()) - { - m_moveTimer->stop(); - } -} - void NotifyWidget::slotDismissed() { emit dismissed(); diff --git a/src/plugins/backends/snore/notifywidget.h b/src/plugins/backends/snore/notifywidget.h index aae7414..3945d97 100644 --- a/src/plugins/backends/snore/notifywidget.h +++ b/src/plugins/backends/snore/notifywidget.h @@ -26,6 +26,7 @@ #include "core/notification/notification.h" #include +#include typedef struct @@ -58,15 +59,11 @@ public: int id(); - - signals: void invoked(); void dismissed(); private slots: - void slotMove(); - void slotDismissed(); void slotInvoked(); @@ -80,16 +77,11 @@ protected: } private: - QColor computeBackgrondColor(const QImage &img); - QTimer *m_moveTimer; - QPoint m_dest; - QPoint m_start; - int m_dist; + + QPropertyAnimation *m_animation; Snore::Notification m_notification; - QObject *m_qmlNotification; - int m_id; QSharedMemory m_mem; bool m_ready;