From cee0edbd45694a05faf3a0b730957f3687cada6b Mon Sep 17 00:00:00 2001 From: defnax Date: Thu, 31 Dec 2020 16:36:04 +0100 Subject: [PATCH] Display to show the wire headshots as circle avatar --- .../src/gui/TheWire/WireGroupItem.cpp | 34 +++++++++++++++++-- .../src/gui/TheWire/WireGroupItem.ui | 22 ++++++++++-- .../src/gui/qss/stylesheet/Standard.qss | 4 +++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/TheWire/WireGroupItem.cpp b/retroshare-gui/src/gui/TheWire/WireGroupItem.cpp index 0355fe279..8ab62260a 100644 --- a/retroshare-gui/src/gui/TheWire/WireGroupItem.cpp +++ b/retroshare-gui/src/gui/TheWire/WireGroupItem.cpp @@ -22,6 +22,10 @@ #include #include #include +#include +#include +#include +#include #include "WireGroupItem.h" #include "WireGroupDialog.h" @@ -31,6 +35,27 @@ #include #include +static QImage getCirclePhoto(const QImage original, int sizePhoto) +{ + QImage target(sizePhoto, sizePhoto, QImage::Format_ARGB32_Premultiplied); + target.fill(Qt::transparent); + + QPainter painter(&target); + painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); + painter.setBrush(QBrush(Qt::white)); + auto scaledPhoto = original + .scaled(sizePhoto, sizePhoto, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation) + .convertToFormat(QImage::Format_ARGB32_Premultiplied); + int margin = 0; + if (scaledPhoto.width() > sizePhoto) { + margin = (scaledPhoto.width() - sizePhoto) / 2; + } + painter.drawEllipse(0, 0, sizePhoto, sizePhoto); + painter.setCompositionMode(QPainter::CompositionMode_SourceIn); + painter.drawImage(0, 0, scaledPhoto, margin, 0); + return target; +} + /** Constructor */ WireGroupItem::WireGroupItem(WireGroupHolder *holder, const RsWireGroup &grp) @@ -54,7 +79,7 @@ void WireGroupItem::setup() label_groupName->setText(QString::fromStdString(mGroup.mMeta.mGroupName)); label_authorId->setId(mGroup.mMeta.mAuthorId); frame_details->setVisible(false); - + if (mGroup.mHeadshot.mData ) { QPixmap pixmap; @@ -63,7 +88,12 @@ void WireGroupItem::setup() mGroup.mHeadshot.mSize, pixmap,GxsIdDetails::ORIGINAL)) { - pixmap = pixmap.scaled(32,32); + //make avatar as circle avatar + QImage orginalImage = pixmap.toImage(); + QImage circleImage = getCirclePhoto(orginalImage,orginalImage.size().width()); + pixmap.convertFromImage(circleImage); + + pixmap = pixmap.scaled(40,40); label_headshot->setPixmap(pixmap); } } diff --git a/retroshare-gui/src/gui/TheWire/WireGroupItem.ui b/retroshare-gui/src/gui/TheWire/WireGroupItem.ui index db3ebc72b..2da79ddc6 100644 --- a/retroshare-gui/src/gui/TheWire/WireGroupItem.ui +++ b/retroshare-gui/src/gui/TheWire/WireGroupItem.ui @@ -35,14 +35,32 @@ QFrame::Raised + + 6 + + + 6 + + + 6 + + + 6 + + + + 40 + 40 + + - 32 - 32 + 40 + 40 diff --git a/retroshare-gui/src/gui/qss/stylesheet/Standard.qss b/retroshare-gui/src/gui/qss/stylesheet/Standard.qss index cdc3fe129..8f5a78ee7 100644 --- a/retroshare-gui/src/gui/qss/stylesheet/Standard.qss +++ b/retroshare-gui/src/gui/qss/stylesheet/Standard.qss @@ -1128,6 +1128,10 @@ PulseReply #line_replyLine , PulseMessage #line{ color: #7ecbfb; } +PulseReply QLabel#label_groupName{ + color: #5b7083; +} + WireDialog QLabel#label_viewMode { font-size: 12pt; }