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
|
|
|
|
2018-01-28 16:29:47 +01:00
|
|
|
#include "messages/message.hpp"
|
2018-01-16 00:26:04 +01:00
|
|
|
#include "messages/selection.hpp"
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
class QPainter;
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
namespace messages {
|
|
|
|
|
|
|
|
namespace layouts {
|
2018-01-28 03:29:42 +01:00
|
|
|
struct MessageLayoutElement;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-28 16:29:47 +01:00
|
|
|
struct MessageLayoutContainer {
|
2018-01-11 20:16:25 +01:00
|
|
|
public:
|
|
|
|
MessageLayoutContainer();
|
|
|
|
|
|
|
|
Margin margin;
|
|
|
|
bool centered;
|
|
|
|
bool enableCompactEmotes;
|
|
|
|
|
|
|
|
int getHeight() const;
|
2018-01-28 16:29:47 +01:00
|
|
|
int getWidth() const;
|
|
|
|
float getScale() const;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
// methods
|
2018-01-28 16:29:47 +01:00
|
|
|
void begin(int width, float scale, Message::MessageFlags flags);
|
2018-04-01 16:41:32 +02:00
|
|
|
void end();
|
2018-01-28 16:29:47 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
void clear();
|
|
|
|
void addElement(MessageLayoutElement *element);
|
|
|
|
void addElementNoLineBreak(MessageLayoutElement *element);
|
|
|
|
void breakLine();
|
|
|
|
bool atStartOfLine();
|
|
|
|
bool fitsInLine(int width);
|
|
|
|
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-16 02:39:31 +01:00
|
|
|
int getLastCharacterIndex() const;
|
|
|
|
void addSelectionText(QString &str, int from, int to);
|
2018-01-15 04:08:48 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
private:
|
2018-01-16 00:26:04 +01:00
|
|
|
struct Line {
|
|
|
|
int startIndex;
|
|
|
|
int endIndex;
|
|
|
|
int startCharIndex;
|
|
|
|
int endCharIndex;
|
|
|
|
QRect rect;
|
|
|
|
};
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// helpers
|
|
|
|
void _addElement(MessageLayoutElement *element);
|
|
|
|
|
|
|
|
// variables
|
2018-01-28 16:29:47 +01:00
|
|
|
float scale;
|
|
|
|
int width;
|
|
|
|
Message::MessageFlags flags;
|
2018-01-11 20:16:25 +01:00
|
|
|
int line;
|
|
|
|
int height;
|
|
|
|
int currentX, currentY;
|
2018-01-16 00:26:04 +01:00
|
|
|
int charIndex = 0;
|
2018-01-11 20:16:25 +01:00
|
|
|
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
|
|
|
|
|
|
|
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
|