summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ImageItem.h73
-rw-r--r--include/MatrixClient.h4
-rw-r--r--include/TimelineItem.h5
-rw-r--r--include/TimelineView.h7
4 files changed, 87 insertions, 2 deletions
diff --git a/include/ImageItem.h b/include/ImageItem.h
new file mode 100644

index 00000000..7dc8773f --- /dev/null +++ b/include/ImageItem.h
@@ -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 diff --git a/include/MatrixClient.h b/include/MatrixClient.h
index 8d517b9a..ad768eeb 100644 --- a/include/MatrixClient.h +++ b/include/MatrixClient.h
@@ -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_; diff --git a/include/TimelineItem.h b/include/TimelineItem.h
index 9af02597..626687ac 100644 --- a/include/TimelineItem.h +++ b/include/TimelineItem.h
@@ -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: diff --git a/include/TimelineView.h b/include/TimelineView.h
index e1254ff0..4400c361 100644 --- a/include/TimelineView.h +++ b/include/TimelineView.h
@@ -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