simplified message.cpp
This commit is contained in:
@@ -22,7 +22,7 @@ MessageLayout::MessageLayout(MessagePtr _message)
|
||||
: message(_message)
|
||||
, buffer(nullptr)
|
||||
{
|
||||
if (_message->hasFlags(Message::Collapsed)) {
|
||||
if (_message->flags & Message::Collapsed) {
|
||||
this->addFlags(MessageLayout::Collapsed);
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,7 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection
|
||||
painter.drawPixmap(0, y, this->container.width, this->container.getHeight(), *pixmap);
|
||||
|
||||
// draw disabled
|
||||
if (this->message->hasFlags(Message::Disabled)) {
|
||||
if (this->message->flags & Message::Disabled) {
|
||||
painter.fillRect(0, y, pixmap->width(), pixmap->height(), themeManager.messages.disabled);
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int messageIndex, Selection &s
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
||||
// draw background
|
||||
painter.fillRect(buffer->rect(), this->message->hasFlags(Message::Highlighted)
|
||||
painter.fillRect(buffer->rect(), this->message->flags & Message::Highlighted
|
||||
? themeManager.messages.backgrounds.highlighted
|
||||
: themeManager.messages.backgrounds.regular);
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@ namespace chatterino {
|
||||
namespace messages {
|
||||
namespace layouts {
|
||||
|
||||
class MessageLayout;
|
||||
struct MessageLayout;
|
||||
typedef std::shared_ptr<MessageLayout> MessageLayoutPtr;
|
||||
typedef uint8_t MessageLayoutFlagsType;
|
||||
|
||||
class MessageLayout : boost::noncopyable
|
||||
struct MessageLayout : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
enum Flags : MessageLayoutFlagsType { Collapsed, RequiresBufferUpdate, RequiresLayout };
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace chatterino {
|
||||
namespace messages {
|
||||
|
||||
namespace layouts {
|
||||
class MessageLayoutElement;
|
||||
struct MessageLayoutElement;
|
||||
|
||||
struct Margin {
|
||||
int top;
|
||||
@@ -41,7 +41,7 @@ struct Margin {
|
||||
}
|
||||
};
|
||||
|
||||
class MessageLayoutContainer
|
||||
struct MessageLayoutContainer
|
||||
{
|
||||
public:
|
||||
MessageLayoutContainer();
|
||||
|
||||
@@ -15,12 +15,12 @@ class QPainter;
|
||||
|
||||
namespace chatterino {
|
||||
namespace messages {
|
||||
class MessageElement;
|
||||
struct MessageElement;
|
||||
class Image;
|
||||
|
||||
namespace layouts {
|
||||
|
||||
class MessageLayoutElement : boost::noncopyable
|
||||
struct MessageLayoutElement : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
MessageLayoutElement(MessageElement &creator, const QSize &size);
|
||||
|
||||
@@ -6,8 +6,6 @@ typedef chatterino::widgets::ScrollbarHighlight SBHighlight;
|
||||
|
||||
namespace chatterino {
|
||||
namespace messages {
|
||||
|
||||
// elements
|
||||
void Message::addElement(MessageElement *element)
|
||||
{
|
||||
this->elements.push_back(std::unique_ptr<MessageElement>(element));
|
||||
@@ -18,64 +16,9 @@ const std::vector<std::unique_ptr<MessageElement>> &Message::getElements() const
|
||||
return this->elements;
|
||||
}
|
||||
|
||||
// Flags
|
||||
Message::MessageFlags Message::getFlags() const
|
||||
{
|
||||
return this->flags;
|
||||
}
|
||||
|
||||
bool Message::hasFlags(MessageFlags _flags) const
|
||||
{
|
||||
return this->flags & _flags;
|
||||
}
|
||||
|
||||
// void Message::setFlags(MessageFlags _flags)
|
||||
//{
|
||||
// this->flags = flags;
|
||||
//}
|
||||
|
||||
void Message::addFlags(MessageFlags _flags)
|
||||
{
|
||||
this->flags = (MessageFlags)((MessageFlagsType)this->flags | (MessageFlagsType)_flags);
|
||||
}
|
||||
|
||||
void Message::removeFlags(MessageFlags _flags)
|
||||
{
|
||||
this->flags = (MessageFlags)((MessageFlagsType)this->flags & ~((MessageFlagsType)_flags));
|
||||
}
|
||||
|
||||
// Parse Time
|
||||
const QTime &Message::getParseTime() const
|
||||
{
|
||||
return this->parseTime;
|
||||
}
|
||||
|
||||
// Id
|
||||
const QString &Message::getId() const
|
||||
{
|
||||
return this->id;
|
||||
}
|
||||
|
||||
void Message::setId(const QString &_id)
|
||||
{
|
||||
this->id = _id;
|
||||
}
|
||||
|
||||
// Search
|
||||
const QString &Message::getSearchText() const
|
||||
{
|
||||
return this->searchText;
|
||||
}
|
||||
|
||||
void Message::setSearchText(const QString &value)
|
||||
{
|
||||
this->searchText = value;
|
||||
}
|
||||
|
||||
// Highlight
|
||||
SBHighlight Message::getScrollBarHighlight() const
|
||||
{
|
||||
if (this->hasFlags(Message::Highlighted)) {
|
||||
if (this->flags & Message::Highlighted) {
|
||||
return SBHighlight(SBHighlight::Highlight);
|
||||
}
|
||||
return SBHighlight();
|
||||
@@ -88,8 +31,8 @@ MessagePtr Message::createSystemMessage(const QString &text)
|
||||
|
||||
message->addElement(new TimestampElement(QTime::currentTime()));
|
||||
message->addElement(new TextElement(text, MessageElement::Text, MessageColor::System));
|
||||
message->addFlags(Message::System);
|
||||
message->setSearchText(text);
|
||||
message->flags &= Message::System;
|
||||
message->searchText = text;
|
||||
|
||||
return MessagePtr(message);
|
||||
}
|
||||
@@ -129,7 +72,7 @@ MessagePtr Message::createTimeoutMessage(const QString &username, const QString
|
||||
}
|
||||
|
||||
MessagePtr message = Message::createSystemMessage(text);
|
||||
message->addFlags(Message::Timeout);
|
||||
message->flags &= Message::Timeout;
|
||||
message->timeoutUser = username;
|
||||
return message;
|
||||
}
|
||||
|
||||
+20
-53
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "messages/messageelement.hpp"
|
||||
#include "util/flagsenum.h"
|
||||
#include "widgets/helper/scrollbarhighlight.hpp"
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -11,15 +12,8 @@
|
||||
|
||||
namespace chatterino {
|
||||
namespace messages {
|
||||
class Message;
|
||||
|
||||
typedef std::shared_ptr<Message> MessagePtr;
|
||||
typedef uint16_t MessageFlagsType;
|
||||
|
||||
class Message
|
||||
{
|
||||
public:
|
||||
enum MessageFlags : MessageFlagsType {
|
||||
struct Message {
|
||||
enum MessageFlags : uint16_t {
|
||||
None = 0,
|
||||
System = (1 << 0),
|
||||
Timeout = (1 << 1),
|
||||
@@ -32,60 +26,33 @@ public:
|
||||
DisconnectedMessage = (1 << 8),
|
||||
};
|
||||
|
||||
// Elements
|
||||
util::FlagsEnum<MessageFlags> flags;
|
||||
QTime parseTime;
|
||||
QString id;
|
||||
QString searchText;
|
||||
QString loginName;
|
||||
QString displayName;
|
||||
QString localizedName;
|
||||
QString timeoutUser;
|
||||
|
||||
// Messages should not be added after the message is done initializing.
|
||||
void addElement(MessageElement *element);
|
||||
const std::vector<std::unique_ptr<MessageElement>> &getElements() const;
|
||||
|
||||
// Message flags
|
||||
MessageFlags getFlags() const;
|
||||
bool hasFlags(MessageFlags flags) const;
|
||||
// void setFlags(MessageFlags flags);
|
||||
void addFlags(MessageFlags flags);
|
||||
void removeFlags(MessageFlags flags);
|
||||
|
||||
// Parse Time
|
||||
const QTime &getParseTime() const;
|
||||
|
||||
// Id
|
||||
const QString &getId() const;
|
||||
void setId(const QString &id);
|
||||
|
||||
// Searching
|
||||
const QString &getSearchText() const;
|
||||
void setSearchText(const QString &value);
|
||||
|
||||
// Scrollbar
|
||||
widgets::ScrollbarHighlight getScrollBarHighlight() const;
|
||||
|
||||
// Usernames
|
||||
QString loginName;
|
||||
QString displayName;
|
||||
QString localizedName;
|
||||
|
||||
// Timeouts
|
||||
const QString &getTimeoutUser(const QString &value) const;
|
||||
void setTimeoutUser();
|
||||
|
||||
// Static
|
||||
static MessagePtr createSystemMessage(const QString &text);
|
||||
|
||||
static MessagePtr createTimeoutMessage(const QString &username,
|
||||
const QString &durationInSeconds, const QString &reason,
|
||||
bool multipleTimes);
|
||||
|
||||
private:
|
||||
static QRegularExpression *cheerRegex;
|
||||
|
||||
MessageFlags flags = MessageFlags::None;
|
||||
QString timeoutUser;
|
||||
bool collapsedDefault = false;
|
||||
QTime parseTime;
|
||||
mutable QString searchText;
|
||||
QString id = "";
|
||||
|
||||
std::vector<std::unique_ptr<MessageElement>> elements;
|
||||
|
||||
public:
|
||||
static std::shared_ptr<Message> createSystemMessage(const QString &text);
|
||||
|
||||
static std::shared_ptr<Message> createTimeoutMessage(const QString &username,
|
||||
const QString &durationInSeconds,
|
||||
const QString &reason, bool multipleTimes);
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Message> MessagePtr;
|
||||
} // namespace messages
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -31,9 +31,9 @@ void MessageBuilder::appendTimestamp()
|
||||
void MessageBuilder::setHighlight(bool value)
|
||||
{
|
||||
if (value) {
|
||||
this->message->addFlags(Message::Highlighted);
|
||||
this->message->flags |= Message::Highlighted;
|
||||
} else {
|
||||
this->message->removeFlags(Message::Highlighted);
|
||||
this->message->flags &= ~Message::Highlighted;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace chatterino {
|
||||
namespace messages {
|
||||
|
||||
class MessageBuilder
|
||||
struct MessageBuilder
|
||||
{
|
||||
public:
|
||||
MessageBuilder();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace chatterino {
|
||||
namespace messages {
|
||||
|
||||
class MessageColor
|
||||
struct MessageColor
|
||||
{
|
||||
public:
|
||||
enum Type { Custom, Text, Link, System };
|
||||
|
||||
@@ -20,12 +20,12 @@ struct EmoteData;
|
||||
}
|
||||
namespace messages {
|
||||
namespace layouts {
|
||||
class MessageLayoutContainer;
|
||||
struct MessageLayoutContainer;
|
||||
}
|
||||
|
||||
using namespace chatterino::messages::layouts;
|
||||
|
||||
class MessageElement : boost::noncopyable
|
||||
struct MessageElement : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
enum Flags : uint32_t {
|
||||
|
||||
Reference in New Issue
Block a user