2018-01-11 20:16:25 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-06-26 17:20:03 +02:00
|
|
|
#include "common/FlagsEnum.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "messages/Message.hpp"
|
|
|
|
#include "messages/Selection.hpp"
|
2018-06-26 17:20:03 +02:00
|
|
|
#include "messages/layouts/MessageLayoutContainer.hpp"
|
|
|
|
#include "messages/layouts/MessageLayoutElement.hpp"
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace chatterino {
|
2018-04-01 16:43:30 +02:00
|
|
|
|
2018-01-28 16:29:47 +01:00
|
|
|
class MessageLayout : boost::noncopyable
|
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
public:
|
2018-05-06 14:38:23 +02:00
|
|
|
enum Flags : uint8_t {
|
|
|
|
RequiresBufferUpdate = 1 << 1,
|
|
|
|
RequiresLayout = 1 << 2,
|
2018-05-24 11:35:50 +02:00
|
|
|
AlternateBackground = 1 << 3,
|
|
|
|
Collapsed = 1 << 4,
|
|
|
|
Expanded = 1 << 5,
|
2018-05-06 14:38:23 +02:00
|
|
|
};
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-05-31 14:15:04 +02:00
|
|
|
MessageLayout(MessagePtr message_);
|
2018-04-06 16:37:30 +02:00
|
|
|
~MessageLayout();
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
const Message *getMessage();
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
// Height
|
|
|
|
int getHeight() const;
|
|
|
|
|
|
|
|
// Flags
|
2018-06-26 17:06:17 +02:00
|
|
|
FlagsEnum<Flags> flags;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
// Layout
|
2018-05-31 14:15:04 +02:00
|
|
|
bool layout(int width, float scale_, MessageElement::Flags flags);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
// Painting
|
2018-08-06 21:17:03 +02:00
|
|
|
void paint(QPainter &painter, int width, int y, int messageIndex,
|
|
|
|
Selection &selection, bool isLastReadMessage,
|
|
|
|
bool isWindowFocused);
|
2018-01-11 20:16:25 +01:00
|
|
|
void invalidateBuffer();
|
|
|
|
void deleteBuffer();
|
2018-04-18 09:12:29 +02:00
|
|
|
void deleteCache();
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
// Elements
|
|
|
|
const MessageLayoutElement *getElementAt(QPoint point);
|
|
|
|
int getLastCharacterIndex() const;
|
|
|
|
int getSelectionIndex(QPoint position);
|
2018-05-23 20:34:37 +02:00
|
|
|
void addSelectionText(QString &str, int from = 0, int to = INT_MAX);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
// Misc
|
|
|
|
bool isDisabled() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// variables
|
2018-05-31 14:15:04 +02:00
|
|
|
MessagePtr message_;
|
|
|
|
MessageLayoutContainer container_;
|
|
|
|
std::shared_ptr<QPixmap> buffer_ = nullptr;
|
|
|
|
bool bufferValid_ = false;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-05-31 14:15:04 +02:00
|
|
|
int height_ = 0;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-05-31 14:15:04 +02:00
|
|
|
int currentLayoutWidth_ = -1;
|
2018-06-04 16:10:54 +02:00
|
|
|
int layoutState_ = -1;
|
2018-05-31 14:15:04 +02:00
|
|
|
float scale_ = -1;
|
|
|
|
unsigned int bufferUpdatedCount_ = 0;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-05-31 14:15:04 +02:00
|
|
|
MessageElement::Flags currentWordFlags_ = MessageElement::None;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-05-31 14:15:04 +02:00
|
|
|
int collapsedHeight_ = 32;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
// 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-04-01 16:43:30 +02:00
|
|
|
using MessageLayoutPtr = std::shared_ptr<MessageLayout>;
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
} // namespace chatterino
|