From b7dc378c65688ad0ba3f4f7d96044c2b04461adb Mon Sep 17 00:00:00 2001 From: Black Hat Date: Sun, 4 Nov 2018 20:03:45 +0800 Subject: [PATCH] Update libqmatrixclient && put string to color inline. --- include/libqmatrixclient | 2 +- src/imageitem.cpp | 25 ++++++++++++------------- src/imageitem.h | 1 - 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/include/libqmatrixclient b/include/libqmatrixclient index 7c7ce3d..a813835 160000 --- a/include/libqmatrixclient +++ b/include/libqmatrixclient @@ -1 +1 @@ -Subproject commit 7c7ce3d468af242364efb53e77ed12047b6a5382 +Subproject commit a81383549df4db8a487a847dca41900f3ab38c27 diff --git a/src/imageitem.cpp b/src/imageitem.cpp index 3ef079a..9a1c23c 100644 --- a/src/imageitem.cpp +++ b/src/imageitem.cpp @@ -6,6 +6,16 @@ ImageItem::ImageItem(QQuickItem *parent) : QQuickPaintedItem(parent) {} +inline QString stringtoColor(QString string) { + int hash = 0; + for (int i = 0; i < string.length(); i++) + hash = string.at(i).unicode() + ((hash << 5) - hash); + QString colour = "#"; + for (int j = 0; j < 3; j++) + colour += ("00" + QString::number((hash >> (j * 8)) & 0xFF, 16)).right(2); + return colour; +} + void ImageItem::paint(QPainter *painter) { QRectF bounding_rect = boundingRect(); @@ -69,9 +79,8 @@ void ImageItem::setPaintable(Paintable *paintable) { if (!paintable) return; disconnect(m_paintable); m_paintable = paintable; - connect(m_paintable, &Paintable::paintableChanged, this, [=] { - this->update(); - }); + connect(m_paintable, &Paintable::paintableChanged, this, + [=] { this->update(); }); emit paintableChanged(); update(); } @@ -99,13 +108,3 @@ void ImageItem::setRound(bool value) { update(); } } - -QString ImageItem::stringtoColor(QString string) { - int hash = 0; - for (int i = 0; i < string.length(); i++) - hash = string.at(i).unicode() + ((hash << 5) - hash); - QString colour = "#"; - for (int j = 0; j < 3; j++) - colour += ("00" + QString::number((hash >> (j * 8)) & 0xFF, 16)).right(2); - return colour; -} diff --git a/src/imageitem.h b/src/imageitem.h index 32ab9bc..f20bdfe 100644 --- a/src/imageitem.h +++ b/src/imageitem.h @@ -47,7 +47,6 @@ class ImageItem : public QQuickPaintedItem { QString m_color; bool m_round = true; - QString stringtoColor(QString string); void paintHint(QPainter* painter, QRectF bounding_rect); };