2018-01-11 20:16:25 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QRect>
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <climits>
|
|
|
|
|
2018-01-17 14:14:31 +01:00
|
|
|
#include "messages/link.hpp"
|
2018-01-11 20:16:25 +01:00
|
|
|
#include "messages/messagecolor.hpp"
|
|
|
|
#include "singletons/fontmanager.hpp"
|
|
|
|
|
|
|
|
class QPainter;
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
namespace messages {
|
2018-01-28 03:29:42 +01:00
|
|
|
struct MessageElement;
|
2018-01-11 20:16:25 +01:00
|
|
|
class Image;
|
|
|
|
|
|
|
|
namespace layouts {
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
struct MessageLayoutElement : boost::noncopyable {
|
2018-01-11 20:16:25 +01:00
|
|
|
public:
|
|
|
|
MessageLayoutElement(MessageElement &creator, const QSize &size);
|
|
|
|
|
|
|
|
const QRect &getRect() const;
|
|
|
|
MessageElement &getCreator() const;
|
|
|
|
void setPosition(QPoint point);
|
|
|
|
bool hasTrailingSpace() const;
|
|
|
|
|
|
|
|
MessageLayoutElement *setTrailingSpace(bool value);
|
2018-01-17 14:14:31 +01:00
|
|
|
MessageLayoutElement *setLink(const Link &link);
|
2018-01-11 20:16:25 +01: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;
|
2018-01-11 20:16:25 +01:00
|
|
|
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;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool trailingSpace = true;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QRect rect;
|
2018-01-17 14:14:31 +01:00
|
|
|
Link link;
|
2018-01-11 20:16:25 +01:00
|
|
|
MessageElement &creator;
|
|
|
|
};
|
|
|
|
|
|
|
|
// IMAGE
|
|
|
|
class ImageLayoutElement : public MessageLayoutElement
|
|
|
|
{
|
|
|
|
public:
|
2018-01-17 14:14:31 +01:00
|
|
|
ImageLayoutElement(MessageElement &creator, Image *image, const QSize &size);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override;
|
|
|
|
virtual int getSelectionIndexCount() override;
|
|
|
|
virtual void paint(QPainter &painter) override;
|
2018-01-13 02:13:59 +01:00
|
|
|
virtual void paintAnimated(QPainter &painter, int yOffset) override;
|
2018-01-11 20:16:25 +01:00
|
|
|
virtual int getMouseOverIndex(const QPoint &abs) override;
|
2018-01-16 00:26:04 +01:00
|
|
|
virtual int getXFromIndex(int index) override;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
private:
|
2018-01-17 14:14:31 +01:00
|
|
|
Image *image;
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// TEXT
|
|
|
|
class TextLayoutElement : public MessageLayoutElement
|
|
|
|
{
|
|
|
|
public:
|
2018-01-17 14:14:31 +01:00
|
|
|
TextLayoutElement(MessageElement &creator, QString &text, const QSize &size, QColor color,
|
2018-01-11 20:16:25 +01:00
|
|
|
FontStyle style, float scale);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override;
|
|
|
|
virtual int getSelectionIndexCount() override;
|
|
|
|
virtual void paint(QPainter &painter) override;
|
2018-01-13 02:13:59 +01:00
|
|
|
virtual void paintAnimated(QPainter &painter, int yOffset) override;
|
2018-01-11 20:16:25 +01:00
|
|
|
virtual int getMouseOverIndex(const QPoint &abs) override;
|
2018-01-16 00:26:04 +01:00
|
|
|
virtual int getXFromIndex(int index) override;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
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:
|
|
|
|
TextIconLayoutElement(MessageElement &creator, const QString &line1, const QString &line2,
|
|
|
|
float scale, const QSize &size);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override;
|
|
|
|
virtual int getSelectionIndexCount() override;
|
|
|
|
virtual void paint(QPainter &painter) override;
|
|
|
|
virtual void paintAnimated(QPainter &painter, int yOffset) override;
|
|
|
|
virtual int getMouseOverIndex(const QPoint &abs) override;
|
|
|
|
virtual int getXFromIndex(int index) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString line1;
|
|
|
|
QString line2;
|
|
|
|
float scale;
|
|
|
|
};
|
2018-01-11 20:16:25 +01:00
|
|
|
} // namespace layouts
|
|
|
|
} // namespace messages
|
|
|
|
} // namespace chatterino
|