2018-01-11 20:16:25 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
#include "common/Emotemap.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "messages/Image.hpp"
|
|
|
|
#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-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
class Channel;
|
|
|
|
struct EmoteData;
|
2018-01-28 03:29:42 +01:00
|
|
|
struct MessageLayoutContainer;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
class MessageElement : boost::noncopyable
|
2018-01-11 20:16:25 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Flags : uint32_t {
|
|
|
|
None = 0,
|
|
|
|
Misc = (1 << 0),
|
|
|
|
Text = (1 << 1),
|
|
|
|
|
|
|
|
Username = (1 << 2),
|
|
|
|
Timestamp = (1 << 3),
|
|
|
|
|
|
|
|
TwitchEmoteImage = (1 << 4),
|
|
|
|
TwitchEmoteText = (1 << 5),
|
|
|
|
TwitchEmote = TwitchEmoteImage | TwitchEmoteText,
|
|
|
|
BttvEmoteImage = (1 << 6),
|
|
|
|
BttvEmoteText = (1 << 7),
|
|
|
|
BttvEmote = BttvEmoteImage | BttvEmoteText,
|
|
|
|
FfzEmoteImage = (1 << 10),
|
|
|
|
FfzEmoteText = (1 << 11),
|
|
|
|
FfzEmote = FfzEmoteImage | FfzEmoteText,
|
|
|
|
EmoteImages = TwitchEmoteImage | BttvEmoteImage | FfzEmoteImage,
|
|
|
|
|
|
|
|
BitsStatic = (1 << 12),
|
|
|
|
BitsAnimated = (1 << 13),
|
|
|
|
|
|
|
|
// Slot 1: Twitch
|
|
|
|
// - Staff badge
|
|
|
|
// - Admin badge
|
|
|
|
// - Global Moderator badge
|
|
|
|
BadgeGlobalAuthority = (1 << 14),
|
|
|
|
|
|
|
|
// Slot 2: Twitch
|
|
|
|
// - Moderator badge
|
|
|
|
// - Broadcaster badge
|
|
|
|
BadgeChannelAuthority = (1 << 15),
|
|
|
|
|
|
|
|
// Slot 3: Twitch
|
|
|
|
// - Subscription badges
|
|
|
|
BadgeSubscription = (1 << 16),
|
|
|
|
|
|
|
|
// Slot 4: Twitch
|
|
|
|
// - Turbo badge
|
|
|
|
// - Prime badge
|
|
|
|
// - Bit badges
|
|
|
|
// - Game badges
|
|
|
|
BadgeVanity = (1 << 17),
|
|
|
|
|
|
|
|
// Slot 5: Chatterino
|
|
|
|
// - Chatterino developer badge
|
|
|
|
// - Chatterino donator badge
|
|
|
|
// - Chatterino top donator badge
|
|
|
|
BadgeChatterino = (1 << 18),
|
|
|
|
|
|
|
|
// Rest of slots: ffz custom badge? bttv custom badge? mywaifu (puke) custom badge?
|
|
|
|
|
|
|
|
Badges = BadgeGlobalAuthority | BadgeChannelAuthority | BadgeSubscription | BadgeVanity |
|
|
|
|
BadgeChatterino,
|
|
|
|
|
|
|
|
ChannelName = (1 << 19),
|
|
|
|
|
|
|
|
BitsAmount = (1 << 20),
|
|
|
|
|
|
|
|
ModeratorTools = (1 << 21),
|
|
|
|
|
|
|
|
EmojiImage = (1 << 23),
|
|
|
|
EmojiText = (1 << 24),
|
|
|
|
EmojiAll = EmojiImage | EmojiText,
|
|
|
|
|
|
|
|
AlwaysShow = (1 << 25),
|
|
|
|
|
|
|
|
// used in the ChannelView class to make the collapse buttons visible if needed
|
|
|
|
Collapsed = (1 << 26),
|
|
|
|
|
2018-07-12 18:56:54 +02:00
|
|
|
// used for dynamic bold usernames
|
|
|
|
BoldUsername = (1 << 27),
|
|
|
|
NonBoldUsername = (1 << 28),
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
Default = Timestamp | Badges | Username | BitsStatic | FfzEmoteImage | BttvEmoteImage |
|
|
|
|
TwitchEmoteImage | BitsAmount | Text | AlwaysShow,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum UpdateFlags : char {
|
|
|
|
Update_Text,
|
|
|
|
Update_Emotes,
|
|
|
|
Update_Images,
|
|
|
|
Update_All = Update_Text | Update_Emotes | Update_Images
|
|
|
|
};
|
|
|
|
|
2018-04-06 16:37:30 +02:00
|
|
|
virtual ~MessageElement();
|
2018-01-11 20:16:25 +01:00
|
|
|
|
|
|
|
MessageElement *setLink(const Link &link);
|
|
|
|
MessageElement *setTooltip(const QString &tooltip);
|
|
|
|
MessageElement *setTrailingSpace(bool value);
|
|
|
|
const QString &getTooltip() const;
|
|
|
|
const Link &getLink() const;
|
|
|
|
bool hasTrailingSpace() const;
|
|
|
|
Flags getFlags() const;
|
|
|
|
|
|
|
|
virtual void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
MessageElement(Flags flags);
|
|
|
|
bool trailingSpace = true;
|
|
|
|
|
|
|
|
private:
|
2018-07-06 19:23:47 +02:00
|
|
|
Link link_;
|
|
|
|
QString tooltip_;
|
|
|
|
Flags flags_;
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// contains a simple image
|
|
|
|
class ImageElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
2018-01-17 14:14:31 +01:00
|
|
|
ImageElement(Image *image, MessageElement::Flags flags);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override;
|
2018-07-06 19:23:47 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Image *image_;
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// contains a text, it will split it into words
|
|
|
|
class TextElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TextElement(const QString &text, MessageElement::Flags flags,
|
|
|
|
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-04-03 02:55:32 +02:00
|
|
|
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags 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-07-06 19:23:47 +02:00
|
|
|
EmoteElement(const EmoteData &data, MessageElement::Flags flags_);
|
2018-04-03 02:55:32 +02:00
|
|
|
~EmoteElement() override = default;
|
2018-01-22 22:38:44 +01:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags_) override;
|
2018-05-16 03:55:56 +02:00
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
const EmoteData data;
|
2018-07-06 19:23:47 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<TextElement> textElement_;
|
2018-01-22 22:38:44 +01:00
|
|
|
};
|
|
|
|
|
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-04-03 02:55:32 +02:00
|
|
|
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags 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
|
|
|
};
|
|
|
|
|
|
|
|
// adds all the custom moderation buttons, adds a variable amount of items depending on settings
|
|
|
|
// fourtf: implement
|
|
|
|
class TwitchModerationElement : public MessageElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TwitchModerationElement();
|
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override;
|
2018-01-11 20:16:25 +01:00
|
|
|
};
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
} // namespace chatterino
|