summary refs log tree commit diff
path: root/src/timeline/widgets
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-07-17 16:37:25 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-07-17 16:37:25 +0300
commit0e814da91c8e041897a4c3f7e6e9234bbc7c6f7a (patch)
tree21f655d30630fe77ba48d07e4b357e2b6c6a5730 /src/timeline/widgets
parentMerge pull request #372 from bebehei/notification (diff)
downloadnheko-0e814da91c8e041897a4c3f7e6e9234bbc7c6f7a.tar.xz
Move all files under src/
Diffstat (limited to 'src/timeline/widgets')
-rw-r--r--src/timeline/widgets/AudioItem.cpp (renamed from src/timeline/widgets/AudioItem.cc)2
-rw-r--r--src/timeline/widgets/AudioItem.h107
-rw-r--r--src/timeline/widgets/FileItem.cpp (renamed from src/timeline/widgets/FileItem.cc)2
-rw-r--r--src/timeline/widgets/FileItem.h82
-rw-r--r--src/timeline/widgets/ImageItem.cpp (renamed from src/timeline/widgets/ImageItem.cc)4
-rw-r--r--src/timeline/widgets/ImageItem.h108
-rw-r--r--src/timeline/widgets/VideoItem.cpp (renamed from src/timeline/widgets/VideoItem.cc)0
-rw-r--r--src/timeline/widgets/VideoItem.h51
8 files changed, 352 insertions, 4 deletions
diff --git a/src/timeline/widgets/AudioItem.cc b/src/timeline/widgets/AudioItem.cpp

index 2ed4f4c0..1e3eb0f0 100644 --- a/src/timeline/widgets/AudioItem.cc +++ b/src/timeline/widgets/AudioItem.cpp
@@ -22,7 +22,7 @@ #include <QPainter> #include <QPixmap> -#include "Logging.hpp" +#include "Logging.h" #include "MatrixClient.h" #include "Utils.h" diff --git a/src/timeline/widgets/AudioItem.h b/src/timeline/widgets/AudioItem.h new file mode 100644
index 00000000..7b0781a2 --- /dev/null +++ b/src/timeline/widgets/AudioItem.h
@@ -0,0 +1,107 @@ +/* + * 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/>. + */ + +#pragma once + +#include <QEvent> +#include <QIcon> +#include <QMediaPlayer> +#include <QMouseEvent> +#include <QSharedPointer> +#include <QWidget> + +#include <mtx.hpp> + +class AudioItem : public QWidget +{ + Q_OBJECT + + Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor) + Q_PROPERTY(QColor iconColor WRITE setIconColor READ iconColor) + Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor) + + Q_PROPERTY(QColor durationBackgroundColor WRITE setDurationBackgroundColor READ + durationBackgroundColor) + Q_PROPERTY(QColor durationForegroundColor WRITE setDurationForegroundColor READ + durationForegroundColor) + +public: + AudioItem(const mtx::events::RoomEvent<mtx::events::msg::Audio> &event, + QWidget *parent = nullptr); + + AudioItem(const QString &url, + const QString &filename, + uint64_t size, + QWidget *parent = nullptr); + + QSize sizeHint() const override; + + void setTextColor(const QColor &color) { textColor_ = color; } + void setIconColor(const QColor &color) { iconColor_ = color; } + void setBackgroundColor(const QColor &color) { backgroundColor_ = color; } + + void setDurationBackgroundColor(const QColor &color) { durationBgColor_ = color; } + void setDurationForegroundColor(const QColor &color) { durationFgColor_ = color; } + + QColor textColor() const { return textColor_; } + QColor iconColor() const { return iconColor_; } + QColor backgroundColor() const { return backgroundColor_; } + + QColor durationBackgroundColor() const { return durationBgColor_; } + QColor durationForegroundColor() const { return durationFgColor_; } + +protected: + void paintEvent(QPaintEvent *event) override; + void resizeEvent(QResizeEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + +signals: + void fileDownloadedCb(const QByteArray &data); + +private slots: + void fileDownloaded(const QByteArray &data); + +private: + void init(); + + enum class AudioState + { + Play, + Pause, + }; + + AudioState state_ = AudioState::Play; + + QUrl url_; + QString text_; + QString readableFileSize_; + QString filenameToSave_; + + mtx::events::RoomEvent<mtx::events::msg::Audio> event_; + + QMediaPlayer *player_; + + QIcon playIcon_; + QIcon pauseIcon_; + + QColor textColor_ = QColor("white"); + QColor iconColor_ = QColor("#38A3D8"); + QColor backgroundColor_ = QColor("#333"); + + QColor durationBgColor_ = QColor("black"); + QColor durationFgColor_ = QColor("blue"); +}; diff --git a/src/timeline/widgets/FileItem.cc b/src/timeline/widgets/FileItem.cpp
index b4555b2f..f8d3272d 100644 --- a/src/timeline/widgets/FileItem.cc +++ b/src/timeline/widgets/FileItem.cpp
@@ -22,7 +22,7 @@ #include <QPainter> #include <QPixmap> -#include "Logging.hpp" +#include "Logging.h" #include "MatrixClient.h" #include "Utils.h" diff --git a/src/timeline/widgets/FileItem.h b/src/timeline/widgets/FileItem.h new file mode 100644
index 00000000..66543e79 --- /dev/null +++ b/src/timeline/widgets/FileItem.h
@@ -0,0 +1,82 @@ +/* + * 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/>. + */ + +#pragma once + +#include <QEvent> +#include <QIcon> +#include <QMouseEvent> +#include <QSharedPointer> +#include <QWidget> + +#include <mtx.hpp> + +class FileItem : public QWidget +{ + Q_OBJECT + + Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor) + Q_PROPERTY(QColor iconColor WRITE setIconColor READ iconColor) + Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor) + +public: + FileItem(const mtx::events::RoomEvent<mtx::events::msg::File> &event, + QWidget *parent = nullptr); + + FileItem(const QString &url, + const QString &filename, + uint64_t size, + QWidget *parent = nullptr); + + QSize sizeHint() const override; + + void setTextColor(const QColor &color) { textColor_ = color; } + void setIconColor(const QColor &color) { iconColor_ = color; } + void setBackgroundColor(const QColor &color) { backgroundColor_ = color; } + + QColor textColor() const { return textColor_; } + QColor iconColor() const { return iconColor_; } + QColor backgroundColor() const { return backgroundColor_; } + +signals: + void fileDownloadedCb(const QByteArray &data); + +protected: + void paintEvent(QPaintEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void resizeEvent(QResizeEvent *event) override; + +private slots: + void fileDownloaded(const QByteArray &data); + +private: + void openUrl(); + void init(); + + QUrl url_; + QString text_; + QString readableFileSize_; + QString filenameToSave_; + + mtx::events::RoomEvent<mtx::events::msg::File> event_; + + QIcon icon_; + + QColor textColor_ = QColor("white"); + QColor iconColor_ = QColor("#38A3D8"); + QColor backgroundColor_ = QColor("#333"); +}; diff --git a/src/timeline/widgets/ImageItem.cc b/src/timeline/widgets/ImageItem.cpp
index b7adb0fa..19b445db 100644 --- a/src/timeline/widgets/ImageItem.cc +++ b/src/timeline/widgets/ImageItem.cpp
@@ -24,11 +24,11 @@ #include <QUuid> #include "Config.h" -#include "Logging.hpp" +#include "ImageItem.h" +#include "Logging.h" #include "MatrixClient.h" #include "Utils.h" #include "dialogs/ImageOverlay.h" -#include "timeline/widgets/ImageItem.h" void ImageItem::downloadMedia(const QUrl &url) diff --git a/src/timeline/widgets/ImageItem.h b/src/timeline/widgets/ImageItem.h new file mode 100644
index 00000000..e9d823f4 --- /dev/null +++ b/src/timeline/widgets/ImageItem.h
@@ -0,0 +1,108 @@ +/* + * 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/>. + */ + +#pragma once + +#include <QEvent> +#include <QMouseEvent> +#include <QSharedPointer> +#include <QWidget> + +#include <mtx.hpp> + +namespace dialogs { +class ImageOverlay; +} + +class ImageItem : public QWidget +{ + Q_OBJECT +public: + ImageItem(const mtx::events::RoomEvent<mtx::events::msg::Image> &event, + QWidget *parent = nullptr); + + ImageItem(const QString &url, + const QString &filename, + uint64_t size, + QWidget *parent = nullptr); + + QSize sizeHint() const override; + +public slots: + //! Show a save as dialog for the image. + void saveAs(); + void setImage(const QPixmap &image); + void saveImage(const QString &filename, const QByteArray &data); + +signals: + void imageDownloaded(const QPixmap &img); + void imageSaved(const QString &filename, const QByteArray &data); + +protected: + void paintEvent(QPaintEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void resizeEvent(QResizeEvent *event) override; + + //! Whether the user can interact with the displayed image. + bool isInteractive_ = true; + +private: + void init(); + void openUrl(); + void downloadMedia(const QUrl &url); + + 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; + + QRectF textRegion_; + QRectF imageRegion_; + + mtx::events::RoomEvent<mtx::events::msg::Image> event_; +}; + +class StickerItem : public ImageItem +{ + Q_OBJECT + +public: + StickerItem(const mtx::events::Sticker &event, QWidget *parent = nullptr) + : ImageItem{QString::fromStdString(event.content.url), + QString::fromStdString(event.content.body), + event.content.info.size, + parent} + , event_{event} + { + isInteractive_ = false; + setCursor(Qt::ArrowCursor); + setMouseTracking(false); + setAttribute(Qt::WA_Hover, false); + } + +private: + mtx::events::Sticker event_; +}; diff --git a/src/timeline/widgets/VideoItem.cc b/src/timeline/widgets/VideoItem.cpp
index daf181b2..daf181b2 100644 --- a/src/timeline/widgets/VideoItem.cc +++ b/src/timeline/widgets/VideoItem.cpp
diff --git a/src/timeline/widgets/VideoItem.h b/src/timeline/widgets/VideoItem.h new file mode 100644
index 00000000..26fa1c35 --- /dev/null +++ b/src/timeline/widgets/VideoItem.h
@@ -0,0 +1,51 @@ +/* + * 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/>. + */ + +#pragma once + +#include <QEvent> +#include <QLabel> +#include <QSharedPointer> +#include <QUrl> +#include <QWidget> + +#include <mtx.hpp> + +class VideoItem : public QWidget +{ + Q_OBJECT + +public: + VideoItem(const mtx::events::RoomEvent<mtx::events::msg::Video> &event, + QWidget *parent = nullptr); + + VideoItem(const QString &url, + const QString &filename, + uint64_t size, + QWidget *parent = nullptr); + +private: + void init(); + + QUrl url_; + QString text_; + QString readableFileSize_; + + QLabel *label_; + + mtx::events::RoomEvent<mtx::events::msg::Video> event_; +};