Avatar: Use QImage instead of QPixmap to avoid dep on QApplication.

That fixes the test suite.
This commit is contained in:
Klaas Freitag 2017-03-09 22:34:36 +01:00
parent e95b73dfac
commit 5e33898a08
7 changed files with 20 additions and 20 deletions

View file

@ -56,7 +56,7 @@ namespace {
namespace OCC { namespace OCC {
static QIcon circleMask( const QPixmap& avatar ) static QIcon circleMask( const QImage& avatar )
{ {
int dim = avatar.width(); int dim = avatar.width();
@ -67,7 +67,7 @@ static QIcon circleMask( const QPixmap& avatar )
QPainterPath clip; QPainterPath clip;
clip.addEllipse(0, 0, dim, dim); clip.addEllipse(0, 0, dim, dim);
imgPainter.setClipPath(clip); imgPainter.setClipPath(clip);
imgPainter.drawPixmap(0, 0, dim, dim, avatar); imgPainter.drawImage(0, 0, avatar);
imgPainter.end(); imgPainter.end();
return QIcon(fixedImage); return QIcon(fixedImage);
@ -216,7 +216,7 @@ void SettingsDialog::accountAdded(AccountState *s)
bool brandingSingleAccount = !Theme::instance()->multiAccount(); bool brandingSingleAccount = !Theme::instance()->multiAccount();
QAction *accountAction; QAction *accountAction;
QPixmap avatar = s->account()->avatar(); QImage avatar = s->account()->avatar();
const QString actionText = brandingSingleAccount ? tr("Account") : s->account()->displayName(); const QString actionText = brandingSingleAccount ? tr("Account") : s->account()->displayName();
if(avatar.isNull()) { if(avatar.isNull()) {
accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"), accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"),
@ -251,7 +251,7 @@ void SettingsDialog::slotAccountAvatarChanged()
if( account && _actionForAccount.contains(account)) { if( account && _actionForAccount.contains(account)) {
QAction *action = _actionForAccount[account]; QAction *action = _actionForAccount[account];
if( action ) { if( action ) {
QPixmap pix = account->avatar(); QImage pix = account->avatar();
if( !pix.isNull() ) { if( !pix.isNull() ) {
action->setIcon( circleMask(pix) ); action->setIcon( circleMask(pix) );
} }

View file

@ -90,13 +90,13 @@ void Account::setDavUser(const QString &newDavUser)
_davUser = newDavUser; _davUser = newDavUser;
} }
QPixmap Account::avatar() const QImage Account::avatar() const
{ {
return _avatarPixmap; return _avatarImg;
} }
void Account::setAvatar(const QPixmap& pixmap) void Account::setAvatar(const QImage &img)
{ {
_avatarPixmap = pixmap; _avatarImg = img;
emit accountChangedAvatar(); emit accountChangedAvatar();
} }

View file

@ -80,8 +80,8 @@ public:
QString davUser() const; QString davUser() const;
void setDavUser(const QString &newDavUser); void setDavUser(const QString &newDavUser);
QPixmap avatar() const; QImage avatar() const;
void setAvatar(const QPixmap& pixmap); void setAvatar(const QImage& img);
/// The name of the account as shown in the toolbar /// The name of the account as shown in the toolbar
QString displayName() const; QString displayName() const;
@ -216,7 +216,7 @@ private:
QWeakPointer<Account> _sharedThis; QWeakPointer<Account> _sharedThis;
QString _id; QString _id;
QString _davUser; QString _davUser;
QPixmap _avatarPixmap; QImage _avatarImg;
QMap<QString, QVariant> _settingsMap; QMap<QString, QVariant> _settingsMap;
QUrl _url; QUrl _url;
QList<QSslCertificate> _approvedCerts; QList<QSslCertificate> _approvedCerts;

View file

@ -256,15 +256,15 @@ void ConnectionValidator::slotUserFetched(const QVariantMap &json)
AvatarJob *job = new AvatarJob(_account, this); AvatarJob *job = new AvatarJob(_account, this);
job->setTimeout(20*1000); job->setTimeout(20*1000);
QObject::connect(job, SIGNAL(avatarPixmap(QPixmap)), this, SLOT(slotAvatarPixmap(QPixmap))); QObject::connect(job, SIGNAL(avatarPixmap(QImage)), this, SLOT(slotAvatarImage(QImage)));
job->start(); job->start();
} }
} }
void ConnectionValidator::slotAvatarPixmap(const QPixmap& pixmap) void ConnectionValidator::slotAvatarImage(const QImage& img)
{ {
_account->setAvatar(pixmap); _account->setAvatar(img);
reportResult(Connected); reportResult(Connected);
} }

View file

@ -71,7 +71,7 @@ namespace OCC {
+-> slotUserFetched +-> slotUserFetched
AvatarJob AvatarJob
| |
+-> slotAvatarPixmap --> reportResult() +-> slotAvatarImage --> reportResult()
\endcode \endcode
*/ */
@ -122,7 +122,7 @@ protected slots:
void slotCapabilitiesRecieved(const QVariantMap&); void slotCapabilitiesRecieved(const QVariantMap&);
void slotUserFetched(const QVariantMap &); void slotUserFetched(const QVariantMap &);
void slotAvatarPixmap(const QPixmap&); void slotAvatarImage(const QImage &img);
private: private:
void reportResult(Status status); void reportResult(Status status);

View file

@ -608,19 +608,19 @@ bool AvatarJob::finished()
{ {
int http_result_code = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); int http_result_code = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QPixmap avPixmap; QImage avImage;
if (http_result_code == 200) { if (http_result_code == 200) {
QByteArray pngData = reply()->readAll(); QByteArray pngData = reply()->readAll();
if( pngData.size() ) { if( pngData.size() ) {
if( avPixmap.loadFromData(pngData) ) { if( avImage.loadFromData(pngData) ) {
qDebug() << "Retrieved Avatar pixmap!"; qDebug() << "Retrieved Avatar pixmap!";
} }
} }
} }
emit(avatarPixmap(avPixmap)); emit(avatarPixmap(avImage));
return true; return true;
} }

View file

@ -150,7 +150,7 @@ signals:
* @brief avatarPixmap - returns either a valid pixmap or not. * @brief avatarPixmap - returns either a valid pixmap or not.
*/ */
void avatarPixmap(QPixmap); void avatarPixmap(QImage);
private slots: private slots:
virtual bool finished() Q_DECL_OVERRIDE; virtual bool finished() Q_DECL_OVERRIDE;