Display conversation images

This commit is contained in:
Pierre HUBERT 2018-12-19 08:49:54 +01:00
parent 9100c14dfd
commit 6062eaf2c8
5 changed files with 51 additions and 13 deletions

View File

@ -50,6 +50,11 @@ QString ConversationMessage::imagePath() const
return mImagePath;
}
bool ConversationMessage::hasImage() const
{
return !mImagePath.isEmpty();
}
void ConversationMessage::setImagePath(const QString &imagePath)
{
mImagePath = imagePath;

View File

@ -27,6 +27,7 @@ public:
void setMessage(const QString &message);
QString imagePath() const;
bool hasImage() const;
void setImagePath(const QString &imagePath);
bool operator<(const ConversationMessage &b) const;

View File

@ -135,7 +135,17 @@ void ImageLoadHelper::ApplyImage(QLabel *label, const QString &url)
void ImageLoadHelper::ApplyImage(QLabel *label, const QPixmap &pixmap)
{
//Check if we need to scale image
if(
(label->maximumWidth() > 100000 || label->maximumHeight() > 100000) || //No maximum size
(label->maximumWidth() > pixmap.width() && label->maximumHeight() > pixmap.height()) //Image smaller than maximum size
){
label->setPixmap(pixmap);
return;
}
//Else we scale image
label->setPixmap(pixmap.scaled(label->maximumSize(), Qt::KeepAspectRatio));
}
bool ImageLoadHelper::IsDownloaded(const QString &url)

View File

@ -21,4 +21,14 @@ void ConversationMessageWidget::setMessage(const ConversationMessage &message, c
ui->nameLabel->setText(user.displayName());
ui->messageLabel->setText(message.message());
ImageLoadHelper::Load(ui->accountImageLabel, user.accountImage());
//Add message image (if any)
if(message.hasImage()){
QLabel *label = new QLabel;
label->setParent(ui->messageContentContainer);
label->setScaledContents(true);
label->setMaximumSize(200, 200);
ui->messageLayout->addWidget(label);
ImageLoadHelper::Load(label, message.imagePath());
}
}

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>183</width>
<height>35</height>
<width>227</width>
<height>53</height>
</rect>
</property>
<property name="windowTitle">
@ -52,6 +52,15 @@
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="messageContentContainer" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>3</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="messageLayout">
<item>
<widget class="QLabel" name="messageLabel">
<property name="sizePolicy">
@ -73,6 +82,9 @@
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../res/ressources.qrc"/>
</resources>