Restrict inline image size to its minimum

This commit is contained in:
Konstantinos Sideris 2017-05-10 13:12:50 +03:00
parent d277d5c68b
commit 6f065530ae

View file

@ -33,7 +33,6 @@ ImageItem::ImageItem(QSharedPointer<MatrixClient> client, const events::MessageE
, event_{event} , event_{event}
, client_{client} , client_{client}
{ {
setMaximumSize(max_width_, max_height_);
setMouseTracking(true); setMouseTracking(true);
setCursor(Qt::PointingHandCursor); setCursor(Qt::PointingHandCursor);
setAttribute(Qt::WA_Hover, true); setAttribute(Qt::WA_Hover, true);
@ -94,7 +93,7 @@ void ImageItem::scaleImage()
height_ = image_.height() * min_aspect_ratio; height_ = image_.height() * min_aspect_ratio;
} }
setMinimumSize(width_, height_); setFixedSize(width_, height_);
scaled_image_ = image_.scaled(width_, height_, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); scaled_image_ = image_.scaled(width_, height_, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
} }
@ -157,10 +156,10 @@ void ImageItem::paintEvent(QPaintEvent *event)
if (image_.isNull()) { if (image_.isNull()) {
int height = fontHeight + 10; int height = fontHeight + 10;
setMinimumSize(max_width_, fontHeight + 10);
QString elidedText = metrics.elidedText(text_, Qt::ElideRight, max_width_ - 10); QString elidedText = metrics.elidedText(text_, Qt::ElideRight, max_width_ - 10);
setFixedSize(metrics.width(elidedText), fontHeight + 10);
painter.setFont(font); painter.setFont(font);
painter.setPen(QPen(QColor(66, 133, 244))); painter.setPen(QPen(QColor(66, 133, 244)));
painter.drawText(QPoint(0, height / 2 + 2), elidedText); painter.drawText(QPoint(0, height / 2 + 2), elidedText);