Update libqmatrixclient && put string to color inline.

This commit is contained in:
Black Hat 2018-11-04 20:03:45 +08:00
parent 5a46810016
commit b7dc378c65
3 changed files with 13 additions and 15 deletions

@ -1 +1 @@
Subproject commit 7c7ce3d468af242364efb53e77ed12047b6a5382 Subproject commit a81383549df4db8a487a847dca41900f3ab38c27

View File

@ -6,6 +6,16 @@
ImageItem::ImageItem(QQuickItem *parent) : QQuickPaintedItem(parent) {} 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) { void ImageItem::paint(QPainter *painter) {
QRectF bounding_rect = boundingRect(); QRectF bounding_rect = boundingRect();
@ -69,9 +79,8 @@ void ImageItem::setPaintable(Paintable *paintable) {
if (!paintable) return; if (!paintable) return;
disconnect(m_paintable); disconnect(m_paintable);
m_paintable = paintable; m_paintable = paintable;
connect(m_paintable, &Paintable::paintableChanged, this, [=] { connect(m_paintable, &Paintable::paintableChanged, this,
this->update(); [=] { this->update(); });
});
emit paintableChanged(); emit paintableChanged();
update(); update();
} }
@ -99,13 +108,3 @@ void ImageItem::setRound(bool value) {
update(); 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;
}

View File

@ -47,7 +47,6 @@ class ImageItem : public QQuickPaintedItem {
QString m_color; QString m_color;
bool m_round = true; bool m_round = true;
QString stringtoColor(QString string);
void paintHint(QPainter* painter, QRectF bounding_rect); void paintHint(QPainter* painter, QRectF bounding_rect);
}; };