Commit a13b48c3 authored by Edric Milaret's avatar Edric Milaret

ui: make photo round

Change-Id: I5738d1a435b0587ad1b1a9d0639ba7ea8f83bedf
Tuleap: #148
parent d0b3375f
......@@ -29,7 +29,7 @@
namespace Interfaces {
PixbufManipulator::PixbufManipulator()
: fallbackAvatar_( QImage(":/images/user/btn-default-userpic.svg"))
: fallbackAvatar_(QImage(":/images/user/btn-default-userpic.svg"))
{}
QImage
......@@ -147,26 +147,35 @@ QVariant PixbufManipulator::decorationRole(const QModelIndex& index)
QVariant PixbufManipulator::decorationRole(const Call* c)
{
QImage photo;
if (c && c->peerContactMethod()
&& c->peerContactMethod()->contact()
&& c->peerContactMethod()->contact()->photo().isValid()) {
return c->peerContactMethod()->contact()->photo().value<QImage>();
photo = c->peerContactMethod()->contact()->photo().value<QImage>();
}
return QVariant::fromValue(scaleAndFrame(fallbackAvatar_, imgSize_));
else
photo = fallbackAvatar_;
return QVariant::fromValue(scaleAndFrame(photo, imgSize_));
}
QVariant PixbufManipulator::decorationRole(const ContactMethod* cm)
{
QImage photo;
if (cm && cm->contact() && cm->contact()->photo().isValid())
return cm->contact()->photo().value<QImage>();
return QVariant::fromValue(scaleAndFrame(fallbackAvatar_, imgSize_));
photo = cm->contact()->photo().value<QImage>();
else
photo = fallbackAvatar_;
return QVariant::fromValue(scaleAndFrame(photo, imgSize_));
}
QVariant PixbufManipulator::decorationRole(const Person* p)
{
QImage photo;
if (p && p->photo().isValid())
return p->photo();
return QVariant::fromValue(scaleAndFrame(fallbackAvatar_, imgSize_));
photo = p->photo().value<QImage>();
else
photo = fallbackAvatar_;
return QVariant::fromValue(scaleAndFrame(photo, imgSize_));
}
} // namespace Interfaces
......@@ -40,6 +40,8 @@ SmartListDelegate::paint(QPainter* painter
) const
{
QStyleOptionViewItem opt(option);
painter->setRenderHint(QPainter::Antialiasing);
opt.decorationSize = QSize(sizeImage_, sizeImage_);
opt.decorationPosition = QStyleOptionViewItem::Left;
opt.decorationAlignment = Qt::AlignCenter;
if (opt.state & QStyle::State_HasFocus)
......
......@@ -19,6 +19,7 @@
#include "windowscontactbackend.h"
#include <QtXml>
#include <QPainter>
#include "personmodel.h"
#include "categorizedcontactmodel.h"
......@@ -289,8 +290,7 @@ WindowsContactBackend::getPersonFromContactFile(const QDir& contactDir,
QImage photo;
photo.load(photoValue);
if (not photo.isNull())
p->setPhoto(photo.scaled(sizePhoto_,sizePhoto_, Qt::KeepAspectRatio,
Qt::SmoothTransformation));
p->setPhoto(getCirclePhoto(photo));
}
}
else if (name == "EmailAddress") {
......@@ -345,6 +345,23 @@ WindowsContactBackend::getPersonFromContactFile(const QDir& contactDir,
}
}
QImage WindowsContactBackend::getCirclePhoto(const QImage original)
{
QImage target(sizePhoto_, sizePhoto_, QImage::Format_ARGB32_Premultiplied);
target.fill(Qt::transparent);
QPainter painter(&target);
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
painter.setBrush(QBrush(Qt::white));
painter.drawEllipse(0, 0, sizePhoto_, sizePhoto_);
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.drawImage(0, 0,
original
.scaled(60, 60, Qt::KeepAspectRatio, Qt::SmoothTransformation)
.convertToFormat(QImage::Format_ARGB32_Premultiplied));
return target;
}
bool
WindowsContactBackend::reload()
{
......
......@@ -55,6 +55,7 @@ private:
private:
bool getPersonFromContactFile(const QDir &contactDir, const QString& contactFileName);
QImage getCirclePhoto(const QImage original);
};
class WindowsContactEditor : public CollectionEditor<Person>
......
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