From e95b73dfac91375e6bdb88d109246f9d3d77afd2 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Mon, 23 Jan 2017 21:36:18 +0100 Subject: [PATCH] Avatar: Set a circle mask around the avatar image. The server displays the avatar cut into a circle, and so we do. --- src/gui/settingsdialog.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index 665738cd4..173466a52 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -40,6 +40,8 @@ #include #include #include +#include +#include namespace { const char TOOLBAR_CSS[] = @@ -54,6 +56,23 @@ namespace { namespace OCC { +static QIcon circleMask( const QPixmap& avatar ) +{ + int dim = avatar.width(); + + QPixmap fixedImage(dim, dim); + fixedImage.fill(Qt::transparent); + + QPainter imgPainter(&fixedImage); + QPainterPath clip; + clip.addEllipse(0, 0, dim, dim); + imgPainter.setClipPath(clip); + imgPainter.drawPixmap(0, 0, dim, dim, avatar); + imgPainter.end(); + + return QIcon(fixedImage); +} + // // Whenever you change something here check both settingsdialog.cpp and settingsdialogmac.cpp ! // @@ -203,7 +222,7 @@ void SettingsDialog::accountAdded(AccountState *s) accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"), actionText); } else { - QIcon icon(avatar); + QIcon icon = circleMask(avatar); accountAction = createActionWithIcon(icon, actionText); } @@ -234,7 +253,7 @@ void SettingsDialog::slotAccountAvatarChanged() if( action ) { QPixmap pix = account->avatar(); if( !pix.isNull() ) { - action->setIcon( QIcon(pix) ); + action->setIcon( circleMask(pix) ); } } }