mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Add some fancy effects to jdenticon
This commit is contained in:
parent
1fdecdcc21
commit
350d1977af
3 changed files with 53 additions and 7 deletions
|
@ -43,7 +43,19 @@ Rectangle {
|
||||||
id: identicon
|
id: identicon
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
visible: img.status != Image.Ready && Settings.useIdenticon
|
visible: img.status != Image.Ready && Settings.useIdenticon
|
||||||
source: Settings.useIdenticon ? "image://jdenticon/" + userid : ""
|
source: Settings.useIdenticon ? "image://jdenticon/" + userid + "?radius=" + radius : ""
|
||||||
|
layer.enabled: true
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
Ripple {
|
||||||
|
rippleTarget: parent
|
||||||
|
color: Qt.rgba(Nheko.colors.alternateBase.r, Nheko.colors.alternateBase.g, Nheko.colors.alternateBase.b, 0.5)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QPainterPath>
|
||||||
#include <QPluginLoader>
|
#include <QPluginLoader>
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
|
|
||||||
|
@ -18,8 +19,13 @@
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "jdenticoninterface.h"
|
#include "jdenticoninterface.h"
|
||||||
|
|
||||||
JdenticonResponse::JdenticonResponse(const QString &key, const QSize &requestedSize)
|
JdenticonResponse::JdenticonResponse(const QString &key,
|
||||||
|
bool crop,
|
||||||
|
double radius,
|
||||||
|
const QSize &requestedSize)
|
||||||
: m_key(key)
|
: m_key(key)
|
||||||
|
, m_crop{crop}
|
||||||
|
, m_radius{radius}
|
||||||
, m_requestedSize(requestedSize.isValid() ? requestedSize : QSize(100, 100))
|
, m_requestedSize(requestedSize.isValid() ? requestedSize : QSize(100, 100))
|
||||||
, m_pixmap{m_requestedSize}
|
, m_pixmap{m_requestedSize}
|
||||||
, jdenticonInterface_{Jdenticon::getJdenticonInterface()}
|
, jdenticonInterface_{Jdenticon::getJdenticonInterface()}
|
||||||
|
@ -32,10 +38,16 @@ JdenticonResponse::run()
|
||||||
{
|
{
|
||||||
m_pixmap.fill(Qt::transparent);
|
m_pixmap.fill(Qt::transparent);
|
||||||
QPainter painter{&m_pixmap};
|
QPainter painter{&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{
|
QSvgRenderer renderer{
|
||||||
jdenticonInterface_->generate(m_key, m_requestedSize.width()).toUtf8()};
|
jdenticonInterface_->generate(m_key, m_requestedSize.width()).toUtf8()};
|
||||||
// m_image = QImage::fromData(jdenticonInterface_->generate(m_key,
|
|
||||||
// size->width()).toUtf8());
|
|
||||||
renderer.render(&painter);
|
renderer.render(&painter);
|
||||||
|
|
||||||
emit finished();
|
emit finished();
|
||||||
|
|
|
@ -23,7 +23,7 @@ class JdenticonResponse
|
||||||
, public QRunnable
|
, public QRunnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JdenticonResponse(const QString &key, const QSize &requestedSize);
|
JdenticonResponse(const QString &key, bool crop, double radius, const QSize &requestedSize);
|
||||||
|
|
||||||
QQuickTextureFactory *textureFactory() const override
|
QQuickTextureFactory *textureFactory() const override
|
||||||
{
|
{
|
||||||
|
@ -33,6 +33,8 @@ public:
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
QString m_key;
|
QString m_key;
|
||||||
|
bool m_crop;
|
||||||
|
double m_radius;
|
||||||
QSize m_requestedSize;
|
QSize m_requestedSize;
|
||||||
QPixmap m_pixmap;
|
QPixmap m_pixmap;
|
||||||
JdenticonInterface *jdenticonInterface_ = nullptr;
|
JdenticonInterface *jdenticonInterface_ = nullptr;
|
||||||
|
@ -48,10 +50,30 @@ public:
|
||||||
static bool isAvailable() { return Jdenticon::getJdenticonInterface() != nullptr; }
|
static bool isAvailable() { return Jdenticon::getJdenticonInterface() != nullptr; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QQuickImageResponse *requestImageResponse(const QString &key,
|
QQuickImageResponse *requestImageResponse(const QString &id,
|
||||||
const QSize &requestedSize) override
|
const QSize &requestedSize) override
|
||||||
{
|
{
|
||||||
JdenticonResponse *response = new JdenticonResponse(key, requestedSize);
|
auto id_ = id;
|
||||||
|
bool crop = true;
|
||||||
|
double radius = 0;
|
||||||
|
|
||||||
|
auto queryStart = id.lastIndexOf('?');
|
||||||
|
if (queryStart != -1) {
|
||||||
|
id_ = id.left(queryStart);
|
||||||
|
auto query = id.midRef(queryStart + 1);
|
||||||
|
auto queryBits = query.split('&');
|
||||||
|
|
||||||
|
for (auto b : queryBits) {
|
||||||
|
if (b == "scale") {
|
||||||
|
crop = false;
|
||||||
|
} else if (b.startsWith("radius=")) {
|
||||||
|
radius = b.mid(7).toDouble();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JdenticonResponse *response =
|
||||||
|
new JdenticonResponse(id_, crop, radius, requestedSize);
|
||||||
pool.start(response);
|
pool.start(response);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue