mirror-chatterino2/src/messages/word.hpp

164 lines
4.4 KiB
C++
Raw Normal View History

#pragma once
2017-01-05 16:07:20 +01:00
2017-06-11 09:31:45 +02:00
#include "messages/lazyloadedimage.hpp"
#include "messages/link.hpp"
2017-09-21 12:15:01 +02:00
#include "messages/messagecolor.hpp"
#include "singletons/fontmanager.hpp"
//#include "wordflags.hpp"
2017-01-18 04:52:47 +01:00
#include <stdint.h>
#include <QRect>
#include <QString>
2017-01-05 16:07:20 +01:00
2017-04-14 17:52:22 +02:00
namespace chatterino {
namespace messages {
2017-01-18 21:30:23 +01:00
2017-01-05 16:07:20 +01:00
class Word
{
public:
enum Flags : uint32_t {
2017-01-05 16:07:20 +01:00
None = 0,
Misc = (1 << 0),
Text = (1 << 1),
2017-01-05 16:07:20 +01:00
TimestampNoSeconds = (1 << 2),
TimestampWithSeconds = (1 << 3),
2017-01-05 16:07:20 +01:00
TwitchEmoteImage = (1 << 4),
TwitchEmoteText = (1 << 5),
BttvEmoteImage = (1 << 6),
BttvEmoteText = (1 << 7),
BttvGifEmoteImage = (1 << 8),
BttvGifEmoteText = (1 << 9),
FfzEmoteImage = (1 << 10),
FfzEmoteText = (1 << 11),
2017-04-12 17:46:44 +02:00
EmoteImages = TwitchEmoteImage | BttvEmoteImage | BttvGifEmoteImage | FfzEmoteImage,
2017-01-05 16:07:20 +01:00
2017-01-22 12:46:35 +01:00
BitsStatic = (1 << 12),
BitsAnimated = (1 << 13),
2017-01-05 16:07:20 +01:00
// 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,
Username = (1 << 19),
BitsAmount = (1 << 20),
ButtonBan = (1 << 21),
ButtonTimeout = (1 << 22),
EmojiImage = (1 << 23),
EmojiText = (1 << 24),
2017-01-15 16:38:30 +01:00
AlwaysShow = (1 << 25),
// used in the ChannelView class to make the collapse buttons visible if needed
Collapsed = (1 << 26),
2017-04-12 17:46:44 +02:00
Default = TimestampNoSeconds | Badges | Username | BitsStatic | FfzEmoteImage |
BttvEmoteImage | BttvGifEmoteImage | TwitchEmoteImage | BitsAmount | Text |
ButtonBan | ButtonTimeout | AlwaysShow
2017-01-05 16:07:20 +01:00
};
2017-02-17 23:51:35 +01:00
Word()
{
}
explicit Word(LazyLoadedImage *_image, Flags getFlags, const QString &copytext,
2017-12-19 03:36:05 +01:00
const QString &tooltip, const Link &getLink = Link());
explicit Word(const QString &_text, Flags getFlags, const MessageColor &textColor,
singletons::FontManager::Type font, const QString &copytext,
const QString &tooltip, const Link &getLink = Link());
2017-04-12 17:46:44 +02:00
bool isImage() const;
bool isText() const;
LazyLoadedImage &getImage() const;
const QString &getText() const;
2017-04-12 17:46:44 +02:00
const QString &getCopyText() const;
bool hasTrailingSpace() const;
Flags getFlags() const;
2017-04-12 17:46:44 +02:00
const QString &getTooltip() const;
const MessageColor &getTextColor() const;
2017-04-12 17:46:44 +02:00
const Link &getLink() const;
int getXOffset() const;
int getYOffset() const;
void setOffset(int _xOffset, int _yOffset);
2017-09-12 19:06:16 +02:00
int getCharacterLength() const;
2017-04-12 17:46:44 +02:00
void updateSize();
QFont &getFont(float scale) const;
QFontMetrics &getFontMetrics(float scale) const;
int getWidth(float scale) const;
int getHeight(float scale) const;
QSize getSize(float scale) const;
short getCharWidth(int index, float scale) const;
2017-01-15 16:38:30 +01:00
2017-01-05 16:07:20 +01:00
private:
2017-09-12 19:06:16 +02:00
LazyLoadedImage *image;
QString text;
MessageColor color;
2017-01-18 04:33:30 +01:00
bool _isImage;
2017-01-05 16:07:20 +01:00
Flags type;
2017-09-12 19:06:16 +02:00
QString copyText;
QString tooltip;
2017-01-11 01:08:20 +01:00
2017-09-12 19:06:16 +02:00
int xOffset = 0;
int yOffset = 0;
2017-01-11 01:08:20 +01:00
2017-09-12 19:06:16 +02:00
bool _hasTrailingSpace = true;
2017-12-31 22:58:35 +01:00
singletons::FontManager::Type font = singletons::FontManager::Medium;
2017-09-12 19:06:16 +02:00
Link link;
2017-01-15 16:38:30 +01:00
struct ScaleDependantData {
float scale;
QSize size;
mutable std::vector<short> charWidthCache;
ScaleDependantData(float _scale)
: scale(_scale)
, size()
{
}
};
mutable std::list<ScaleDependantData> dataByScale;
inline ScaleDependantData &getDataByScale(float scale) const;
std::vector<short> &getCharacterWidthCache(float scale) const;
2017-01-05 16:07:20 +01:00
};
2017-04-14 17:52:22 +02:00
} // namespace messages
} // namespace chatterino