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/widgets/channelview.cpp \
|
||||||
src/twitch/twitchchannel.cpp \
|
src/twitch/twitchchannel.cpp \
|
||||||
src/widgets/rippleeffectlabel.cpp \
|
src/widgets/rippleeffectlabel.cpp \
|
||||||
src/widgets/rippleeffectbutton.cpp
|
src/widgets/rippleeffectbutton.cpp \
|
||||||
|
src/messages/messagecolor.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/asyncexec.hpp \
|
src/asyncexec.hpp \
|
||||||
|
@ -161,7 +162,8 @@ HEADERS += \
|
||||||
src/widgets/rippleeffectbutton.hpp \
|
src/widgets/rippleeffectbutton.hpp \
|
||||||
src/widgets/rippleeffectlabel.hpp \
|
src/widgets/rippleeffectlabel.hpp \
|
||||||
src/widgets/qualitypopup.hpp \
|
src/widgets/qualitypopup.hpp \
|
||||||
src/widgets/emotepopup.hpp
|
src/widgets/emotepopup.hpp \
|
||||||
|
src/messages/messagecolor.h
|
||||||
|
|
||||||
PRECOMPILED_HEADER =
|
PRECOMPILED_HEADER =
|
||||||
|
|
||||||
|
|
|
@ -38,21 +38,17 @@ void MessageBuilder::appendTimestamp(time_t time)
|
||||||
{
|
{
|
||||||
char timeStampBuffer[69];
|
char timeStampBuffer[69];
|
||||||
|
|
||||||
// TODO(pajlada): Fix this
|
|
||||||
QColor systemMessageColor(140, 127, 127);
|
|
||||||
// QColor &systemMessageColor = ColorScheme::getInstance().SystemMessageColor;
|
|
||||||
|
|
||||||
// Add word for timestamp with no seconds
|
// Add word for timestamp with no seconds
|
||||||
strftime(timeStampBuffer, 69, "%H:%M", localtime(&time));
|
strftime(timeStampBuffer, 69, "%H:%M", localtime(&time));
|
||||||
QString timestampNoSeconds(timeStampBuffer);
|
QString timestampNoSeconds(timeStampBuffer);
|
||||||
appendWord(Word(timestampNoSeconds, Word::TimestampNoSeconds, systemMessageColor, QString(),
|
appendWord(Word(timestampNoSeconds, Word::TimestampNoSeconds,
|
||||||
QString()));
|
MessageColor(MessageColor::System), QString(), QString()));
|
||||||
|
|
||||||
// Add word for timestamp with seconds
|
// Add word for timestamp with seconds
|
||||||
strftime(timeStampBuffer, 69, "%H:%M:%S", localtime(&time));
|
strftime(timeStampBuffer, 69, "%H:%M:%S", localtime(&time));
|
||||||
QString timestampWithSeconds(timeStampBuffer);
|
QString timestampWithSeconds(timeStampBuffer);
|
||||||
appendWord(Word(timestampWithSeconds, Word::TimestampWithSeconds, systemMessageColor, QString(),
|
appendWord(Word(timestampWithSeconds, Word::TimestampWithSeconds,
|
||||||
QString()));
|
MessageColor(MessageColor::System), QString(), QString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MessageBuilder::matchLink(const QString &string)
|
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
|
// 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)
|
const QString &tooltip, const Link &link)
|
||||||
: image(nullptr)
|
: image(nullptr)
|
||||||
, text(text)
|
, text(text)
|
||||||
|
@ -96,7 +96,7 @@ const QString &Word::getTooltip() const
|
||||||
return this->tooltip;
|
return this->tooltip;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QColor &Word::getColor() const
|
const MessageColor &Word::getColor() const
|
||||||
{
|
{
|
||||||
return this->color;
|
return this->color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "fontmanager.hpp"
|
#include "fontmanager.hpp"
|
||||||
#include "messages/lazyloadedimage.hpp"
|
#include "messages/lazyloadedimage.hpp"
|
||||||
#include "messages/link.hpp"
|
#include "messages/link.hpp"
|
||||||
|
#include "messages/messagecolor.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
|
@ -90,7 +91,7 @@ public:
|
||||||
|
|
||||||
explicit Word(LazyLoadedImage *_image, Type getType, const QString ©text,
|
explicit Word(LazyLoadedImage *_image, Type getType, const QString ©text,
|
||||||
const QString &getTooltip, const Link &getLink = Link());
|
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());
|
const QString ©text, const QString &getTooltip, const Link &getLink = Link());
|
||||||
|
|
||||||
LazyLoadedImage &getImage() const;
|
LazyLoadedImage &getImage() const;
|
||||||
|
@ -107,7 +108,7 @@ public:
|
||||||
QFontMetrics &getFontMetrics() const;
|
QFontMetrics &getFontMetrics() const;
|
||||||
Type getType() const;
|
Type getType() const;
|
||||||
const QString &getTooltip() const;
|
const QString &getTooltip() const;
|
||||||
const QColor &getColor() const;
|
const MessageColor &getColor() const;
|
||||||
const Link &getLink() const;
|
const Link &getLink() const;
|
||||||
int getXOffset() const;
|
int getXOffset() const;
|
||||||
int getYOffset() const;
|
int getYOffset() const;
|
||||||
|
@ -119,7 +120,7 @@ public:
|
||||||
private:
|
private:
|
||||||
LazyLoadedImage *image;
|
LazyLoadedImage *image;
|
||||||
QString text;
|
QString text;
|
||||||
QColor color;
|
MessageColor color;
|
||||||
bool _isImage;
|
bool _isImage;
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
|
|
|
@ -105,7 +105,8 @@ SharedMessage TwitchMessageBuilder::parse()
|
||||||
long int i = 0;
|
long int i = 0;
|
||||||
|
|
||||||
for (QString split : splits) {
|
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
|
// twitch emote
|
||||||
if (currentTwitchEmote != twitchEmotes.end() && currentTwitchEmote->first == i) {
|
if (currentTwitchEmote != twitchEmotes.end() && currentTwitchEmote->first == i) {
|
||||||
|
@ -184,17 +185,18 @@ SharedMessage TwitchMessageBuilder::parse()
|
||||||
Link(Link::Url, QString("https://blog.twitch.tv/"
|
Link(Link::Url, QString("https://blog.twitch.tv/"
|
||||||
"introducing-cheering-celebrate-"
|
"introducing-cheering-celebrate-"
|
||||||
"together-da62af41fac6"))));
|
"together-da62af41fac6"))));
|
||||||
this->appendWord(Word(image, Word::BitsStatic, QString("cheer"),
|
this->appendWord(Word(
|
||||||
QString("Twitch Cheer"),
|
image, Word::BitsStatic, QString("cheer"), QString("Twitch Cheer"),
|
||||||
Link(Link::Url, QString("https://blog.twitch.tv/"
|
Link(Link::Url,
|
||||||
"introducing-cheering-celebrate-"
|
QString("https://blog.twitch.tv/"
|
||||||
"together-da62af41fac6"))));
|
"introducing-cheering-celebrate-together-da62af41fac6"))));
|
||||||
|
|
||||||
this->appendWord(Word(QString("x" + string.mid(5)), Word::BitsAmount, bitsColor,
|
this->appendWord(Word(
|
||||||
QString(string.mid(5)), QString("Twitch Cheer"),
|
QString("x" + string.mid(5)), Word::BitsAmount, MessageColor(bitsColor),
|
||||||
Link(Link::Url, QString("https://blog.twitch.tv/"
|
QString(string.mid(5)), QString("Twitch Cheer"),
|
||||||
"introducing-cheering-celebrate-"
|
Link(Link::Url,
|
||||||
"together-da62af41fac6"))));
|
QString("https://blog.twitch.tv/"
|
||||||
|
"introducing-cheering-celebrate-together-da62af41fac6"))));
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -218,7 +220,7 @@ SharedMessage TwitchMessageBuilder::parse()
|
||||||
link = Link();
|
link = Link();
|
||||||
} else {
|
} else {
|
||||||
link = Link(Link::Url, linkString);
|
link = Link(Link::Url, linkString);
|
||||||
textColor = this->colorScheme.TextLink;
|
textColor = MessageColor(MessageColor::Link);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->appendWord(Word(string, Word::Text, textColor, string, QString(), link));
|
this->appendWord(Word(string, Word::Text, textColor, string, QString(), link));
|
||||||
|
@ -278,7 +280,7 @@ void TwitchMessageBuilder::parseRoomID()
|
||||||
void TwitchMessageBuilder::parseChannelName()
|
void TwitchMessageBuilder::parseChannelName()
|
||||||
{
|
{
|
||||||
QString channelName("#" + this->channel->name);
|
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(),
|
QString(channelName), QString(),
|
||||||
Link(Link::Url, this->channel->name + "\n" + this->messageID)));
|
Link(Link::Url, this->channel->name + "\n" + this->messageID)));
|
||||||
}
|
}
|
||||||
|
@ -359,8 +361,8 @@ void TwitchMessageBuilder::appendUsername()
|
||||||
usernameString += ": ";
|
usernameString += ": ";
|
||||||
}
|
}
|
||||||
|
|
||||||
this->appendWord(Word(usernameString, Word::Username, this->usernameColor, usernameString,
|
this->appendWord(Word(usernameString, Word::Username, MessageColor(this->usernameColor),
|
||||||
QString(), Link(Link::UserInfo, this->userName)));
|
usernameString, QString(), Link(Link::UserInfo, this->userName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchMessageBuilder::parseHighlights()
|
void TwitchMessageBuilder::parseHighlights()
|
||||||
|
|
|
@ -470,7 +470,7 @@ void ChannelView::updateMessageBuffer(messages::MessageRef *messageRef, QPixmap
|
||||||
}
|
}
|
||||||
// text
|
// text
|
||||||
else {
|
else {
|
||||||
QColor color = wordPart.getWord().getColor();
|
QColor color = wordPart.getWord().getColor().getColor(this->colorScheme);
|
||||||
|
|
||||||
this->colorScheme.normalizeColor(color);
|
this->colorScheme.normalizeColor(color);
|
||||||
|
|
||||||
|
|
|
@ -74,8 +74,8 @@ ChatWidget::ChatWidget(ChannelManager &_channelManager, NotebookPage *parent)
|
||||||
// CTRL+R: Change Channel
|
// CTRL+R: Change Channel
|
||||||
ezShortcut(this, "CTRL+R", &ChatWidget::doChangeChannel);
|
ezShortcut(this, "CTRL+R", &ChatWidget::doChangeChannel);
|
||||||
|
|
||||||
// CTRL+C: Copy
|
// CTRL+C: Copy
|
||||||
ezShortcut(this, "CTRL+B", &ChatWidget::doCopy);
|
// ezShortcut(this, "CTRL+B", &ChatWidget::doCopy);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// F12: Toggle message spawning
|
// F12: Toggle message spawning
|
||||||
|
|
|
@ -160,6 +160,10 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget, EmoteManager &emoteMan
|
||||||
|
|
||||||
notebook->previousTab();
|
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 *)
|
void ChatWidgetInput::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
|
@ -54,7 +54,6 @@ private:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void editTextChanged();
|
void editTextChanged();
|
||||||
// void editKeyPressed(QKeyEvent *event);
|
|
||||||
|
|
||||||
friend class ChatWidget;
|
friend class ChatWidget;
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,7 +39,7 @@ void EmotePopup::loadChannel(std::shared_ptr<Channel> _channel)
|
||||||
messages::MessageBuilder builder1;
|
messages::MessageBuilder builder1;
|
||||||
|
|
||||||
builder1.appendWord(
|
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;
|
builder1.getMessage()->centered = true;
|
||||||
emoteChannel->addMessage(builder1.getMessage());
|
emoteChannel->addMessage(builder1.getMessage());
|
||||||
|
|
Loading…
Reference in a new issue