d->ui->setSource(QUrl("qrc:/Main.qml"));
d->ui->setResizeMode(QDeclarativeView::SizeRootObjectToView);
- d->ui->engine()->addImageProvider(QLatin1String("user"), new UserImageProvider(&d->friendModel));
+ d->ui->engine()->addImageProvider(QLatin1String("user"), new UserImageProvider(&d->friendModel, &d->profile));
d->ui->show();
GeoMap* geoMap = qobject_cast<GeoMap*>(d->ui->rootObject()->findChild<QObject*>("geoMap"));
{
qDebug() << __PRETTY_FUNCTION__;
Q_D(SituareEngine);
- if(user->type())
+ if(user->type()) {
emit userLocationReady(user);
- else
+ d->profile.setProfile(*user);
+ } else {
emit friendImageReady(user);
-
- d->friendModel.resetFriends();
+ d->friendModel.resetFriends();
+ }
}
void SituareEngine::initializeGpsAndAutocentering()
d->toggleProgressIndicator(false);
emit userLocationReady(user);
- d->profile.setAddress(user->address());
- d->profile.setImageUrl(user->profileImageUrl().toString());
- d->profile.setMessage(user->note());
- d->profile.setName(user->name());
- d->profile.setTime(user->timestamp());
+ d->profile.setProfile(*user);
emit friendsLocationsReady(friendsList);
d->friendModel.setFriends(friendsList);
import Qt 4.7
Item {
- id: delegate
-
- height: details.item.y + details.item.height + 5
-// anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter; margins: 10 }
+ id: profileView
anchors.fill: parent
- clip: true
- Rectangle {
- id: background
- anchors {
- left: parent.left
- right: parent.right
- rightMargin: border.width
- top: parent.top
- topMargin: 5
- bottom: parent.bottom
- bottomMargin: border.width
- }
+ Item {
+ id: profileItem
- gradient: Gradient {
- GradientStop {
- position: 0
- color: "#777777"
+ anchors.centerIn: parent
+ width: parent.width
+ height: childrenRect.height
+ clip: true
+
+ Rectangle {
+ id: background
+ anchors {
+ left: parent.left
+ right: parent.right
+ rightMargin: border.width
+ top: parent.top
+ topMargin: 5
+ bottom: dummyBottomMarginItem.bottom
+ bottomMargin: border.width
}
- GradientStop {
- position: 1
- color: "#222222"
+ gradient: Gradient {
+ GradientStop {
+ position: 0
+ color: "#777777"
+ }
+
+ GradientStop {
+ position: 1
+ color: "#222222"
+ }
}
+ border { width: 1; color: "#777777" }
+ radius: 5
}
- border { width: 1; color: "#777777" }
- radius: 5
- }
- Image {
- id: image
- source: userProfile.imageUrl
- anchors { horizontalCenter: parent.horizontalCenter }
- y: 4
- }
+ Image {
+ id: image
+ source: "image://user/" + userProfile.userId
+ anchors { horizontalCenter: parent.horizontalCenter }
+ y: 4
+ }
- BorderImage {
- id: borderImage
- anchors.fill: image
- anchors.margins: -8
- source: "qrc:/res/images/profile_pic_border.png"
- border.left: 24; border.top: 24
- border.right: 24; border.bottom: 24
- horizontalTileMode: BorderImage.Stretch
- verticalTileMode: BorderImage.Stretch
- }
+ BorderImage {
+ id: borderImage
+ anchors.fill: image
+ anchors.margins: -8
+ source: "qrc:/res/images/profile_pic_border.png"
+ border.left: 24; border.top: 24
+ border.right: 24; border.bottom: 24
+ horizontalTileMode: BorderImage.Stretch
+ verticalTileMode: BorderImage.Stretch
+ }
- Text {
- id: primaryText
- text: userProfile.name
- anchors { left: parent.left; right: parent.right; top: borderImage.bottom; margins: 5 }
- horizontalAlignment: Text.AlignHCenter
- clip: true;
- wrapMode: Text.Wrap
- Behavior on height {
- id: textHeightBehavior
- NumberAnimation { duration: 150 }
+ Text {
+ id: primaryText
+ text: userProfile.name
+ anchors { left: parent.left; right: parent.right; top: borderImage.bottom; margins: 5 }
+ horizontalAlignment: Text.AlignHCenter
+ clip: true;
+ wrapMode: Text.Wrap
+ Behavior on height {
+ id: textHeightBehavior
+ NumberAnimation { duration: 150 }
+ }
}
- }
- Loader {
- id: details
- z: 1
- sourceComponent: detailsComponent
- anchors { left: primaryText.left; right: primaryText.right; top: primaryText.bottom }
- }
+ Loader {
+ id: details
+ z: 1
+ sourceComponent: detailsComponent
+ anchors { left: primaryText.left; right: primaryText.right; top: primaryText.bottom }
+ }
+
+ Component {
+ id: detailsComponent
+ Item {
+ height: messageRow.height + addressRow.height + timeRow.height
+ width: parent.width
+ DetailEditorRow { id: messageRow; image: "qrc:/res/images/envelope.png"; text: userProfile.message }
+ DetailRow { id: addressRow; state: "expanded"; anchors.top: messageRow.bottom; image: "qrc:/res/images/compass.png"; text: userProfile.address }
+ DetailRow { id: timeRow; state: "expanded"; anchors.top: addressRow.bottom; image: "qrc:/res/images/clock.png"; text: userProfile.time }
+ }
+ }
- Component {
- id: detailsComponent
Item {
- height: messageRow.height + addressRow.height + timeRow.height
- width: parent.width
- DetailEditorRow { id: messageRow; image: "qrc:/res/images/envelope.png"; text: userProfile.message }
- DetailRow { id: addressRow; state: "expanded"; anchors.top: messageRow.bottom; image: "qrc:/res/images/compass.png"; text: userProfile.address }
- DetailRow { id: timeRow; state: "expanded"; anchors.top: addressRow.bottom; image: "qrc:/res/images/clock.png"; text: userProfile.time }
+ id: dummyBottomMarginItem
+ anchors { left: details.left; right: details.right; top: details.bottom }
+ height: 5
}
}
}
#include "userimageprovider.h"
#include "../user/friendmodel.h"
+#include "../user/profile.h"
-UserImageProvider::UserImageProvider(FriendModel* friendModel) :
+UserImageProvider::UserImageProvider(FriendModel* friendModel, Profile *profile) :
QDeclarativeImageProvider(QDeclarativeImageProvider::Image),
- friendModel(friendModel)
+ friendModel(friendModel),
+ profile(profile)
{
}
QImage UserImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
- Q_UNUSED(size);
- Q_UNUSED(requestedSize);
Q_ASSERT(friendModel);
+ Q_ASSERT(profile);
for (int i=0; i<friendModel->rowCount(); ++i) {
const QModelIndex index = friendModel->index(i);
const QPixmap pixmap = friendModel->data(index, FriendModel::ImageRole).value<QPixmap>();
if (!pixmap.isNull()) {
QImage image = pixmap.toImage();
+ size->setHeight(image.height());
+ size->setWidth(image.width());
if (requestedSize.isValid())
image = image.scaled(requestedSize);
return image;
break;
}
}
+ if ((profile->userId() == id) && !profile->pixmap().isNull()) {
+ QImage image = profile->pixmap().toImage();
+ size->setHeight(image.height());
+ size->setWidth(image.width());
+ if (requestedSize.isValid())
+ image = image.scaled(requestedSize);
+ return image;
+ }
+
return QImage();
}
#include <QDeclarativeImageProvider>
class FriendModel;
+class Profile;
class UserImageProvider : public QDeclarativeImageProvider
{
public:
- UserImageProvider(FriendModel* friendModel);
+ UserImageProvider(FriendModel* friendModel, Profile *profile);
virtual ~UserImageProvider();
virtual QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
private:
FriendModel* friendModel;
+ Profile* profile;
};
qDebug() << __PRETTY_FUNCTION__;
}
-const QString& Profile::name() const
+void Profile::setProfile(const User &user)
{
qDebug() << __PRETTY_FUNCTION__;
- return m_name;
-}
-
-void Profile::setName(const QString &name)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_name = name;
+ m_profile = user;
emit nameChanged();
+ emit messageChanged();
+ emit timeChanged();
+ emit addressChanged();
+ emit userIdChanged();
}
-const QString& Profile::message() const
+const QString& Profile::name() const
{
qDebug() << __PRETTY_FUNCTION__;
- return m_message;
+ return m_profile.name();
}
-void Profile::setMessage(const QString &message)
+const QString& Profile::message() const
{
qDebug() << __PRETTY_FUNCTION__;
- m_message = message;
- emit messageChanged();
+ return m_profile.note();
}
const QString& Profile::time() const
{
qDebug() << __PRETTY_FUNCTION__;
- return m_time;
-}
-
-void Profile::setTime(const QString &time)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_time = time;
- emit timeChanged();
+ return m_profile.timestamp();
}
const QString& Profile::address() const
{
qDebug() << __PRETTY_FUNCTION__;
- return m_address;
-}
-
-void Profile::setAddress(const QString &address)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_address = address;
- emit addressChanged();
+ return m_profile.address();
}
-const QString& Profile::imageUrl() const
+const QPixmap& Profile::pixmap() const
{
qDebug() << __PRETTY_FUNCTION__;
- return m_imageUrl;
+ return m_profile.profileImage();
}
-void Profile::setImageUrl(const QString &imageUrl)
+const QString& Profile::userId() const
{
qDebug() << __PRETTY_FUNCTION__;
- m_imageUrl = imageUrl;
- emit imageUrlChanged();
+ return m_profile.userId();
}
#include <QObject>
#include <QString>
+#include "user.h"
+
class Profile : public QObject
{
Q_OBJECT
- Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
- Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged)
- Q_PROPERTY(QString time READ time WRITE setTime NOTIFY timeChanged)
- Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged)
- Q_PROPERTY(QString imageUrl READ imageUrl WRITE setImageUrl NOTIFY imageUrlChanged)
+ Q_PROPERTY(QString name READ name NOTIFY nameChanged)
+ Q_PROPERTY(QString message READ message NOTIFY messageChanged)
+ Q_PROPERTY(QString time READ time NOTIFY timeChanged)
+ Q_PROPERTY(QString address READ address NOTIFY addressChanged)
+ Q_PROPERTY(QString userId READ userId NOTIFY userIdChanged)
public:
explicit Profile(QObject *parent = 0);
+ void setProfile(const User &user);
+
const QString& name() const;
- void setName(const QString &name);
const QString& message() const;
- void setMessage(const QString &message);
const QString& time() const;
- void setTime(const QString &time);
const QString& address() const;
- void setAddress(const QString &address);
- const QString& imageUrl() const;
- void setImageUrl(const QString &imageUrl);
+ const QPixmap& pixmap() const;
+
+ const QString& userId() const;
signals:
void nameChanged();
void messageChanged();
void timeChanged();
void addressChanged();
- void imageUrlChanged();
+ void userIdChanged();
private:
- QString m_name;
- QString m_message;
- QString m_time;
- QString m_address;
- QString m_imageUrl;
+ User m_profile;
};
#endif // PROFILE_H