Can enlarge conversation images.

This commit is contained in:
Pierre HUBERT 2018-12-22 08:18:17 +01:00
parent 6062eaf2c8
commit aa334d0110
6 changed files with 135 additions and 6 deletions

View File

@ -33,7 +33,9 @@ SOURCES += \
widgets/conversationmessagewidget.cpp \
data/conversationmessageslist.cpp \
helpers/imageloadhelper.cpp \
utils/filesutils.cpp
utils/filesutils.cpp \
widgets/remoteimagemanager.cpp \
widgets/clickablelabel.cpp
HEADERS += \
helpers/accounthelper.h \
@ -69,7 +71,9 @@ HEADERS += \
data/conversationmessageslist.h \
helpers/imageloadhelper.h \
utils/filesutils.h \
data/qlabelholder.h
data/qlabelholder.h \
widgets/remoteimagemanager.h \
widgets/clickablelabel.h
FORMS += \
widgets/loginwidget.ui \

View File

@ -0,0 +1,11 @@
#include "clickablelabel.h"
ClickableLabel::ClickableLabel(QWidget *parent) : QLabel (parent)
{
}
void ClickableLabel::mousePressEvent(QMouseEvent *)
{
emit clicked();
}

26
widgets/clickablelabel.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef CLICKABLELABEL_H
#define CLICKABLELABEL_H
#include <QLabel>
class ClickableLabel : public QLabel
{
Q_OBJECT
public:
ClickableLabel(QWidget *parent=nullptr);
signals:
/**
* This signal is emitted when the a click is made o the view
*/
void clicked();
protected:
void mousePressEvent(QMouseEvent*) override;
};
#endif // CLICKABLELABEL_H

View File

@ -2,7 +2,8 @@
#include "ui_conversationmessagewidget.h"
#include "../data/user.h"
#include "../data/conversationmessage.h"
#include "../helpers/imageloadhelper.h"
#include "remoteimagemanager.h"
#include "clickablelabel.h"
ConversationMessageWidget::ConversationMessageWidget(QWidget *parent) :
QWidget(parent),
@ -20,15 +21,15 @@ void ConversationMessageWidget::setMessage(const ConversationMessage &message, c
{
ui->nameLabel->setText(user.displayName());
ui->messageLabel->setText(message.message());
ImageLoadHelper::Load(ui->accountImageLabel, user.accountImage());
new RemoteImageManager(ui->accountImageLabel, user.accountImage(), this);
//Add message image (if any)
if(message.hasImage()){
QLabel *label = new QLabel;
ClickableLabel *label = new ClickableLabel;
label->setParent(ui->messageContentContainer);
label->setScaledContents(true);
label->setMaximumSize(200, 200);
ui->messageLayout->addWidget(label);
ImageLoadHelper::Load(label, message.imagePath());
(new RemoteImageManager(label, message.imagePath(), this))->setEnlargeable(true);
}
}

View File

@ -0,0 +1,42 @@
#include <QLabel>
#include "remoteimagemanager.h"
#include "clickablelabel.h"
#include "../helpers/imageloadhelper.h"
RemoteImageManager::RemoteImageManager(QLabel *label, const QString &url, QObject *parent) : QObject(parent)
{
//Load remote image
ImageLoadHelper::Load(label, url);
mUrl = url;
}
RemoteImageManager::RemoteImageManager(ClickableLabel *label, const QString &url, QObject *parent) : QObject (parent)
{
//Load remote image
ImageLoadHelper::Load(label, url);
mUrl = url;
connect(label, &ClickableLabel::clicked, this, &RemoteImageManager::enlarge);
}
bool RemoteImageManager::enlargeable() const
{
return mEnlargeable;
}
void RemoteImageManager::setEnlargeable(bool enlargeable)
{
mEnlargeable = enlargeable;
}
void RemoteImageManager::enlarge()
{
if(!enlargeable())
return;
//Open the image in a bigger label (to improve)
QLabel *label = new QLabel;
ImageLoadHelper::Load(label, mUrl);
label->show();
}

View File

@ -0,0 +1,45 @@
/**
* This object has to be used in all classes
* in order to manage remote image management
*
* @author Pierre HUBERT
*/
#ifndef REMOTEIMAGEMANAGER_H
#define REMOTEIMAGEMANAGER_H
#include <QObject>
class QLabel;
class ClickableLabel;
class RemoteImageManager : public QObject
{
Q_OBJECT
public:
explicit RemoteImageManager(QLabel *label, const QString &url, QObject *parent); //Avoid loss of memory : force parent = nullptr);
explicit RemoteImageManager(ClickableLabel *label, const QString &url, QObject *parent);
/**
* Note that the enlargable feature is currently available only with
* the ClickableLabel widgets
*/
bool enlargeable() const;
void setEnlargeable(bool enlargeable);
signals:
public slots:
/**
* This slot is triggered when we want to enlarge the image
*/
void enlarge();
private:
//Private URL
QString mUrl;
bool mEnlargeable = false;
};
#endif // REMOTEIMAGEMANAGER_H