mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-31 01:50:47 +03:00
Finish fixing rounded avatars
This commit is contained in:
parent
350fc593ed
commit
dcdf00dcc5
1 changed files with 27 additions and 7 deletions
|
@ -19,6 +19,25 @@
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "jdenticoninterface.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,
|
JdenticonResponse::JdenticonResponse(const QString &key,
|
||||||
bool crop,
|
bool crop,
|
||||||
double radius,
|
double radius,
|
||||||
|
@ -37,19 +56,20 @@ void
|
||||||
JdenticonResponse::run()
|
JdenticonResponse::run()
|
||||||
{
|
{
|
||||||
m_pixmap.fill(Qt::transparent);
|
m_pixmap.fill(Qt::transparent);
|
||||||
QPainter painter{&m_pixmap};
|
|
||||||
|
QPainter painter;
|
||||||
|
painter.begin(&m_pixmap);
|
||||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||||
|
|
||||||
QPainterPath ppath;
|
|
||||||
ppath.addRoundedRect(m_pixmap.rect(), m_radius, m_radius);
|
|
||||||
|
|
||||||
painter.setClipPath(ppath);
|
|
||||||
|
|
||||||
QSvgRenderer renderer{
|
QSvgRenderer renderer{
|
||||||
jdenticonInterface_->generate(m_key, m_requestedSize.width()).toUtf8()};
|
jdenticonInterface_->generate(m_key, m_requestedSize.width()).toUtf8()};
|
||||||
renderer.render(&painter);
|
renderer.render(&painter);
|
||||||
|
|
||||||
|
painter.end();
|
||||||
|
|
||||||
|
m_pixmap = clipRadius(m_pixmap, m_radius);
|
||||||
|
|
||||||
emit finished();
|
emit finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +84,7 @@ getJdenticonInterface()
|
||||||
|
|
||||||
bool plugins = pluginsDir.cd("plugins");
|
bool plugins = pluginsDir.cd("plugins");
|
||||||
if (plugins) {
|
if (plugins) {
|
||||||
for (QString fileName : pluginsDir.entryList(QDir::Files)) {
|
for (const QString &fileName : pluginsDir.entryList(QDir::Files)) {
|
||||||
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
|
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
|
||||||
QObject *plugin = pluginLoader.instance();
|
QObject *plugin = pluginLoader.instance();
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
|
|
Loading…
Reference in a new issue