2018-01-11 20:16:25 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-08-16 00:16:33 +02:00
|
|
|
#include "common/Common.hpp"
|
2018-06-26 17:20:03 +02:00
|
|
|
#include "common/FlagsEnum.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-08-11 22:23:06 +02:00
|
|
|
struct Message;
|
|
|
|
using MessagePtr = std::shared_ptr<const Message>;
|
|
|
|
|
|
|
|
struct Selection;
|
|
|
|
struct MessageLayoutContainer;
|
|
|
|
class MessageLayoutElement;
|
|
|
|
|
|
|
|
enum class MessageElementFlag;
|
|
|
|
using MessageElementFlags = FlagsEnum<MessageElementFlag>;
|
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
enum class MessageLayoutFlag : uint8_t {
|
|
|
|
RequiresBufferUpdate = 1 << 1,
|
|
|
|
RequiresLayout = 1 << 2,
|
|
|
|
AlternateBackground = 1 << 3,
|
|
|
|
Collapsed = 1 << 4,
|
|
|
|
Expanded = 1 << 5,
|
2018-10-21 13:29:52 +02:00
|
|
|
IgnoreHighlights = 1 << 6,
|
2018-08-07 07:55:31 +02:00
|
|
|
};
|
|
|
|
using MessageLayoutFlags = FlagsEnum<MessageLayoutFlag>;
|
|
|
|
|
2018-01-28 16:29:47 +01:00
|
|
|
class MessageLayout : boost::noncopyable
|
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
public:
|
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
|
|
|
|
|
|
|
int getHeight() const;
|
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageLayoutFlags flags;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
bool layout(int width, float scale_, MessageElementFlags 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;
|
2018-10-02 12:56:10 +02:00
|
|
|
int getFirstMessageCharacterIndex() const;
|
2018-01-11 20:16:25 +01:00
|
|
|
int getSelectionIndex(QPoint position);
|
2018-08-16 00:16:33 +02:00
|
|
|
void addSelectionText(QString &str, int from = 0, int to = INT_MAX,
|
|
|
|
CopyMode copymode = CopyMode::Everything);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
// Misc
|
|
|
|
bool isDisabled() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// variables
|
2018-05-31 14:15:04 +02:00
|
|
|
MessagePtr message_;
|
2018-08-11 22:23:06 +02:00
|
|
|
std::shared_ptr<MessageLayoutContainer> container_;
|
2018-09-20 13:09:37 +02:00
|
|
|
std::shared_ptr<QPixmap> buffer_{};
|
2018-05-31 14:15:04 +02:00
|
|
|
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;
|
2018-12-02 19:20:14 +01:00
|
|
|
unsigned int layoutCount_ = 0;
|
2018-05-31 14:15:04 +02:00
|
|
|
unsigned int bufferUpdatedCount_ = 0;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElementFlags currentWordFlags_;
|
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-08-07 07:55:31 +02:00
|
|
|
void actuallyLayout(int width, MessageElementFlags 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
|