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

120 lines
3.3 KiB
C++
Raw Normal View History

#pragma once
#include <QPoint>
#include <QRect>
#include <QString>
#include <boost/noncopyable.hpp>
#include <climits>
2018-08-02 14:23:27 +02:00
#include "messages/Image.hpp"
2018-06-26 14:09:39 +02:00
#include "messages/Link.hpp"
#include "messages/MessageColor.hpp"
2018-06-28 19:46:45 +02:00
#include "singletons/Fonts.hpp"
class QPainter;
namespace chatterino {
class MessageElement;
class MessageLayoutElement : boost::noncopyable
{
public:
2018-07-06 19:23:47 +02:00
MessageLayoutElement(MessageElement &creator_, const QSize &size);
2018-04-06 16:37:30 +02:00
virtual ~MessageLayoutElement();
const QRect &getRect() const;
MessageElement &getCreator() const;
void setPosition(QPoint point);
bool hasTrailingSpace() const;
MessageLayoutElement *setTrailingSpace(bool value);
2018-07-06 19:23:47 +02:00
MessageLayoutElement *setLink(const Link &link_);
2018-08-06 21:17:03 +02:00
virtual void addCopyTextToString(QString &str, int from = 0,
int to = INT_MAX) const = 0;
virtual int getSelectionIndexCount() = 0;
virtual void paint(QPainter &painter) = 0;
2018-01-13 02:13:59 +01:00
virtual void paintAnimated(QPainter &painter, int yOffset) = 0;
virtual int getMouseOverIndex(const QPoint &abs) = 0;
2018-01-16 00:26:04 +01:00
virtual int getXFromIndex(int index) = 0;
2018-01-17 14:14:31 +01:00
const Link &getLink() const;
protected:
bool trailingSpace = true;
private:
2018-07-06 19:23:47 +02:00
QRect rect_;
Link link_;
MessageElement &creator_;
};
// IMAGE
class ImageLayoutElement : public MessageLayoutElement
{
public:
2018-08-06 21:17:03 +02:00
ImageLayoutElement(MessageElement &creator, ImagePtr image,
const QSize &size);
protected:
2018-08-06 21:17:03 +02:00
void addCopyTextToString(QString &str, int from = 0,
int to = INT_MAX) const override;
2018-04-01 16:43:30 +02:00
int getSelectionIndexCount() override;
void paint(QPainter &painter) override;
void paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) override;
int getXFromIndex(int index) override;
private:
2018-08-02 14:23:27 +02:00
ImagePtr image_;
};
// TEXT
class TextLayoutElement : public MessageLayoutElement
{
public:
2018-08-06 21:17:03 +02:00
TextLayoutElement(MessageElement &creator_, QString &text,
const QSize &size, QColor color, FontStyle style,
float scale);
protected:
2018-08-06 21:17:03 +02:00
void addCopyTextToString(QString &str, int from = 0,
int to = INT_MAX) const override;
2018-04-01 16:43:30 +02:00
int getSelectionIndexCount() override;
void paint(QPainter &painter) override;
void paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) override;
int getXFromIndex(int index) override;
private:
QString text;
QColor color;
FontStyle style;
float scale;
};
2018-01-17 14:14:31 +01:00
// TEXT ICON
// two lines of text (characters) in the size of a normal chat badge
class TextIconLayoutElement : public MessageLayoutElement
{
public:
2018-08-06 21:17:03 +02:00
TextIconLayoutElement(MessageElement &creator_, const QString &line1,
const QString &line2, float scale, const QSize &size);
2018-01-17 14:14:31 +01:00
protected:
2018-08-06 21:17:03 +02:00
void addCopyTextToString(QString &str, int from = 0,
int to = INT_MAX) const override;
2018-04-01 16:43:30 +02:00
int getSelectionIndexCount() override;
void paint(QPainter &painter) override;
void paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) override;
int getXFromIndex(int index) override;
2018-01-17 14:14:31 +01:00
private:
float scale;
2018-01-17 14:14:31 +01:00
QString line1;
QString line2;
};
2018-04-01 16:43:30 +02:00
} // namespace chatterino