diff --git a/QtIdenticon.pro b/QtIdenticon.pro index 2dbb9601bc14ede54577a54a6b5e6ec2c4e048d4..fd462bd2dc09455a47f3da8be419acac860330d6 100644 --- a/QtIdenticon.pro +++ b/QtIdenticon.pro @@ -3,8 +3,11 @@ ###################################################################### TEMPLATE = lib -CONFIG += plugin +CONFIG += plugin c++11 TARGET = qtjdenticon +TARGET = $$qtLibraryTarget($$TARGET) +uri = im.nheko.qtjdenticon + INCLUDEPATH = includes INCLUDEPATH += . VERSION = 0.1.0 diff --git a/src/identicon.cpp b/src/identicon.cpp index cb92b8eabfa7d90977437c80384f6bc3d6b36002..23ed0e907775d9360182a10ed037a9f52e1fee6f 100644 --- a/src/identicon.cpp +++ b/src/identicon.cpp @@ -1,7 +1,7 @@ #include "identicon.h" IdenticonStyle Identicon::defaultStyle_ = {}; -Identicon::Identicon(QByteArray &hash, int size) +Identicon::Identicon(QString &hash, int size) { size_ = size; hash_ = hash; @@ -10,18 +10,11 @@ Identicon::Identicon(QByteArray &hash, int size) Identicon Identicon::fromHash(QByteArray &hash, int size) { - Identicon fromHash(hash, size); + QString str = QString(hash); + Identicon fromHash(str, size); return fromHash; } -Identicon -Identicon::fromHash(QString &hash, int size) -{ - QByteArray hashArr = QByteArray::fromStdString(hash.toStdString()); - Identicon identicon(hashArr, size); - return identicon; -} - QString Identicon::generateSvg(Identicon &icon, bool fragment) { diff --git a/src/identicon.h b/src/identicon.h index c383f160844542951eede583497d88ef05ce6e93..16fe3d69e1bed8d1bbc00b9c7310cea659210366 100644 --- a/src/identicon.h +++ b/src/identicon.h @@ -11,14 +11,14 @@ class Identicon { private: - QByteArray hash_; + QString hash_; int size_; rendering::IconGenerator iconGenerator_; IdenticonStyle style_; static IdenticonStyle defaultStyle_; public: - Identicon(QByteArray &hash, int size); + Identicon(QString &hash, int size); int size() { return size_; } rendering::Rectangle getIconBounds(); static Identicon fromHash(QByteArray &hash, int size); diff --git a/src/identiconstyle.cpp b/src/identiconstyle.cpp index ce44a1045ccb45c3b7c0e9e6d9f2b9a94df9135a..3f6ef19a8c8c58a81812700ff1fcbb7743bbacf5 100644 --- a/src/identiconstyle.cpp +++ b/src/identiconstyle.cpp @@ -1,3 +1,5 @@ +#include <stdexcept> + #include "identiconstyle.h" #include <stdexcept> diff --git a/src/jdenticonplugin.cpp b/src/jdenticonplugin.cpp index 290bfc79d38cbd9e05707fd956d27e3664622979..f74887d4d65f54e56dbfcf886c6ff42a1033752d 100644 --- a/src/jdenticonplugin.cpp +++ b/src/jdenticonplugin.cpp @@ -5,7 +5,8 @@ QString JdenticonPlugin::generate(const QString &message, uint16_t size) { - QByteArray byteArr = QByteArray::fromStdString(message.toStdString()); - Identicon identicon(byteArr, size); + //QByteArray byteArr = QByteArray::fromStdString(message.toStdString()); + QString copy = message; + Identicon identicon(copy, size); return identicon.generateSvg(identicon, false); } diff --git a/src/jdenticonplugin.h b/src/jdenticonplugin.h index 3e5d2d5c083250a2809b99a7ab94aa696226d8dc..7aec984e68745c3db934730614473c420f987693 100644 --- a/src/jdenticonplugin.h +++ b/src/jdenticonplugin.h @@ -11,7 +11,7 @@ class JdenticonPlugin , JdenticonInterface { Q_OBJECT - Q_PLUGIN_METADATA(IID "redsky17.Qt.JdenticonInterface") + Q_PLUGIN_METADATA(IID "im.nheko.JdenticonInterface") Q_INTERFACES(JdenticonInterface) public: diff --git a/src/qtidenticon.cpp b/src/qtidenticon.cpp index ace743603b414fc7be7bf2f3f9827190f64089a3..cd77143f43fffbf4844832a3928290c8771f8ca6 100644 --- a/src/qtidenticon.cpp +++ b/src/qtidenticon.cpp @@ -13,7 +13,7 @@ main(int argc, char *argv[]) }; for (QString hash : hashes) { QByteArray hashArr = QByteArray::fromStdString(hash.toStdString()); - Identicon test(hashArr, 256); + Identicon test(hash, 256); qInfo() << hash; qInfo() << test.generateSvg(test, false); } diff --git a/src/rendering/colortheme.cpp b/src/rendering/colortheme.cpp index 9fe805f2c033cd573c58b5c42e34bfa989b68b9b..9b0ebf5d69285b5024835f97eb0e6b156725019e 100644 --- a/src/rendering/colortheme.cpp +++ b/src/rendering/colortheme.cpp @@ -1,3 +1,5 @@ +#include <stdexcept> + #include "colortheme.h" #include <stdexcept> diff --git a/src/rendering/colorutils.cpp b/src/rendering/colorutils.cpp index 41ec3cf41f7d562d0ec903a95fdbbd4639abfe60..285eb26e378911cea6a869e1a8e0ec0ab4c25bdc 100644 --- a/src/rendering/colorutils.cpp +++ b/src/rendering/colorutils.cpp @@ -1,3 +1,5 @@ +#include <stdexcept> + #include "colorutils.h" #include <stdexcept> diff --git a/src/rendering/icongenerator.cpp b/src/rendering/icongenerator.cpp index 83aab17104df64d554aedc3ba38fb0ec96da9e6d..60c1765e3203606d73cf9dbe24baa5eaa234bcdd 100644 --- a/src/rendering/icongenerator.cpp +++ b/src/rendering/icongenerator.cpp @@ -1,5 +1,6 @@ #include "icongenerator.h" +#include <QCryptographicHash> namespace rendering { QList<QPoint> IconGenerator::shapeOne_({QPoint(1, 0), @@ -34,7 +35,7 @@ IconGenerator::getCategories() } QList<shapes::Shape> -IconGenerator::getShapes(ColorTheme &theme, QByteArray &hash) +IconGenerator::getShapes(ColorTheme &theme, QString &hash) { QList<shapes::Shape> shapes; QList<int> usedColorThemeIndexes; @@ -63,6 +64,7 @@ IconGenerator::getShapes(ColorTheme &theme, QByteArray &hash) auto definitionSize = category.getDefinitions().size(); qDebug() << "definitionSize " << definitionSize; auto shape = category.getDefinitions()[octet % definitionSize]; + qDebug() << "Shape # " << (octet % definitionSize) ; auto positions = category.getPositions(); shapes::Shape newShape = {shape, theme[colorThemeIndex], positions, startRotationIndex}; shapes.append(newShape); @@ -74,12 +76,13 @@ void IconGenerator::generate(Renderer &renderer, Rectangle &rect, IdenticonStyle &style, - QByteArray &hash) + QString &input) { - auto hue = getHue(hash); + auto hue = getHue(input); qDebug() << "hue" << hue; auto colorTheme = ColorTheme(hue, style); + QString hash = QString(QCryptographicHash::hash(input.toUtf8(),QCryptographicHash::Sha1).toHex()); RenderBackground(renderer, rect, style, colorTheme, hash); RenderForeground(renderer, rect, style, colorTheme, hash); diff --git a/src/rendering/icongenerator.h b/src/rendering/icongenerator.h index 80b3852e99660a9d781eb427aab01643b58fb59b..d02816af92af6b2f7a27f5b754a31db1bb9c5c1d 100644 --- a/src/rendering/icongenerator.h +++ b/src/rendering/icongenerator.h @@ -1,6 +1,7 @@ #ifndef ICONGENERATOR_H #define ICONGENERATOR_H +#include <QString> #include <QList> #include <QtDebug> @@ -38,12 +39,12 @@ private: protected: QList<shapes::ShapeCategory> getCategories(); - virtual QList<shapes::Shape> getShapes(ColorTheme &theme, QByteArray &hash); + virtual QList<shapes::Shape> getShapes(ColorTheme &theme, QString &hash); virtual void RenderBackground(Renderer &renderer, Rectangle rect, IdenticonStyle &style, ColorTheme &colorTheme, - QByteArray &hash) + QString &hash) { Q_UNUSED(rect); Q_UNUSED(style); @@ -66,7 +67,7 @@ protected: Rectangle &rect, IdenticonStyle &style, ColorTheme &colorTheme, - QByteArray &hash) + QString &hash) { Q_UNUSED(style); // Ensure rect is quadratic and a multiple of the cell count @@ -97,9 +98,10 @@ protected: // renderer.endShape(); } } - static int hashQString(const QString &input) + + static uint32_t hashQString(const QString &input) { - auto hash = 0; + uint32_t hash = 0; for (int i = 0; i < input.length(); i++) { hash = input.at(i).digitValue() + ((hash << 5) - hash); @@ -107,34 +109,27 @@ protected: return hash; } - static qreal getHue(QByteArray &hash) + static qreal getHue(const QString &input) { // Create a color for the input - auto hashInt = hashQString(hash); + auto hash = hashQString(input); // create a hue value based on the hash of the input. - auto userHue = qAbs(hashInt % 360); + auto userHue = hash % 360; return userHue / 360.0; } - static char getOctet(QByteArray &arr, const int index) + static char getOctet(QString &arr, const int index) { - auto byteIndex = index / 2; - auto byteValue = arr.at(byteIndex); - - if (byteIndex * 2 == index) { - byteValue = byteValue >> 4; - } else { - byteValue = byteValue & 0xf; - } - - return byteValue; + char at = arr.at(index).toLatin1(); + char decval = (at >= 'A') ? (at - 'A' + 10) : (at - '0'); + return decval; } public: IconGenerator(); virtual int cellCount() { return 4; } - void generate(Renderer &renderer, Rectangle &rect, IdenticonStyle &style, QByteArray &hash); + void generate(Renderer &renderer, Rectangle &rect, IdenticonStyle &style, QString &hash); virtual ~IconGenerator() = default; };