mirror of
https://github.com/nextcloud/desktop.git
synced 2024-12-16 02:31:37 +03:00
Avatar: Set a circle mask around the avatar image.
The server displays the avatar cut into a circle, and so we do.
This commit is contained in:
parent
c00e3e8c0a
commit
e95b73dfac
1 changed files with 21 additions and 2 deletions
|
@ -40,6 +40,8 @@
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QWidgetAction>
|
#include <QWidgetAction>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPainterPath>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const char TOOLBAR_CSS[] =
|
const char TOOLBAR_CSS[] =
|
||||||
|
@ -54,6 +56,23 @@ namespace {
|
||||||
|
|
||||||
namespace OCC {
|
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 !
|
// 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"),
|
accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"),
|
||||||
actionText);
|
actionText);
|
||||||
} else {
|
} else {
|
||||||
QIcon icon(avatar);
|
QIcon icon = circleMask(avatar);
|
||||||
accountAction = createActionWithIcon(icon, actionText);
|
accountAction = createActionWithIcon(icon, actionText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +253,7 @@ void SettingsDialog::slotAccountAvatarChanged()
|
||||||
if( action ) {
|
if( action ) {
|
||||||
QPixmap pix = account->avatar();
|
QPixmap pix = account->avatar();
|
||||||
if( !pix.isNull() ) {
|
if( !pix.isNull() ) {
|
||||||
action->setIcon( QIcon(pix) );
|
action->setIcon( circleMask(pix) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue