Add initial support for inline images

This commit is contained in:
Konstantinos Sideris 2017-04-28 14:56:45 +03:00
parent 4b4035eebc
commit c9d03b793b
10 changed files with 382 additions and 5 deletions

73
include/ImageItem.h Normal file
View file

@ -0,0 +1,73 @@
/*
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TIMELINE_IMAGE_ITEM_H
#define TIMELINE_IMAGE_ITEM_H
#include <QEvent>
#include <QMouseEvent>
#include <QSharedPointer>
#include <QWidget>
#include "MatrixClient.h"
class ImageItem : public QWidget
{
Q_OBJECT
public:
ImageItem(QSharedPointer<MatrixClient> client,
const Event &event,
const QString &body,
const QUrl &url,
QWidget *parent = nullptr);
void setImage(const QPixmap &image);
QSize sizeHint() const override;
protected:
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private slots:
void imageDownloaded(const QString &event_id, const QPixmap &img);
private:
void scaleImage();
void openUrl();
int max_width_ = 500;
int max_height_ = 300;
int width_;
int height_;
QPixmap scaled_image_;
QPixmap image_;
QUrl url_;
QString text_;
int bottom_height_ = 30;
Event event_;
QSharedPointer<MatrixClient> client_;
};
#endif // TIMELINE_IMAGE_ITEM_H

View file

@ -42,6 +42,7 @@ public:
void versions() noexcept;
void fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url);
void fetchOwnAvatar(const QUrl &avatar_url);
void downloadImage(const QString &event_id, const QUrl &url);
inline QString getHomeServer();
inline int transactionId();
@ -68,6 +69,7 @@ signals:
void roomAvatarRetrieved(const QString &roomid, const QPixmap &img);
void ownAvatarRetrieved(const QPixmap &img);
void imageDownloaded(const QString &event_id, const QPixmap &img);
// Returned profile data for the user's account.
void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name);
@ -84,6 +86,7 @@ private:
GetOwnProfile,
GetOwnAvatar,
GetProfile,
Image,
InitialSync,
Login,
Logout,
@ -105,6 +108,7 @@ private:
void onInitialSyncResponse(QNetworkReply *reply);
void onSyncResponse(QNetworkReply *reply);
void onRoomAvatarResponse(QNetworkReply *reply);
void onImageResponse(QNetworkReply *reply);
// Client API prefix.
QString api_url_;

View file

@ -23,6 +23,7 @@
#include <QWidget>
#include "Sync.h"
#include "ImageItem.h"
class TimelineItem : public QWidget
{
@ -35,6 +36,10 @@ public:
TimelineItem(const QString &userid, const QString &color, const QString &body, QWidget *parent = 0);
TimelineItem(const QString &body, QWidget *parent = 0);
// For inline images.
TimelineItem(ImageItem *image, const Event &event, const QString &color, QWidget *parent);
TimelineItem(ImageItem *image, const Event &event, QWidget *parent);
~TimelineItem();
private:

View file

@ -49,11 +49,13 @@ class TimelineView : public QWidget
Q_OBJECT
public:
explicit TimelineView(QWidget *parent = 0);
explicit TimelineView(const QList<Event> &events, QWidget *parent = 0);
TimelineView(QSharedPointer<MatrixClient> client, QWidget *parent = 0);
TimelineView(const QList<Event> &events, QSharedPointer<MatrixClient> client, QWidget *parent = 0);
~TimelineView();
// FIXME: Reduce the parameters
void addHistoryItem(const Event &event, const QString &color, bool with_sender);
void addImageItem(const QString &body, const QUrl &url, const Event &event, const QString &color, bool with_sender);
int addEvents(const QList<Event> &events);
void addUserTextMessage(const QString &msg, int txn_id);
void updatePendingMessage(int txn_id, QString event_id);
@ -76,6 +78,7 @@ private:
QString last_sender_;
QList<PendingMessage> pending_msgs_;
QSharedPointer<MatrixClient> client_;
};
#endif // HISTORY_VIEW_H