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.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

View File

@ -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 &notification)
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 &notification)
@ -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());
}

View File

@ -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;

View File

@ -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
}