Commit 6e9f09ef authored by Jonah Brüchert's avatar Jonah Brüchert 🌳

Implement setting a photo

parent cc96d95e
......@@ -20,6 +20,7 @@
import QtQuick 2.6
import QtQuick.Controls 2.2 as Controls
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.1
import org.kde.kirigami 2.4 as Kirigami
import org.kde.people 1.0 as KPeople
import org.kde.kcontacts 1.0 as KContacts
......@@ -83,6 +84,33 @@ Kirigami.ScrollablePage {
id: form
wideMode: true
Controls.Button {
Kirigami.FormData.label: i18n("Photo")
// Square button
implicitWidth: Kirigami.Units.gridUnit * 5
implicitHeight: implicitWidth
contentItem: Item {
// Doesn't like to be scaled when being the direct contentItem
Kirigami.Icon {
anchors.fill: parent
anchors.margins: Kirigami.Units.smallSpacing
source: fileDialog.fileUrl != "" ? fileDialog.fileUrl : root.person.photo
}
}
FileDialog {
id: fileDialog
selectExisting: true
selectMultiple: false
onAccepted: addressee.addPhotoFromFile(fileUrl)
}
onClicked: {
fileDialog.open()
}
}
Controls.TextField {
id: name
Kirigami.FormData.label: i18n("Name:")
......
......@@ -23,6 +23,9 @@
#include <QStandardPaths>
#include <QCryptographicHash>
#include <QFile>
#include <QWindow>
#include <KContacts/Picture>
#include "phonesmodel.h"
#include "imppmodel.h"
......@@ -53,6 +56,25 @@ ImppModel* Addressee::impps() const
return m_imppModel;
}
void Addressee::setPhoto(QImage &data) {
auto photo = m_addressee.photo();
// Scale the photo down to make sure contacts are not taking too
// long time to load their photos
QSize size(200, 200);
photo.setData(data.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation));
m_addressee.setPhoto(photo);
}
QImage Addressee::photo() {
return m_addressee.photo().data();
}
Q_SCRIPTABLE void Addressee::addPhotoFromFile(const QString &path) {
QImage image(QUrl(path).toLocalFile());
setPhoto(image);
}
Addressee::Addressee(QObject* parent)
: QObject(parent)
, m_phonesModel(new PhonesModel(this))
......
......@@ -23,6 +23,7 @@
#include <KContacts/VCardConverter>
#include <QObject>
#include <QImage>
#define PROPERTY(type, name, setName) \
type name() const { return m_addressee.name(); }\
......@@ -54,6 +55,10 @@ public:
Q_PROPERTY(ImppModel* impps READ impps CONSTANT)
ImppModel* impps() const;
Q_PROPERTY(QImage photo READ photo WRITE setPhoto NOTIFY photoChanged)
void setPhoto(QImage &data);
QImage photo();
Q_PROPERTY(QStringList emails READ emails WRITE setEmails NOTIFY emailsChanged)
PROPERTY(QStringList, emails, setEmails)
......@@ -67,6 +72,8 @@ public:
Q_EMIT emailsChanged(emails());
}
Q_SCRIPTABLE void addPhotoFromFile(const QString &path);
QByteArray raw() const;
void setRaw(const QByteArray &raw);
......@@ -74,6 +81,7 @@ Q_SIGNALS:
void urlChanged(const QUrl &url);
void anyNameChanged();
void phoneNumbersChanged();
void photoChanged();
private:
friend class PhonesModel;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment