From 9a0e18dea75d171e992e7d4a2f173949588674ea Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sat, 7 Jul 2018 13:39:53 +0300 Subject: Add a timeline message when encryption is enabled --- include/timeline/TimelineView.h | 43 ++++--------------------------------- include/ui/InfoMessage.hpp | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 39 deletions(-) create mode 100644 include/ui/InfoMessage.hpp (limited to 'include') diff --git a/include/timeline/TimelineView.h b/include/timeline/TimelineView.h index 81212c27..5af359c5 100644 --- a/include/timeline/TimelineView.h +++ b/include/timeline/TimelineView.h @@ -107,40 +107,6 @@ enum class TimelineDirection Bottom, }; -class DateSeparator : public QWidget -{ - Q_OBJECT - - Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor) - Q_PROPERTY(QColor boxColor WRITE setBoxColor READ boxColor) - -public: - DateSeparator(QDateTime datetime, QWidget *parent = nullptr); - - void setTextColor(QColor color) { textColor_ = color; } - void setBoxColor(QColor color) { boxColor_ = color; } - - QColor textColor() const { return textColor_; } - QColor boxColor() const { return boxColor_; } - -protected: - void paintEvent(QPaintEvent *event) override; - -private: - static constexpr int VPadding = 6; - static constexpr int HPadding = 12; - static constexpr int HMargin = 20; - - int width_; - int height_; - - QString msg_; - QFont font_; - - QColor textColor_ = QColor("black"); - QColor boxColor_ = QColor("white"); -}; - class TimelineView : public QWidget { Q_OBJECT @@ -162,7 +128,6 @@ public: uint64_t size); void updatePendingMessage(const std::string &txn_id, const QString &event_id); void scrollDown(); - QLabel *createDateSeparator(QDateTime datetime); //! Remove an item from the timeline with the given Event ID. void removeEvent(const QString &event_id); @@ -220,7 +185,7 @@ private: void getMessages(); //! HACK: Fixing layout flickering when adding to the bottom //! of the timeline. - void pushTimelineItem(TimelineItem *item) + void pushTimelineItem(QWidget *item) { item->hide(); scroll_layout_->addWidget(item); @@ -230,7 +195,7 @@ private: //! Decides whether or not to show or hide the scroll down button. void toggleScrollDownButton(); void init(); - void addTimelineItem(TimelineItem *item, + void addTimelineItem(QWidget *item, TimelineDirection direction = TimelineDirection::Bottom); void updateLastSender(const QString &user_id, TimelineDirection direction); void notifyForLastEvent(); @@ -295,8 +260,8 @@ private: const QDateTime &second = QDateTime::currentDateTime()) const; // Return nullptr if the event couldn't be parsed. - TimelineItem *parseMessageEvent(const mtx::events::collections::TimelineEvents &event, - TimelineDirection direction); + QWidget *parseMessageEvent(const mtx::events::collections::TimelineEvents &event, + TimelineDirection direction); QVBoxLayout *top_layout_; QVBoxLayout *scroll_layout_; diff --git a/include/ui/InfoMessage.hpp b/include/ui/InfoMessage.hpp new file mode 100644 index 00000000..58f98b0c --- /dev/null +++ b/include/ui/InfoMessage.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include +#include +#include + +class InfoMessage : public QWidget +{ + Q_OBJECT + + Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor) + Q_PROPERTY(QColor boxColor WRITE setBoxColor READ boxColor) + +public: + explicit InfoMessage(QWidget *parent = nullptr); + InfoMessage(QString msg, QWidget *parent = nullptr); + + void setTextColor(QColor color) { textColor_ = color; } + void setBoxColor(QColor color) { boxColor_ = color; } + void saveDatetime(QDateTime datetime) { datetime_ = datetime; } + + QColor textColor() const { return textColor_; } + QColor boxColor() const { return boxColor_; } + QDateTime datetime() const { return datetime_; } + +protected: + void paintEvent(QPaintEvent *event) override; + + int width_; + int height_; + + QString msg_; + QFont font_; + + QDateTime datetime_; + + QColor textColor_ = QColor("black"); + QColor boxColor_ = QColor("white"); +}; + +class DateSeparator : public InfoMessage +{ + Q_OBJECT + +public: + DateSeparator(QDateTime datetime, QWidget *parent = nullptr); +}; -- cgit 1.5.1