Skip to content
Snippets Groups Projects
Commit a13b48c3 authored by Edric Milaret's avatar Edric Milaret
Browse files

ui: make photo round

Change-Id: I5738d1a435b0587ad1b1a9d0639ba7ea8f83bedf
Tuleap: #148
parent d0b3375f
No related branches found
No related tags found
No related merge requests found
...@@ -147,26 +147,35 @@ QVariant PixbufManipulator::decorationRole(const QModelIndex& index) ...@@ -147,26 +147,35 @@ QVariant PixbufManipulator::decorationRole(const QModelIndex& index)
QVariant PixbufManipulator::decorationRole(const Call* c) QVariant PixbufManipulator::decorationRole(const Call* c)
{ {
QImage photo;
if (c && c->peerContactMethod() if (c && c->peerContactMethod()
&& c->peerContactMethod()->contact() && c->peerContactMethod()->contact()
&& c->peerContactMethod()->contact()->photo().isValid()) { && 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) QVariant PixbufManipulator::decorationRole(const ContactMethod* cm)
{ {
QImage photo;
if (cm && cm->contact() && cm->contact()->photo().isValid()) if (cm && cm->contact() && cm->contact()->photo().isValid())
return cm->contact()->photo().value<QImage>(); photo = cm->contact()->photo().value<QImage>();
return QVariant::fromValue(scaleAndFrame(fallbackAvatar_, imgSize_)); else
photo = fallbackAvatar_;
return QVariant::fromValue(scaleAndFrame(photo, imgSize_));
} }
QVariant PixbufManipulator::decorationRole(const Person* p) QVariant PixbufManipulator::decorationRole(const Person* p)
{ {
QImage photo;
if (p && p->photo().isValid()) if (p && p->photo().isValid())
return p->photo(); photo = p->photo().value<QImage>();
return QVariant::fromValue(scaleAndFrame(fallbackAvatar_, imgSize_)); else
photo = fallbackAvatar_;
return QVariant::fromValue(scaleAndFrame(photo, imgSize_));
} }
} // namespace Interfaces } // namespace Interfaces
...@@ -40,6 +40,8 @@ SmartListDelegate::paint(QPainter* painter ...@@ -40,6 +40,8 @@ SmartListDelegate::paint(QPainter* painter
) const ) const
{ {
QStyleOptionViewItem opt(option); QStyleOptionViewItem opt(option);
painter->setRenderHint(QPainter::Antialiasing);
opt.decorationSize = QSize(sizeImage_, sizeImage_);
opt.decorationPosition = QStyleOptionViewItem::Left; opt.decorationPosition = QStyleOptionViewItem::Left;
opt.decorationAlignment = Qt::AlignCenter; opt.decorationAlignment = Qt::AlignCenter;
if (opt.state & QStyle::State_HasFocus) if (opt.state & QStyle::State_HasFocus)
... ...
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "windowscontactbackend.h" #include "windowscontactbackend.h"
#include <QtXml> #include <QtXml>
#include <QPainter>
#include "personmodel.h" #include "personmodel.h"
#include "categorizedcontactmodel.h" #include "categorizedcontactmodel.h"
...@@ -289,8 +290,7 @@ WindowsContactBackend::getPersonFromContactFile(const QDir& contactDir, ...@@ -289,8 +290,7 @@ WindowsContactBackend::getPersonFromContactFile(const QDir& contactDir,
QImage photo; QImage photo;
photo.load(photoValue); photo.load(photoValue);
if (not photo.isNull()) if (not photo.isNull())
p->setPhoto(photo.scaled(sizePhoto_,sizePhoto_, Qt::KeepAspectRatio, p->setPhoto(getCirclePhoto(photo));
Qt::SmoothTransformation));
} }
} }
else if (name == "EmailAddress") { else if (name == "EmailAddress") {
...@@ -345,6 +345,23 @@ WindowsContactBackend::getPersonFromContactFile(const QDir& contactDir, ...@@ -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 bool
WindowsContactBackend::reload() WindowsContactBackend::reload()
{ {
... ...
......
...@@ -55,6 +55,7 @@ private: ...@@ -55,6 +55,7 @@ private:
private: private:
bool getPersonFromContactFile(const QDir &contactDir, const QString& contactFileName); bool getPersonFromContactFile(const QDir &contactDir, const QString& contactFileName);
QImage getCirclePhoto(const QImage original);
}; };
class WindowsContactEditor : public CollectionEditor<Person> class WindowsContactEditor : public CollectionEditor<Person>
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment