Commit 43e91bc6 authored by Alexandre Lision's avatar Alexandre Lision

profile: add account decoration role

Put to use the other decoration roles in the ui for Persons, Call
and Accounts

Tuleap: #530
Change-Id: I04f75d346c9ba9f9b92a5038faa4aa97a70eb45c
parent f02a32b4
......@@ -231,11 +231,7 @@
result.msgView.layer.cornerRadius = 5.0f;
[result updateWidthConstraint:finalWidth];
Person* p = qvariant_cast<Person*>(qIdx.data((int)Person::Role::Object));
QVariant photo = GlobalInstances::pixmapManipulator().contactPhoto(p, QSize(50,50));
[result.photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
[result.photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(qIdx.data(Qt::DecorationRole)))];
return result;
}
......
......@@ -176,8 +176,7 @@ NSInteger const PHOTO_TAG = 400;
auto call = qvariant_cast<Call*>(qIdx.data((int)Call::Role::Object));
NSImageView* photoView = [result viewWithTag:PHOTO_TAG];
QVariant photo = GlobalInstances::pixmapManipulator().callPhoto(call, QSize(50,50));
[photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
[photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(qIdx.data(Qt::DecorationRole)))];
NSTextField* details = [result viewWithTag:DETAILS_TAG];
[details setStringValue:qIdx.data((int)Call::Role::FormattedDate).toString().toNSString()];
......
......@@ -176,8 +176,8 @@ NSInteger const CALL_BUTTON_TAG = 400;
NSImageView* photoView = [result viewWithTag:IMAGE_TAG];
Person* p = qvariant_cast<Person*>(qIdx.data((int)Person::Role::Object));
QVariant photo = GlobalInstances::pixmapManipulator().contactPhoto(p, QSize(40,40));
[photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
[photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(qIdx.data(Qt::DecorationRole)))];
[((ContextualTableCellView*) result) setContextualsControls:[NSMutableArray arrayWithObject:[result viewWithTag:CALL_BUTTON_TAG]]];
NSTextField* details = [result viewWithTag:DETAILS_TAG];
......
......@@ -241,9 +241,8 @@ NSInteger const CANCEL_BUTTON_TAG = 600;
NSTextField* displayName = [result viewWithTag:DISPLAYNAME_TAG];
[displayName setStringValue:qIdx.data((int)Ring::Role::Name).toString().toNSString()];
NSImageView* photoView = [result viewWithTag:IMAGE_TAG];
Person* p = qvariant_cast<Person*>(qIdx.data((int)Person::Role::Object));
QVariant photo = GlobalInstances::pixmapManipulator().contactPhoto(p, QSize(50,50));
[photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
[photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(qIdx.data(Qt::DecorationRole)))];
return result;
}
......
......@@ -19,6 +19,10 @@
#import <QuartzCore/QuartzCore.h>
//Qt
#import <QSize>
//Ring
#import <interfaces/pixmapmanipulatori.h>
#import <call.h>
......@@ -50,16 +54,19 @@ namespace Interfaces {
QVariant decorationRole(const Call* c) override;
QVariant decorationRole(const ContactMethod* cm) override;
QVariant decorationRole(const Person* p) override;
QVariant decorationRole(const Account* acc) override;
private:
//Helper
QPixmap drawDefaultUserPixmap(const QSize& size, bool displayPresence, bool isPresent);
QPixmap drawDefaultUserPixmap(const QSize& size, bool displayPresence = false, bool isPresent = false);
CGImageRef resizeCGImage(CGImageRef image, const QSize& size);
/**
* Return a version of size destSize centered of the bigger photo
*/
QPixmap crop(QPixmap& photo, const QSize& destSize);
const QSize decorationSize = {80,80};
};
} // namespace Interfaces
......@@ -34,6 +34,8 @@
//Ring
#import <person.h>
#import <profilemodel.h>
#import <profile.h>
#import <contactmethod.h>
namespace Interfaces {
......@@ -84,7 +86,7 @@ namespace Interfaces {
painter.drawRoundedRect(0,0,pxm.height(),pxm.height(),radius,radius);
}
else {
pxm = drawDefaultUserPixmap(size, false, false);
pxm = drawDefaultUserPixmap(size);
}
return pxm;
......@@ -130,7 +132,7 @@ namespace Interfaces {
if (n->contact()) {
return contactPhoto(n->contact(), size, displayPresence);
} else {
return drawDefaultUserPixmap(size, false, false);
return drawDefaultUserPixmap(size);
}
}
......@@ -139,8 +141,10 @@ namespace Interfaces {
QImage image;
//For now, ENCODING is only base64 and image type PNG or JPG
const bool ret = image.loadFromData(QByteArray::fromBase64(data),type.toLatin1());
if (!ret)
if (!ret) {
qDebug() << "vCard image loading failed";
return drawDefaultUserPixmap(decorationSize);
}
return QPixmap::fromImage(image);
}
......@@ -248,20 +252,33 @@ namespace Interfaces {
QVariant ImageManipulationDelegate::decorationRole(const Call* c)
{
Q_UNUSED(c)
return QVariant();
if (c && c->peerContactMethod()
&& c->peerContactMethod()->contact()) {
return contactPhoto(c->peerContactMethod()->contact(), decorationSize);
} else
return drawDefaultUserPixmap(decorationSize);
}
QVariant ImageManipulationDelegate::decorationRole(const ContactMethod* cm)
{
Q_UNUSED(cm)
return QVariant();
QImage photo;
if (cm && cm->contact() && cm->contact()->photo().isValid())
return contactPhoto(cm->contact(), decorationSize);
else
return drawDefaultUserPixmap(decorationSize);
}
QVariant ImageManipulationDelegate::decorationRole(const Person* p)
{
Q_UNUSED(p)
return QVariant();
return contactPhoto(const_cast<Person*>(p), decorationSize);
}
QVariant ImageManipulationDelegate::decorationRole(const Account* acc)
{
Q_UNUSED(acc)
if (auto pro = ProfileModel::instance().selectedProfile())
return contactPhoto(pro->person(), decorationSize);
return drawDefaultUserPixmap(decorationSize);
}
} // namespace Interfaces
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