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; return mImagePath;
} }
bool ConversationMessage::hasImage() const
{
return !mImagePath.isEmpty();
}
void ConversationMessage::setImagePath(const QString &imagePath) void ConversationMessage::setImagePath(const QString &imagePath)
{ {
mImagePath = imagePath; mImagePath = imagePath;

View File

@ -27,6 +27,7 @@ public:
void setMessage(const QString &message); void setMessage(const QString &message);
QString imagePath() const; QString imagePath() const;
bool hasImage() const;
void setImagePath(const QString &imagePath); void setImagePath(const QString &imagePath);
bool operator<(const ConversationMessage &b) const; 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) 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); label->setPixmap(pixmap);
return;
}
//Else we scale image
label->setPixmap(pixmap.scaled(label->maximumSize(), Qt::KeepAspectRatio));
} }
bool ImageLoadHelper::IsDownloaded(const QString &url) 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->nameLabel->setText(user.displayName());
ui->messageLabel->setText(message.message()); ui->messageLabel->setText(message.message());
ImageLoadHelper::Load(ui->accountImageLabel, user.accountImage()); 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> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>183</width> <width>227</width>
<height>35</height> <height>53</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -52,6 +52,15 @@
</property> </property>
</widget> </widget>
</item> </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> <item>
<widget class="QLabel" name="messageLabel"> <widget class="QLabel" name="messageLabel">
<property name="sizePolicy"> <property name="sizePolicy">
@ -73,6 +82,9 @@
</item> </item>
</layout> </layout>
</widget> </widget>
</item>
</layout>
</widget>
<resources> <resources>
<include location="../res/ressources.qrc"/> <include location="../res/ressources.qrc"/>
</resources> </resources>