mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 01:16:20 -05:00
Display to show the wire headshots as circle avatar
This commit is contained in:
parent
bfcfff4d0c
commit
cee0edbd45
@ -22,6 +22,10 @@
|
||||
#include <QMessageBox>
|
||||
#include <QMouseEvent>
|
||||
#include <QBuffer>
|
||||
#include <QPixmap>
|
||||
#include <QImage>
|
||||
#include <QSize>
|
||||
#include <QPainter>
|
||||
|
||||
#include "WireGroupItem.h"
|
||||
#include "WireGroupDialog.h"
|
||||
@ -31,6 +35,27 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -35,14 +35,32 @@
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_headshot">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
<width>40</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -1128,6 +1128,10 @@ PulseReply #line_replyLine , PulseMessage #line{
|
||||
color: #7ecbfb;
|
||||
}
|
||||
|
||||
PulseReply QLabel#label_groupName{
|
||||
color: #5b7083;
|
||||
}
|
||||
|
||||
WireDialog QLabel#label_viewMode {
|
||||
font-size: 12pt;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user