diff --git a/channel.cpp b/channel.cpp index a35b673e..0673ff4c 100644 --- a/channel.cpp +++ b/channel.cpp @@ -1,4 +1,5 @@ #include "channel.h" +#include "message.h" const Channel Channel::whispers = Channel(QString("/whispers")); const Channel Channel::mentions = Channel(QString("/mentions")); @@ -7,12 +8,18 @@ QMap Channel::channels = QMap(); Channel::Channel(QString channel) { + messageMutex = new QMutex(); name = (channel.length() > 0 && channel[0] == '#') ? channel.mid(1) : channel; subLink = "https://www.twitch.tv/" + name + "/subscribe?ref=in_chat_subscriber_link"; channelLink = "https://twitch.tv/" + name; popoutPlayerLink = "https://player.twitch.tv/?channel=" + name; } +//Channel::~Channel() +//{ +//// delete messages; +//} + Channel* Channel::addChannel(const QString &channel) { auto c = getChannel(channel); @@ -42,10 +49,10 @@ Channel* Channel::getChannel(const QString &channel) auto a = channels.find(channel); if (a == channels.end()) { - return *a; + return NULL; } - return NULL; + return a.value(); } void Channel::removeChannel(const QString &channel) @@ -70,3 +77,18 @@ bool Channel::getIsLive() { return isLive ; } int Channel::getStreamViewerCount() { return streamViewerCount; } QString Channel::getStreamStatus() { return streamStatus ; } QString Channel::getStreamGame() { return streamGame ; } + +QVector* Channel::getMessagesClone() +{ + messageMutex->lock(); + auto M = new QVector(*messages); + messageMutex->unlock(); + return M; +} + +void Channel::addMessage(Message *message) +{ + messageMutex->lock(); +// messages + messageMutex->unlock(); +} diff --git a/channel.h b/channel.h index 9fb5111a..99443825 100644 --- a/channel.h +++ b/channel.h @@ -3,6 +3,10 @@ #include "QString" #include "QMap" +#include "QMutex" +#include "QVector" + +class Message; class Channel { @@ -24,9 +28,16 @@ public: QString getStreamStatus(); QString getStreamGame(); + void addMessage(Message* message); +// ~Channel(); + + QVector* getMessagesClone(); + private: Channel(QString channel); + QMutex* messageMutex; + static QMap channels; int referenceCount = 1; @@ -35,6 +46,8 @@ private: int roomID; + QVector* messages = new QVector(); + QString subLink = ""; QString channelLink = ""; QString popoutPlayerLink = ""; diff --git a/chatterino.pro b/chatterino.pro index e93d6a1d..3c732a15 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -5,7 +5,7 @@ #------------------------------------------------- QT += core gui network -CONFIG += communi c++11 +CONFIG += communi COMMUNI += core model util include(lib/libcommuni/src/src.pri) @@ -50,7 +50,11 @@ SOURCES += main.cpp\ account.cpp \ emotes.cpp \ lazyloadedimage.cpp \ - concurrentmap.cpp + concurrentmap.cpp \ + message.cpp \ + word.cpp \ + link.cpp \ + fonts.cpp HEADERS += mainwindow.h \ chatwidget.h \ @@ -76,7 +80,11 @@ HEADERS += mainwindow.h \ emotes.h \ lazyloadedimage.h \ twitchemotevalue.h \ - concurrentmap.h + concurrentmap.h \ + message.h \ + word.h \ + link.h \ + fonts.h FORMS += \ dialog.ui diff --git a/chatwidgetview.cpp b/chatwidgetview.cpp index a0f47ee0..12588004 100644 --- a/chatwidgetview.cpp +++ b/chatwidgetview.cpp @@ -1,10 +1,17 @@ #include "chatwidgetview.h" +#include "QScroller" +#include "QPainter" ChatWidgetView::ChatWidgetView() : QWidget(), - scrollbar(this) + scrollbar(this), + m_channel(NULL) { + auto scroll = QScroller::scroller(this); + scroll->scrollTo(QPointF(0, 100)); + + m_channel = Channel::getChannel("ian678"); } void ChatWidgetView::resizeEvent(QResizeEvent *) @@ -12,3 +19,16 @@ void ChatWidgetView::resizeEvent(QResizeEvent *) scrollbar.resize(scrollbar.width(), height()); scrollbar.move(width() - scrollbar.width(), 0); } + +void ChatWidgetView::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + + auto c = channel(); + + if (c == NULL) return; + + auto M = c->getMessagesClone(); + + delete M; +} diff --git a/chatwidgetview.h b/chatwidgetview.h index 31018eeb..c9ce6051 100644 --- a/chatwidgetview.h +++ b/chatwidgetview.h @@ -3,6 +3,8 @@ #include #include "scrollbar.h" +#include "QPaintEvent" +#include "channel.h" class ChatWidgetView : public QWidget { @@ -11,11 +13,18 @@ class ChatWidgetView : public QWidget public: ChatWidgetView(); + Channel* channel() { + return m_channel; + } + protected: void resizeEvent(QResizeEvent *); private: ScrollBar scrollbar; + Channel* m_channel; + + void paintEvent(QPaintEvent *); }; #endif // CHATVIEW_H diff --git a/colorscheme.cpp b/colorscheme.cpp index 0356b957..eed9c2ec 100644 --- a/colorscheme.cpp +++ b/colorscheme.cpp @@ -7,6 +7,8 @@ void ColorScheme::setColors(float hue, float multiplyer) { IsLightTheme = multiplyer > 0; + SystemMessageColor = QColor(140, 127, 127); + auto isLightTheme = IsLightTheme; auto getColor = [isLightTheme, multiplyer] (qreal h, qreal s, qreal l, qreal a = 1.0) diff --git a/colorscheme.h b/colorscheme.h index 78405f0c..38bc00de 100644 --- a/colorscheme.h +++ b/colorscheme.h @@ -9,6 +9,8 @@ class ColorScheme public: bool IsLightTheme; + QColor SystemMessageColor; + QColor DropPreviewBackground; QColor TooltipBackground; diff --git a/concurrentmap.h b/concurrentmap.h index 613872ba..5cbaab27 100644 --- a/concurrentmap.h +++ b/concurrentmap.h @@ -27,7 +27,7 @@ public: return true; } - TValue getOrAdd(const TKey &name, function addLambda) { + TValue getOrAdd(const TKey &name, std::function addLambda) { mutex->lock(); auto a = map->find(name); if (a == map->end()) { diff --git a/emotes.cpp b/emotes.cpp index b2b84d5d..457a951a 100644 --- a/emotes.cpp +++ b/emotes.cpp @@ -9,24 +9,42 @@ ConcurrentMap* Emotes::m_fFzChannelEmoteFromCaches ConcurrentMap* Emotes::m_twitchEmoteFromCache = new ConcurrentMap(); ConcurrentMap* Emotes::m_miscImageFromCache = new ConcurrentMap(); -//QMutex* Emotes::mutexBttvEmote = new QMutex(); -//QMap* Emotes::mapBttvEmote = new QMap(); - -//LazyLoadedImage* Emotes::getBttvEmote(const QString &name) { -// mutexBttvEmote->lock(); -// auto a = mapBttvEmote->find(name); -// if (a == mapBttvEmote->end()) { -// mutexBttvEmote->unlock(); -// return NULL; -// } -// mutexBttvEmote->unlock(); -// return a.value(); -//} - -//void - - Emotes::Emotes() { } + +LazyLoadedImage* Emotes::getCheerImage(long long amount, bool animated) +{ +#warning "xD" +// object image; + +// if (cheer >= 100000) +// { +// image = GuiEngine.Current.GetImage(ImageType.Cheer100000); +// } +// else if (cheer >= 10000) +// { +// image = GuiEngine.Current.GetImage(ImageType.Cheer10000); +// } +// else if (cheer >= 5000) +// { +// image = GuiEngine.Current.GetImage(ImageType.Cheer5000); +// } +// else if (cheer >= 1000) +// { +// image = GuiEngine.Current.GetImage(ImageType.Cheer1000); +// } +// else if (cheer >= 100) +// { +// image = GuiEngine.Current.GetImage(ImageType.Cheer100); +// } +// else +// { +// image = GuiEngine.Current.GetImage(ImageType.Cheer1); +// } + +// words.Add(new Word { Type = SpanType.Image, Value = image, Tooltip = "Twitch Cheer " + cheer }); + + return new LazyLoadedImage(""); +} diff --git a/emotes.h b/emotes.h index 4efe7c2a..a43cdd52 100644 --- a/emotes.h +++ b/emotes.h @@ -19,6 +19,10 @@ public: static ConcurrentMap& twitchEmoteFromCache() { return *m_twitchEmoteFromCache ; } static ConcurrentMap& miscImageFromCache() { return *m_miscImageFromCache ; } + static void loadGlobalEmotes(); + + static LazyLoadedImage* getCheerImage(long long int amount, bool animated); + private: Emotes(); diff --git a/fonts.cpp b/fonts.cpp new file mode 100644 index 00000000..a82fd54a --- /dev/null +++ b/fonts.cpp @@ -0,0 +1,27 @@ +#include "fonts.h" + +#define DEFAULT_FONT "Arial" + +QFont* Fonts::medium = new QFont(DEFAULT_FONT); +QFont* Fonts::mediumBold = new QFont(DEFAULT_FONT); +QFont* Fonts::mediumItalic = new QFont(DEFAULT_FONT); +QFont* Fonts::small = new QFont(DEFAULT_FONT); +QFont* Fonts::large = new QFont(DEFAULT_FONT); +QFont* Fonts::veryLarge = new QFont(DEFAULT_FONT); + +Fonts::Fonts() +{ + +} + +QFont& Fonts::getFont(Type type) +{ + if (type == Medium ) return *medium ; + if (type == MediumBold ) return *mediumBold ; + if (type == MediumItalic) return *mediumItalic; + if (type == Small ) return *small ; + if (type == Large ) return *large ; + if (type == VeryLarge ) return *veryLarge ; + + return *medium; +} diff --git a/fonts.h b/fonts.h new file mode 100644 index 00000000..a1937d1c --- /dev/null +++ b/fonts.h @@ -0,0 +1,31 @@ +#ifndef FONTS_H +#define FONTS_H + +#include "QFont" + +class Fonts +{ +public: + enum Type : char { + Medium, + MediumBold, + MediumItalic, + Small, + Large, + VeryLarge + }; + + static QFont& getFont(Type type); + +private: + Fonts(); + + static QFont* medium; + static QFont* mediumBold; + static QFont* mediumItalic; + static QFont* small; + static QFont* large; + static QFont* veryLarge; +}; + +#endif // FONTS_H diff --git a/images/admin_bg.png b/images/admin_bg.png new file mode 100644 index 00000000..3c6a5e4f Binary files /dev/null and b/images/admin_bg.png differ diff --git a/images/broadcaster_bg.png b/images/broadcaster_bg.png new file mode 100644 index 00000000..a4278aba Binary files /dev/null and b/images/broadcaster_bg.png differ diff --git a/images/globalmod_bg.png b/images/globalmod_bg.png new file mode 100644 index 00000000..10d69fb9 Binary files /dev/null and b/images/globalmod_bg.png differ diff --git a/images/moderator_bg.png b/images/moderator_bg.png new file mode 100644 index 00000000..6d92034b Binary files /dev/null and b/images/moderator_bg.png differ diff --git a/images/staff_bg.png b/images/staff_bg.png new file mode 100644 index 00000000..c973739a Binary files /dev/null and b/images/staff_bg.png differ diff --git a/images/turbo_bg.png b/images/turbo_bg.png new file mode 100644 index 00000000..7e40bfcc Binary files /dev/null and b/images/turbo_bg.png differ diff --git a/ircmanager.cpp b/ircmanager.cpp index a74eaa33..d2d00f5f 100644 --- a/ircmanager.cpp +++ b/ircmanager.cpp @@ -8,8 +8,9 @@ #include "QJsonDocument" #include "QJsonObject" #include "QJsonArray" +#include "channel.h" -Account* IrcManager::account = NULL; +Account* IrcManager::account = const_cast(Account::anon()); IrcConnection* IrcManager::connection = NULL; QMutex* IrcManager::connectionMutex = new QMutex(); long IrcManager::connectionIteration = 0; @@ -113,6 +114,7 @@ void IrcManager::beginConnecting() c->setNickName("justinfan123"); c->setRealName("justinfan123"); c->sendRaw("JOIN #fourtf"); + c->sendRaw("JOIN #ian678"); c->sendCommand(IrcCommand::createCapability("REQ", "twitch.tv/commands")); c->sendCommand(IrcCommand::createCapability("REQ", "twitch.tv/tags")); @@ -147,12 +149,19 @@ void IrcManager::messageReceived(IrcMessage *message) { qInfo(message->command().toStdString().c_str()); -// if (message->command() == "") + // if (message->command() == "") } void IrcManager::privateMessageReceived(IrcPrivateMessage *message) { qInfo(message->content().toStdString().c_str()); + + qInfo(message->target().toStdString().c_str()); + auto c = Channel::getChannel(message->target().mid(1)); + + if (c != NULL) { + c->addMessage(new Message(*message, *c)); + } } bool IrcManager::isTwitchBlockedUser(QString const &username) @@ -198,7 +207,7 @@ bool IrcManager::tryAddIgnoredUser(QString const &username, QString& errorMessag void IrcManager::addIgnoredUser(QString const &username) { QString errorMessage; - if (tryAddIgnoredUser(username, errorMessage)) { + if (!tryAddIgnoredUser(username, errorMessage)) { #warning "xD" } } @@ -231,7 +240,7 @@ bool IrcManager::tryRemoveIgnoredUser(QString const &username, QString& errorMes void IrcManager::removeIgnoredUser(QString const &username) { QString errorMessage; - if (tryRemoveIgnoredUser(username, errorMessage)) { + if (!tryRemoveIgnoredUser(username, errorMessage)) { #warning "xD" } } diff --git a/ircmanager.h b/ircmanager.h index ec9e525d..ec707995 100644 --- a/ircmanager.h +++ b/ircmanager.h @@ -9,6 +9,7 @@ #include "QMap" #include "account.h" #include "qnetworkaccessmanager.h" +#include "message.h" class IrcManager { diff --git a/lazyloadedimage.cpp b/lazyloadedimage.cpp index 0b8092a0..b60a00ee 100644 --- a/lazyloadedimage.cpp +++ b/lazyloadedimage.cpp @@ -1,6 +1,11 @@ #include "lazyloadedimage.h" -LazyLoadedImage::LazyLoadedImage() +LazyLoadedImage::LazyLoadedImage(QString url) +{ + +} + +LazyLoadedImage::LazyLoadedImage(QImage *image) { } diff --git a/lazyloadedimage.h b/lazyloadedimage.h index cb4e5e99..52fde36f 100644 --- a/lazyloadedimage.h +++ b/lazyloadedimage.h @@ -1,11 +1,21 @@ #ifndef LAZYLOADEDIMAGE_H #define LAZYLOADEDIMAGE_H +#include "QString" +#include "QImage" class LazyLoadedImage { public: - LazyLoadedImage(); + LazyLoadedImage(QString url); + LazyLoadedImage(QImage* image); + + QImage* image() { + return m_image; + } + +private: + QImage* m_image = NULL; }; -#endif // LAZYLOADEDIMAGE_H \ No newline at end of file +#endif // LAZYLOADEDIMAGE_H diff --git a/link.cpp b/link.cpp new file mode 100644 index 00000000..0d9028fc --- /dev/null +++ b/link.cpp @@ -0,0 +1,6 @@ +#include "link.h" + +Link::Link() +{ + +} diff --git a/link.h b/link.h new file mode 100644 index 00000000..f606d420 --- /dev/null +++ b/link.h @@ -0,0 +1,11 @@ +#ifndef LINK_H +#define LINK_H + + +class Link +{ +public: + Link(); +}; + +#endif // LINK_H \ No newline at end of file diff --git a/main.cpp b/main.cpp index 26678c1b..715a7903 100644 --- a/main.cpp +++ b/main.cpp @@ -12,6 +12,9 @@ int main(int argc, char *argv[]) MainWindow w; w.show(); + Channel::addChannel("ian678"); + Channel::addChannel("fourtf"); + IrcManager::connect(); return a.exec(); diff --git a/message.cpp b/message.cpp new file mode 100644 index 00000000..ce844197 --- /dev/null +++ b/message.cpp @@ -0,0 +1,183 @@ +#include "message.h" +#include "qcolor.h" +#include "colorscheme.h" +#include "emotes.h" + +LazyLoadedImage* Message::badgeStaff = new LazyLoadedImage(new QImage(":/images/staff_bg.png")); +LazyLoadedImage* Message::badgeAdmin = new LazyLoadedImage(new QImage(":/images/admin_bg.png")); +LazyLoadedImage* Message::badgeModerator = new LazyLoadedImage(new QImage(":/images/moderator_bg.png")); +LazyLoadedImage* Message::badgeGlobalmod = new LazyLoadedImage(new QImage(":/images/globalmod_bg.png")); +LazyLoadedImage* Message::badgeTurbo = new LazyLoadedImage(new QImage(":/images/turbo_bg.png")); +LazyLoadedImage* Message::badgeBroadcaster = new LazyLoadedImage(new QImage(":/images/broadcaster_bg.png")); +LazyLoadedImage* Message::badgePremium = new LazyLoadedImage(new QImage(":/images/twitchprime_bg.png")); + +Message::Message(const QString &text) +{ + +} + +Message::Message(const IrcPrivateMessage& ircMessage, const Channel& Channel) +{ + m_parseTime = std::chrono::system_clock::now(); + + auto words = new QList(); + + // timestamps + iterator = ircMessage.tags().find("tmi-sent-ts"); + time_t time = std::time(NULL); + + if (iterator != ircMessage.tags().end()) + { + time = strtoll(iterator.value().toString().toStdString().c_str(), NULL, 10); + } + + char timeStampBuffer[69]; + + strftime(timeStampBuffer, 69, "%H:%M", localtime(&time)); + QString timestamp = QString(timeStampBuffer); + + strftime(timeStampBuffer, 69, "%H:%M:%S", localtime(&time)); + QString timestampWithSeconds = QString(timeStampBuffer); + + words->append(new Word(timestamp, Word::TimestampNoSeconds)); + words->append(new Word(timestampWithSeconds, Word::TimestampWithSeconds)); + + // username + m_userName = ircMessage.account(); + + if (m_userName.isEmpty()) + { + auto iterator = ircMessage.tags().find("login"); + + if (iterator != ircMessage.tags().end()) + { + m_userName = iterator.value().toString(); + } + } + + // display name + QString displayName; + + auto iterator = ircMessage.tags().find("display-name"); + if (iterator == ircMessage.tags().end()) { + displayName = m_userName; + } + else { + displayName = iterator.value().toString(); + } + + // highlights +#warning "xD" + + // color + QColor usernameColor = ColorScheme::getInstance().SystemMessageColor; + + iterator = ircMessage.tags().find("color"); + if (iterator != ircMessage.tags().end()) + { + usernameColor = QColor(iterator.value().toString()); + } + + // bits + QString bits = ""; + + iterator = ircMessage.tags().find("bits"); + if (iterator != ircMessage.tags().end()) + { + bits = iterator.value().toString(); + } + + // badges + iterator = ircMessage.tags().find("badges"); + + if (iterator != ircMessage.tags().end()) + { + auto badges = iterator.value().toString().split(','); + + for (QString badge : badges) + { + if (badge.startsWith("bits/")) + { + + } + else if (badge == "staff/1") + { + QString a(""); + QString b("Twitch Staff"); + words->append(*new Word(badgeStaff, Word::BadgeStaff, a, b)); + } +// else if (badge == "admin/1") +// { +// words->append(*new Word(badgeAdmin, Word::BadgeAdmin, "", "Twitch Admin")); +// } +// else if (badge == "global_mod/1") +// { +// words->append(*new Word(badgeGlobalmod, Word::BadgeGlobalMod, "", "Global Moderator")); +// } +// else if (badge == "moderator/1") +// { +//#warning "xD" +// words->append(*new Word(badgeTurbo, Word::BadgeModerator, "", "Channel Moderator")); // custom badge +// } +// else if (badge == "turbo/1") +// { +// words->append(*new Word(badgeStaff, Word::BadgeTurbo, "", "Turbo Subscriber")); +// } +// else if (badge == "broadcaster/1") +// { +// words->append(*new Word(badgeBroadcaster, Word::BadgeBroadcaster, "", "Channel Broadcaster")); +// } +// else if (badge == "premium/1") +// { +// words->append(*new Word(badgeTwitchPrime, Word::BadgePremium, "", "Twitch Prime")); +// } + + +// case "staff/1": +// Badges |= MessageBadges.Staff; +// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeStaff), Tooltip = }); +// break; +// case "admin/1": +// Badges |= MessageBadges.Admin; +// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeAdmin), Tooltip = "Twitch Admin" }); +// break; +// case "global_mod/1": +// Badges |= MessageBadges.GlobalMod; +// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeGlobalmod), Tooltip = "Global Moderator" }); +// break; +// case "moderator/1": +// Badges |= MessageBadges.Mod; +// if (channel.ModeratorBadge == null) +// { +// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeModerator), Tooltip = "Channel Moderator" }); +// } +// else +// { +// words.Add(new Word { Type = SpanType.LazyLoadedImage, Value = channel.ModeratorBadge, Tooltip = channel.ModeratorBadge.Tooltip }); +// } +// break; +// case "turbo/1": +// Badges |= MessageBadges.Turbo; +// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeTurbo), Tooltip = "Turbo Subscriber" }); +// break; +// case "broadcaster/1": +// Badges |= MessageBadges.Broadcaster; +// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeBroadcaster), Tooltip = "Channel Broadcaster" }); +// break; +// case "premium/1": +// Badges |= MessageBadges.Broadcaster; +// words.Add(new Word { Type = SpanType.Image, Value = GuiEngine.Current.GetImage(ImageType.BadgeTwitchPrime), Tooltip = "Twitch Prime" }); +// break; + + +// long long int cheer = strtoll(badge.mid(5).toStdString().c_str(), NULL, 10); + +// auto image = Emotes::getCheerImage(cheer, false); +// auto imageAnimated = Emotes::getCheerImage(cheer, true); + +// words->append(*new Word(image, Word::Bits)); +// words->append(*new Word(imageAnimated, Word::BitsAnimated)); + + } + } +} diff --git a/message.cpp.xT5964 b/message.cpp.xT5964 new file mode 100644 index 00000000..19102c10 --- /dev/null +++ b/message.cpp.xT5964 @@ -0,0 +1,40 @@ +#include "message.h" +#include "qcolor.h" +#include "colorscheme.h" + +Message::Message(const QString &text) +{ + +} + +Message::Message(const IrcPrivateMessage& ircMessage, const Channel& Channel) +{ + m_parseTime = std::chrono::system_clock::now(); + + auto words = new QList(); + + // username + m_userName = ircMessage.account(); + + if (m_userName.isEmpty()) + { + auto iterator = ircMessage.tags().find("login"); + + if (iterator != ircMessage.tags().end()) + { + m_userName = iterator.value().toString(); + } + } + + // highlights +#warning "xD" + + // color + QColor usernameColor = ColorScheme::SystemMessageColor; + + auto iterator = ircMessage.tags().find("color"); + if (iterator != ircMessage.tags().end()) + { + usernameColor = QColor(iterator.value().toString()); + } +} diff --git a/message.h b/message.h new file mode 100644 index 00000000..b13e0664 --- /dev/null +++ b/message.h @@ -0,0 +1,75 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include "IrcMessage" +#include "word.h" +#include "chrono" +#include "channel.h" + +class Message +{ +public: +// enum Badges : char { +// None = 0, +// Mod = 1, +// Turbo = 2, +// Sub = 4, +// Staff = 8, +// GlobalMod = 16, +// Admin = 32, +// Broadcaster = 64, +// }; + + Message(const QString& text); + Message(const IrcPrivateMessage& ircMessage, const Channel& Channel); + + bool canHighlightTab() { + return m_highlightTab; + } + + QString timeoutUser() { + return m_timeoutUser; + } + + int timeoutCount() { + return m_timeoutCount; + } + + QString userName() { + return m_userName; + } + + QString displayName() { + return m_displayName; + } + + QList words() { + return m_words; + } + + bool disabled() { + return m_disabled; + } + +private: + static LazyLoadedImage* badgeStaff; + static LazyLoadedImage* badgeAdmin; + static LazyLoadedImage* badgeGlobalmod; + static LazyLoadedImage* badgeModerator; + static LazyLoadedImage* badgeTurbo; + static LazyLoadedImage* badgeBroadcaster; + static LazyLoadedImage* badgePremium; + + bool m_highlightTab = false; + QString m_timeoutUser = ""; + int m_timeoutCount = 0; + bool m_disabled = false; + std::chrono::time_point m_parseTime; + + QString m_userName = ""; + QString m_displayName = ""; + + QList m_words; +}; + +#endif // MESSAGE_H diff --git a/resources.qrc b/resources.qrc index f6c92dc7..2a1347a8 100644 --- a/resources.qrc +++ b/resources.qrc @@ -18,5 +18,11 @@ images/tool_moreCollapser_off16.png images/twitchprime_bg.png qss/settings.qss + images/admin_bg.png + images/broadcaster_bg.png + images/globalmod_bg.png + images/moderator_bg.png + images/staff_bg.png + images/turbo_bg.png diff --git a/word.cpp b/word.cpp new file mode 100644 index 00000000..95c940bf --- /dev/null +++ b/word.cpp @@ -0,0 +1,27 @@ +#include "word.h" + +Word::Word(LazyLoadedImage* image, Type type, const QString& copytext, const QString& tooltip) +{ + this->image = image; + this->text = NULL; + m_isImage = true; + m_type = type; + m_copyText = new QString(copytext); + m_tooltip = new QString(tooltip); +} + +Word::Word(const QString& text, Type type, const QString& copytext, const QString& tooltip) +{ + this->image = NULL; + this->text = new QString(text); + m_isImage = false; + m_type = type; + m_copyText = new QString(copytext); + m_tooltip = new QString(tooltip); +} + +Word::~Word() +{ + delete m_copyText; + delete m_tooltip; +} diff --git a/word.h b/word.h new file mode 100644 index 00000000..428a2e82 --- /dev/null +++ b/word.h @@ -0,0 +1,116 @@ +#ifndef WORD_H +#define WORD_H + +#include "lazyloadedimage.h" +#include "QString" +#include "fonts.h" +#include "QRect" + +class Word +{ +public: + enum Type : long int { + None = 0, + Misc = 1, + Text = 2, + + TimestampNoSeconds = 4, + TimestampWithSeconds = 8, + + TwitchEmoteImage = 0x10, + TwitchEmoteText = 0x20, + BttvEmoteImage = 0x40, + BttvEmoteText = 0x80, + BttvGifEmoteImage = 0x100, + BttvGifEmoteText = 0x200, + FfzEmoteImage = 0x400, + FfzEmoteText = 0x800, + + Bits = 0x1000, + BitsAnimated = 0x2000, + + BadgeStaff = 0x4000, + BadgeAdmin = 0x8000, + BadgeGlobalMod = 0x10000, + BadgeModerator = 0x20000, + BadgeTurbo = 0x40000, + BadgeBroadcaster = 0x80000, + BadgePremium = 0x100000, + BadgeChatterino = 0x200000, + BadgeBits = 0x400000, + }; + + Word(LazyLoadedImage* image, Type type, const QString& copytext, const QString& tooltip = ""); + Word(const QString& text, Type type, const QString& copytext, const QString& tooltip = ""); + + ~Word(); + + LazyLoadedImage& getImage() { + return *image; + } + + QString& getText() { + return *text; + } + + int width() { + return m_width; + } + + int height() { + return m_height; + } + + int x() { + return m_x; + } + + int y() { + return m_y; + } + + QRect rect() { + return QRect(m_x, m_y, m_width, m_height); + } + + bool isImage() { + return m_isImage; + } + + QString* copyText() { + return m_copyText; + } + + bool hasTrailingSpace() { + return m_hasTrailingSpace; + } + + QFont& getFont() { + return Fonts::getFont(m_font); + } + + Type type() { + return m_type; + } + + QString& tooltip() { + return *m_tooltip; + } + +private: + LazyLoadedImage* image; + QString* text; + bool m_isImage; + + Type m_type; + QString* m_copyText; + QString* m_tooltip; + int m_x; + int m_y; + int m_width; + int m_height; + bool m_hasTrailingSpace; + Fonts::Type m_font = Fonts::Medium; +}; + +#endif // WORD_H