From e3a4d869cf0cc12a61f2b4faee44ab1d9751cca8 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 27 Jun 2017 21:46:49 +0200 Subject: Show Avatar images --- framework/qml/People.qml | 8 ++++---- framework/src/CMakeLists.txt | 1 + framework/src/domain/contactcontroller.cpp | 1 + framework/src/domain/contactcontroller.h | 1 + framework/src/domain/peoplemodel.cpp | 6 +++++- framework/src/domain/peoplemodel.h | 3 ++- framework/src/frameworkplugin.cpp | 3 +++ framework/src/kubeimage.cpp | 24 ++++++++++++++++++++++++ framework/src/kubeimage.h | 15 +++++++++++++++ 9 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 framework/src/kubeimage.cpp create mode 100644 framework/src/kubeimage.h (limited to 'framework') diff --git a/framework/qml/People.qml b/framework/qml/People.qml index aa23a78d..3445a5ba 100644 --- a/framework/qml/People.qml +++ b/framework/qml/People.qml @@ -149,13 +149,13 @@ Item { } } - Rectangle { + Kube.KubeImage { id: avatarPlaceholder height: parent.height width: height - color: "lightgrey" + imageData: model.imageData } Column { @@ -241,13 +241,13 @@ Item { height: Kube.Units.gridUnit * 8 width: personPageRoot.width - Kube.Units.largeSpacing - Rectangle { + Kube.KubeImage { id: avatar height: parent.height width: height - color: "lightgrey" + imageData: contactController.imageData } //TODO replace with Kube.Heading once it is there diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index 1b92e8c3..1c53530f 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt @@ -39,6 +39,7 @@ set(SRCS accounts/accountsmodel.cpp fabric.cpp sinkfabric.cpp + kubeimage.cpp ) add_library(frameworkplugin SHARED ${SRCS}) diff --git a/framework/src/domain/contactcontroller.cpp b/framework/src/domain/contactcontroller.cpp index 90ef6323..bc536bf6 100644 --- a/framework/src/domain/contactcontroller.cpp +++ b/framework/src/domain/contactcontroller.cpp @@ -59,6 +59,7 @@ void ContactController::loadContact(const QVariant &contact) } setCompany(addressee.organization()); setJobTitle(addressee.role()); + setImageData(addressee.photo().rawData()); } } diff --git a/framework/src/domain/contactcontroller.h b/framework/src/domain/contactcontroller.h index fea42430..72d8eee1 100644 --- a/framework/src/domain/contactcontroller.h +++ b/framework/src/domain/contactcontroller.h @@ -41,6 +41,7 @@ class ContactController : public Kube::Controller KUBE_CONTROLLER_PROPERTY(QString, Country, country) KUBE_CONTROLLER_PROPERTY(QString, Company, company) KUBE_CONTROLLER_PROPERTY(QString, JobTitle, jobTitle) + KUBE_CONTROLLER_PROPERTY(QByteArray, ImageData, imageData) KUBE_CONTROLLER_ACTION(save) diff --git a/framework/src/domain/peoplemodel.cpp b/framework/src/domain/peoplemodel.cpp index c9e7248c..099c680a 100644 --- a/framework/src/domain/peoplemodel.cpp +++ b/framework/src/domain/peoplemodel.cpp @@ -38,6 +38,7 @@ PeopleModel::PeopleModel(QObject *parent) query.request(); query.request(); query.request(); + query.request(); runQuery(query); } @@ -65,7 +66,8 @@ QHash< int, QByteArray > PeopleModel::roleNames() const {Type, "type"}, {DomainObject, "domainObject"}, {FirstName, "firstName"}, - {LastName, "lastName"} + {LastName, "lastName"}, + {ImageData, "imageData"} }; return roles; } @@ -96,6 +98,8 @@ QVariant PeopleModel::data(const QModelIndex &idx, int role) const return contact->getFirstname(); case LastName: return contact->getLastname(); + case ImageData: + return contact->getPhoto(); } return QSortFilterProxyModel::data(idx, role); } diff --git a/framework/src/domain/peoplemodel.h b/framework/src/domain/peoplemodel.h index a59e752c..69d07417 100644 --- a/framework/src/domain/peoplemodel.h +++ b/framework/src/domain/peoplemodel.h @@ -51,7 +51,8 @@ public: Addressbook, DomainObject, FirstName, - LastName + LastName, + ImageData }; QHash roleNames() const Q_DECL_OVERRIDE; diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp index 84ada236..9c79f515 100644 --- a/framework/src/frameworkplugin.cpp +++ b/framework/src/frameworkplugin.cpp @@ -33,6 +33,7 @@ #include "accounts/accountfactory.h" #include "settings/settings.h" #include "fabric.h" +#include "kubeimage.h" #include @@ -62,4 +63,6 @@ void FrameworkPlugin::registerTypes (const char *uri) qmlRegisterType(uri, 1, 0, "Listener"); qmlRegisterSingletonType(uri, 1, 0, "Fabric", fabric_singletontype_provider); + + qmlRegisterType(uri, 1, 0, "KubeImage"); } diff --git a/framework/src/kubeimage.cpp b/framework/src/kubeimage.cpp new file mode 100644 index 00000000..4fec7f3d --- /dev/null +++ b/framework/src/kubeimage.cpp @@ -0,0 +1,24 @@ +#include "kubeimage.h" + +#include +#include +#include + +KubeImage::KubeImage(QQuickItem *parent) + :QQuickItem(parent) +{ + setFlag(QQuickItem::ItemHasContents); +} + +QSGNode *KubeImage::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *updatePaintNodeData) +{ + QSGSimpleTextureNode *node = static_cast(oldNode); + if (!node) { + node = new QSGSimpleTextureNode(); + auto img = QImage::fromData(mImageData); + QSGTexture *texture = window()->createTextureFromImage(img); + node->setTexture(texture); + } + node->setRect(boundingRect()); + return node; +} diff --git a/framework/src/kubeimage.h b/framework/src/kubeimage.h new file mode 100644 index 00000000..da4efed0 --- /dev/null +++ b/framework/src/kubeimage.h @@ -0,0 +1,15 @@ + +#include + +class KubeImage : public QQuickItem { + Q_OBJECT + Q_PROPERTY(QByteArray imageData MEMBER mImageData) +public: + KubeImage(QQuickItem *parent = nullptr); + +protected: + QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *updatePaintNodeData) Q_DECL_OVERRIDE; + +private: + QByteArray mImageData; +}; -- cgit v1.2.3