mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
added MessageColor to represet special colors
This commit is contained in:
parent
38d118c5dc
commit
bd4601a5d4
12 changed files with 102 additions and 45 deletions
|
@ -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 =
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
38
src/messages/messagecolor.cpp
Normal file
38
src/messages/messagecolor.cpp
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
25
src/messages/messagecolor.h
Normal file
25
src/messages/messagecolor.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <QColor>
|
||||
|
||||
#include <colorscheme.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "fontmanager.hpp"
|
||||
#include "messages/lazyloadedimage.hpp"
|
||||
#include "messages/link.hpp"
|
||||
#include "messages/messagecolor.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <QRect>
|
||||
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -54,7 +54,6 @@ private:
|
|||
|
||||
private slots:
|
||||
void editTextChanged();
|
||||
// void editKeyPressed(QKeyEvent *event);
|
||||
|
||||
friend class ChatWidget;
|
||||
};
|
||||
|
|
|
@ -39,7 +39,7 @@ void EmotePopup::loadChannel(std::shared_ptr<Channel> _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());
|
||||
|
|
Loading…
Reference in a new issue