mirror of
https://gitlab.com/comunic/comunicmessages
synced 2024-12-04 19:24:11 +00:00
Display conversation images
This commit is contained in:
parent
9100c14dfd
commit
6062eaf2c8
@ -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;
|
||||||
|
@ -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;
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
label->setPixmap(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)
|
bool ImageLoadHelper::IsDownloaded(const QString &url)
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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">
|
||||||
@ -53,22 +53,34 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="messageLabel">
|
<widget class="QWidget" name="messageContentContainer" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<horstretch>3</horstretch>
|
<horstretch>3</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<layout class="QVBoxLayout" name="messageLayout">
|
||||||
<string>Message content</string>
|
<item>
|
||||||
</property>
|
<widget class="QLabel" name="messageLabel">
|
||||||
<property name="textFormat">
|
<property name="sizePolicy">
|
||||||
<enum>Qt::PlainText</enum>
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
</property>
|
<horstretch>3</horstretch>
|
||||||
<property name="wordWrap">
|
<verstretch>0</verstretch>
|
||||||
<bool>true</bool>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Message content</string>
|
||||||
|
</property>
|
||||||
|
<property name="textFormat">
|
||||||
|
<enum>Qt::PlainText</enum>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
Loading…
Reference in New Issue
Block a user