Skip to content

Commit

Permalink
Avatar: macOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
guruz committed Apr 12, 2017
1 parent 5e33898 commit 554d1b8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/3rdparty/qtmacgoodies
38 changes: 38 additions & 0 deletions src/gui/settingsdialogmac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,30 @@
#include <QPushButton>
#include <QDebug>
#include <QSettings>
#include <QPainter>
#include <QPainterPath>

namespace OCC {

// Duplicate in settingsdialog.cpp
static QIcon circleMask( const QImage& 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.drawImage(0, 0, avatar);
imgPainter.end();

return QIcon(fixedImage);
}


//
// Whenever you change something here check both settingsdialog.cpp and settingsdialogmac.cpp !
//
Expand Down Expand Up @@ -125,6 +146,8 @@ void SettingsDialogMac::accountAdded(AccountState *s)
connect( accountSettings, &AccountSettings::folderChanged, _gui, &ownCloudGui::slotFoldersChanged);
connect( accountSettings, &AccountSettings::openFolderAlias, _gui, &ownCloudGui::slotFolderOpenAction);

connect(s->account().data(), SIGNAL(accountChangedAvatar()), this, SLOT(slotAccountAvatarChanged()));

slotRefreshActivity(s);
}

Expand All @@ -147,4 +170,19 @@ void SettingsDialogMac::slotRefreshActivity( AccountState* accountState )
}
}

void SettingsDialogMac::slotAccountAvatarChanged()
{
Account *account = static_cast<Account*>(sender());
auto list = findChildren<AccountSettings*>(QString());
foreach(auto p, list) {
if (p->accountsState()->account() == account) {
int idx = indexForPanel(p);
QImage pix = account->avatar();
if (!pix.isNull()) {
setPreferencesPanelIcon(idx, circleMask(pix));
}
}
}
}

}
1 change: 1 addition & 0 deletions src/gui/settingsdialogmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public slots:
private slots:
void accountAdded(AccountState *);
void accountRemoved(AccountState *);
void slotAccountAvatarChanged();
private:
void closeEvent(QCloseEvent *event);

Expand Down

0 comments on commit 554d1b8

Please sign in to comment.