2018-01-11 20:16:25 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-02 12:56:10 +02:00
|
|
|
#include "common/FlagsEnum.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "messages/Link.hpp"
|
2018-01-11 20:16:25 +01:00
|
|
|
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <pajlada/signals/signalholder.hpp>
|
2022-11-16 00:32:15 +01:00
|
|
|
#include <QPen>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QRect>
|
|
|
|
#include <QString>
|
2021-12-19 15:57:56 +01:00
|
|
|
|
2022-11-16 00:32:15 +01:00
|
|
|
#include <climits>
|
|
|
|
#include <cstdint>
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
class QPainter;
|
|
|
|
|
|
|
|
namespace chatterino {
|
2018-04-03 02:55:32 +02:00
|
|
|
class MessageElement;
|
2018-08-11 22:23:06 +02:00
|
|
|
class Image;
|
|
|
|
using ImagePtr = std::shared_ptr<Image>;
|
|
|
|
enum class FontStyle : uint8_t;
|
2022-12-31 15:41:01 +01:00
|
|
|
enum class MessageElementFlag : int64_t;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
class MessageLayoutElement : boost::noncopyable
|
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
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();
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2022-11-10 21:36:19 +01:00
|
|
|
bool reversedNeutral = false;
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
const QRect &getRect() const;
|
|
|
|
MessageElement &getCreator() const;
|
|
|
|
void setPosition(QPoint point);
|
|
|
|
bool hasTrailingSpace() const;
|
2021-04-26 00:25:23 +02:00
|
|
|
int getLine() const;
|
|
|
|
void setLine(int line);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
MessageLayoutElement *setTrailingSpace(bool value);
|
2018-07-06 19:23:47 +02:00
|
|
|
MessageLayoutElement *setLink(const Link &link_);
|
2018-09-30 18:18:30 +02:00
|
|
|
MessageLayoutElement *setText(const QString &text_);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2022-11-16 00:32:15 +01:00
|
|
|
virtual void addCopyTextToString(QString &str, uint32_t from = 0,
|
|
|
|
uint32_t to = UINT32_MAX) const = 0;
|
2018-09-30 18:18:30 +02:00
|
|
|
virtual int getSelectionIndexCount() const = 0;
|
2018-01-11 20:16:25 +01:00
|
|
|
virtual void paint(QPainter &painter) = 0;
|
2018-01-13 02:13:59 +01:00
|
|
|
virtual void paintAnimated(QPainter &painter, int yOffset) = 0;
|
2018-09-30 18:18:30 +02:00
|
|
|
virtual int getMouseOverIndex(const QPoint &abs) const = 0;
|
2018-01-16 00:26:04 +01:00
|
|
|
virtual int getXFromIndex(int index) = 0;
|
2019-05-21 19:33:12 +02:00
|
|
|
|
2018-01-17 14:14:31 +01:00
|
|
|
const Link &getLink() const;
|
2018-09-30 18:18:30 +02:00
|
|
|
const QString &getText() const;
|
2018-10-02 12:56:10 +02:00
|
|
|
FlagsEnum<MessageElementFlag> getFlags() const;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool trailingSpace = true;
|
|
|
|
|
|
|
|
private:
|
2018-09-30 18:18:30 +02:00
|
|
|
QString text_;
|
2018-07-06 19:23:47 +02:00
|
|
|
QRect rect_;
|
|
|
|
Link link_;
|
|
|
|
MessageElement &creator_;
|
2021-04-26 00:25:23 +02:00
|
|
|
int line_{};
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// IMAGE
|
|
|
|
class ImageLayoutElement : public MessageLayoutElement
|
|
|
|
{
|
|
|
|
public:
|
2018-08-06 21:17:03 +02:00
|
|
|
ImageLayoutElement(MessageElement &creator, ImagePtr image,
|
|
|
|
const QSize &size);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
protected:
|
2022-11-16 00:32:15 +01:00
|
|
|
void addCopyTextToString(QString &str, uint32_t from = 0,
|
|
|
|
uint32_t to = UINT32_MAX) const override;
|
2018-09-30 18:18:30 +02:00
|
|
|
int getSelectionIndexCount() const override;
|
2018-04-01 16:43:30 +02:00
|
|
|
void paint(QPainter &painter) override;
|
|
|
|
void paintAnimated(QPainter &painter, int yOffset) override;
|
2018-09-30 18:18:30 +02:00
|
|
|
int getMouseOverIndex(const QPoint &abs) const override;
|
2018-04-01 16:43:30 +02:00
|
|
|
int getXFromIndex(int index) override;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
ImagePtr image_;
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
|
|
|
|
2019-09-08 11:30:06 +02:00
|
|
|
class ImageWithBackgroundLayoutElement : public ImageLayoutElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImageWithBackgroundLayoutElement(MessageElement &creator, ImagePtr image,
|
|
|
|
const QSize &size, QColor color);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paint(QPainter &painter) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QColor color_;
|
|
|
|
};
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
class ImageWithCircleBackgroundLayoutElement : public ImageLayoutElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImageWithCircleBackgroundLayoutElement(MessageElement &creator,
|
|
|
|
ImagePtr image,
|
|
|
|
const QSize &imageSize, QColor color,
|
|
|
|
int padding);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paint(QPainter &painter) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const QColor color_;
|
|
|
|
const QSize imageSize_;
|
|
|
|
const int padding_;
|
|
|
|
};
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// TEXT
|
|
|
|
class TextLayoutElement : public MessageLayoutElement
|
|
|
|
{
|
|
|
|
public:
|
2018-08-06 21:17:03 +02:00
|
|
|
TextLayoutElement(MessageElement &creator_, QString &text,
|
2018-11-14 17:26:08 +01:00
|
|
|
const QSize &size, QColor color_, FontStyle style_,
|
|
|
|
float scale_);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-10-23 10:32:13 +02:00
|
|
|
void listenToLinkChanges();
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
protected:
|
2022-11-16 00:32:15 +01:00
|
|
|
void addCopyTextToString(QString &str, uint32_t from = 0,
|
|
|
|
uint32_t to = UINT32_MAX) const override;
|
2018-09-30 18:18:30 +02:00
|
|
|
int getSelectionIndexCount() const override;
|
2018-04-01 16:43:30 +02:00
|
|
|
void paint(QPainter &painter) override;
|
|
|
|
void paintAnimated(QPainter &painter, int yOffset) override;
|
2018-09-30 18:18:30 +02:00
|
|
|
int getMouseOverIndex(const QPoint &abs) const override;
|
2018-04-01 16:43:30 +02:00
|
|
|
int getXFromIndex(int index) override;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-11-14 17:26:08 +01:00
|
|
|
QColor color_;
|
|
|
|
FontStyle style_;
|
|
|
|
float scale_;
|
2018-10-23 10:32:13 +02:00
|
|
|
|
2021-12-19 15:57:56 +01:00
|
|
|
pajlada::Signals::SignalHolder managedConnections_;
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
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:
|
2022-11-16 00:32:15 +01:00
|
|
|
void addCopyTextToString(QString &str, uint32_t from = 0,
|
|
|
|
uint32_t to = UINT32_MAX) const override;
|
2018-09-30 18:18:30 +02:00
|
|
|
int getSelectionIndexCount() const override;
|
2018-04-01 16:43:30 +02:00
|
|
|
void paint(QPainter &painter) override;
|
|
|
|
void paintAnimated(QPainter &painter, int yOffset) override;
|
2018-09-30 18:18:30 +02:00
|
|
|
int getMouseOverIndex(const QPoint &abs) const override;
|
2018-04-01 16:43:30 +02:00
|
|
|
int getXFromIndex(int index) override;
|
2018-01-17 14:14:31 +01:00
|
|
|
|
|
|
|
private:
|
2018-04-14 21:59:51 +02:00
|
|
|
float scale;
|
2018-01-17 14:14:31 +01:00
|
|
|
QString line1;
|
|
|
|
QString line2;
|
|
|
|
};
|
2018-04-01 16:43:30 +02:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
class ReplyCurveLayoutElement : public MessageLayoutElement
|
|
|
|
{
|
|
|
|
public:
|
2022-11-02 09:19:44 +01:00
|
|
|
ReplyCurveLayoutElement(MessageElement &creator, int width, float thickness,
|
|
|
|
float radius, float neededMargin);
|
2022-07-31 12:45:25 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paint(QPainter &painter) override;
|
|
|
|
void paintAnimated(QPainter &painter, int yOffset) override;
|
|
|
|
int getMouseOverIndex(const QPoint &abs) const override;
|
|
|
|
int getXFromIndex(int index) override;
|
2022-11-16 00:32:15 +01:00
|
|
|
void addCopyTextToString(QString &str, uint32_t from = 0,
|
|
|
|
uint32_t to = UINT32_MAX) const override;
|
2022-07-31 12:45:25 +02:00
|
|
|
int getSelectionIndexCount() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const QPen pen_;
|
2022-11-02 09:19:44 +01:00
|
|
|
const float radius_;
|
2022-07-31 12:45:25 +02:00
|
|
|
const float neededMargin_;
|
|
|
|
};
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
} // namespace chatterino
|