2018-01-11 20:16:25 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
#include "common/FlagsEnum.hpp"
|
2020-12-13 13:12:50 +01:00
|
|
|
#include "messages/ImageSet.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"
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
#include <QRect>
|
|
|
|
#include <QString>
|
|
|
|
#include <QTime>
|
|
|
|
#include <boost/noncopyable.hpp>
|
2018-04-03 02:55:32 +02:00
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
2018-09-06 16:11:25 +02:00
|
|
|
#include <pajlada/signals/signalholder.hpp>
|
2018-09-30 18:18:30 +02:00
|
|
|
#include <vector>
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
class Channel;
|
2018-01-28 03:29:42 +01:00
|
|
|
struct MessageLayoutContainer;
|
2019-09-08 11:30:06 +02:00
|
|
|
class MessageLayoutElement;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
class Image;
|
|
|
|
using ImagePtr = std::shared_ptr<Image>;
|
|
|
|
|
|
|
|
struct Emote;
|
|
|
|
using EmotePtr = std::shared_ptr<const Emote>;
|
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
enum class MessageElementFlag : int64_t {
|
|
|
|
None = 0LL,
|
|
|
|
Misc = (1LL << 0),
|
|
|
|
Text = (1LL << 1),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
Username = (1LL << 2),
|
|
|
|
Timestamp = (1LL << 3),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
TwitchEmoteImage = (1LL << 4),
|
|
|
|
TwitchEmoteText = (1LL << 5),
|
2018-08-07 07:55:31 +02:00
|
|
|
TwitchEmote = TwitchEmoteImage | TwitchEmoteText,
|
2020-10-25 10:36:00 +01:00
|
|
|
BttvEmoteImage = (1LL << 6),
|
|
|
|
BttvEmoteText = (1LL << 7),
|
2018-08-07 07:55:31 +02:00
|
|
|
BttvEmote = BttvEmoteImage | BttvEmoteText,
|
2020-08-08 15:37:22 +02:00
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
ChannelPointReward = (1LL << 8),
|
2020-08-09 11:50:53 +02:00
|
|
|
ChannelPointRewardImage = ChannelPointReward | TwitchEmoteImage,
|
2020-08-08 15:37:22 +02:00
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
FfzEmoteImage = (1LL << 10),
|
|
|
|
FfzEmoteText = (1LL << 11),
|
2018-08-07 07:55:31 +02:00
|
|
|
FfzEmote = FfzEmoteImage | FfzEmoteText,
|
|
|
|
EmoteImages = TwitchEmoteImage | BttvEmoteImage | FfzEmoteImage,
|
2019-06-22 14:34:54 +02:00
|
|
|
EmoteText = TwitchEmoteText | BttvEmoteText | FfzEmoteText,
|
2018-08-07 07:55:31 +02:00
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
BitsStatic = (1LL << 12),
|
|
|
|
BitsAnimated = (1LL << 13),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
|
|
|
// Slot 1: Twitch
|
|
|
|
// - Staff badge
|
|
|
|
// - Admin badge
|
|
|
|
// - Global Moderator badge
|
2020-10-25 10:36:00 +01:00
|
|
|
BadgeGlobalAuthority = (1LL << 14),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
|
|
|
// Slot 2: Twitch
|
|
|
|
// - Moderator badge
|
|
|
|
// - Broadcaster badge
|
2020-10-25 10:36:00 +01:00
|
|
|
BadgeChannelAuthority = (1LL << 15),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
|
|
|
// Slot 3: Twitch
|
|
|
|
// - Subscription badges
|
2020-10-25 10:36:00 +01:00
|
|
|
BadgeSubscription = (1LL << 16),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
|
|
|
// Slot 4: Twitch
|
|
|
|
// - Turbo badge
|
|
|
|
// - Prime badge
|
|
|
|
// - Bit badges
|
|
|
|
// - Game badges
|
2020-10-25 10:36:00 +01:00
|
|
|
BadgeVanity = (1LL << 17),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
|
|
|
// Slot 5: Chatterino
|
|
|
|
// - Chatterino developer badge
|
|
|
|
// - Chatterino donator badge
|
|
|
|
// - Chatterino top donator badge
|
2020-10-25 10:36:00 +01:00
|
|
|
BadgeChatterino = (1LL << 18),
|
|
|
|
|
|
|
|
// Slot 6: FrankerFaceZ
|
|
|
|
// - FFZ developer badge
|
|
|
|
// - FFZ bot badge
|
|
|
|
// - FFZ donator badge
|
|
|
|
BadgeFfz = (1LL << 32),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
|
|
|
Badges = BadgeGlobalAuthority | BadgeChannelAuthority | BadgeSubscription |
|
2020-10-25 10:36:00 +01:00
|
|
|
BadgeVanity | BadgeChatterino | BadgeFfz,
|
2018-08-07 07:55:31 +02:00
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
ChannelName = (1LL << 19),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
BitsAmount = (1LL << 20),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
ModeratorTools = (1LL << 21),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
EmojiImage = (1LL << 23),
|
|
|
|
EmojiText = (1LL << 24),
|
2018-08-07 07:55:31 +02:00
|
|
|
EmojiAll = EmojiImage | EmojiText,
|
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
AlwaysShow = (1LL << 25),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
|
|
|
// used in the ChannelView class to make the collapse buttons visible if
|
|
|
|
// needed
|
2020-10-25 10:36:00 +01:00
|
|
|
Collapsed = (1LL << 26),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
|
|
|
// used for dynamic bold usernames
|
2020-10-25 10:36:00 +01:00
|
|
|
BoldUsername = (1LL << 27),
|
|
|
|
NonBoldUsername = (1LL << 28),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
|
|
|
// for links
|
2020-10-25 10:36:00 +01:00
|
|
|
LowercaseLink = (1LL << 29),
|
|
|
|
OriginalLink = (1LL << 30),
|
2018-08-07 07:55:31 +02:00
|
|
|
|
2019-12-06 05:10:56 +01:00
|
|
|
// ZeroWidthEmotes are emotes that are supposed to overlay over any pre-existing emotes
|
|
|
|
// e.g. BTTV's SoSnowy during christmas season
|
2020-10-25 10:36:00 +01:00
|
|
|
ZeroWidthEmote = (1LL << 31),
|
|
|
|
|
|
|
|
// (1LL << 32) is used by BadgeFfz, it is next to BadgeChatterino
|
2019-12-06 05:10:56 +01:00
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
Default = Timestamp | Badges | Username | BitsStatic | FfzEmoteImage |
|
|
|
|
BttvEmoteImage | TwitchEmoteImage | BitsAmount | Text |
|
|
|
|
AlwaysShow,
|
|
|
|
};
|
|
|
|
using MessageElementFlags = FlagsEnum<MessageElementFlag>;
|
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
class MessageElement : boost::noncopyable
|
2018-01-11 20:16:25 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum UpdateFlags : char {
|
2018-08-07 07:55:31 +02:00
|
|
|
Update_Text = 1,
|
|
|
|
Update_Emotes = 2,
|
|
|
|
Update_Images = 4,
|
2018-01-11 20:16:25 +01:00
|
|
|
Update_All = Update_Text | Update_Emotes | Update_Images
|
|
|
|
};
|
2020-05-10 12:11:10 +02:00
|
|
|
enum ThumbnailType : char {
|
|
|
|
Link_Thumbnail = 1,
|
|
|
|
};
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-04-06 16:37:30 +02:00
|
|
|
virtual ~MessageElement();
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
MessageElement *setLink(const Link &link);
|
2018-09-30 18:18:30 +02:00
|
|
|
MessageElement *setText(const QString &text);
|
2018-01-11 20:16:25 +01:00
|
|
|
MessageElement *setTooltip(const QString &tooltip);
|
2020-05-10 12:11:10 +02:00
|
|
|
MessageElement *setThumbnailType(const ThumbnailType type);
|
|
|
|
MessageElement *setThumbnail(const ImagePtr &thumbnail);
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
MessageElement *setTrailingSpace(bool value);
|
|
|
|
const QString &getTooltip() const;
|
2020-05-10 12:11:10 +02:00
|
|
|
const ImagePtr &getThumbnail() const;
|
|
|
|
const ThumbnailType &getThumbnailType() const;
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
const Link &getLink() const;
|
|
|
|
bool hasTrailingSpace() const;
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElementFlags getFlags() const;
|
2018-09-06 16:11:25 +02:00
|
|
|
MessageElement *updateLink();
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
virtual void addToContainer(MessageLayoutContainer &container,
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElementFlags flags) = 0;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-10-23 10:32:13 +02:00
|
|
|
pajlada::Signals::NoArgSignal linkChanged;
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
protected:
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElement(MessageElementFlags flags);
|
2018-01-11 20:16:25 +01:00
|
|
|
bool trailingSpace = true;
|
|
|
|
|
|
|
|
private:
|
2018-09-30 18:18:30 +02:00
|
|
|
QString text_;
|
2018-07-06 19:23:47 +02:00
|
|
|
Link link_;
|
|
|
|
QString tooltip_;
|
2020-05-10 12:11:10 +02:00
|
|
|
ImagePtr thumbnail_;
|
|
|
|
ThumbnailType thumbnailType_;
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElementFlags flags_;
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
|
|
|
|
2018-12-04 21:07:55 +01:00
|
|
|
// used when layout element doesn't have a creator
|
|
|
|
class EmptyElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EmptyElement();
|
|
|
|
|
|
|
|
void addToContainer(MessageLayoutContainer &container,
|
|
|
|
MessageElementFlags flags) override;
|
|
|
|
|
|
|
|
static EmptyElement &instance();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ImagePtr image_;
|
|
|
|
};
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// contains a simple image
|
|
|
|
class ImageElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
2018-08-07 07:55:31 +02:00
|
|
|
ImageElement(ImagePtr image, MessageElementFlags flags);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
void addToContainer(MessageLayoutContainer &container,
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElementFlags flags) override;
|
2018-07-06 19:23:47 +02:00
|
|
|
|
|
|
|
private:
|
2018-08-02 14:23:27 +02:00
|
|
|
ImagePtr image_;
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// contains a text, it will split it into words
|
|
|
|
class TextElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
2018-08-07 07:55:31 +02:00
|
|
|
TextElement(const QString &text, MessageElementFlags flags,
|
2018-01-11 20:16:25 +01:00
|
|
|
const MessageColor &color = MessageColor::Text,
|
2018-05-23 04:22:17 +02:00
|
|
|
FontStyle style = FontStyle::ChatMedium);
|
2018-04-03 02:55:32 +02:00
|
|
|
~TextElement() override = default;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
void addToContainer(MessageLayoutContainer &container,
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElementFlags flags) override;
|
2018-07-06 19:23:47 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
MessageColor color_;
|
|
|
|
FontStyle style_;
|
|
|
|
|
|
|
|
struct Word {
|
|
|
|
QString text;
|
|
|
|
int width = -1;
|
|
|
|
};
|
|
|
|
std::vector<Word> words_;
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
|
|
|
|
2018-01-22 22:38:44 +01:00
|
|
|
// contains emote data and will pick the emote based on :
|
|
|
|
// a) are images for the emote type enabled
|
|
|
|
// b) which size it wants
|
|
|
|
class EmoteElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
2018-08-07 07:55:31 +02:00
|
|
|
EmoteElement(const EmotePtr &data, MessageElementFlags flags_);
|
2018-01-22 22:38:44 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
void addToContainer(MessageLayoutContainer &container,
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElementFlags flags_) override;
|
2018-08-02 14:23:27 +02:00
|
|
|
EmotePtr getEmote() const;
|
2018-07-06 19:23:47 +02:00
|
|
|
|
2019-09-08 11:30:06 +02:00
|
|
|
protected:
|
|
|
|
virtual MessageLayoutElement *makeImageLayoutElement(const ImagePtr &image,
|
|
|
|
const QSize &size);
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
private:
|
|
|
|
std::unique_ptr<TextElement> textElement_;
|
2018-08-02 14:23:27 +02:00
|
|
|
EmotePtr emote_;
|
2018-01-22 22:38:44 +01:00
|
|
|
};
|
|
|
|
|
2019-06-22 14:34:54 +02:00
|
|
|
class BadgeElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BadgeElement(const EmotePtr &data, MessageElementFlags flags_);
|
|
|
|
|
|
|
|
void addToContainer(MessageLayoutContainer &container,
|
|
|
|
MessageElementFlags flags_) override;
|
|
|
|
|
2019-08-21 01:52:01 +02:00
|
|
|
EmotePtr getEmote() const;
|
|
|
|
|
2020-03-14 13:06:24 +01:00
|
|
|
protected:
|
|
|
|
virtual MessageLayoutElement *makeImageLayoutElement(const ImagePtr &image,
|
|
|
|
const QSize &size);
|
|
|
|
|
2019-06-22 14:34:54 +02:00
|
|
|
private:
|
|
|
|
EmotePtr emote_;
|
|
|
|
};
|
|
|
|
|
2020-03-14 13:06:24 +01:00
|
|
|
class ModBadgeElement : public BadgeElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ModBadgeElement(const EmotePtr &data, MessageElementFlags flags_);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
MessageLayoutElement *makeImageLayoutElement(const ImagePtr &image,
|
|
|
|
const QSize &size) override;
|
|
|
|
};
|
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
class FfzBadgeElement : public BadgeElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FfzBadgeElement(const EmotePtr &data, MessageElementFlags flags_,
|
|
|
|
QColor &color);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
MessageLayoutElement *makeImageLayoutElement(const ImagePtr &image,
|
|
|
|
const QSize &size) override;
|
|
|
|
QColor color;
|
|
|
|
};
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// contains a text, formated depending on the preferences
|
|
|
|
class TimestampElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
2018-07-06 18:29:29 +02:00
|
|
|
TimestampElement(QTime time_ = QTime::currentTime());
|
2018-04-03 02:55:32 +02:00
|
|
|
~TimestampElement() override = default;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
void addToContainer(MessageLayoutContainer &container,
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElementFlags flags) override;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
TextElement *formatTime(const QTime &time);
|
2018-07-06 18:29:29 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
QTime time_;
|
|
|
|
std::unique_ptr<TextElement> element_;
|
|
|
|
QString format_;
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
// adds all the custom moderation buttons, adds a variable amount of items
|
|
|
|
// depending on settings fourtf: implement
|
2018-01-11 20:16:25 +01:00
|
|
|
class TwitchModerationElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TwitchModerationElement();
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
void addToContainer(MessageLayoutContainer &container,
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElementFlags flags) override;
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2020-07-04 15:15:59 +02:00
|
|
|
// contains a full message string that's split into words on space and parses irc colors that are then put into segments
|
|
|
|
// these segments are later passed to "MultiColorTextLayoutElement" elements to be rendered :)
|
|
|
|
class IrcTextElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IrcTextElement(const QString &text, MessageElementFlags flags,
|
|
|
|
FontStyle style = FontStyle::ChatMedium);
|
|
|
|
~IrcTextElement() override = default;
|
|
|
|
|
|
|
|
void addToContainer(MessageLayoutContainer &container,
|
|
|
|
MessageElementFlags flags) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FontStyle style_;
|
|
|
|
|
|
|
|
struct Segment {
|
|
|
|
QString text;
|
|
|
|
int fg = -1;
|
|
|
|
int bg = -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Word {
|
|
|
|
QString text;
|
|
|
|
int width = -1;
|
|
|
|
std::vector<Segment> segments;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<Word> words_;
|
|
|
|
};
|
|
|
|
|
2020-08-08 15:37:22 +02:00
|
|
|
// Forces a linebreak
|
|
|
|
class LinebreakElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LinebreakElement(MessageElementFlags flags);
|
|
|
|
|
|
|
|
void addToContainer(MessageLayoutContainer &container,
|
|
|
|
MessageElementFlags flags) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Image element which will pick the quality of the image based on ui scale
|
|
|
|
class ScalingImageElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScalingImageElement(ImageSet images, MessageElementFlags flags);
|
|
|
|
|
|
|
|
void addToContainer(MessageLayoutContainer &container,
|
|
|
|
MessageElementFlags flags) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ImageSet images_;
|
|
|
|
};
|
2018-01-11 20:16:25 +01:00
|
|
|
} // namespace chatterino
|