Move notification code from qml back to c++
This commit is contained in:
parent
90e3b40c6a
commit
a54d03e3b0
|
@ -205,8 +205,12 @@ void SnoreCorePrivate::setLocalSttingsPrefix(const QString &prefix)
|
||||||
|
|
||||||
QString SnoreCorePrivate::tempPath()
|
QString SnoreCorePrivate::tempPath()
|
||||||
{
|
{
|
||||||
|
#if 1
|
||||||
static QTemporaryDir dir;
|
static QTemporaryDir dir;
|
||||||
return dir.path();
|
return dir.path();
|
||||||
|
#else
|
||||||
|
return QDir::temp().path() + QLatin1String("/libsnore/");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this is somehow horrible code
|
// TODO: this is somehow horrible code
|
||||||
|
|
|
@ -13,47 +13,12 @@ Rectangle {
|
||||||
height: snoreBaseSize * 9
|
height: snoreBaseSize * 9
|
||||||
|
|
||||||
|
|
||||||
function update(nTitle, bBody, nImage, nAppIcon, color, textColor, isUpdate)
|
|
||||||
{
|
|
||||||
title.text = nTitle
|
|
||||||
title.color = textColor
|
|
||||||
body.text = bBody
|
|
||||||
body.color = textColor
|
|
||||||
appIcon.source = nAppIcon
|
|
||||||
image.source = nImage
|
|
||||||
root.color = color
|
|
||||||
|
|
||||||
if (!isUpdate) {
|
|
||||||
var corner = window.corner
|
|
||||||
var id = window.id
|
|
||||||
var space = (id + 1) * height * 0.025
|
|
||||||
|
|
||||||
animation.target = window
|
|
||||||
|
|
||||||
window.y = space + (space + height) * id
|
|
||||||
if (corner == Qt.TopRightCorner || corner == Qt.BottomRightCorner) {
|
|
||||||
animation.from = Screen.desktopAvailableWidth
|
|
||||||
animation.to = Screen.desktopAvailableWidth - width
|
|
||||||
} else {
|
|
||||||
animation.from = -width
|
|
||||||
animation.to = 0
|
|
||||||
}
|
|
||||||
if (corner == Qt.TopRightCorner || corner == Qt.TopLeftCorner) {
|
|
||||||
window.y = space + (space + height) * id
|
|
||||||
} else {
|
|
||||||
window.y = Screen.desktopAvailableHeight - (space + (space + height) * (id + 1))
|
|
||||||
}
|
|
||||||
|
|
||||||
animation.start()
|
|
||||||
window.visible = true
|
|
||||||
utils.raiseWindowToFront(window.wid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NumberAnimation{
|
NumberAnimation{
|
||||||
id: animation
|
id: animation
|
||||||
|
objectName: "animation"
|
||||||
properties: "x"
|
properties: "x"
|
||||||
duration: 500
|
duration: 500
|
||||||
|
target: window
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
@ -65,6 +30,7 @@ Rectangle {
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: title
|
id: title
|
||||||
|
objectName: "title"
|
||||||
color: "#000000"
|
color: "#000000"
|
||||||
text: "Title"
|
text: "Title"
|
||||||
font.pointSize: body.font.pointSize * 1.5
|
font.pointSize: body.font.pointSize * 1.5
|
||||||
|
@ -81,6 +47,7 @@ Rectangle {
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: body
|
id: body
|
||||||
|
objectName: "body"
|
||||||
color: "#000000"
|
color: "#000000"
|
||||||
text: "Body"
|
text: "Body"
|
||||||
font.pointSize: 10
|
font.pointSize: 10
|
||||||
|
@ -99,6 +66,7 @@ Rectangle {
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
id: image
|
id: image
|
||||||
|
objectName: "image"
|
||||||
fillMode: Image.PreserveAspectFit
|
fillMode: Image.PreserveAspectFit
|
||||||
width: height
|
width: height
|
||||||
smooth: true
|
smooth: true
|
||||||
|
@ -111,6 +79,7 @@ Rectangle {
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
id: appIcon
|
id: appIcon
|
||||||
|
objectName: "appIcon"
|
||||||
fillMode: Image.PreserveAspectFit
|
fillMode: Image.PreserveAspectFit
|
||||||
height: root.height * 0.30
|
height: root.height * 0.30
|
||||||
width: root.height * 0.30
|
width: root.height * 0.30
|
||||||
|
|
|
@ -21,6 +21,9 @@
|
||||||
#include "libsnore/log.h"
|
#include "libsnore/log.h"
|
||||||
#include "libsnore/utils.h"
|
#include "libsnore/utils.h"
|
||||||
|
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
#include <QQmlProperty>
|
||||||
|
|
||||||
using namespace Snore;
|
using namespace Snore;
|
||||||
|
|
||||||
NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) :
|
NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) :
|
||||||
|
@ -30,7 +33,6 @@ NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) :
|
||||||
m_ready(true)
|
m_ready(true)
|
||||||
{
|
{
|
||||||
rootContext()->setContextProperty(QLatin1String("window"), this);
|
rootContext()->setContextProperty(QLatin1String("window"), this);
|
||||||
rootContext()->setContextProperty(QLatin1String("utils"), new Utils(this));
|
|
||||||
|
|
||||||
QString font = qApp->font().family();
|
QString font = qApp->font().family();
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
@ -45,6 +47,11 @@ NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) :
|
||||||
#endif
|
#endif
|
||||||
rootContext()->setContextProperty(QLatin1String("snoreFont"), font);
|
rootContext()->setContextProperty(QLatin1String("snoreFont"), font);
|
||||||
setSource(QUrl::fromEncoded("qrc:/notification.qml"));
|
setSource(QUrl::fromEncoded("qrc:/notification.qml"));
|
||||||
|
m_appIcon = rootObject()->findChild<QObject*>(QLatin1String("appIcon"));
|
||||||
|
m_image = rootObject()->findChild<QObject*>(QLatin1String("image"));
|
||||||
|
m_title = rootObject()->findChild<QObject*>(QLatin1String("title"));
|
||||||
|
m_body = rootObject()->findChild<QObject*>(QLatin1String("body"));
|
||||||
|
m_animation = rootObject()->findChild<QObject*>(QLatin1String("animation"));
|
||||||
|
|
||||||
setFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowDoesNotAcceptFocus
|
setFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowDoesNotAcceptFocus
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
|
@ -94,18 +101,45 @@ void NotifyWidget::display(const Notification ¬ification)
|
||||||
if (vcolor.isValid()) {
|
if (vcolor.isValid()) {
|
||||||
color = vcolor.value<QColor>();
|
color = vcolor.value<QColor>();
|
||||||
} else {
|
} else {
|
||||||
color = computeBackgrondColor(notification.application().icon().image().scaled(20, 20));
|
color = computeBackgrondColor(notification.application().icon().pixmap(QSize(20,20)).toImage());
|
||||||
notification.application().hints().setPrivateValue(parent(), "backgroundColor", color);
|
notification.application().hints().setPrivateValue(parent(), "backgroundColor", color);
|
||||||
}
|
}
|
||||||
QColor textColor = compueTextColor(color);
|
QColor textColor = compueTextColor(color);
|
||||||
QMetaObject::invokeMethod(rootObject(), "update", Qt::QueuedConnection,
|
int appIconWidht = m_appIcon->property("width").toInt();
|
||||||
Q_ARG(QVariant, notification.title(Utils::ALL_MARKUP)),
|
m_appIcon->setProperty("source", QUrl::fromLocalFile(notification.application().icon().localUrl(QSize(appIconWidht,appIconWidht))));
|
||||||
Q_ARG(QVariant, notification.text(Utils::ALL_MARKUP)),
|
int imageWidth = m_image->property("width").toInt();
|
||||||
Q_ARG(QVariant, QUrl::fromLocalFile(notification.icon().localUrl())),
|
m_image->setProperty("source", QUrl::fromLocalFile(notification.icon().localUrl(QSize(imageWidth,imageWidth))));
|
||||||
Q_ARG(QVariant, QUrl::fromLocalFile(notification.application().icon().localUrl())),
|
|
||||||
Q_ARG(QVariant, color),
|
|
||||||
Q_ARG(QVariant, textColor),
|
m_title->setProperty("text", notification.title(Utils::ALL_MARKUP));
|
||||||
Q_ARG(QVariant, notification.isUpdate()));
|
m_title->setProperty("color", textColor);
|
||||||
|
|
||||||
|
m_body->setProperty("text", notification.text(Utils::ALL_MARKUP));
|
||||||
|
m_body->setProperty("color", textColor);
|
||||||
|
rootObject()->setProperty("color", color);
|
||||||
|
|
||||||
|
|
||||||
|
if (!notification.isUpdate()) {
|
||||||
|
QDesktopWidget desktop;
|
||||||
|
double space = (id() + 1) * height() * 0.025;
|
||||||
|
setY(space + (space + height()) * id());
|
||||||
|
if (corner() == Qt::TopRightCorner || corner() == Qt::BottomRightCorner) {
|
||||||
|
m_animation->setProperty("from", desktop.availableGeometry().width());
|
||||||
|
m_animation->setProperty("to", desktop.availableGeometry().width() - width());
|
||||||
|
} else {
|
||||||
|
m_animation->setProperty("from", -width());
|
||||||
|
m_animation->setProperty("to", 0);
|
||||||
|
}
|
||||||
|
if (corner() == Qt::TopRightCorner || corner() == Qt::TopLeftCorner) {
|
||||||
|
setY(space + (space + height()) * id());
|
||||||
|
} else {
|
||||||
|
setY(desktop.availableGeometry().height() - (space + (space + height()) * (id() + 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(m_animation, "start");
|
||||||
|
setVisible(true);
|
||||||
|
Utils::raiseWindowToFront(winId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotifyWidget::acquire()
|
bool NotifyWidget::acquire()
|
||||||
|
@ -169,11 +203,6 @@ Qt::Corner NotifyWidget::corner()
|
||||||
return static_cast<Qt::Corner>(m_parent->settingsValue(QLatin1String("Position")).toInt());
|
return static_cast<Qt::Corner>(m_parent->settingsValue(QLatin1String("Position")).toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
qlonglong NotifyWidget::wid()
|
|
||||||
{
|
|
||||||
return this->winId();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotifyWidget::slotDismissed()
|
void NotifyWidget::slotDismissed()
|
||||||
{
|
{
|
||||||
emit dismissed();
|
emit dismissed();
|
||||||
|
|
|
@ -42,9 +42,6 @@ class NotifyWidget : public QQuickView
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Q_PROPERTY(int id READ id)
|
|
||||||
Q_PROPERTY(Qt::Corner corner READ corner)
|
|
||||||
Q_PROPERTY(qlonglong wid READ wid)
|
|
||||||
explicit NotifyWidget(int pos, const SnoreNotifier *parent);
|
explicit NotifyWidget(int pos, const SnoreNotifier *parent);
|
||||||
~NotifyWidget();
|
~NotifyWidget();
|
||||||
|
|
||||||
|
@ -57,7 +54,6 @@ public:
|
||||||
|
|
||||||
int id();
|
int id();
|
||||||
Qt::Corner corner();
|
Qt::Corner corner();
|
||||||
qlonglong wid();
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void invoked();
|
void invoked();
|
||||||
|
@ -77,6 +73,15 @@ private:
|
||||||
const SnoreNotifier *m_parent;
|
const SnoreNotifier *m_parent;
|
||||||
QSharedMemory m_mem;
|
QSharedMemory m_mem;
|
||||||
bool m_ready;
|
bool m_ready;
|
||||||
|
|
||||||
|
QObject *m_appIcon;
|
||||||
|
QObject *m_image;
|
||||||
|
|
||||||
|
QObject *m_title;
|
||||||
|
|
||||||
|
QObject *m_body;
|
||||||
|
QObject *m_animation;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NOTIFYWIDGET_H
|
#endif // NOTIFYWIDGET_H
|
||||||
|
|
Loading…
Reference in New Issue