use a qporpertyanimation instead of a qtimer...
This commit is contained in:
parent
5f987723b5
commit
091d2be1f5
|
@ -31,7 +31,7 @@ using namespace Snore;
|
||||||
|
|
||||||
NotifyWidget::NotifyWidget(int pos,QWidget *parent) :
|
NotifyWidget::NotifyWidget(int pos,QWidget *parent) :
|
||||||
QDeclarativeView(QUrl("qrc:/notification.qml"), parent),
|
QDeclarativeView(QUrl("qrc:/notification.qml"), parent),
|
||||||
m_moveTimer(new QTimer(this)),
|
m_animation( new QPropertyAnimation(this, "pos")),
|
||||||
m_id(pos),
|
m_id(pos),
|
||||||
m_mem(QString("SnoreNotifyWidget_rev%1_id%2").arg(QString::number(SHARED_MEM_TYPE_REV()), QString::number(m_id))),
|
m_mem(QString("SnoreNotifyWidget_rev%1_id%2").arg(QString::number(SHARED_MEM_TYPE_REV()), QString::number(m_id))),
|
||||||
m_ready(true)
|
m_ready(true)
|
||||||
|
@ -66,12 +66,9 @@ NotifyWidget::NotifyWidget(int pos,QWidget *parent) :
|
||||||
|
|
||||||
setResizeMode(QDeclarativeView::SizeRootObjectToView);
|
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(invoked()), this, SLOT(slotInvoked()));
|
||||||
connect( m_qmlNotification, SIGNAL(dismissed()), this, SLOT(slotDismissed()));
|
connect( m_qmlNotification, SIGNAL(dismissed()), this, SLOT(slotDismissed()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NotifyWidget::~NotifyWidget()
|
NotifyWidget::~NotifyWidget()
|
||||||
|
@ -81,17 +78,8 @@ NotifyWidget::~NotifyWidget()
|
||||||
void NotifyWidget::display(const Notification ¬ification)
|
void NotifyWidget::display(const Notification ¬ification)
|
||||||
{
|
{
|
||||||
update(notification);
|
update(notification);
|
||||||
m_dist = 0;
|
|
||||||
m_moveTimer->start();
|
|
||||||
snoreDebug( SNORE_DEBUG ) << notification.id();
|
snoreDebug( SNORE_DEBUG ) << notification.id();
|
||||||
move(m_start);
|
|
||||||
show();
|
show();
|
||||||
}
|
|
||||||
|
|
||||||
void NotifyWidget::update(const Notification ¬ification)
|
|
||||||
{
|
|
||||||
snoreDebug( SNORE_DEBUG ) << m_id << notification.id();
|
|
||||||
m_notification = notification;
|
|
||||||
|
|
||||||
QRect desktop = QDesktopWidget().availableGeometry();
|
QRect desktop = QDesktopWidget().availableGeometry();
|
||||||
|
|
||||||
|
@ -99,9 +87,19 @@ void NotifyWidget::update(const Notification ¬ification)
|
||||||
|
|
||||||
int space = 10 * logicalDpiY() / dpisScale();
|
int space = 10 * logicalDpiY() / dpisScale();
|
||||||
|
|
||||||
m_dest = QPoint(desktop.topRight().x() - width(), desktop.topRight().y() + space + (space + height()) * m_id);
|
QPoint dest(desktop.topRight().x() - width(), desktop.topRight().y() + space + (space + height()) * m_id);
|
||||||
m_start = QPoint(desktop.topRight().x(), m_dest.y());
|
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;
|
QColor color;
|
||||||
QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor");
|
QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor");
|
||||||
if(vcolor.isValid())
|
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, QUrl::fromLocalFile(notification.application().icon().localUrl())),
|
||||||
Q_ARG( QVariant, color),
|
Q_ARG( QVariant, color),
|
||||||
Q_ARG( QVariant, textColor));
|
Q_ARG( QVariant, textColor));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotifyWidget::acquire()
|
bool NotifyWidget::acquire()
|
||||||
|
@ -181,16 +177,6 @@ int NotifyWidget::id()
|
||||||
return m_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()
|
void NotifyWidget::slotDismissed()
|
||||||
{
|
{
|
||||||
emit dismissed();
|
emit dismissed();
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "core/notification/notification.h"
|
#include "core/notification/notification.h"
|
||||||
|
|
||||||
#include <QtDeclarative>
|
#include <QtDeclarative>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -58,15 +59,11 @@ public:
|
||||||
|
|
||||||
int id();
|
int id();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void invoked();
|
void invoked();
|
||||||
void dismissed();
|
void dismissed();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotMove();
|
|
||||||
|
|
||||||
void slotDismissed();
|
void slotDismissed();
|
||||||
|
|
||||||
void slotInvoked();
|
void slotInvoked();
|
||||||
|
@ -80,16 +77,11 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QColor computeBackgrondColor(const QImage &img);
|
QColor computeBackgrondColor(const QImage &img);
|
||||||
QTimer *m_moveTimer;
|
|
||||||
QPoint m_dest;
|
QPropertyAnimation *m_animation;
|
||||||
QPoint m_start;
|
|
||||||
int m_dist;
|
|
||||||
Snore::Notification m_notification;
|
Snore::Notification m_notification;
|
||||||
|
|
||||||
QObject *m_qmlNotification;
|
QObject *m_qmlNotification;
|
||||||
|
|
||||||
int m_id;
|
int m_id;
|
||||||
QSharedMemory m_mem;
|
QSharedMemory m_mem;
|
||||||
bool m_ready;
|
bool m_ready;
|
||||||
|
|
Loading…
Reference in New Issue