mirror of
https://gitlab.com/comunic/comunicmessages
synced 2024-12-04 19:24:11 +00:00
Can enlarge conversation images.
This commit is contained in:
parent
6062eaf2c8
commit
aa334d0110
@ -33,7 +33,9 @@ SOURCES += \
|
|||||||
widgets/conversationmessagewidget.cpp \
|
widgets/conversationmessagewidget.cpp \
|
||||||
data/conversationmessageslist.cpp \
|
data/conversationmessageslist.cpp \
|
||||||
helpers/imageloadhelper.cpp \
|
helpers/imageloadhelper.cpp \
|
||||||
utils/filesutils.cpp
|
utils/filesutils.cpp \
|
||||||
|
widgets/remoteimagemanager.cpp \
|
||||||
|
widgets/clickablelabel.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
helpers/accounthelper.h \
|
helpers/accounthelper.h \
|
||||||
@ -69,7 +71,9 @@ HEADERS += \
|
|||||||
data/conversationmessageslist.h \
|
data/conversationmessageslist.h \
|
||||||
helpers/imageloadhelper.h \
|
helpers/imageloadhelper.h \
|
||||||
utils/filesutils.h \
|
utils/filesutils.h \
|
||||||
data/qlabelholder.h
|
data/qlabelholder.h \
|
||||||
|
widgets/remoteimagemanager.h \
|
||||||
|
widgets/clickablelabel.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
widgets/loginwidget.ui \
|
widgets/loginwidget.ui \
|
||||||
|
11
widgets/clickablelabel.cpp
Normal file
11
widgets/clickablelabel.cpp
Normal 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
26
widgets/clickablelabel.h
Normal 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
|
@ -2,7 +2,8 @@
|
|||||||
#include "ui_conversationmessagewidget.h"
|
#include "ui_conversationmessagewidget.h"
|
||||||
#include "../data/user.h"
|
#include "../data/user.h"
|
||||||
#include "../data/conversationmessage.h"
|
#include "../data/conversationmessage.h"
|
||||||
#include "../helpers/imageloadhelper.h"
|
#include "remoteimagemanager.h"
|
||||||
|
#include "clickablelabel.h"
|
||||||
|
|
||||||
ConversationMessageWidget::ConversationMessageWidget(QWidget *parent) :
|
ConversationMessageWidget::ConversationMessageWidget(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
@ -20,15 +21,15 @@ 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());
|
new RemoteImageManager(ui->accountImageLabel, user.accountImage(), this);
|
||||||
|
|
||||||
//Add message image (if any)
|
//Add message image (if any)
|
||||||
if(message.hasImage()){
|
if(message.hasImage()){
|
||||||
QLabel *label = new QLabel;
|
ClickableLabel *label = new ClickableLabel;
|
||||||
label->setParent(ui->messageContentContainer);
|
label->setParent(ui->messageContentContainer);
|
||||||
label->setScaledContents(true);
|
label->setScaledContents(true);
|
||||||
label->setMaximumSize(200, 200);
|
label->setMaximumSize(200, 200);
|
||||||
ui->messageLayout->addWidget(label);
|
ui->messageLayout->addWidget(label);
|
||||||
ImageLoadHelper::Load(label, message.imagePath());
|
(new RemoteImageManager(label, message.imagePath(), this))->setEnlargeable(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
42
widgets/remoteimagemanager.cpp
Normal file
42
widgets/remoteimagemanager.cpp
Normal 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();
|
||||||
|
}
|
45
widgets/remoteimagemanager.h
Normal file
45
widgets/remoteimagemanager.h
Normal 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
|
Loading…
Reference in New Issue
Block a user