Renamed private members
This commit is contained in:
@@ -31,55 +31,55 @@ protected:
|
||||
typedef std::shared_ptr<std::vector<Chunk>> ChunkVector;
|
||||
|
||||
public:
|
||||
LimitedQueue(int _limit = 1000)
|
||||
: limit(_limit)
|
||||
LimitedQueue(int limit = 1000)
|
||||
: limit_(limit)
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mutex);
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
this->chunks = std::make_shared<std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
this->chunks_ = std::make_shared<std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
Chunk chunk = std::make_shared<std::vector<T>>();
|
||||
chunk->resize(this->chunkSize);
|
||||
this->chunks->push_back(chunk);
|
||||
this->firstChunkOffset = 0;
|
||||
this->lastChunkEnd = 0;
|
||||
chunk->resize(this->chunkSize_);
|
||||
this->chunks_->push_back(chunk);
|
||||
this->firstChunkOffset_ = 0;
|
||||
this->lastChunkEnd_ = 0;
|
||||
}
|
||||
|
||||
// return true if an item was deleted
|
||||
// deleted will be set if the item was deleted
|
||||
bool pushBack(const T &item, T &deleted)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mutex);
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
Chunk lastChunk = this->chunks->back();
|
||||
Chunk lastChunk = this->chunks_->back();
|
||||
|
||||
// still space in the last chunk
|
||||
if (lastChunk->size() <= this->lastChunkEnd) {
|
||||
if (lastChunk->size() <= this->lastChunkEnd_) {
|
||||
// create new chunk vector
|
||||
ChunkVector newVector =
|
||||
std::make_shared<std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
|
||||
// copy chunks
|
||||
for (Chunk &chunk : *this->chunks) {
|
||||
for (Chunk &chunk : *this->chunks_) {
|
||||
newVector->push_back(chunk);
|
||||
}
|
||||
|
||||
// push back new chunk
|
||||
Chunk newChunk = std::make_shared<std::vector<T>>();
|
||||
newChunk->resize(this->chunkSize);
|
||||
newChunk->resize(this->chunkSize_);
|
||||
newVector->push_back(newChunk);
|
||||
|
||||
// replace current chunk vector
|
||||
this->chunks = newVector;
|
||||
this->lastChunkEnd = 0;
|
||||
lastChunk = this->chunks->back();
|
||||
this->chunks_ = newVector;
|
||||
this->lastChunkEnd_ = 0;
|
||||
lastChunk = this->chunks_->back();
|
||||
}
|
||||
|
||||
lastChunk->at(this->lastChunkEnd++) = item;
|
||||
lastChunk->at(this->lastChunkEnd_++) = item;
|
||||
|
||||
return this->deleteFirstItem(deleted);
|
||||
}
|
||||
@@ -90,41 +90,41 @@ public:
|
||||
std::vector<T> acceptedItems;
|
||||
|
||||
if (this->space() > 0) {
|
||||
std::lock_guard<std::mutex> lock(this->mutex);
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
// create new vector to clone chunks into
|
||||
ChunkVector newChunks =
|
||||
std::make_shared<std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
|
||||
newChunks->resize(this->chunks->size());
|
||||
newChunks->resize(this->chunks_->size());
|
||||
|
||||
// copy chunks except for first one
|
||||
for (size_t i = 1; i < this->chunks->size(); i++) {
|
||||
newChunks->at(i) = this->chunks->at(i);
|
||||
for (size_t i = 1; i < this->chunks_->size(); i++) {
|
||||
newChunks->at(i) = this->chunks_->at(i);
|
||||
}
|
||||
|
||||
// create new chunk for the first one
|
||||
size_t offset = std::min(this->space(), items.size());
|
||||
Chunk newFirstChunk = std::make_shared<std::vector<T>>();
|
||||
newFirstChunk->resize(this->chunks->front()->size() + offset);
|
||||
newFirstChunk->resize(this->chunks_->front()->size() + offset);
|
||||
|
||||
for (size_t i = 0; i < offset; i++) {
|
||||
newFirstChunk->at(i) = items[items.size() - offset + i];
|
||||
acceptedItems.push_back(items[items.size() - offset + i]);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < this->chunks->at(0)->size(); i++) {
|
||||
newFirstChunk->at(i + offset) = this->chunks->at(0)->at(i);
|
||||
for (size_t i = 0; i < this->chunks_->at(0)->size(); i++) {
|
||||
newFirstChunk->at(i + offset) = this->chunks_->at(0)->at(i);
|
||||
}
|
||||
|
||||
newChunks->at(0) = newFirstChunk;
|
||||
|
||||
this->chunks = newChunks;
|
||||
this->chunks_ = newChunks;
|
||||
// qDebug() << acceptedItems.size();
|
||||
// qDebug() << this->chunks->at(0)->size();
|
||||
|
||||
if (this->chunks->size() == 1) {
|
||||
this->lastChunkEnd += offset;
|
||||
if (this->chunks_->size() == 1) {
|
||||
this->lastChunkEnd_ += offset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,15 +134,15 @@ public:
|
||||
// replace an single item, return index if successful, -1 if unsuccessful
|
||||
int replaceItem(const T &item, const T &replacement)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mutex);
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
int x = 0;
|
||||
|
||||
for (size_t i = 0; i < this->chunks->size(); i++) {
|
||||
Chunk &chunk = this->chunks->at(i);
|
||||
for (size_t i = 0; i < this->chunks_->size(); i++) {
|
||||
Chunk &chunk = this->chunks_->at(i);
|
||||
|
||||
size_t start = i == 0 ? this->firstChunkOffset : 0;
|
||||
size_t end = i == chunk->size() - 1 ? this->lastChunkEnd : chunk->size();
|
||||
size_t start = i == 0 ? this->firstChunkOffset_ : 0;
|
||||
size_t end = i == chunk->size() - 1 ? this->lastChunkEnd_ : chunk->size();
|
||||
|
||||
for (size_t j = start; j < end; j++) {
|
||||
if (chunk->at(j) == item) {
|
||||
@@ -154,7 +154,7 @@ public:
|
||||
}
|
||||
|
||||
newChunk->at(j) = replacement;
|
||||
this->chunks->at(i) = newChunk;
|
||||
this->chunks_->at(i) = newChunk;
|
||||
|
||||
return x;
|
||||
}
|
||||
@@ -168,15 +168,15 @@ public:
|
||||
// replace an item at index, return true if worked
|
||||
bool replaceItem(size_t index, const T &replacement)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mutex);
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
size_t x = 0;
|
||||
|
||||
for (size_t i = 0; i < this->chunks->size(); i++) {
|
||||
Chunk &chunk = this->chunks->at(i);
|
||||
for (size_t i = 0; i < this->chunks_->size(); i++) {
|
||||
Chunk &chunk = this->chunks_->at(i);
|
||||
|
||||
size_t start = i == 0 ? this->firstChunkOffset : 0;
|
||||
size_t end = i == chunk->size() - 1 ? this->lastChunkEnd : chunk->size();
|
||||
size_t start = i == 0 ? this->firstChunkOffset_ : 0;
|
||||
size_t end = i == chunk->size() - 1 ? this->lastChunkEnd_ : chunk->size();
|
||||
|
||||
for (size_t j = start; j < end; j++) {
|
||||
if (x == index) {
|
||||
@@ -188,7 +188,7 @@ public:
|
||||
}
|
||||
|
||||
newChunk->at(j) = replacement;
|
||||
this->chunks->at(i) = newChunk;
|
||||
this->chunks_->at(i) = newChunk;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -202,26 +202,26 @@ public:
|
||||
|
||||
LimitedQueueSnapshot<T> getSnapshot()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mutex);
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
return LimitedQueueSnapshot<T>(this->chunks, this->limit - this->space(),
|
||||
this->firstChunkOffset, this->lastChunkEnd);
|
||||
return LimitedQueueSnapshot<T>(this->chunks_, this->limit_ - this->space(),
|
||||
this->firstChunkOffset_, this->lastChunkEnd_);
|
||||
}
|
||||
|
||||
private:
|
||||
size_t space()
|
||||
{
|
||||
size_t totalSize = 0;
|
||||
for (Chunk &chunk : *this->chunks) {
|
||||
for (Chunk &chunk : *this->chunks_) {
|
||||
totalSize += chunk->size();
|
||||
}
|
||||
|
||||
totalSize -= this->chunks->back()->size() - this->lastChunkEnd;
|
||||
if (this->chunks->size() != 1) {
|
||||
totalSize -= this->firstChunkOffset;
|
||||
totalSize -= this->chunks_->back()->size() - this->lastChunkEnd_;
|
||||
if (this->chunks_->size() != 1) {
|
||||
totalSize -= this->firstChunkOffset_;
|
||||
}
|
||||
|
||||
return this->limit - totalSize;
|
||||
return this->limit_ - totalSize;
|
||||
}
|
||||
|
||||
bool deleteFirstItem(T &deleted)
|
||||
@@ -231,39 +231,39 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
deleted = this->chunks->front()->at(this->firstChunkOffset);
|
||||
deleted = this->chunks_->front()->at(this->firstChunkOffset_);
|
||||
|
||||
this->firstChunkOffset++;
|
||||
this->firstChunkOffset_++;
|
||||
|
||||
// need to delete the first chunk
|
||||
if (this->firstChunkOffset == this->chunks->front()->size() - 1) {
|
||||
if (this->firstChunkOffset_ == this->chunks_->front()->size() - 1) {
|
||||
// copy the chunk vector
|
||||
ChunkVector newVector =
|
||||
std::make_shared<std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
|
||||
// delete first chunk
|
||||
bool first = true;
|
||||
for (Chunk &chunk : *this->chunks) {
|
||||
for (Chunk &chunk : *this->chunks_) {
|
||||
if (!first) {
|
||||
newVector->push_back(chunk);
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
||||
this->chunks = newVector;
|
||||
this->firstChunkOffset = 0;
|
||||
this->chunks_ = newVector;
|
||||
this->firstChunkOffset_ = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ChunkVector chunks;
|
||||
std::mutex mutex;
|
||||
ChunkVector chunks_;
|
||||
std::mutex mutex_;
|
||||
|
||||
size_t firstChunkOffset;
|
||||
size_t lastChunkEnd;
|
||||
size_t limit;
|
||||
size_t firstChunkOffset_;
|
||||
size_t lastChunkEnd_;
|
||||
size_t limit_;
|
||||
|
||||
const size_t chunkSize = 100;
|
||||
const size_t chunkSize_ = 100;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -12,28 +12,28 @@ class LimitedQueueSnapshot
|
||||
public:
|
||||
LimitedQueueSnapshot() = default;
|
||||
|
||||
LimitedQueueSnapshot(std::shared_ptr<std::vector<std::shared_ptr<std::vector<T>>>> _chunks,
|
||||
size_t _length, size_t _firstChunkOffset, size_t _lastChunkEnd)
|
||||
: chunks(_chunks)
|
||||
, length(_length)
|
||||
, firstChunkOffset(_firstChunkOffset)
|
||||
, lastChunkEnd(_lastChunkEnd)
|
||||
LimitedQueueSnapshot(std::shared_ptr<std::vector<std::shared_ptr<std::vector<T>>>> chunks,
|
||||
size_t length, size_t firstChunkOffset, size_t lastChunkEnd)
|
||||
: chunks_(chunks)
|
||||
, length_(length)
|
||||
, firstChunkOffset_(firstChunkOffset)
|
||||
, lastChunkEnd_(lastChunkEnd)
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t getLength()
|
||||
{
|
||||
return this->length;
|
||||
return this->length_;
|
||||
}
|
||||
|
||||
T const &operator[](std::size_t index) const
|
||||
{
|
||||
index += this->firstChunkOffset;
|
||||
index += this->firstChunkOffset_;
|
||||
|
||||
size_t x = 0;
|
||||
|
||||
for (size_t i = 0; i < this->chunks->size(); i++) {
|
||||
auto &chunk = this->chunks->at(i);
|
||||
for (size_t i = 0; i < this->chunks_->size(); i++) {
|
||||
auto &chunk = this->chunks_->at(i);
|
||||
|
||||
if (x <= index && x + chunk->size() > index) {
|
||||
return chunk->at(index - x);
|
||||
@@ -43,15 +43,15 @@ public:
|
||||
|
||||
assert(false && "out of range");
|
||||
|
||||
return this->chunks->at(0)->at(0);
|
||||
return this->chunks_->at(0)->at(0);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::vector<std::shared_ptr<std::vector<T>>>> chunks;
|
||||
std::shared_ptr<std::vector<std::shared_ptr<std::vector<T>>>> chunks_;
|
||||
|
||||
size_t length = 0;
|
||||
size_t firstChunkOffset = 0;
|
||||
size_t lastChunkEnd = 0;
|
||||
size_t length_ = 0;
|
||||
size_t firstChunkOffset_ = 0;
|
||||
size_t lastChunkEnd_ = 0;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -9,12 +9,12 @@ namespace chatterino {
|
||||
|
||||
void Message::addElement(MessageElement *element)
|
||||
{
|
||||
this->elements.push_back(std::unique_ptr<MessageElement>(element));
|
||||
this->elements_.push_back(std::unique_ptr<MessageElement>(element));
|
||||
}
|
||||
|
||||
const std::vector<std::unique_ptr<MessageElement>> &Message::getElements() const
|
||||
{
|
||||
return this->elements;
|
||||
return this->elements_;
|
||||
}
|
||||
|
||||
SBHighlight Message::getScrollBarHighlight() const
|
||||
|
||||
@@ -62,7 +62,7 @@ struct Message {
|
||||
ScrollbarHighlight getScrollBarHighlight() const;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<MessageElement>> elements;
|
||||
std::vector<std::unique_ptr<MessageElement>> elements_;
|
||||
|
||||
public:
|
||||
static std::shared_ptr<Message> createSystemMessage(const QString &text);
|
||||
|
||||
@@ -10,18 +10,18 @@
|
||||
namespace chatterino {
|
||||
|
||||
MessageBuilder::MessageBuilder()
|
||||
: message(new Message)
|
||||
: message_(new Message)
|
||||
{
|
||||
}
|
||||
|
||||
MessagePtr MessageBuilder::getMessage()
|
||||
{
|
||||
return this->message;
|
||||
return this->message_;
|
||||
}
|
||||
|
||||
void MessageBuilder::append(MessageElement *element)
|
||||
{
|
||||
this->message->addElement(element);
|
||||
this->message_->addElement(element);
|
||||
}
|
||||
|
||||
void MessageBuilder::appendTimestamp()
|
||||
@@ -32,9 +32,9 @@ void MessageBuilder::appendTimestamp()
|
||||
void MessageBuilder::setHighlight(bool value)
|
||||
{
|
||||
if (value) {
|
||||
this->message->flags |= Message::Highlighted;
|
||||
this->message_->flags |= Message::Highlighted;
|
||||
} else {
|
||||
this->message->flags &= ~Message::Highlighted;
|
||||
this->message_->flags &= ~Message::Highlighted;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
MessagePtr message;
|
||||
MessagePtr message_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
MessageColor::MessageColor(const QColor &_color)
|
||||
: type(Type::Custom)
|
||||
, customColor(_color)
|
||||
MessageColor::MessageColor(const QColor &color)
|
||||
: type_(Type::Custom)
|
||||
, customColor_(color)
|
||||
{
|
||||
}
|
||||
|
||||
MessageColor::MessageColor(Type _type)
|
||||
: type(_type)
|
||||
MessageColor::MessageColor(Type type)
|
||||
: type_(type)
|
||||
{
|
||||
}
|
||||
|
||||
const QColor &MessageColor::getColor(Theme &themeManager) const
|
||||
{
|
||||
switch (this->type) {
|
||||
switch (this->type_) {
|
||||
case Type::Custom:
|
||||
return this->customColor;
|
||||
return this->customColor_;
|
||||
case Type::Text:
|
||||
return themeManager.messages.textColors.regular;
|
||||
case Type::System:
|
||||
|
||||
@@ -10,13 +10,13 @@ struct MessageColor {
|
||||
enum Type { Custom, Text, Link, System };
|
||||
|
||||
MessageColor(const QColor &color);
|
||||
MessageColor(Type type = Text);
|
||||
MessageColor(Type type_ = Text);
|
||||
|
||||
const QColor &getColor(Theme &themeManager) const;
|
||||
|
||||
private:
|
||||
Type type;
|
||||
QColor customColor;
|
||||
Type type_;
|
||||
QColor customColor_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
MessageElement::MessageElement(Flags _flags)
|
||||
: flags(_flags)
|
||||
MessageElement::MessageElement(Flags flags)
|
||||
: flags_(flags)
|
||||
{
|
||||
DebugCount::increase("message elements");
|
||||
}
|
||||
@@ -21,15 +21,15 @@ MessageElement::~MessageElement()
|
||||
DebugCount::decrease("message elements");
|
||||
}
|
||||
|
||||
MessageElement *MessageElement::setLink(const Link &_link)
|
||||
MessageElement *MessageElement::setLink(const Link &link)
|
||||
{
|
||||
this->link = _link;
|
||||
this->link_ = link;
|
||||
return this;
|
||||
}
|
||||
|
||||
MessageElement *MessageElement::setTooltip(const QString &_tooltip)
|
||||
MessageElement *MessageElement::setTooltip(const QString &tooltip)
|
||||
{
|
||||
this->tooltip = _tooltip;
|
||||
this->tooltip_ = tooltip;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -41,12 +41,12 @@ MessageElement *MessageElement::setTrailingSpace(bool value)
|
||||
|
||||
const QString &MessageElement::getTooltip() const
|
||||
{
|
||||
return this->tooltip;
|
||||
return this->tooltip_;
|
||||
}
|
||||
|
||||
const Link &MessageElement::getLink() const
|
||||
{
|
||||
return this->link;
|
||||
return this->link_;
|
||||
}
|
||||
|
||||
bool MessageElement::hasTrailingSpace() const
|
||||
@@ -56,58 +56,58 @@ bool MessageElement::hasTrailingSpace() const
|
||||
|
||||
MessageElement::Flags MessageElement::getFlags() const
|
||||
{
|
||||
return this->flags;
|
||||
return this->flags_;
|
||||
}
|
||||
|
||||
// IMAGE
|
||||
ImageElement::ImageElement(Image *_image, MessageElement::Flags flags)
|
||||
ImageElement::ImageElement(Image *image, MessageElement::Flags flags)
|
||||
: MessageElement(flags)
|
||||
, image(_image)
|
||||
, image_(image)
|
||||
{
|
||||
this->setTooltip(_image->getTooltip());
|
||||
this->setTooltip(image->getTooltip());
|
||||
}
|
||||
|
||||
void ImageElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags)
|
||||
void ImageElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags)
|
||||
{
|
||||
if (_flags & this->getFlags()) {
|
||||
QSize size(this->image->getScaledWidth() * container.getScale(),
|
||||
this->image->getScaledHeight() * container.getScale());
|
||||
if (flags & this->getFlags()) {
|
||||
QSize size(this->image_->getScaledWidth() * container.getScale(),
|
||||
this->image_->getScaledHeight() * container.getScale());
|
||||
|
||||
container.addElement(
|
||||
(new ImageLayoutElement(*this, this->image, size))->setLink(this->getLink()));
|
||||
(new ImageLayoutElement(*this, this->image_, size))->setLink(this->getLink()));
|
||||
}
|
||||
}
|
||||
|
||||
// EMOTE
|
||||
EmoteElement::EmoteElement(const EmoteData &_data, MessageElement::Flags flags)
|
||||
EmoteElement::EmoteElement(const EmoteData &data, MessageElement::Flags flags)
|
||||
: MessageElement(flags)
|
||||
, data(_data)
|
||||
, data(data)
|
||||
{
|
||||
if (_data.isValid()) {
|
||||
if (data.isValid()) {
|
||||
this->setTooltip(data.image1x->getTooltip());
|
||||
this->textElement.reset(
|
||||
new TextElement(_data.image1x->getCopyString(), MessageElement::Misc));
|
||||
this->textElement_.reset(
|
||||
new TextElement(data.image1x->getCopyString(), MessageElement::Misc));
|
||||
}
|
||||
}
|
||||
|
||||
void EmoteElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags)
|
||||
void EmoteElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags)
|
||||
{
|
||||
if (_flags & this->getFlags()) {
|
||||
if (_flags & MessageElement::EmoteImages) {
|
||||
if (flags & this->getFlags()) {
|
||||
if (flags & MessageElement::EmoteImages) {
|
||||
if (!this->data.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Image *_image = this->data.getImage(container.getScale());
|
||||
Image *image = this->data.getImage(container.getScale());
|
||||
|
||||
QSize size(int(container.getScale() * _image->getScaledWidth()),
|
||||
int(container.getScale() * _image->getScaledHeight()));
|
||||
QSize size(int(container.getScale() * image->getScaledWidth()),
|
||||
int(container.getScale() * image->getScaledHeight()));
|
||||
|
||||
container.addElement(
|
||||
(new ImageLayoutElement(*this, _image, size))->setLink(this->getLink()));
|
||||
(new ImageLayoutElement(*this, image, size))->setLink(this->getLink()));
|
||||
} else {
|
||||
if (this->textElement) {
|
||||
this->textElement->addToContainer(container, MessageElement::Misc);
|
||||
if (this->textElement_) {
|
||||
this->textElement_->addToContainer(container, MessageElement::Misc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,31 +115,31 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container, MessageElem
|
||||
|
||||
// TEXT
|
||||
TextElement::TextElement(const QString &text, MessageElement::Flags flags,
|
||||
const MessageColor &_color, FontStyle _style)
|
||||
const MessageColor &color, FontStyle style)
|
||||
: MessageElement(flags)
|
||||
, color(_color)
|
||||
, style(_style)
|
||||
, color_(color)
|
||||
, style_(style)
|
||||
{
|
||||
for (QString word : text.split(' ')) {
|
||||
this->words.push_back({word, -1});
|
||||
this->words_.push_back({word, -1});
|
||||
// fourtf: add logic to store multiple spaces after message
|
||||
}
|
||||
}
|
||||
|
||||
void TextElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags)
|
||||
void TextElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
if (_flags & this->getFlags()) {
|
||||
QFontMetrics metrics = app->fonts->getFontMetrics(this->style, container.getScale());
|
||||
if (flags & this->getFlags()) {
|
||||
QFontMetrics metrics = app->fonts->getFontMetrics(this->style_, container.getScale());
|
||||
|
||||
for (Word &word : this->words) {
|
||||
for (Word &word : this->words_) {
|
||||
auto getTextLayoutElement = [&](QString text, int width, bool trailingSpace) {
|
||||
QColor color = this->color.getColor(*app->themes);
|
||||
QColor color = this->color_.getColor(*app->themes);
|
||||
app->themes->normalizeColor(color);
|
||||
|
||||
auto e = (new TextLayoutElement(*this, text, QSize(width, metrics.height()), color,
|
||||
this->style, container.getScale()))
|
||||
this->style_, container.getScale()))
|
||||
->setLink(this->getLink());
|
||||
e->setTrailingSpace(trailingSpace);
|
||||
return e;
|
||||
@@ -206,25 +206,25 @@ void TextElement::addToContainer(MessageLayoutContainer &container, MessageEleme
|
||||
}
|
||||
|
||||
// TIMESTAMP
|
||||
TimestampElement::TimestampElement(QTime _time)
|
||||
TimestampElement::TimestampElement(QTime time)
|
||||
: MessageElement(MessageElement::Timestamp)
|
||||
, time(_time)
|
||||
, element(this->formatTime(_time))
|
||||
, time_(time)
|
||||
, element_(this->formatTime(time))
|
||||
{
|
||||
assert(this->element != nullptr);
|
||||
assert(this->element_ != nullptr);
|
||||
}
|
||||
|
||||
void TimestampElement::addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags _flags)
|
||||
MessageElement::Flags flags)
|
||||
{
|
||||
if (_flags & this->getFlags()) {
|
||||
if (flags & this->getFlags()) {
|
||||
auto app = getApp();
|
||||
if (app->settings->timestampFormat != this->format) {
|
||||
this->format = app->settings->timestampFormat.getValue();
|
||||
this->element.reset(this->formatTime(this->time));
|
||||
if (app->settings->timestampFormat != this->format_) {
|
||||
this->format_ = app->settings->timestampFormat.getValue();
|
||||
this->element_.reset(this->formatTime(this->time_));
|
||||
}
|
||||
|
||||
this->element->addToContainer(container, _flags);
|
||||
this->element_->addToContainer(container, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,9 +244,9 @@ TwitchModerationElement::TwitchModerationElement()
|
||||
}
|
||||
|
||||
void TwitchModerationElement::addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags _flags)
|
||||
MessageElement::Flags flags)
|
||||
{
|
||||
if (_flags & MessageElement::ModeratorTools) {
|
||||
if (flags & MessageElement::ModeratorTools) {
|
||||
QSize size(int(container.getScale() * 16), int(container.getScale() * 16));
|
||||
|
||||
for (const ModerationAction &m : getApp()->moderationActions->items.getVector()) {
|
||||
|
||||
@@ -120,34 +120,26 @@ protected:
|
||||
bool trailingSpace = true;
|
||||
|
||||
private:
|
||||
Link link;
|
||||
QString tooltip;
|
||||
Flags flags;
|
||||
Link link_;
|
||||
QString tooltip_;
|
||||
Flags flags_;
|
||||
};
|
||||
|
||||
// contains a simple image
|
||||
class ImageElement : public MessageElement
|
||||
{
|
||||
Image *image;
|
||||
|
||||
public:
|
||||
ImageElement(Image *image, MessageElement::Flags flags);
|
||||
|
||||
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override;
|
||||
|
||||
private:
|
||||
Image *image_;
|
||||
};
|
||||
|
||||
// contains a text, it will split it into words
|
||||
class TextElement : public MessageElement
|
||||
{
|
||||
MessageColor color;
|
||||
FontStyle style;
|
||||
|
||||
struct Word {
|
||||
QString text;
|
||||
int width = -1;
|
||||
};
|
||||
std::vector<Word> words;
|
||||
|
||||
public:
|
||||
TextElement(const QString &text, MessageElement::Flags flags,
|
||||
const MessageColor &color = MessageColor::Text,
|
||||
@@ -155,6 +147,16 @@ public:
|
||||
~TextElement() override = default;
|
||||
|
||||
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override;
|
||||
|
||||
private:
|
||||
MessageColor color_;
|
||||
FontStyle style_;
|
||||
|
||||
struct Word {
|
||||
QString text;
|
||||
int width = -1;
|
||||
};
|
||||
std::vector<Word> words_;
|
||||
};
|
||||
|
||||
// contains emote data and will pick the emote based on :
|
||||
@@ -162,15 +164,16 @@ public:
|
||||
// b) which size it wants
|
||||
class EmoteElement : public MessageElement
|
||||
{
|
||||
std::unique_ptr<TextElement> textElement;
|
||||
|
||||
public:
|
||||
EmoteElement(const EmoteData &data, MessageElement::Flags flags);
|
||||
EmoteElement(const EmoteData &data, MessageElement::Flags flags_);
|
||||
~EmoteElement() override = default;
|
||||
|
||||
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override;
|
||||
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags_) override;
|
||||
|
||||
const EmoteData data;
|
||||
|
||||
private:
|
||||
std::unique_ptr<TextElement> textElement_;
|
||||
};
|
||||
|
||||
// contains a text, formated depending on the preferences
|
||||
@@ -182,7 +185,7 @@ public:
|
||||
|
||||
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override;
|
||||
|
||||
TextElement *formatTime(const QTime &time_);
|
||||
TextElement *formatTime(const QTime &time);
|
||||
|
||||
private:
|
||||
QTime time_;
|
||||
|
||||
@@ -15,46 +15,46 @@ namespace chatterino {
|
||||
|
||||
int MessageLayoutContainer::getHeight() const
|
||||
{
|
||||
return this->height;
|
||||
return this->height_;
|
||||
}
|
||||
|
||||
int MessageLayoutContainer::getWidth() const
|
||||
{
|
||||
return this->width;
|
||||
return this->width_;
|
||||
}
|
||||
|
||||
float MessageLayoutContainer::getScale() const
|
||||
{
|
||||
return this->scale;
|
||||
return this->scale_;
|
||||
}
|
||||
|
||||
// methods
|
||||
void MessageLayoutContainer::begin(int _width, float _scale, Message::MessageFlags _flags)
|
||||
void MessageLayoutContainer::begin(int width, float scale, Message::MessageFlags flags)
|
||||
{
|
||||
this->clear();
|
||||
this->width = _width;
|
||||
this->scale = _scale;
|
||||
this->flags = _flags;
|
||||
auto mediumFontMetrics = getApp()->fonts->getFontMetrics(FontStyle::ChatMedium, _scale);
|
||||
this->textLineHeight = mediumFontMetrics.height();
|
||||
this->spaceWidth = mediumFontMetrics.width(' ');
|
||||
this->dotdotdotWidth = mediumFontMetrics.width("...");
|
||||
this->_canAddMessages = true;
|
||||
this->_isCollapsed = false;
|
||||
this->width_ = width;
|
||||
this->scale_ = scale;
|
||||
this->flags_ = flags;
|
||||
auto mediumFontMetrics = getApp()->fonts->getFontMetrics(FontStyle::ChatMedium, scale);
|
||||
this->textLineHeight_ = mediumFontMetrics.height();
|
||||
this->spaceWidth_ = mediumFontMetrics.width(' ');
|
||||
this->dotdotdotWidth_ = mediumFontMetrics.width("...");
|
||||
this->canAddMessages_ = true;
|
||||
this->isCollapsed_ = false;
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::clear()
|
||||
{
|
||||
this->elements.clear();
|
||||
this->lines.clear();
|
||||
this->elements_.clear();
|
||||
this->lines_.clear();
|
||||
|
||||
this->height = 0;
|
||||
this->line = 0;
|
||||
this->currentX = 0;
|
||||
this->currentY = 0;
|
||||
this->lineStart = 0;
|
||||
this->lineHeight = 0;
|
||||
this->charIndex = 0;
|
||||
this->height_ = 0;
|
||||
this->line_ = 0;
|
||||
this->currentX_ = 0;
|
||||
this->currentY_ = 0;
|
||||
this->lineStart_ = 0;
|
||||
this->lineHeight_ = 0;
|
||||
this->charIndex_ = 0;
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::addElement(MessageLayoutElement *element)
|
||||
@@ -73,7 +73,7 @@ void MessageLayoutContainer::addElementNoLineBreak(MessageLayoutElement *element
|
||||
|
||||
bool MessageLayoutContainer::canAddElements()
|
||||
{
|
||||
return this->_canAddMessages;
|
||||
return this->canAddMessages_;
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::_addElement(MessageLayoutElement *element, bool forceAdd)
|
||||
@@ -84,34 +84,34 @@ void MessageLayoutContainer::_addElement(MessageLayoutElement *element, bool for
|
||||
}
|
||||
|
||||
// top margin
|
||||
if (this->elements.size() == 0) {
|
||||
this->currentY = this->margin.top * this->scale;
|
||||
if (this->elements_.size() == 0) {
|
||||
this->currentY_ = this->margin.top * this->scale_;
|
||||
}
|
||||
|
||||
int newLineHeight = element->getRect().height();
|
||||
|
||||
// compact emote offset
|
||||
bool isCompactEmote = !(this->flags & Message::DisableCompactEmotes) &&
|
||||
bool isCompactEmote = !(this->flags_ & Message::DisableCompactEmotes) &&
|
||||
element->getCreator().getFlags() & MessageElement::EmoteImages;
|
||||
|
||||
if (isCompactEmote) {
|
||||
newLineHeight -= COMPACT_EMOTES_OFFSET * this->scale;
|
||||
newLineHeight -= COMPACT_EMOTES_OFFSET * this->scale_;
|
||||
}
|
||||
|
||||
// update line height
|
||||
this->lineHeight = std::max(this->lineHeight, newLineHeight);
|
||||
this->lineHeight_ = std::max(this->lineHeight_, newLineHeight);
|
||||
|
||||
// set move element
|
||||
element->setPosition(QPoint(this->currentX, this->currentY - element->getRect().height()));
|
||||
element->setPosition(QPoint(this->currentX_, this->currentY_ - element->getRect().height()));
|
||||
|
||||
// add element
|
||||
this->elements.push_back(std::unique_ptr<MessageLayoutElement>(element));
|
||||
this->elements_.push_back(std::unique_ptr<MessageLayoutElement>(element));
|
||||
|
||||
// set current x
|
||||
this->currentX += element->getRect().width();
|
||||
this->currentX_ += element->getRect().width();
|
||||
|
||||
if (element->hasTrailingSpace()) {
|
||||
this->currentX += this->spaceWidth;
|
||||
this->currentX_ += this->spaceWidth_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,66 +119,66 @@ void MessageLayoutContainer::breakLine()
|
||||
{
|
||||
int xOffset = 0;
|
||||
|
||||
if (this->flags & Message::Centered && this->elements.size() > 0) {
|
||||
xOffset = (width - this->elements.at(this->elements.size() - 1)->getRect().right()) / 2;
|
||||
if (this->flags_ & Message::Centered && this->elements_.size() > 0) {
|
||||
xOffset = (width_ - this->elements_.at(this->elements_.size() - 1)->getRect().right()) / 2;
|
||||
}
|
||||
|
||||
for (size_t i = lineStart; i < this->elements.size(); i++) {
|
||||
MessageLayoutElement *element = this->elements.at(i).get();
|
||||
for (size_t i = lineStart_; i < this->elements_.size(); i++) {
|
||||
MessageLayoutElement *element = this->elements_.at(i).get();
|
||||
|
||||
bool isCompactEmote = !(this->flags & Message::DisableCompactEmotes) &&
|
||||
bool isCompactEmote = !(this->flags_ & Message::DisableCompactEmotes) &&
|
||||
element->getCreator().getFlags() & MessageElement::EmoteImages;
|
||||
|
||||
int yExtra = 0;
|
||||
if (isCompactEmote) {
|
||||
yExtra = (COMPACT_EMOTES_OFFSET / 2) * this->scale;
|
||||
yExtra = (COMPACT_EMOTES_OFFSET / 2) * this->scale_;
|
||||
}
|
||||
|
||||
// if (element->getCreator().getFlags() & MessageElement::Badges) {
|
||||
if (element->getRect().height() < this->textLineHeight) {
|
||||
yExtra -= (this->textLineHeight - element->getRect().height()) / 2;
|
||||
if (element->getRect().height() < this->textLineHeight_) {
|
||||
yExtra -= (this->textLineHeight_ - element->getRect().height()) / 2;
|
||||
}
|
||||
|
||||
element->setPosition(QPoint(element->getRect().x() + xOffset + this->margin.left,
|
||||
element->getRect().y() + this->lineHeight + yExtra));
|
||||
element->getRect().y() + this->lineHeight_ + yExtra));
|
||||
}
|
||||
|
||||
if (this->lines.size() != 0) {
|
||||
this->lines.back().endIndex = this->lineStart;
|
||||
this->lines.back().endCharIndex = this->charIndex;
|
||||
if (this->lines_.size() != 0) {
|
||||
this->lines_.back().endIndex = this->lineStart_;
|
||||
this->lines_.back().endCharIndex = this->charIndex_;
|
||||
}
|
||||
this->lines.push_back({(int)lineStart, 0, this->charIndex, 0,
|
||||
QRect(-100000, this->currentY, 200000, lineHeight)});
|
||||
this->lines_.push_back({(int)lineStart_, 0, this->charIndex_, 0,
|
||||
QRect(-100000, this->currentY_, 200000, lineHeight_)});
|
||||
|
||||
for (int i = this->lineStart; i < this->elements.size(); i++) {
|
||||
this->charIndex += this->elements[i]->getSelectionIndexCount();
|
||||
for (int i = this->lineStart_; i < this->elements_.size(); i++) {
|
||||
this->charIndex_ += this->elements_[i]->getSelectionIndexCount();
|
||||
}
|
||||
|
||||
this->lineStart = this->elements.size();
|
||||
this->lineStart_ = this->elements_.size();
|
||||
// this->currentX = (int)(this->scale * 8);
|
||||
|
||||
if (this->canCollapse() && line + 1 >= MAX_UNCOLLAPSED_LINES) {
|
||||
this->_canAddMessages = false;
|
||||
if (this->canCollapse() && line_ + 1 >= MAX_UNCOLLAPSED_LINES) {
|
||||
this->canAddMessages_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this->currentX = 0;
|
||||
this->currentY += this->lineHeight;
|
||||
this->height = this->currentY + (this->margin.bottom * this->scale);
|
||||
this->lineHeight = 0;
|
||||
this->line++;
|
||||
this->currentX_ = 0;
|
||||
this->currentY_ += this->lineHeight_;
|
||||
this->height_ = this->currentY_ + (this->margin.bottom * this->scale_);
|
||||
this->lineHeight_ = 0;
|
||||
this->line_++;
|
||||
}
|
||||
|
||||
bool MessageLayoutContainer::atStartOfLine()
|
||||
{
|
||||
return this->lineStart == this->elements.size();
|
||||
return this->lineStart_ == this->elements_.size();
|
||||
}
|
||||
|
||||
bool MessageLayoutContainer::fitsInLine(int _width)
|
||||
{
|
||||
return this->currentX + _width <=
|
||||
(this->width - this->margin.left - this->margin.right -
|
||||
(this->line + 1 == MAX_UNCOLLAPSED_LINES ? this->dotdotdotWidth : 0));
|
||||
return this->currentX_ + _width <=
|
||||
(this->width_ - this->margin.left - this->margin.right -
|
||||
(this->line_ + 1 == MAX_UNCOLLAPSED_LINES ? this->dotdotdotWidth_ : 0));
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::end()
|
||||
@@ -188,42 +188,42 @@ void MessageLayoutContainer::end()
|
||||
static QString dotdotdotText("...");
|
||||
|
||||
auto *element = new TextLayoutElement(
|
||||
dotdotdot, dotdotdotText, QSize(this->dotdotdotWidth, this->textLineHeight),
|
||||
QColor("#00D80A"), FontStyle::ChatMediumBold, this->scale);
|
||||
dotdotdot, dotdotdotText, QSize(this->dotdotdotWidth_, this->textLineHeight_),
|
||||
QColor("#00D80A"), FontStyle::ChatMediumBold, this->scale_);
|
||||
|
||||
// getApp()->themes->messages.textColors.system
|
||||
this->_addElement(element, true);
|
||||
this->_isCollapsed = true;
|
||||
this->isCollapsed_ = true;
|
||||
}
|
||||
|
||||
if (!this->atStartOfLine()) {
|
||||
this->breakLine();
|
||||
}
|
||||
|
||||
this->height += this->lineHeight;
|
||||
this->height_ += this->lineHeight_;
|
||||
|
||||
if (this->lines.size() != 0) {
|
||||
this->lines[0].rect.setTop(-100000);
|
||||
this->lines.back().rect.setBottom(100000);
|
||||
this->lines.back().endIndex = this->elements.size();
|
||||
this->lines.back().endCharIndex = this->charIndex;
|
||||
if (this->lines_.size() != 0) {
|
||||
this->lines_[0].rect.setTop(-100000);
|
||||
this->lines_.back().rect.setBottom(100000);
|
||||
this->lines_.back().endIndex = this->elements_.size();
|
||||
this->lines_.back().endCharIndex = this->charIndex_;
|
||||
}
|
||||
}
|
||||
|
||||
bool MessageLayoutContainer::canCollapse()
|
||||
{
|
||||
return getApp()->settings->collpseMessagesMinLines.getValue() > 0 &&
|
||||
this->flags & Message::MessageFlags::Collapsed;
|
||||
this->flags_ & Message::MessageFlags::Collapsed;
|
||||
}
|
||||
|
||||
bool MessageLayoutContainer::isCollapsed()
|
||||
{
|
||||
return this->_isCollapsed;
|
||||
return this->isCollapsed_;
|
||||
}
|
||||
|
||||
MessageLayoutElement *MessageLayoutContainer::getElementAt(QPoint point)
|
||||
{
|
||||
for (std::unique_ptr<MessageLayoutElement> &element : this->elements) {
|
||||
for (std::unique_ptr<MessageLayoutElement> &element : this->elements_) {
|
||||
if (element->getRect().contains(point)) {
|
||||
return element.get();
|
||||
}
|
||||
@@ -235,7 +235,7 @@ MessageLayoutElement *MessageLayoutContainer::getElementAt(QPoint point)
|
||||
// painting
|
||||
void MessageLayoutContainer::paintElements(QPainter &painter)
|
||||
{
|
||||
for (const std::unique_ptr<MessageLayoutElement> &element : this->elements) {
|
||||
for (const std::unique_ptr<MessageLayoutElement> &element : this->elements_) {
|
||||
#ifdef FOURTF
|
||||
painter.setPen(QColor(0, 255, 0));
|
||||
painter.drawRect(element->getRect());
|
||||
@@ -247,7 +247,7 @@ void MessageLayoutContainer::paintElements(QPainter &painter)
|
||||
|
||||
void MessageLayoutContainer::paintAnimatedElements(QPainter &painter, int yOffset)
|
||||
{
|
||||
for (const std::unique_ptr<MessageLayoutElement> &element : this->elements) {
|
||||
for (const std::unique_ptr<MessageLayoutElement> &element : this->elements_) {
|
||||
element->paintAnimated(painter, yOffset);
|
||||
}
|
||||
}
|
||||
@@ -267,13 +267,13 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
// fully selected
|
||||
if (selection.selectionMin.messageIndex < messageIndex &&
|
||||
selection.selectionMax.messageIndex > messageIndex) {
|
||||
for (Line &line : this->lines) {
|
||||
for (Line &line : this->lines_) {
|
||||
QRect rect = line.rect;
|
||||
|
||||
rect.setTop(std::max(0, rect.top()) + yOffset);
|
||||
rect.setBottom(std::min(this->height, rect.bottom()) + yOffset);
|
||||
rect.setLeft(this->elements[line.startIndex]->getRect().left());
|
||||
rect.setRight(this->elements[line.endIndex - 1]->getRect().right());
|
||||
rect.setBottom(std::min(this->height_, rect.bottom()) + yOffset);
|
||||
rect.setLeft(this->elements_[line.startIndex]->getRect().left());
|
||||
rect.setRight(this->elements_[line.endIndex - 1]->getRect().right());
|
||||
|
||||
painter.fillRect(rect, selectionColor);
|
||||
}
|
||||
@@ -285,24 +285,24 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
|
||||
// start in this message
|
||||
if (selection.selectionMin.messageIndex == messageIndex) {
|
||||
for (; lineIndex < this->lines.size(); lineIndex++) {
|
||||
Line &line = this->lines[lineIndex];
|
||||
for (; lineIndex < this->lines_.size(); lineIndex++) {
|
||||
Line &line = this->lines_[lineIndex];
|
||||
index = line.startCharIndex;
|
||||
|
||||
bool returnAfter = false;
|
||||
bool breakAfter = false;
|
||||
int x = this->elements[line.startIndex]->getRect().left();
|
||||
int r = this->elements[line.endIndex - 1]->getRect().right();
|
||||
int x = this->elements_[line.startIndex]->getRect().left();
|
||||
int r = this->elements_[line.endIndex - 1]->getRect().right();
|
||||
|
||||
if (line.endCharIndex < selection.selectionMin.charIndex) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = line.startIndex; i < line.endIndex; i++) {
|
||||
int c = this->elements[i]->getSelectionIndexCount();
|
||||
int c = this->elements_[i]->getSelectionIndexCount();
|
||||
|
||||
if (index + c > selection.selectionMin.charIndex) {
|
||||
x = this->elements[i]->getXFromIndex(selection.selectionMin.charIndex - index);
|
||||
x = this->elements_[i]->getXFromIndex(selection.selectionMin.charIndex - index);
|
||||
|
||||
// ends in same line
|
||||
if (selection.selectionMax.messageIndex == messageIndex &&
|
||||
@@ -311,10 +311,10 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
returnAfter = true;
|
||||
index = line.startCharIndex;
|
||||
for (int i = line.startIndex; i < line.endIndex; i++) {
|
||||
int c = this->elements[i]->getSelectionIndexCount();
|
||||
int c = this->elements_[i]->getSelectionIndexCount();
|
||||
|
||||
if (index + c > selection.selectionMax.charIndex) {
|
||||
r = this->elements[i]->getXFromIndex(
|
||||
r = this->elements_[i]->getXFromIndex(
|
||||
selection.selectionMax.charIndex - index);
|
||||
break;
|
||||
}
|
||||
@@ -325,14 +325,14 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
|
||||
if (selection.selectionMax.messageIndex != messageIndex) {
|
||||
int lineIndex2 = lineIndex + 1;
|
||||
for (; lineIndex2 < this->lines.size(); lineIndex2++) {
|
||||
Line &line = this->lines[lineIndex2];
|
||||
for (; lineIndex2 < this->lines_.size(); lineIndex2++) {
|
||||
Line &line = this->lines_[lineIndex2];
|
||||
QRect rect = line.rect;
|
||||
|
||||
rect.setTop(std::max(0, rect.top()) + yOffset);
|
||||
rect.setBottom(std::min(this->height, rect.bottom()) + yOffset);
|
||||
rect.setLeft(this->elements[line.startIndex]->getRect().left());
|
||||
rect.setRight(this->elements[line.endIndex - 1]->getRect().right());
|
||||
rect.setBottom(std::min(this->height_, rect.bottom()) + yOffset);
|
||||
rect.setLeft(this->elements_[line.startIndex]->getRect().left());
|
||||
rect.setRight(this->elements_[line.endIndex - 1]->getRect().right());
|
||||
|
||||
painter.fillRect(rect, selectionColor);
|
||||
}
|
||||
@@ -350,7 +350,7 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
QRect rect = line.rect;
|
||||
|
||||
rect.setTop(std::max(0, rect.top()) + yOffset);
|
||||
rect.setBottom(std::min(this->height, rect.bottom()) + yOffset);
|
||||
rect.setBottom(std::min(this->height_, rect.bottom()) + yOffset);
|
||||
rect.setLeft(x);
|
||||
rect.setRight(r);
|
||||
|
||||
@@ -367,8 +367,8 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
}
|
||||
|
||||
// start in this message
|
||||
for (; lineIndex < this->lines.size(); lineIndex++) {
|
||||
Line &line = this->lines[lineIndex];
|
||||
for (; lineIndex < this->lines_.size(); lineIndex++) {
|
||||
Line &line = this->lines_[lineIndex];
|
||||
index = line.startCharIndex;
|
||||
|
||||
// just draw the garbage
|
||||
@@ -376,21 +376,21 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
QRect rect = line.rect;
|
||||
|
||||
rect.setTop(std::max(0, rect.top()) + yOffset);
|
||||
rect.setBottom(std::min(this->height, rect.bottom()) + yOffset);
|
||||
rect.setLeft(this->elements[line.startIndex]->getRect().left());
|
||||
rect.setRight(this->elements[line.endIndex - 1]->getRect().right());
|
||||
rect.setBottom(std::min(this->height_, rect.bottom()) + yOffset);
|
||||
rect.setLeft(this->elements_[line.startIndex]->getRect().left());
|
||||
rect.setRight(this->elements_[line.endIndex - 1]->getRect().right());
|
||||
|
||||
painter.fillRect(rect, selectionColor);
|
||||
continue;
|
||||
}
|
||||
|
||||
int r = this->elements[line.endIndex - 1]->getRect().right();
|
||||
int r = this->elements_[line.endIndex - 1]->getRect().right();
|
||||
|
||||
for (int i = line.startIndex; i < line.endIndex; i++) {
|
||||
int c = this->elements[i]->getSelectionIndexCount();
|
||||
int c = this->elements_[i]->getSelectionIndexCount();
|
||||
|
||||
if (index + c > selection.selectionMax.charIndex) {
|
||||
r = this->elements[i]->getXFromIndex(selection.selectionMax.charIndex - index);
|
||||
r = this->elements_[i]->getXFromIndex(selection.selectionMax.charIndex - index);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -400,8 +400,8 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
QRect rect = line.rect;
|
||||
|
||||
rect.setTop(std::max(0, rect.top()) + yOffset);
|
||||
rect.setBottom(std::min(this->height, rect.bottom()) + yOffset);
|
||||
rect.setLeft(this->elements[line.startIndex]->getRect().left());
|
||||
rect.setBottom(std::min(this->height_, rect.bottom()) + yOffset);
|
||||
rect.setLeft(this->elements_[line.startIndex]->getRect().left());
|
||||
rect.setRight(r);
|
||||
|
||||
painter.fillRect(rect, selectionColor);
|
||||
@@ -412,23 +412,23 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
// selection
|
||||
int MessageLayoutContainer::getSelectionIndex(QPoint point)
|
||||
{
|
||||
if (this->elements.size() == 0) {
|
||||
if (this->elements_.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto line = this->lines.begin();
|
||||
auto line = this->lines_.begin();
|
||||
|
||||
for (; line != this->lines.end(); line++) {
|
||||
for (; line != this->lines_.end(); line++) {
|
||||
if (line->rect.contains(point)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int lineStart = line == this->lines.end() ? this->lines.back().startIndex : line->startIndex;
|
||||
if (line != this->lines.end()) {
|
||||
int lineStart = line == this->lines_.end() ? this->lines_.back().startIndex : line->startIndex;
|
||||
if (line != this->lines_.end()) {
|
||||
line++;
|
||||
}
|
||||
int lineEnd = line == this->lines.end() ? this->elements.size() : line->startIndex;
|
||||
int lineEnd = line == this->lines_.end() ? this->elements_.size() : line->startIndex;
|
||||
|
||||
int index = 0;
|
||||
|
||||
@@ -440,17 +440,17 @@ int MessageLayoutContainer::getSelectionIndex(QPoint point)
|
||||
|
||||
// before line
|
||||
if (i < lineStart) {
|
||||
index += this->elements[i]->getSelectionIndexCount();
|
||||
index += this->elements_[i]->getSelectionIndexCount();
|
||||
continue;
|
||||
}
|
||||
|
||||
// this is the word
|
||||
if (point.x() < this->elements[i]->getRect().right()) {
|
||||
index += this->elements[i]->getMouseOverIndex(point);
|
||||
if (point.x() < this->elements_[i]->getRect().right()) {
|
||||
index += this->elements_[i]->getMouseOverIndex(point);
|
||||
break;
|
||||
}
|
||||
|
||||
index += this->elements[i]->getSelectionIndexCount();
|
||||
index += this->elements_[i]->getSelectionIndexCount();
|
||||
}
|
||||
|
||||
return index;
|
||||
@@ -459,10 +459,10 @@ int MessageLayoutContainer::getSelectionIndex(QPoint point)
|
||||
// fourtf: no idea if this is acurate LOL
|
||||
int MessageLayoutContainer::getLastCharacterIndex() const
|
||||
{
|
||||
if (this->lines.size() == 0) {
|
||||
if (this->lines_.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
return this->lines.back().endCharIndex;
|
||||
return this->lines_.back().endCharIndex;
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::addSelectionText(QString &str, int from, int to)
|
||||
@@ -470,7 +470,7 @@ void MessageLayoutContainer::addSelectionText(QString &str, int from, int to)
|
||||
int index = 0;
|
||||
bool first = true;
|
||||
|
||||
for (std::unique_ptr<MessageLayoutElement> &ele : this->elements) {
|
||||
for (std::unique_ptr<MessageLayoutElement> &ele : this->elements_) {
|
||||
int c = ele->getSelectionIndexCount();
|
||||
|
||||
if (first) {
|
||||
|
||||
@@ -51,7 +51,7 @@ struct MessageLayoutContainer {
|
||||
float getScale() const;
|
||||
|
||||
// methods
|
||||
void begin(int width, float scale, Message::MessageFlags flags);
|
||||
void begin(int width_, float scale_, Message::MessageFlags flags_);
|
||||
void end();
|
||||
|
||||
void clear();
|
||||
@@ -60,7 +60,7 @@ struct MessageLayoutContainer {
|
||||
void addElementNoLineBreak(MessageLayoutElement *element);
|
||||
void breakLine();
|
||||
bool atStartOfLine();
|
||||
bool fitsInLine(int width);
|
||||
bool fitsInLine(int width_);
|
||||
MessageLayoutElement *getElementAt(QPoint point);
|
||||
|
||||
// painting
|
||||
@@ -86,28 +86,27 @@ private:
|
||||
|
||||
// helpers
|
||||
void _addElement(MessageLayoutElement *element, bool forceAdd = false);
|
||||
|
||||
// variables
|
||||
float scale = 1.f;
|
||||
int width = 0;
|
||||
Message::MessageFlags flags = Message::MessageFlags::None;
|
||||
int line = 0;
|
||||
int height = 0;
|
||||
int currentX = 0;
|
||||
int currentY = 0;
|
||||
int charIndex = 0;
|
||||
size_t lineStart = 0;
|
||||
int lineHeight = 0;
|
||||
int spaceWidth = 4;
|
||||
int textLineHeight = 0;
|
||||
int dotdotdotWidth = 0;
|
||||
bool _canAddMessages = true;
|
||||
bool _isCollapsed = false;
|
||||
|
||||
bool canCollapse();
|
||||
|
||||
std::vector<std::unique_ptr<MessageLayoutElement>> elements;
|
||||
std::vector<Line> lines;
|
||||
// variables
|
||||
float scale_ = 1.f;
|
||||
int width_ = 0;
|
||||
Message::MessageFlags flags_ = Message::MessageFlags::None;
|
||||
int line_ = 0;
|
||||
int height_ = 0;
|
||||
int currentX_ = 0;
|
||||
int currentY_ = 0;
|
||||
int charIndex_ = 0;
|
||||
size_t lineStart_ = 0;
|
||||
int lineHeight_ = 0;
|
||||
int spaceWidth_ = 4;
|
||||
int textLineHeight_ = 0;
|
||||
int dotdotdotWidth_ = 0;
|
||||
bool canAddMessages_ = true;
|
||||
bool isCollapsed_ = false;
|
||||
|
||||
std::vector<std::unique_ptr<MessageLayoutElement>> elements_;
|
||||
std::vector<Line> lines_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -11,13 +11,13 @@ namespace chatterino {
|
||||
|
||||
const QRect &MessageLayoutElement::getRect() const
|
||||
{
|
||||
return this->rect;
|
||||
return this->rect_;
|
||||
}
|
||||
|
||||
MessageLayoutElement::MessageLayoutElement(MessageElement &_creator, const QSize &size)
|
||||
: creator(_creator)
|
||||
MessageLayoutElement::MessageLayoutElement(MessageElement &creator, const QSize &size)
|
||||
: creator_(creator)
|
||||
{
|
||||
this->rect.setSize(size);
|
||||
this->rect_.setSize(size);
|
||||
DebugCount::increase("message layout elements");
|
||||
}
|
||||
|
||||
@@ -28,12 +28,12 @@ MessageLayoutElement::~MessageLayoutElement()
|
||||
|
||||
MessageElement &MessageLayoutElement::getCreator() const
|
||||
{
|
||||
return this->creator;
|
||||
return this->creator_;
|
||||
}
|
||||
|
||||
void MessageLayoutElement::setPosition(QPoint point)
|
||||
{
|
||||
this->rect.moveTopLeft(point);
|
||||
this->rect_.moveTopLeft(point);
|
||||
}
|
||||
|
||||
bool MessageLayoutElement::hasTrailingSpace() const
|
||||
@@ -50,13 +50,13 @@ MessageLayoutElement *MessageLayoutElement::setTrailingSpace(bool value)
|
||||
|
||||
MessageLayoutElement *MessageLayoutElement::setLink(const Link &_link)
|
||||
{
|
||||
this->link = _link;
|
||||
this->link_ = _link;
|
||||
return this;
|
||||
}
|
||||
|
||||
const Link &MessageLayoutElement::getLink() const
|
||||
{
|
||||
return this->link;
|
||||
return this->link_;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -20,7 +20,7 @@ class Image;
|
||||
class MessageLayoutElement : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
MessageLayoutElement(MessageElement &creator, const QSize &size);
|
||||
MessageLayoutElement(MessageElement &creator_, const QSize &size);
|
||||
virtual ~MessageLayoutElement();
|
||||
|
||||
const QRect &getRect() const;
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
bool hasTrailingSpace() const;
|
||||
|
||||
MessageLayoutElement *setTrailingSpace(bool value);
|
||||
MessageLayoutElement *setLink(const Link &link);
|
||||
MessageLayoutElement *setLink(const Link &link_);
|
||||
|
||||
virtual void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const = 0;
|
||||
virtual int getSelectionIndexCount() = 0;
|
||||
@@ -43,16 +43,16 @@ protected:
|
||||
bool trailingSpace = true;
|
||||
|
||||
private:
|
||||
QRect rect;
|
||||
Link link;
|
||||
MessageElement &creator;
|
||||
QRect rect_;
|
||||
Link link_;
|
||||
MessageElement &creator_;
|
||||
};
|
||||
|
||||
// IMAGE
|
||||
class ImageLayoutElement : public MessageLayoutElement
|
||||
{
|
||||
public:
|
||||
ImageLayoutElement(MessageElement &creator, Image *image, const QSize &size);
|
||||
ImageLayoutElement(MessageElement &creator_, Image *image, const QSize &size);
|
||||
|
||||
protected:
|
||||
void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override;
|
||||
@@ -70,7 +70,7 @@ private:
|
||||
class TextLayoutElement : public MessageLayoutElement
|
||||
{
|
||||
public:
|
||||
TextLayoutElement(MessageElement &creator, QString &text, const QSize &size, QColor color,
|
||||
TextLayoutElement(MessageElement &creator_, QString &text, const QSize &size, QColor color,
|
||||
FontStyle style, float scale);
|
||||
|
||||
protected:
|
||||
@@ -93,7 +93,7 @@ private:
|
||||
class TextIconLayoutElement : public MessageLayoutElement
|
||||
{
|
||||
public:
|
||||
TextIconLayoutElement(MessageElement &creator, const QString &line1, const QString &line2,
|
||||
TextIconLayoutElement(MessageElement &creator_, const QString &line1, const QString &line2,
|
||||
float scale, const QSize &size);
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user