diff options
author | Loren Burkholder <computersemiexpert@outlook.com> | 2021-08-30 20:19:17 -0400 |
---|---|---|
committer | Loren Burkholder <computersemiexpert@outlook.com> | 2021-09-11 19:35:31 -0400 |
commit | dcdf00dcc5785be21514e6eb4cebe78f39691e7f (patch) | |
tree | 4df4194b1fc4d968f24e6b125ab1b90a7150dac1 /src | |
parent | Use better id loading methodology (diff) | |
download | nheko-dcdf00dcc5785be21514e6eb4cebe78f39691e7f.tar.xz |
Finish fixing rounded avatars
Diffstat (limited to 'src')
-rw-r--r-- | src/JdenticonProvider.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/JdenticonProvider.cpp b/src/JdenticonProvider.cpp index 5495b2d3..c76e2b23 100644 --- a/src/JdenticonProvider.cpp +++ b/src/JdenticonProvider.cpp @@ -19,6 +19,25 @@ #include "Utils.h" #include "jdenticoninterface.h" +static QPixmap +clipRadius(QPixmap img, double radius) +{ + QPixmap out(img.size()); + out.fill(Qt::transparent); + + QPainter painter(&out); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setRenderHint(QPainter::SmoothPixmapTransform, true); + + QPainterPath ppath; + ppath.addRoundedRect(img.rect(), radius, radius, Qt::SizeMode::RelativeSize); + + painter.setClipPath(ppath); + painter.drawPixmap(img.rect(), img); + + return out; +} + JdenticonResponse::JdenticonResponse(const QString &key, bool crop, double radius, @@ -37,19 +56,20 @@ void JdenticonResponse::run() { m_pixmap.fill(Qt::transparent); - QPainter painter{&m_pixmap}; + + QPainter painter; + painter.begin(&m_pixmap); painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::SmoothPixmapTransform, true); - QPainterPath ppath; - ppath.addRoundedRect(m_pixmap.rect(), m_radius, m_radius); - - painter.setClipPath(ppath); - QSvgRenderer renderer{ jdenticonInterface_->generate(m_key, m_requestedSize.width()).toUtf8()}; renderer.render(&painter); + painter.end(); + + m_pixmap = clipRadius(m_pixmap, m_radius); + emit finished(); } @@ -64,7 +84,7 @@ getJdenticonInterface() bool plugins = pluginsDir.cd("plugins"); if (plugins) { - for (QString fileName : pluginsDir.entryList(QDir::Files)) { + for (const QString &fileName : pluginsDir.entryList(QDir::Files)) { QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); QObject *plugin = pluginLoader.instance(); if (plugin) { |