Chatterino
MessageLayoutElement.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "common/FlagsEnum.hpp"
4 #include "messages/Link.hpp"
7 
8 #include <QPen>
9 #include <QPoint>
10 #include <QRect>
11 #include <QString>
12 #include <boost/noncopyable.hpp>
13 #include <pajlada/signals/signalholder.hpp>
14 
15 #include <climits>
16 #include <cstdint>
17 
18 class QPainter;
19 
20 namespace chatterino {
21 class MessageElement;
22 class Image;
23 using ImagePtr = std::shared_ptr<Image>;
24 enum class FontStyle : uint8_t;
25 
26 class MessageLayoutElement : boost::noncopyable
27 {
28 public:
29  MessageLayoutElement(MessageElement &creator_, const QSize &size);
30  virtual ~MessageLayoutElement();
31 
32  bool reversedNeutral = false;
33 
34  const QRect &getRect() const;
35  MessageElement &getCreator() const;
36  void setPosition(QPoint point);
37  bool hasTrailingSpace() const;
38  int getLine() const;
39  void setLine(int line);
40 
41  MessageLayoutElement *setTrailingSpace(bool value);
42  MessageLayoutElement *setLink(const Link &link_);
43  MessageLayoutElement *setText(const QString &text_);
44 
45  virtual void addCopyTextToString(QString &str, uint32_t from = 0,
46  uint32_t to = UINT32_MAX) const = 0;
47  virtual int getSelectionIndexCount() const = 0;
48  virtual void paint(QPainter &painter) = 0;
49  virtual void paintAnimated(QPainter &painter, int yOffset) = 0;
50  virtual int getMouseOverIndex(const QPoint &abs) const = 0;
51  virtual int getXFromIndex(int index) = 0;
52 
53  const Link &getLink() const;
54  const QString &getText() const;
55  FlagsEnum<MessageElementFlag> getFlags() const;
56 
57 protected:
58  bool trailingSpace = true;
59 
60 private:
61  QString text_;
62  QRect rect_;
63  Link link_;
64  MessageElement &creator_;
65  int line_{};
66 };
67 
68 // IMAGE
70 {
71 public:
73  const QSize &size);
74 
75 protected:
76  void addCopyTextToString(QString &str, uint32_t from = 0,
77  uint32_t to = UINT32_MAX) const override;
78  int getSelectionIndexCount() const override;
79  void paint(QPainter &painter) override;
80  void paintAnimated(QPainter &painter, int yOffset) override;
81  int getMouseOverIndex(const QPoint &abs) const override;
82  int getXFromIndex(int index) override;
83 
85 };
86 
88 {
89 public:
91  const QSize &size, QColor color);
92 
93 protected:
94  void paint(QPainter &painter) override;
95 
96 private:
97  QColor color_;
98 };
99 
101 {
102 public:
104  ImagePtr image,
105  const QSize &imageSize, QColor color,
106  int padding);
107 
108 protected:
109  void paint(QPainter &painter) override;
110 
111 private:
112  const QColor color_;
113  const QSize imageSize_;
114  const int padding_;
115 };
116 
117 // TEXT
119 {
120 public:
121  TextLayoutElement(MessageElement &creator_, QString &text,
122  const QSize &size, QColor color_, FontStyle style_,
123  float scale_);
124 
125  void listenToLinkChanges();
126 
127 protected:
128  void addCopyTextToString(QString &str, uint32_t from = 0,
129  uint32_t to = UINT32_MAX) const override;
130  int getSelectionIndexCount() const override;
131  void paint(QPainter &painter) override;
132  void paintAnimated(QPainter &painter, int yOffset) override;
133  int getMouseOverIndex(const QPoint &abs) const override;
134  int getXFromIndex(int index) override;
135 
136  QColor color_;
138  float scale_;
139 
140  pajlada::Signals::SignalHolder managedConnections_;
141 };
142 
143 // TEXT ICON
144 // two lines of text (characters) in the size of a normal chat badge
146 {
147 public:
148  TextIconLayoutElement(MessageElement &creator_, const QString &line1,
149  const QString &line2, float scale, const QSize &size);
150 
151 protected:
152  void addCopyTextToString(QString &str, uint32_t from = 0,
153  uint32_t to = UINT32_MAX) const override;
154  int getSelectionIndexCount() const override;
155  void paint(QPainter &painter) override;
156  void paintAnimated(QPainter &painter, int yOffset) override;
157  int getMouseOverIndex(const QPoint &abs) const override;
158  int getXFromIndex(int index) override;
159 
160 private:
161  float scale;
162  QString line1;
163  QString line2;
164 };
165 
167 {
168 public:
169  ReplyCurveLayoutElement(MessageElement &creator, int width, float thickness,
170  float radius, float neededMargin);
171 
172 protected:
173  void paint(QPainter &painter) override;
174  void paintAnimated(QPainter &painter, int yOffset) override;
175  int getMouseOverIndex(const QPoint &abs) const override;
176  int getXFromIndex(int index) override;
177  void addCopyTextToString(QString &str, uint32_t from = 0,
178  uint32_t to = UINT32_MAX) const override;
179  int getSelectionIndexCount() const override;
180 
181 private:
182  const QPen pen_;
183  const float radius_;
184  const float neededMargin_;
185 };
186 
187 } // namespace chatterino
FontStyle style_
Definition: MessageLayoutElement.hpp:137
Definition: MessageLayoutElement.hpp:26
QColor color_
Definition: MessageLayoutElement.hpp:136
Definition: Application.cpp:48
Definition: MessageLayoutElement.hpp:145
Definition: MessageLayoutElement.hpp:69
Definition: MessageLayoutElement.hpp:166
float scale_
Definition: MessageLayoutElement.hpp:138
Definition: MessageElement.hpp:162
Definition: MessageLayoutElement.hpp:87
Definition: MessageLayoutElement.hpp:100
Definition: MessageLayoutElement.hpp:118
pajlada::Signals::SignalHolder managedConnections_
Definition: MessageLayoutElement.hpp:140
ImagePtr image_
Definition: MessageLayoutElement.hpp:84
FontStyle
Definition: Fonts.hpp:20
std::shared_ptr< Image > ImagePtr
Definition: ModerationAction.hpp:14