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;
|
||||
}
|
||||
|
||||
bool ConversationMessage::hasImage() const
|
||||
{
|
||||
return !mImagePath.isEmpty();
|
||||
}
|
||||
|
||||
void ConversationMessage::setImagePath(const QString &imagePath)
|
||||
{
|
||||
mImagePath = imagePath;
|
||||
|
@ -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;
|
||||
|
@ -135,7 +135,17 @@ void ImageLoadHelper::ApplyImage(QLabel *label, const QString &url)
|
||||
|
||||
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)
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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">
|
||||
@ -53,22 +53,34 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="messageLabel">
|
||||
<widget class="QWidget" name="messageContentContainer" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>3</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Message content</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="messageLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="messageLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>3</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</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>
|
||||
</item>
|
||||
</layout>
|
||||
|
Loading…
Reference in New Issue
Block a user