Commit 908e4b3d authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Allow learner to select profile image.

Profile images can be set in user profile settings and are
saved in shared data storage. All images are resized to 120x120.
parent f51c7eec
......@@ -38,6 +38,7 @@ target_link_libraries(
learnerprofile
LINK_PRIVATE
${KDE4_KDECORE_LIBS}
${KDE4_KFILE_LIBS}
${QT_QTSQL_LIBRARY}
)
......
/*
* Copyright 2013 Andreas Cord-Landwehr <cordlandwehr@kde.org>
* Copyright 2013-2014 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -22,7 +22,11 @@
#include "learner_p.h"
#include "learninggoal.h"
#include <QHash>
#include <QFileInfo>
#include <QPixmap>
#include <KDebug>
#include <KGlobal>
#include <KStandardDirs>
using namespace LearnerProfile;
......@@ -67,6 +71,28 @@ void Learner::setIdentifier(int identifier)
emit identifierChanged();
}
QString Learner::imageUrl() const
{
QString path = d->imageUrl();
if (!QFileInfo(path).exists()) {
return QString();
}
return path;
}
void Learner::importImage(const QString &path)
{
if (!QFileInfo(path).exists()) {
kWarning() << "image path points to a non-existing file, aborting: " << path;
return;
}
QPixmap image = QPixmap(path);
image = image.scaled(120, 120);
image.save(d->imageUrl());
emit imageUrlChanged();
kDebug() << "saved scaled image from " << path << " at " << d->imageUrl();
}
QList< LearningGoal* > Learner::goals() const
{
return d->m_goals;
......
/*
* Copyright 2013 Andreas Cord-Landwehr <cordlandwehr@kde.org>
* Copyright 2013-2014 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -38,6 +38,7 @@ class LIBLEARNERPROFILE_EXPORT Learner : public QObject
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(int id READ identifier WRITE setIdentifier NOTIFY identifierChanged)
Q_PROPERTY(QString imageUrl READ imageUrl NOTIFY imageUrlChanged)
Q_PROPERTY(QList<LearnerProfile::LearningGoal*> goals READ goals NOTIFY goalCountChanged)
public:
......@@ -56,6 +57,8 @@ public:
QString name() const;
void setName(const QString &name);
QString imageUrl() const;
void importImage(const QString &path);
int identifier() const;
void setIdentifier(int identifier);
QList<LearningGoal *> goals() const;
......@@ -68,6 +71,7 @@ public:
Q_SIGNALS:
void nameChanged();
void imageUrlChanged();
void identifierChanged();
void goalAboutToBeAdded(LearningGoal*,int);
void goalAdded();
......
/*
* Copyright 2013 Andreas Cord-Landwehr <cordlandwehr@kde.org>
* Copyright 2013-2014 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -24,6 +24,8 @@
#include <QString>
#include <QList>
#include <QHash>
#include <KGlobal>
#include <KStandardDirs>
#include "learninggoal.h"
namespace LearnerProfile
......@@ -37,10 +39,15 @@ public:
: m_name(QString())
, m_identifier(-1)
{
}
~LearnerPrivate() {}
QString imageUrl() const
{
QString relPath = QString("images/learner%1.png").arg(m_identifier);
return KGlobal::dirs()->locateLocal("appdata", relPath);
}
QString m_name;
int m_identifier;
QList<LearningGoal*> m_goals;
......
/*
* Copyright 2013 Andreas Cord-Landwehr <cordlandwehr@kde.org>
* Copyright 2013-2014 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -25,10 +25,13 @@
#include <QObject>
#include <QList>
#include <KDebug>
#include <KFileDialog>
#include <QtGui>
#include <KLocale>
using namespace LearnerProfile;
ProfileManager::ProfileManager(QObject* parent)
ProfileManager::ProfileManager(QObject *parent)
: QObject(parent)
, d(new ProfileManagerPrivate)
{
......@@ -58,6 +61,12 @@ int ProfileManager::profileCount() const
return profiles().length();
}
void ProfileManager::openImageFileDialog()
{
KUrl imageUrl = KFileDialog::getImageOpenUrl();
d->m_activeProfile->importImage(imageUrl.toLocalFile());
}
Learner * ProfileManager::addProfile(const QString &name)
{
Learner *learner = new Learner(this);
......
......@@ -49,6 +49,7 @@ public:
Q_INVOKABLE LearnerProfile::Learner * addProfile(const QString &name);
Q_INVOKABLE void removeProfile(LearnerProfile::Learner *learner);
Q_INVOKABLE LearnerProfile::Learner * profile(int index);
Q_INVOKABLE void openImageFileDialog();
QList< LearningGoal* > goals() const;
/**
* Register learning goal if not registered yet. The registered goals will be stored at the
......
......@@ -49,8 +49,26 @@ PlasmaComponents.Page {
id: imageLearner
width: 120
height: 120
anchors { right: root.right; topMargin: 30; rightMargin: 30; top: root.top }
source: "../images/user-identity.png"
anchors {
top: root.top
right: root.right
topMargin: 30
rightMargin: 30
}
cache: false
source: profile.imageUrl ? profile.imageUrl : "../images/user-identity.png"
Connections {
target: profile
onImageUrlChanged: {
imageLearner.source = "" // trigger reload
if (profile.imageUrl) {
imageLearner.source = profile.imageUrl
} else {
imageLearner.source = "../images/user-identity.png"
}
}
}
}
PlasmaComponents.Label {
......@@ -85,6 +103,11 @@ PlasmaComponents.Page {
enabled: profileManager.profileCount > 1
onClicked: root.state = "deleteConfirmation"
}
PlasmaComponents.ToolButton {
iconSource: "insert-image"
text: i18n("Change Image")
onClicked: profileManager.openImageFileDialog()
}
}
Item {
......
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