Commit da51e385 authored by Edric Milaret's avatar Edric Milaret

im: make the text bubble round

Change-Id: I5cb0c36a45cc953abb9a3cd34a4ed32dc1d204e1
Tuleap: #232
parent 63c34b6e
......@@ -57,6 +57,8 @@ ImDelegate::paint(QPainter* painter,
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
painter->setRenderHint(QPainter::Antialiasing);
if (index.isValid()) {
auto msg = index.data(Qt::DisplayRole).toString();
opt.text.clear();
......@@ -73,19 +75,28 @@ ImDelegate::paint(QPainter* painter,
formatMsg(index, msg);
QRect textRect = getBoundingRect(dir, msg, opt);
QRect bubbleRect(textRect.left() - padding_, textRect.top() - padding_, textRect.width() + padding_, textRect.height() + padding_);
bubbleRect.setBottom(bubbleRect.bottom() + padding_);
bubbleRect.setRight(bubbleRect.right() + padding_);
QRect bubbleRect(textRect.left() - bubblePadding_,
textRect.top() - bubblePadding_,
textRect.width() + bubblePadding_,
textRect.height() + bubblePadding_);
bubbleRect.setBottom(bubbleRect.bottom() + bubblePadding_);
bubbleRect.setRight(bubbleRect.right() + bubblePadding_);
opt.decorationSize = iconSize_;
opt.decorationPosition = (dir == Qt::AlignRight ? QStyleOptionViewItem::Right : QStyleOptionViewItem::Left);
opt.decorationAlignment = Qt::AlignTop | Qt::AlignHCenter;
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
if (dir == Qt::AlignRight) {
painter->fillRect(bubbleRect, blue);
}
else {
painter->fillRect(bubbleRect, grey);
}
painter->save();
QPen pen(blue, padding_);
if (dir == Qt::AlignRight)
pen.setColor(grey);
QPainterPath path;
path.addRoundedRect(bubbleRect, padding_, padding_);
painter->setPen(pen);
painter->fillPath(path, pen.color());
painter->drawPath(path);
painter->restore();
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, msg);
}
}
......
......@@ -46,5 +46,6 @@ private:
const QColor grey {"#f2f2f2"};
const QSize iconSize_ {38,38};
constexpr static int padding_ = 5;
constexpr static int bubblePadding_ = 2;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment