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

84 lines
2 KiB
C++
Raw Normal View History

#pragma once
2018-06-26 14:09:39 +02:00
#include "messages/layouts/MessageLayoutContainer.hpp"
#include "messages/layouts/MessageLayoutElement.hpp"
#include "messages/Message.hpp"
#include "messages/Selection.hpp"
2018-06-26 15:33:51 +02:00
#include "common/FlagsEnum.hpp"
#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
{
public:
enum Flags : uint8_t {
RequiresBufferUpdate = 1 << 1,
RequiresLayout = 1 << 2,
AlternateBackground = 1 << 3,
Collapsed = 1 << 4,
Expanded = 1 << 5,
};
MessageLayout(MessagePtr message_);
2018-04-06 16:37:30 +02:00
~MessageLayout();
Message *getMessage();
// Height
int getHeight() const;
// Flags
2018-06-26 17:06:17 +02:00
FlagsEnum<Flags> flags;
// Layout
bool layout(int width, float scale_, MessageElement::Flags flags);
// Painting
void paint(QPainter &painter, int width, int y, int messageIndex, Selection &selection,
2018-01-23 22:48:33 +01:00
bool isLastReadMessage, bool isWindowFocused);
void invalidateBuffer();
void deleteBuffer();
2018-04-18 09:12:29 +02:00
void deleteCache();
// Elements
const MessageLayoutElement *getElementAt(QPoint point);
int getLastCharacterIndex() const;
int getSelectionIndex(QPoint position);
void addSelectionText(QString &str, int from = 0, int to = INT_MAX);
// 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 layoutState_ = -1;
float scale_ = -1;
unsigned int bufferUpdatedCount_ = 0;
MessageElement::Flags currentWordFlags_ = MessageElement::None;
int collapsedHeight_ = 32;
// methods
2018-01-17 16:52:51 +01:00
void actuallyLayout(int width, MessageElement::Flags flags);
void updateBuffer(QPixmap *pixmap, int messageIndex, Selection &selection);
};
2018-04-01 16:43:30 +02:00
using MessageLayoutPtr = std::shared_ptr<MessageLayout>;
} // namespace chatterino