2018-01-11 20:16:25 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "messages/layouts/messagelayoutcontainer.hpp"
|
|
|
|
#include "messages/layouts/messagelayoutelement.hpp"
|
|
|
|
#include "messages/message.hpp"
|
|
|
|
#include "messages/selection.hpp"
|
2018-01-28 15:28:02 +01:00
|
|
|
#include "util/flagsenum.hpp"
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
namespace messages {
|
|
|
|
namespace layouts {
|
2018-01-28 04:07:45 +01:00
|
|
|
struct MessageLayout : boost::noncopyable {
|
2018-01-11 20:16:25 +01:00
|
|
|
public:
|
2018-01-28 04:07:45 +01:00
|
|
|
enum Flags : uint8_t { Collapsed, RequiresBufferUpdate, RequiresLayout };
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
MessageLayout(MessagePtr message);
|
|
|
|
|
|
|
|
Message *getMessage();
|
|
|
|
|
|
|
|
// Height
|
|
|
|
int getHeight() const;
|
|
|
|
|
|
|
|
// Flags
|
2018-01-28 04:07:45 +01:00
|
|
|
util::FlagsEnum<Flags> flags;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
// Layout
|
2018-01-17 16:52:51 +01:00
|
|
|
bool layout(int width, float scale, MessageElement::Flags flags);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
// Painting
|
2018-01-23 22:48:33 +01:00
|
|
|
void paint(QPainter &painter, int y, int messageIndex, Selection &selection,
|
|
|
|
bool isLastReadMessage, bool isWindowFocused);
|
2018-01-11 20:16:25 +01:00
|
|
|
void invalidateBuffer();
|
|
|
|
void deleteBuffer();
|
|
|
|
|
|
|
|
// Elements
|
|
|
|
const MessageLayoutElement *getElementAt(QPoint point);
|
|
|
|
int getLastCharacterIndex() const;
|
|
|
|
int getSelectionIndex(QPoint position);
|
2018-01-16 02:39:31 +01:00
|
|
|
void addSelectionText(QString &str, int from, int to);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
// Misc
|
|
|
|
bool isDisabled() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// variables
|
|
|
|
MessagePtr message;
|
|
|
|
MessageLayoutContainer container;
|
|
|
|
std::shared_ptr<QPixmap> buffer = nullptr;
|
|
|
|
bool bufferValid = false;
|
|
|
|
|
|
|
|
int height = 0;
|
|
|
|
|
|
|
|
int currentLayoutWidth = -1;
|
|
|
|
int fontGeneration = -1;
|
|
|
|
int emoteGeneration = -1;
|
2018-01-23 21:56:25 +01:00
|
|
|
QString timestampFormat;
|
2018-01-11 20:16:25 +01:00
|
|
|
float scale = -1;
|
|
|
|
unsigned int bufferUpdatedCount = 0;
|
|
|
|
|
2018-01-17 17:02:34 +01:00
|
|
|
MessageElement::Flags currentWordFlags = MessageElement::None;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
int collapsedHeight = 32;
|
|
|
|
|
|
|
|
// methods
|
2018-01-17 16:52:51 +01:00
|
|
|
void actuallyLayout(int width, MessageElement::Flags flags);
|
2018-01-11 20:16:25 +01:00
|
|
|
void updateBuffer(QPixmap *pixmap, int messageIndex, Selection &selection);
|
|
|
|
};
|
|
|
|
|
2018-01-28 04:07:45 +01:00
|
|
|
typedef std::shared_ptr<MessageLayout> MessageLayoutPtr;
|
2018-01-11 20:16:25 +01:00
|
|
|
} // namespace layouts
|
|
|
|
} // namespace messages
|
|
|
|
} // namespace chatterino
|