diff --git a/chatterino.pro b/chatterino.pro index a396e741b..56f9af623 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -98,7 +98,8 @@ SOURCES += \ src/widgets/channelview.cpp \ src/twitch/twitchchannel.cpp \ src/widgets/rippleeffectlabel.cpp \ - src/widgets/rippleeffectbutton.cpp + src/widgets/rippleeffectbutton.cpp \ + src/messages/messagecolor.cpp HEADERS += \ src/asyncexec.hpp \ @@ -161,7 +162,8 @@ HEADERS += \ src/widgets/rippleeffectbutton.hpp \ src/widgets/rippleeffectlabel.hpp \ src/widgets/qualitypopup.hpp \ - src/widgets/emotepopup.hpp + src/widgets/emotepopup.hpp \ + src/messages/messagecolor.h PRECOMPILED_HEADER = diff --git a/src/messages/messagebuilder.cpp b/src/messages/messagebuilder.cpp index ebc98746f..26f69a645 100644 --- a/src/messages/messagebuilder.cpp +++ b/src/messages/messagebuilder.cpp @@ -38,21 +38,17 @@ void MessageBuilder::appendTimestamp(time_t time) { char timeStampBuffer[69]; - // TODO(pajlada): Fix this - QColor systemMessageColor(140, 127, 127); - // QColor &systemMessageColor = ColorScheme::getInstance().SystemMessageColor; - // Add word for timestamp with no seconds strftime(timeStampBuffer, 69, "%H:%M", localtime(&time)); QString timestampNoSeconds(timeStampBuffer); - appendWord(Word(timestampNoSeconds, Word::TimestampNoSeconds, systemMessageColor, QString(), - QString())); + appendWord(Word(timestampNoSeconds, Word::TimestampNoSeconds, + MessageColor(MessageColor::System), QString(), QString())); // Add word for timestamp with seconds strftime(timeStampBuffer, 69, "%H:%M:%S", localtime(&time)); QString timestampWithSeconds(timeStampBuffer); - appendWord(Word(timestampWithSeconds, Word::TimestampWithSeconds, systemMessageColor, QString(), - QString())); + appendWord(Word(timestampWithSeconds, Word::TimestampWithSeconds, + MessageColor(MessageColor::System), QString(), QString())); } QString MessageBuilder::matchLink(const QString &string) diff --git a/src/messages/messagecolor.cpp b/src/messages/messagecolor.cpp new file mode 100644 index 000000000..474d11eb3 --- /dev/null +++ b/src/messages/messagecolor.cpp @@ -0,0 +1,38 @@ +#include "messagecolor.h" + +namespace chatterino { +namespace messages { +MessageColor::MessageColor(const QColor &color) + : type(Type::Custom) + , color(color) +{ +} + +MessageColor::MessageColor(Type type) + : type(type) +{ +} + +MessageColor::Type MessageColor::getType() const +{ + return this->type; +} + +const QColor &MessageColor::getColor(ColorScheme &colorScheme) const +{ + switch (this->type) { + case Type::Custom: + return this->color; + case Type::Text: + return colorScheme.Text; + case Type::System: + return colorScheme.SystemMessageColor; + case Type::Link: + return colorScheme.TextLink; + } + + static QColor _default; + return _default; +} +} +} diff --git a/src/messages/messagecolor.h b/src/messages/messagecolor.h new file mode 100644 index 000000000..3ea078861 --- /dev/null +++ b/src/messages/messagecolor.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include + +namespace chatterino { +namespace messages { +class MessageColor +{ +public: + enum Type { Custom, Text, Link, System }; + + explicit MessageColor(const QColor &color); + explicit MessageColor(Type type = Text); + + Type getType() const; + const QColor &getColor(ColorScheme &colorScheme) const; + +private: + Type type; + QColor color; +}; +} +} diff --git a/src/messages/word.cpp b/src/messages/word.cpp index d24cde4d9..fc81a76f1 100644 --- a/src/messages/word.cpp +++ b/src/messages/word.cpp @@ -17,7 +17,7 @@ Word::Word(LazyLoadedImage *image, Type type, const QString ©text, const QSt } // Text word -Word::Word(const QString &text, Type type, const QColor &color, const QString ©text, +Word::Word(const QString &text, Type type, const MessageColor &color, const QString ©text, const QString &tooltip, const Link &link) : image(nullptr) , text(text) @@ -96,7 +96,7 @@ const QString &Word::getTooltip() const return this->tooltip; } -const QColor &Word::getColor() const +const MessageColor &Word::getColor() const { return this->color; } diff --git a/src/messages/word.hpp b/src/messages/word.hpp index 00416ba89..6c3182d11 100644 --- a/src/messages/word.hpp +++ b/src/messages/word.hpp @@ -3,6 +3,7 @@ #include "fontmanager.hpp" #include "messages/lazyloadedimage.hpp" #include "messages/link.hpp" +#include "messages/messagecolor.h" #include #include @@ -90,7 +91,7 @@ public: explicit Word(LazyLoadedImage *_image, Type getType, const QString ©text, const QString &getTooltip, const Link &getLink = Link()); - explicit Word(const QString &_text, Type getType, const QColor &getColor, + explicit Word(const QString &_text, Type getType, const MessageColor &getColor, const QString ©text, const QString &getTooltip, const Link &getLink = Link()); LazyLoadedImage &getImage() const; @@ -107,7 +108,7 @@ public: QFontMetrics &getFontMetrics() const; Type getType() const; const QString &getTooltip() const; - const QColor &getColor() const; + const MessageColor &getColor() const; const Link &getLink() const; int getXOffset() const; int getYOffset() const; @@ -119,7 +120,7 @@ public: private: LazyLoadedImage *image; QString text; - QColor color; + MessageColor color; bool _isImage; Type type; diff --git a/src/twitch/twitchmessagebuilder.cpp b/src/twitch/twitchmessagebuilder.cpp index 5acbdb92d..f182e7a0f 100644 --- a/src/twitch/twitchmessagebuilder.cpp +++ b/src/twitch/twitchmessagebuilder.cpp @@ -105,7 +105,8 @@ SharedMessage TwitchMessageBuilder::parse() long int i = 0; for (QString split : splits) { - QColor textColor = ircMessage->isAction() ? this->usernameColor : this->colorScheme.Text; + MessageColor textColor = ircMessage->isAction() ? MessageColor(this->usernameColor) + : MessageColor(MessageColor::Text); // twitch emote if (currentTwitchEmote != twitchEmotes.end() && currentTwitchEmote->first == i) { @@ -184,17 +185,18 @@ SharedMessage TwitchMessageBuilder::parse() Link(Link::Url, QString("https://blog.twitch.tv/" "introducing-cheering-celebrate-" "together-da62af41fac6")))); - this->appendWord(Word(image, Word::BitsStatic, QString("cheer"), - QString("Twitch Cheer"), - Link(Link::Url, QString("https://blog.twitch.tv/" - "introducing-cheering-celebrate-" - "together-da62af41fac6")))); + this->appendWord(Word( + image, Word::BitsStatic, QString("cheer"), QString("Twitch Cheer"), + Link(Link::Url, + QString("https://blog.twitch.tv/" + "introducing-cheering-celebrate-together-da62af41fac6")))); - this->appendWord(Word(QString("x" + string.mid(5)), Word::BitsAmount, bitsColor, - QString(string.mid(5)), QString("Twitch Cheer"), - Link(Link::Url, QString("https://blog.twitch.tv/" - "introducing-cheering-celebrate-" - "together-da62af41fac6")))); + this->appendWord(Word( + QString("x" + string.mid(5)), Word::BitsAmount, MessageColor(bitsColor), + QString(string.mid(5)), QString("Twitch Cheer"), + Link(Link::Url, + QString("https://blog.twitch.tv/" + "introducing-cheering-celebrate-together-da62af41fac6")))); continue; } @@ -218,7 +220,7 @@ SharedMessage TwitchMessageBuilder::parse() link = Link(); } else { link = Link(Link::Url, linkString); - textColor = this->colorScheme.TextLink; + textColor = MessageColor(MessageColor::Link); } this->appendWord(Word(string, Word::Text, textColor, string, QString(), link)); @@ -278,7 +280,7 @@ void TwitchMessageBuilder::parseRoomID() void TwitchMessageBuilder::parseChannelName() { QString channelName("#" + this->channel->name); - this->appendWord(Word(channelName, Word::Misc, this->colorScheme.SystemMessageColor, + this->appendWord(Word(channelName, Word::Misc, MessageColor(MessageColor::System), QString(channelName), QString(), Link(Link::Url, this->channel->name + "\n" + this->messageID))); } @@ -359,8 +361,8 @@ void TwitchMessageBuilder::appendUsername() usernameString += ": "; } - this->appendWord(Word(usernameString, Word::Username, this->usernameColor, usernameString, - QString(), Link(Link::UserInfo, this->userName))); + this->appendWord(Word(usernameString, Word::Username, MessageColor(this->usernameColor), + usernameString, QString(), Link(Link::UserInfo, this->userName))); } void TwitchMessageBuilder::parseHighlights() diff --git a/src/widgets/channelview.cpp b/src/widgets/channelview.cpp index e7b2734c6..490be9f2d 100644 --- a/src/widgets/channelview.cpp +++ b/src/widgets/channelview.cpp @@ -470,7 +470,7 @@ void ChannelView::updateMessageBuffer(messages::MessageRef *messageRef, QPixmap } // text else { - QColor color = wordPart.getWord().getColor(); + QColor color = wordPart.getWord().getColor().getColor(this->colorScheme); this->colorScheme.normalizeColor(color); diff --git a/src/widgets/chatwidget.cpp b/src/widgets/chatwidget.cpp index 99bb811b0..d5afe70f2 100644 --- a/src/widgets/chatwidget.cpp +++ b/src/widgets/chatwidget.cpp @@ -74,8 +74,8 @@ ChatWidget::ChatWidget(ChannelManager &_channelManager, NotebookPage *parent) // CTRL+R: Change Channel ezShortcut(this, "CTRL+R", &ChatWidget::doChangeChannel); - // CTRL+C: Copy - ezShortcut(this, "CTRL+B", &ChatWidget::doCopy); +// CTRL+C: Copy +// ezShortcut(this, "CTRL+B", &ChatWidget::doCopy); #ifndef NDEBUG // F12: Toggle message spawning diff --git a/src/widgets/chatwidgetinput.cpp b/src/widgets/chatwidgetinput.cpp index 8666513df..b752111d7 100644 --- a/src/widgets/chatwidgetinput.cpp +++ b/src/widgets/chatwidgetinput.cpp @@ -160,6 +160,10 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget, EmoteManager &emoteMan notebook->previousTab(); } + } else if (event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier) { + event->accept(); + + this->chatWidget->doCopy(); } }); @@ -188,16 +192,6 @@ void ChatWidgetInput::editTextChanged() { } -// void -// ChatWidgetInput::editKeyPressed(QKeyEvent *event) -//{ -// if (event->key() == Qt::Key_Enter) { -// event->accept(); -// IrcManager::send("PRIVMSG #" + edit.toPlainText(); -// edit.setText(QString()); -// } -//} - void ChatWidgetInput::paintEvent(QPaintEvent *) { QPainter painter(this); diff --git a/src/widgets/chatwidgetinput.hpp b/src/widgets/chatwidgetinput.hpp index 3a1724781..ebf5b7637 100644 --- a/src/widgets/chatwidgetinput.hpp +++ b/src/widgets/chatwidgetinput.hpp @@ -54,7 +54,6 @@ private: private slots: void editTextChanged(); - // void editKeyPressed(QKeyEvent *event); friend class ChatWidget; }; diff --git a/src/widgets/emotepopup.cpp b/src/widgets/emotepopup.cpp index 281dd1d68..ec30e1b64 100644 --- a/src/widgets/emotepopup.cpp +++ b/src/widgets/emotepopup.cpp @@ -39,7 +39,7 @@ void EmotePopup::loadChannel(std::shared_ptr _channel) messages::MessageBuilder builder1; builder1.appendWord( - Word(title, Word::Type::Text, QColor(255, 255, 255), QString(), QString())); + Word(title, Word::Type::Text, MessageColor(MessageColor::Text), QString(), QString())); builder1.getMessage()->centered = true; emoteChannel->addMessage(builder1.getMessage());