Use ImageItem in MessageDelegate.

This commit is contained in:
Black Hat
2018-09-10 09:51:02 +08:00
parent 13a8d6b889
commit 0f3d7db0d1
11 changed files with 91 additions and 18 deletions

View File

@@ -14,8 +14,12 @@ void ImageItem::paint(QPainter *painter) {
if (m_image.isNull()) {
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(m_color));
painter->drawEllipse(0, 0, int(bounding_rect.width()),
int(bounding_rect.height()));
if (m_round)
painter->drawEllipse(0, 0, int(bounding_rect.width()),
int(bounding_rect.height()));
else
painter->drawRect(0, 0, int(bounding_rect.width()),
int(bounding_rect.height()));
painter->setPen(QPen(Qt::white, 2));
QFont font;
font.setPixelSize(22);
@@ -33,11 +37,13 @@ void ImageItem::paint(QPainter *painter) {
QPointF center = bounding_rect.center() - scaled.rect().center();
QPainterPath clip;
clip.addEllipse(
0, 0, bounding_rect.width(),
bounding_rect.height()); // this is the shape we want to clip to
painter->setClipPath(clip);
if (m_round) {
QPainterPath clip;
clip.addEllipse(
0, 0, bounding_rect.width(),
bounding_rect.height()); // this is the shape we want to clip to
painter->setClipPath(clip);
}
if (center.x() < 0) center.setX(0);
if (center.y() < 0) center.setY(0);
@@ -66,3 +72,11 @@ void ImageItem::setDefaultColor(QString color) {
update();
}
}
void ImageItem::setRound(bool value) {
if (m_round != value) {
m_round = value;
emit roundChanged();
update();
}
}