ported to qtquick, no dpi scaling yet

This commit is contained in:
Patrick von Reth 2014-09-20 15:36:28 +02:00
parent b331644379
commit 11d875ac89
7 changed files with 24 additions and 24 deletions

View File

@ -33,7 +33,7 @@ include(KDECompilerSettings)
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5Declarative REQUIRED)
find_package(Qt5Quick REQUIRED)

View File

@ -63,6 +63,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
case SnorePlugin::FRONTEND:
case SnorePlugin::PLUGIN:
if (!info->load()->initialize(this)) {
info->load()->deinitialize();
info->unload();
break;
}

View File

@ -8,7 +8,7 @@ set( SNORE_SRC
add_library(libsnore_backend_snore MODULE ${SNORE_SRC} )
target_link_libraries(libsnore_backend_snore Snore::Libsnore Qt5::Declarative)
target_link_libraries(libsnore_backend_snore Snore::Libsnore Qt5::Quick)
install(TARGETS libsnore_backend_snore ${SNORE_PLUGIN_INSTALL_PATH})

View File

@ -1,4 +1,4 @@
import QtQuick 1.1
import QtQuick 2.3

View File

@ -25,19 +25,18 @@
#include <QtDeclarative/QDeclarativeView>
#include <QLayout>
#include <QSize>
using namespace Snore;
NotifyWidget::NotifyWidget(int pos, QWidget *parent) :
QDeclarativeView(QUrl("qrc:/notification.qml"), parent),
m_animation(new QPropertyAnimation(this, "pos")),
NotifyWidget::NotifyWidget(int pos, QWindow *parent) :
QQuickView(QUrl("qrc:/notification.qml"), parent),
m_animationX(new QPropertyAnimation(this, "x")),
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)
{
m_qmlNotification = rootObject();
this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowDoesNotAcceptFocus
setFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowDoesNotAcceptFocus
#ifdef Q_OS_MAC
| Qt::SubWindow
#else
@ -45,8 +44,8 @@ NotifyWidget::NotifyWidget(int pos, QWidget *parent) :
#endif
);
setFocusPolicy(Qt::NoFocus);
setAttribute(Qt::WA_ShowWithoutActivating, true);
// setFocusPolicy(Qt::NoFocus);
// setAttribute(Qt::WA_ShowWithoutActivating, true);
if (m_mem.create(sizeof(SHARED_MEM_TYPE))) {
m_mem.lock();
@ -64,7 +63,7 @@ NotifyWidget::NotifyWidget(int pos, QWidget *parent) :
snoreDebug(SNORE_DEBUG) << "Status" << data->free << data->date.elapsed() / 1000;
}
setResizeMode(QDeclarativeView::SizeRootObjectToView);
setResizeMode(QQuickView::SizeRootObjectToView);
connect(m_qmlNotification, SIGNAL(invoked()), this, SLOT(slotInvoked()));
connect(m_qmlNotification, SIGNAL(dismissed()), this, SLOT(slotDismissed()));
@ -83,17 +82,17 @@ void NotifyWidget::display(const Notification &notification)
QRect desktop = QDesktopWidget().availableGeometry();
// snoreDebug( SNORE_DEBUG ) << computeSize() << devicePixelRatio();
resize(computeSize());
int space = 10 * logicalDpiY() / dpisScale();
int space = 10 * devicePixelRatio();
QPoint dest(desktop.topRight().x() - width(), desktop.topRight().y() + space + (space + height()) * m_id);
QPoint start(desktop.topRight().x(), dest.y());
setY(desktop.topRight().y() + space + (space + height()) * m_id);
m_animation->setDuration(500);
m_animation->setStartValue(start);
m_animation->setEndValue(dest);
m_animation->start();
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)
@ -202,5 +201,5 @@ QSize NotifyWidget::computeSize()
{
int width = 365;
int height = 100;
return QSize(width * logicalDpiX() / dpisScale(), height * logicalDpiY() / dpisScale());
return QSize(width * devicePixelRatio(), height * devicePixelRatio());
}

View File

@ -24,7 +24,7 @@
#include <QSharedMemory>
#include "core/notification/notification.h"
#include <QtDeclarative>
#include <QtQuick/QtQuick>
#include <QPropertyAnimation>
typedef struct {
@ -38,12 +38,12 @@ inline int SHARED_MEM_TYPE_REV()
return 1;
}
class NotifyWidget : public QDeclarativeView
class NotifyWidget : public QQuickView
{
Q_OBJECT
public:
explicit NotifyWidget(int pos, QWidget *parent = 0);
explicit NotifyWidget(int pos, QWindow *parent = 0);
~NotifyWidget();
void display(const Snore::Notification &notification);
@ -76,7 +76,7 @@ protected:
private:
QColor computeBackgrondColor(const QImage &img);
QPropertyAnimation *m_animation;
QPropertyAnimation *m_animationX;
Snore::Notification m_notification;
QObject *m_qmlNotification;
int m_id;

View File

@ -65,7 +65,7 @@ bool Toasty::initialize(SnoreCore *snore)
if (SnoreSecondaryBackend::initialize(snore)) {
setDefaultValue("DeviceID", "", "The ID provided for your device by Toasty");
m_key = value("DeviceID").toString();
snoreDebug(SNORE_DEBUG) << m_key;
snoreDebug(SNORE_DEBUG) << m_key << !m_key.isEmpty();
return !m_key.isEmpty();
}
return false;