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