From 6062eaf2c8aafbfb5b9e8cc42aa501b00626647b Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 19 Dec 2018 08:49:54 +0100 Subject: [PATCH] Display conversation images --- data/conversationmessage.cpp | 5 ++++ data/conversationmessage.h | 1 + helpers/imageloadhelper.cpp | 12 ++++++++- widgets/conversationmessagewidget.cpp | 10 ++++++++ widgets/conversationmessagewidget.ui | 36 ++++++++++++++++++--------- 5 files changed, 51 insertions(+), 13 deletions(-) diff --git a/data/conversationmessage.cpp b/data/conversationmessage.cpp index 766a731..a8fd140 100644 --- a/data/conversationmessage.cpp +++ b/data/conversationmessage.cpp @@ -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; diff --git a/data/conversationmessage.h b/data/conversationmessage.h index ad552ed..05be0e5 100644 --- a/data/conversationmessage.h +++ b/data/conversationmessage.h @@ -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; diff --git a/helpers/imageloadhelper.cpp b/helpers/imageloadhelper.cpp index d3b9ba1..741df17 100644 --- a/helpers/imageloadhelper.cpp +++ b/helpers/imageloadhelper.cpp @@ -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) diff --git a/widgets/conversationmessagewidget.cpp b/widgets/conversationmessagewidget.cpp index 90066c6..6dd048e 100644 --- a/widgets/conversationmessagewidget.cpp +++ b/widgets/conversationmessagewidget.cpp @@ -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()); + } } diff --git a/widgets/conversationmessagewidget.ui b/widgets/conversationmessagewidget.ui index d517891..116d602 100644 --- a/widgets/conversationmessagewidget.ui +++ b/widgets/conversationmessagewidget.ui @@ -6,8 +6,8 @@ 0 0 - 183 - 35 + 227 + 53 @@ -53,22 +53,34 @@ - + 3 0 - - Message content - - - Qt::PlainText - - - true - + + + + + + 3 + 0 + + + + Message content + + + Qt::PlainText + + + true + + + +