mirror-chatterino2/src/messages/layouts/messagelayoutcontainer.hpp

119 lines
2.6 KiB
C++
Raw Normal View History

#pragma once
#include <memory>
#include <vector>
#include <QPoint>
2018-01-15 04:08:48 +01:00
#include <QRect>
2018-01-28 16:29:47 +01:00
#include "messages/message.hpp"
2018-01-16 00:26:04 +01:00
#include "messages/selection.hpp"
class QPainter;
namespace chatterino {
namespace messages {
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)
{
}
};
2018-01-28 16:29:47 +01:00
struct MessageLayoutContainer {
2018-04-01 16:43:30 +02:00
MessageLayoutContainer() = default;
2018-04-01 16:43:30 +02:00
Margin margin = {4, 8, 4, 8};
bool centered = false;
bool enableCompactEmotes = false;
int getHeight() const;
2018-01-28 16:29:47 +01:00
int getWidth() const;
float getScale() const;
// 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
void clear();
2018-04-18 09:12:29 +02:00
bool canAddElements();
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-04-10 03:29:00 +02:00
void paintSelection(QPainter &painter, int messageIndex, Selection &selection, int yOffset);
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
bool isCollapsed();
private:
2018-01-16 00:26:04 +01:00
struct Line {
int startIndex;
int endIndex;
int startCharIndex;
int endCharIndex;
QRect rect;
};
// helpers
void _addElement(MessageLayoutElement *element, bool forceAdd = false);
// variables
2018-04-01 16:43:30 +02:00
float scale = 1.f;
int width = 0;
Message::MessageFlags flags = Message::MessageFlags::None;
int line = 0;
int height = 0;
int currentX = 0;
int currentY = 0;
2018-01-16 00:26:04 +01:00
int charIndex = 0;
size_t lineStart = 0;
int lineHeight = 0;
int spaceWidth = 4;
2018-05-23 13:31:55 +02:00
int textLineHeight = 0;
int dotdotdotWidth = 0;
bool _canAddMessages = true;
bool _isCollapsed = false;
bool canCollapse();
2018-01-15 04:08:48 +01:00
2018-04-01 16:43:30 +02:00
std::vector<std::unique_ptr<MessageLayoutElement>> elements;
2018-01-15 04:08:48 +01:00
std::vector<Line> lines;
};
2018-04-01 16:43:30 +02:00
} // namespace layouts
2018-01-13 02:13:59 +01:00
} // namespace messages
} // namespace chatterino