Commit 87c999fb authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Kateryna Kostiuk

invite list: fixes fallback avatars

- adds fallback avatars for invites
- uses fallback avatar image file for contacts and invites with
  only ringIds

Change-Id: Ia7b702b17533a7aeccb777b3d851420327392b63
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent 0febcfa9
......@@ -276,6 +276,7 @@ SET_SOURCE_FILES_PROPERTIES(${myApp_ICON} PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
SET(ring_ICONS
${CMAKE_CURRENT_SOURCE_DIR}/data/default_avatar_overlay.png
${CMAKE_CURRENT_SOURCE_DIR}/data/symbol_name.png
${CMAKE_CURRENT_SOURCE_DIR}/data/background-light.png
${CMAKE_CURRENT_SOURCE_DIR}/data/background-dark.png
......
......@@ -67,6 +67,7 @@ namespace Interfaces {
private:
//Helper
QPixmap drawDefaultUserPixmap(const QSize& size, const char color, const char letter);
QPixmap drawDefaultUserPixmapUriOnly(const QSize& size, const char color);
CGImageRef resizeCGImage(CGImageRef image, const QSize& size);
QHash<QString, QPixmap> m_hDefaultUserPixmap;
......
......@@ -204,12 +204,15 @@ namespace Interfaces {
char letterForDefaultUserPixmap(const lrc::api::contact::Info& contact)
{
if (!contact.profileInfo.alias.empty())
if (!contact.profileInfo.alias.empty()) {
return std::toupper(contact.profileInfo.alias.at(0));
else if(contact.profileInfo.type == lrc::api::profile::Type::RING && !contact.registeredName.empty())
} else if((contact.profileInfo.type == lrc::api::profile::Type::RING ||
contact.profileInfo.type == lrc::api::profile::Type::PENDING) &&
!contact.registeredName.empty()) {
return std::toupper(contact.registeredName.at(0));
else
} else {
return std::toupper(contact.profileInfo.uri.at(0));
}
}
QVariant ImageManipulationDelegate::conversationPhoto(const lrc::api::conversation::Info& conversation,
......@@ -274,8 +277,16 @@ namespace Interfaces {
return pxm;
} else {
char color = contact.profileInfo.uri.at(0);
char letter = letterForDefaultUserPixmap(contact);
return drawDefaultUserPixmap(size, color, letter);
if (!contact.profileInfo.alias.empty()) {
return drawDefaultUserPixmap(size, color, std::toupper(contact.profileInfo.alias.at(0)));
} else if((contact.profileInfo.type == lrc::api::profile::Type::RING ||
contact.profileInfo.type == lrc::api::profile::Type::PENDING) &&
!contact.registeredName.empty()) {
return drawDefaultUserPixmap(size, color, std::toupper(contact.registeredName.at(0)));
} else {
return drawDefaultUserPixmapUriOnly(size, color);
}
}
} catch (const std::out_of_range& e) {
return drawDefaultUserPixmap(size, '?', '?');
......@@ -322,6 +333,36 @@ namespace Interfaces {
return avatar;
}
QPixmap ImageManipulationDelegate::drawDefaultUserPixmapUriOnly(const QSize& size, const char color) {
// We start with a transparent avatar
QPixmap avatar(size);
avatar.fill(Qt::transparent);
// We pick a color based on the passed character
QColor avColor = ImageManipulationDelegate::avatarColors_[color % 16];
// We draw a circle with this color
QPainter painter(&avatar);
painter.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
painter.setPen(Qt::transparent);
painter.setBrush(avColor);
painter.drawEllipse(avatar.rect());
// Then we paint the avatar in the circle
QRect textRect = avatar.rect();
QImage defaultAvatarImage;
QRect rect = QRect(0, 0, size.width(), size.height());
NSURL *bundleURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSString *imagePath = [bundleURL.absoluteString stringByAppendingString:@"Contents/Resources/default_avatar_overlay.png"];
if (defaultAvatarImage.load(QString::fromNSString(imagePath).mid(7))) {
painter.drawImage(avatar.rect(), defaultAvatarImage);
} else {
painter.drawText(avatar.rect(), QString('?'), QTextOption(Qt::AlignCenter));
}
return avatar;
}
CGImageRef ImageManipulationDelegate::resizeCGImage(CGImageRef image, const QSize& size) {
// create context, keeping original image properties
CGContextRef context = CGBitmapContextCreate(NULL, size.width(), size.height(),
......
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