qml power

This commit is contained in:
Patrick von Reth 2014-09-21 12:06:30 +02:00
parent 11d875ac89
commit 4c6033e1a2
4 changed files with 26 additions and 43 deletions

View File

@ -1,15 +1,12 @@
import QtQuick 2.3 import QtQuick 2.3
import QtQuick.Window 2.2
Rectangle { Rectangle {
objectName: "qmlNotification"
id: root id: root
width: 365 property int dpi: Screen.pixelDensity*25.4
height: 100
property int startWidth: 350 width: 3.7 * dpi
property int startHeight: 100 height: 1 * dpi
signal dismissed() signal dismissed()
@ -24,8 +21,25 @@ Rectangle {
appIcon.source = nAppIcon appIcon.source = nAppIcon
image.source = nImage image.source = nImage
root.color = color 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 { MouseArea {
id: mouseArea2 id: mouseArea2
anchors.fill: parent anchors.fill: parent

View File

@ -28,12 +28,12 @@
using namespace Snore; using namespace Snore;
NotifyWidget::NotifyWidget(int pos, QWindow *parent) : NotifyWidget::NotifyWidget(int pos, QWindow *parent) :
QQuickView(QUrl("qrc:/notification.qml"), parent), QQuickView(QUrl("qrc:/notification.qml"),parent),
m_animationX(new QPropertyAnimation(this, "x")),
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)
{ {
rootContext()->setContextProperty("window", this);
m_qmlNotification = rootObject(); m_qmlNotification = rootObject();
setFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowDoesNotAcceptFocus 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; 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(invoked()), this, SLOT(slotInvoked()));
connect(m_qmlNotification, SIGNAL(dismissed()), this, SLOT(slotDismissed())); connect(m_qmlNotification, SIGNAL(dismissed()), this, SLOT(slotDismissed()));
} }
NotifyWidget::~NotifyWidget() NotifyWidget::~NotifyWidget()
@ -79,20 +78,6 @@ void NotifyWidget::display(const Notification &notification)
update(notification); update(notification);
snoreDebug(SNORE_DEBUG) << notification.id(); snoreDebug(SNORE_DEBUG) << notification.id();
show(); 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 &notification) void NotifyWidget::update(const Notification &notification)
@ -196,10 +181,3 @@ QColor NotifyWidget::computeBackgrondColor(const QImage &img)
return QColor(r / s, g / s, b / s); return QColor(r / s, g / s, b / s);
} }
QSize NotifyWidget::computeSize()
{
int width = 365;
int height = 100;
return QSize(width * devicePixelRatio(), height * devicePixelRatio());
}

View File

@ -43,6 +43,7 @@ class NotifyWidget : public QQuickView
Q_OBJECT Q_OBJECT
public: public:
Q_PROPERTY(int id READ id)
explicit NotifyWidget(int pos, QWindow *parent = 0); explicit NotifyWidget(int pos, QWindow *parent = 0);
~NotifyWidget(); ~NotifyWidget();
@ -65,18 +66,9 @@ private slots:
void slotInvoked(); void slotInvoked();
protected:
QSize computeSize();
inline float dpisScale()
{
return 96.0;
}
private: private:
QColor computeBackgrondColor(const QImage &img); QColor computeBackgrondColor(const QImage &img);
QPropertyAnimation *m_animationX;
Snore::Notification m_notification; Snore::Notification m_notification;
QObject *m_qmlNotification; QObject *m_qmlNotification;
int m_id; int m_id;

View File

@ -27,7 +27,7 @@ using namespace Snore;
SnoreNotifier::SnoreNotifier(): SnoreNotifier::SnoreNotifier():
SnoreBackend("Snore", true, true, true), 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) void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
{ {
NotifyWidget *w = m_widgets[notification.hints().privateValue(this, "id").toInt()]; NotifyWidget *w = m_widgets[notification.hints().privateValue(this, "id").toInt()];
w->hide();
w->release(); w->release();
//the timer will show the next //the timer will show the next
} }