2018-01-11 20:16:25 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <QPoint>
|
2018-01-15 04:08:48 +01:00
|
|
|
#include <QRect>
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
class QPainter;
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
namespace messages {
|
|
|
|
class Selection;
|
|
|
|
|
|
|
|
namespace layouts {
|
|
|
|
class MessageLayoutElement;
|
|
|
|
|
|
|
|
struct Margin {
|
|
|
|
int top;
|
|
|
|
int right;
|
|
|
|
int bottom;
|
|
|
|
int left;
|
|
|
|
|
|
|
|
Margin()
|
|
|
|
: Margin(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Margin(int value)
|
|
|
|
: Margin(value, value, value, value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Margin(int _top, int _right, int _bottom, int _left)
|
|
|
|
: top(_top)
|
|
|
|
, right(_right)
|
|
|
|
, bottom(_bottom)
|
|
|
|
, left(_left)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MessageLayoutContainer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MessageLayoutContainer();
|
|
|
|
|
|
|
|
float scale;
|
|
|
|
Margin margin;
|
|
|
|
bool centered;
|
|
|
|
bool enableCompactEmotes;
|
|
|
|
int width;
|
|
|
|
|
|
|
|
int getHeight() const;
|
|
|
|
|
|
|
|
// methods
|
|
|
|
void clear();
|
|
|
|
void addElement(MessageLayoutElement *element);
|
|
|
|
void addElementNoLineBreak(MessageLayoutElement *element);
|
|
|
|
void breakLine();
|
|
|
|
bool atStartOfLine();
|
|
|
|
bool fitsInLine(int width);
|
|
|
|
void finish();
|
|
|
|
MessageLayoutElement *getElementAt(QPoint point);
|
|
|
|
|
|
|
|
// painting
|
|
|
|
void paintElements(QPainter &painter);
|
2018-01-13 02:13:59 +01:00
|
|
|
void paintAnimatedElements(QPainter &painter, int yOffset);
|
2018-01-11 20:16:25 +01:00
|
|
|
void paintSelection(QPainter &painter, int messageIndex, Selection &selection);
|
|
|
|
|
2018-01-15 04:08:48 +01:00
|
|
|
// selection
|
|
|
|
int getSelectionIndex(QPoint point);
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
private:
|
|
|
|
// helpers
|
|
|
|
void _addElement(MessageLayoutElement *element);
|
|
|
|
|
|
|
|
// variables
|
|
|
|
int line;
|
|
|
|
int height;
|
|
|
|
int currentX, currentY;
|
|
|
|
size_t lineStart = 0;
|
|
|
|
int lineHeight = 0;
|
|
|
|
int spaceWidth = 4;
|
|
|
|
std::vector<std::unique_ptr<MessageLayoutElement>> elements;
|
2018-01-15 04:08:48 +01:00
|
|
|
|
|
|
|
struct Line {
|
|
|
|
int startIndex;
|
|
|
|
QRect rect;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<Line> lines;
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
|
|
|
} // namespace layouts
|
2018-01-13 02:13:59 +01:00
|
|
|
} // namespace messages
|
|
|
|
} // namespace chatterino
|