added brace wrapping after if and for

This commit is contained in:
fourtf
2018-10-21 13:43:02 +02:00
parent c6e1ec3c71
commit e259b9e39f
138 changed files with 4738 additions and 2237 deletions
+7 -3
View File
@@ -19,7 +19,8 @@ EmotePtr cachedOrMakeEmotePtr(Emote &&emote, const EmoteMap &cache)
{
// reuse old shared_ptr if nothing changed
auto it = cache.find(emote.name);
if (it != cache.end() && *it->second == emote) return it->second;
if (it != cache.end() && *it->second == emote)
return it->second;
return std::make_shared<Emote>(std::move(emote));
}
@@ -32,10 +33,13 @@ EmotePtr cachedOrMakeEmotePtr(
std::lock_guard<std::mutex> guard(mutex);
auto shared = cache[id].lock();
if (shared && *shared == emote) {
if (shared && *shared == emote)
{
// reuse old shared_ptr if nothing changed
return shared;
} else {
}
else
{
shared = std::make_shared<Emote>(std::move(emote));
cache[id] = shared;
return shared;
+46 -22
View File
@@ -34,7 +34,8 @@ namespace detail {
assertInGuiThread();
DebugCount::increase("images");
if (this->animated()) {
if (this->animated())
{
DebugCount::increase("animated images");
this->gifTimerConnection_ =
@@ -48,7 +49,8 @@ namespace detail {
assertInGuiThread();
DebugCount::decrease("images");
if (this->animated()) {
if (this->animated())
{
DebugCount::decrease("animated images");
}
@@ -59,7 +61,8 @@ namespace detail {
{
this->durationOffset_ += GIF_FRAME_LENGTH;
while (true) {
while (true)
{
this->index_ %= this->items_.size();
// TODO: Figure out what this was supposed to achieve
@@ -67,10 +70,13 @@ namespace detail {
// this->index_ = this->index_;
// }
if (this->durationOffset_ > this->items_[this->index_].duration) {
if (this->durationOffset_ > this->items_[this->index_].duration)
{
this->durationOffset_ -= this->items_[this->index_].duration;
this->index_ = (this->index_ + 1) % this->items_.size();
} else {
}
else
{
break;
}
}
@@ -83,13 +89,15 @@ namespace detail {
boost::optional<QPixmap> Frames::current() const
{
if (this->items_.size() == 0) return boost::none;
if (this->items_.size() == 0)
return boost::none;
return this->items_[this->index_].image;
}
boost::optional<QPixmap> Frames::first() const
{
if (this->items_.size() == 0) return boost::none;
if (this->items_.size() == 0)
return boost::none;
return this->items_.front().image;
}
@@ -98,15 +106,18 @@ namespace detail {
{
QVector<Frame<QImage>> frames;
if (reader.imageCount() == 0) {
if (reader.imageCount() == 0)
{
log("Error while reading image {}: '{}'", url.string,
reader.errorString());
return frames;
}
QImage image;
for (int index = 0; index < reader.imageCount(); ++index) {
if (reader.read(&image)) {
for (int index = 0; index < reader.imageCount(); ++index)
{
if (reader.read(&image))
{
QPixmap::fromImage(image);
int duration = std::max(20, reader.nextImageDelay());
@@ -114,7 +125,8 @@ namespace detail {
}
}
if (frames.size() == 0) {
if (frames.size() == 0)
{
log("Error while reading image {}: '{}'", url.string,
reader.errorString());
}
@@ -131,11 +143,13 @@ namespace detail {
std::lock_guard<std::mutex> lock(mutex);
int i = 0;
while (!queued.empty()) {
while (!queued.empty())
{
queued.front().first(queued.front().second);
queued.pop();
if (++i > 50) {
if (++i > 50)
{
QTimer::singleShot(3, [&] {
assignDelayed(queued, mutex, loadedEventQueued);
});
@@ -171,7 +185,8 @@ namespace detail {
static std::atomic_bool loadedEventQueued{false};
if (!loadedEventQueued) {
if (!loadedEventQueued)
{
loadedEventQueued = true;
QTimer::singleShot(100, [=] {
@@ -192,9 +207,12 @@ ImagePtr Image::fromUrl(const Url &url, qreal scale)
auto shared = cache[url].lock();
if (!shared) {
if (!shared)
{
cache[url] = shared = ImagePtr(new Image(url, scale));
} else {
}
else
{
// Warn("same image loaded multiple times: {}", url.string);
}
@@ -241,7 +259,8 @@ boost::optional<QPixmap> Image::pixmap() const
{
assertInGuiThread();
if (this->shouldLoad_) {
if (this->shouldLoad_)
{
const_cast<Image *>(this)->shouldLoad_ = false;
const_cast<Image *>(this)->load();
}
@@ -294,7 +313,8 @@ void Image::load()
req.setUseQuickLoadCache(true);
req.onSuccess([that = this, weak = weakOf(this)](auto result) -> Outcome {
auto shared = weak.lock();
if (!shared) return Failure;
if (!shared)
return Failure;
auto data = result.getData();
@@ -313,7 +333,8 @@ void Image::load()
});
req.onError([weak = weakOf(this)](auto result) -> bool {
auto shared = weak.lock();
if (!shared) return false;
if (!shared)
return false;
shared->empty_ = true;
@@ -325,9 +346,12 @@ void Image::load()
bool Image::operator==(const Image &other) const
{
if (this->isEmpty() && other.isEmpty()) return true;
if (!this->url_.string.isEmpty() && this->url_ == other.url_) return true;
if (this->frames_->first() == other.frames_->first()) return true;
if (this->isEmpty() && other.isEmpty())
return true;
if (!this->url_.string.isEmpty() && this->url_ == other.url_)
return true;
if (this->frames_->first() == other.frames_->first())
return true;
return false;
}
+4 -2
View File
@@ -67,11 +67,13 @@ const ImagePtr &ImageSet::getImage(float scale) const
else if (scale > 1.5)
quality = 2;
if (!this->imageX3_->isEmpty() && quality == 3) {
if (!this->imageX3_->isEmpty() && quality == 3)
{
return this->imageX3_;
}
if (!this->imageX2_->isEmpty() && quality == 2) {
if (!this->imageX2_->isEmpty() && quality == 2)
{
return this->imageX2_;
}
+44 -22
View File
@@ -60,13 +60,15 @@ public:
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);
}
@@ -91,7 +93,8 @@ public:
{
std::vector<T> acceptedItems;
if (this->space() > 0) {
if (this->space() > 0)
{
std::lock_guard<std::mutex> lock(this->mutex_);
// create new vector to clone chunks into
@@ -101,21 +104,25 @@ public:
newChunks->resize(this->chunks_->size());
// copy chunks except for first one
for (size_t i = 1; i < this->chunks_->size(); 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(), static_cast<qsizetype>(items.size()));
size_t offset =
std::min(this->space(), static_cast<qsizetype>(items.size()));
Chunk newFirstChunk = std::make_shared<std::vector<T>>();
newFirstChunk->resize(this->chunks_->front()->size() + offset);
for (size_t i = 0; i < offset; i++) {
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++) {
for (size_t i = 0; i < this->chunks_->at(0)->size(); i++)
{
newFirstChunk->at(i + offset) = this->chunks_->at(0)->at(i);
}
@@ -125,7 +132,8 @@ public:
// qDebug() << acceptedItems.size();
// qDebug() << this->chunks->at(0)->size();
if (this->chunks_->size() == 1) {
if (this->chunks_->size() == 1)
{
this->lastChunkEnd_ += offset;
}
}
@@ -140,19 +148,23 @@ public:
int x = 0;
for (size_t i = 0; i < this->chunks_->size(); 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();
for (size_t j = start; j < end; j++) {
if (chunk->at(j) == item) {
for (size_t j = start; j < end; j++)
{
if (chunk->at(j) == item)
{
Chunk newChunk = std::make_shared<std::vector<T>>();
newChunk->resize(chunk->size());
for (size_t k = 0; k < chunk->size(); k++) {
for (size_t k = 0; k < chunk->size(); k++)
{
newChunk->at(k) = chunk->at(k);
}
@@ -175,19 +187,23 @@ public:
size_t x = 0;
for (size_t i = 0; i < this->chunks_->size(); 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();
for (size_t j = start; j < end; j++) {
if (x == index) {
for (size_t j = start; j < end; j++)
{
if (x == index)
{
Chunk newChunk = std::make_shared<std::vector<T>>();
newChunk->resize(chunk->size());
for (size_t k = 0; k < chunk->size(); k++) {
for (size_t k = 0; k < chunk->size(); k++)
{
newChunk->at(k) = chunk->at(k);
}
@@ -217,12 +233,14 @@ private:
qsizetype 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) {
if (this->chunks_->size() != 1)
{
totalSize -= this->firstChunkOffset_;
}
@@ -232,7 +250,8 @@ private:
bool deleteFirstItem(T &deleted)
{
// determine if the first chunk should be deleted
if (space() > 0) {
if (space() > 0)
{
return false;
}
@@ -241,15 +260,18 @@ private:
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_) {
if (!first) {
for (Chunk &chunk : *this->chunks_)
{
if (!first)
{
newVector->push_back(chunk);
}
first = false;
+4 -2
View File
@@ -33,10 +33,12 @@ public:
size_t x = 0;
for (size_t i = 0; i < this->chunks_->size(); i++) {
for (size_t i = 0; i < this->chunks_->size(); i++)
{
auto &chunk = this->chunks_->at(i);
if (x <= index && x + chunk->size() > index) {
if (x <= index && x + chunk->size() > index)
{
return chunk->at(index - x);
}
x += chunk->size();
+5 -2
View File
@@ -21,9 +21,12 @@ Message::~Message()
SBHighlight Message::getScrollBarHighlight() const
{
if (this->flags.has(MessageFlag::Highlighted)) {
if (this->flags.has(MessageFlag::Highlighted))
{
return SBHighlight(SBHighlight::Highlight);
} else if (this->flags.has(MessageFlag::Subscription)) {
}
else if (this->flags.has(MessageFlag::Subscription))
{
return SBHighlight(SBHighlight::Subscription);
}
return SBHighlight();
+37 -16
View File
@@ -52,7 +52,8 @@ MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &username,
QString text;
text.append(username);
if (!durationInSeconds.isEmpty()) {
if (!durationInSeconds.isEmpty())
{
text.append(" has been timed out");
// TODO: Implement who timed the user out
@@ -60,21 +61,26 @@ MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &username,
text.append(" for ");
bool ok = true;
int timeoutSeconds = durationInSeconds.toInt(&ok);
if (ok) {
if (ok)
{
text.append(formatTime(timeoutSeconds));
}
} else {
}
else
{
text.append(" has been permanently banned");
}
if (reason.length() > 0) {
if (reason.length() > 0)
{
text.append(": \"");
text.append(parseTagString(reason));
text.append("\"");
}
text.append(".");
if (multipleTimes) {
if (multipleTimes)
{
text.append(" (multiple times)");
}
@@ -99,24 +105,33 @@ MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count)
QString text;
if (action.isBan()) {
if (action.reason.isEmpty()) {
if (action.isBan())
{
if (action.reason.isEmpty())
{
text = QString("%1 banned %2.") //
.arg(action.source.name)
.arg(action.target.name);
} else {
}
else
{
text = QString("%1 banned %2: \"%3\".") //
.arg(action.source.name)
.arg(action.target.name)
.arg(action.reason);
}
} else {
if (action.reason.isEmpty()) {
}
else
{
if (action.reason.isEmpty())
{
text = QString("%1 timed out %2 for %3.") //
.arg(action.source.name)
.arg(action.target.name)
.arg(formatTime(action.duration));
} else {
}
else
{
text = QString("%1 timed out %2 for %3: \"%4\".") //
.arg(action.source.name)
.arg(action.target.name)
@@ -124,7 +139,8 @@ MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count)
.arg(action.reason);
}
if (count > 1) {
if (count > 1)
{
text.append(QString(" (%1 times)").arg(count));
}
}
@@ -145,11 +161,14 @@ MessageBuilder::MessageBuilder(const UnbanAction &action)
QString text;
if (action.wasBan()) {
if (action.wasBan())
{
text = QString("%1 unbanned %2.") //
.arg(action.source.name)
.arg(action.target.name);
} else {
}
else
{
text = QString("%1 untimedout %2.") //
.arg(action.source.name)
.arg(action.target.name);
@@ -193,14 +212,16 @@ QString MessageBuilder::matchLink(const QString &string)
static QRegularExpression spotifyRegex(
"\\bspotify:", QRegularExpression::CaseInsensitiveOption);
if (!linkParser.hasMatch()) {
if (!linkParser.hasMatch())
{
return QString();
}
QString captured = linkParser.getCaptured();
if (!captured.contains(httpRegex) && !captured.contains(ftpRegex) &&
!captured.contains(spotifyRegex)) {
!captured.contains(spotifyRegex))
{
captured.insert(0, "http://");
}
+2 -1
View File
@@ -17,7 +17,8 @@ MessageColor::MessageColor(Type type)
const QColor &MessageColor::getColor(Theme &themeManager) const
{
switch (this->type_) {
switch (this->type_)
{
case Type::Custom:
return this->customColor_;
case Type::Text:
+44 -21
View File
@@ -84,7 +84,8 @@ ImageElement::ImageElement(ImagePtr image, MessageElementFlags flags)
void ImageElement::addToContainer(MessageLayoutContainer &container,
MessageElementFlags flags)
{
if (flags.hasAny(this->getFlags())) {
if (flags.hasAny(this->getFlags()))
{
auto size = QSize(this->image_->width() * container.getScale(),
this->image_->height() * container.getScale());
@@ -112,10 +113,13 @@ EmotePtr EmoteElement::getEmote() const
void EmoteElement::addToContainer(MessageLayoutContainer &container,
MessageElementFlags flags)
{
if (flags.hasAny(this->getFlags())) {
if (flags.has(MessageElementFlag::EmoteImages)) {
if (flags.hasAny(this->getFlags()))
{
if (flags.has(MessageElementFlag::EmoteImages))
{
auto image = this->emote_->images.getImage(container.getScale());
if (image->isEmpty()) return;
if (image->isEmpty())
return;
auto emoteScale = getSettings()->emoteScale.getValue();
@@ -125,8 +129,11 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container,
container.addElement((new ImageLayoutElement(*this, image, size))
->setLink(this->getLink()));
} else {
if (this->textElement_) {
}
else
{
if (this->textElement_)
{
this->textElement_->addToContainer(container,
MessageElementFlag::Misc);
}
@@ -141,7 +148,8 @@ TextElement::TextElement(const QString &text, MessageElementFlags flags,
, color_(color)
, style_(style)
{
for (const auto &word : text.split(' ')) {
for (const auto &word : text.split(' '))
{
this->words_.push_back({word, -1});
// fourtf: add logic to store multiple spaces after message
}
@@ -152,11 +160,13 @@ void TextElement::addToContainer(MessageLayoutContainer &container,
{
auto app = getApp();
if (flags.hasAny(this->getFlags())) {
if (flags.hasAny(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) {
auto color = this->color_.getColor(*app->themes);
@@ -171,7 +181,8 @@ void TextElement::addToContainer(MessageLayoutContainer &container,
// If URL link was changed,
// Should update it in MessageLayoutElement too!
if (this->getLink().type == Link::Url) {
if (this->getLink().type == Link::Url)
{
this->linkChanged.connect(
[this, e]() { e->setLink(this->getLink()); });
}
@@ -184,17 +195,20 @@ void TextElement::addToContainer(MessageLayoutContainer &container,
// }
// see if the text fits in the current line
if (container.fitsInLine(word.width)) {
if (container.fitsInLine(word.width))
{
container.addElementNoLineBreak(getTextLayoutElement(
word.text, word.width, this->hasTrailingSpace()));
continue;
}
// see if the text fits in the next line
if (!container.atStartOfLine()) {
if (!container.atStartOfLine())
{
container.breakLine();
if (container.fitsInLine(word.width)) {
if (container.fitsInLine(word.width))
{
container.addElementNoLineBreak(getTextLayoutElement(
word.text, word.width, this->hasTrailingSpace()));
continue;
@@ -226,13 +240,15 @@ void TextElement::addToContainer(MessageLayoutContainer &container,
wordStart = i;
width = charWidth;
if (isSurrogate) i++;
if (isSurrogate)
i++;
continue;
}
width += charWidth;
if (isSurrogate) i++;
if (isSurrogate)
i++;
}
container.addElement(getTextLayoutElement(
@@ -254,9 +270,11 @@ TimestampElement::TimestampElement(QTime time)
void TimestampElement::addToContainer(MessageLayoutContainer &container,
MessageElementFlags flags)
{
if (flags.hasAny(this->getFlags())) {
if (flags.hasAny(this->getFlags()))
{
auto app = getApp();
if (getSettings()->timestampFormat != this->format_) {
if (getSettings()->timestampFormat != this->format_)
{
this->format_ = getSettings()->timestampFormat.getValue();
this->element_.reset(this->formatTime(this->time_));
}
@@ -284,17 +302,22 @@ TwitchModerationElement::TwitchModerationElement()
void TwitchModerationElement::addToContainer(MessageLayoutContainer &container,
MessageElementFlags flags)
{
if (flags.has(MessageElementFlag::ModeratorTools)) {
if (flags.has(MessageElementFlag::ModeratorTools))
{
QSize size(int(container.getScale() * 16),
int(container.getScale() * 16));
for (const auto &action :
getApp()->moderationActions->items.getVector()) {
if (auto image = action.getImage()) {
getApp()->moderationActions->items.getVector())
{
if (auto image = action.getImage())
{
container.addElement(
(new ImageLayoutElement(*this, image.get(), size))
->setLink(Link(Link::UserAction, action.getAction())));
} else {
}
else
{
container.addElement(
(new TextIconLayoutElement(*this, action.getLine1(),
action.getLine2(),
+2 -1
View File
@@ -59,7 +59,8 @@ struct Selection {
, selectionMin(start)
, selectionMax(end)
{
if (selectionMin > selectionMax) {
if (selectionMin > selectionMax)
{
std::swap(this->selectionMin, this->selectionMax);
}
}
+40 -19
View File
@@ -64,7 +64,8 @@ bool MessageLayout::layout(int width, float scale, MessageElementFlags flags)
this->currentLayoutWidth_ = width;
// check if layout state changed
if (this->layoutState_ != app->windows->getGeneration()) {
if (this->layoutState_ != app->windows->getGeneration())
{
layoutRequired = true;
this->flags.set(MessageLayoutFlag::RequiresBufferUpdate);
this->layoutState_ = app->windows->getGeneration();
@@ -82,13 +83,15 @@ bool MessageLayout::layout(int width, float scale, MessageElementFlags flags)
layoutRequired |= this->scale_ != scale;
this->scale_ = scale;
if (!layoutRequired) {
if (!layoutRequired)
{
return false;
}
int oldHeight = this->container_->getHeight();
this->actuallyLayout(width, flags);
if (widthChanged || this->container_->getHeight() != oldHeight) {
if (widthChanged || this->container_->getHeight() != oldHeight)
{
this->deleteBuffer();
}
this->invalidateBuffer();
@@ -109,11 +112,13 @@ void MessageLayout::actuallyLayout(int width, MessageElementFlags _flags)
this->container_->begin(width, this->scale_, messageFlags);
for (const auto &element : this->message_->elements) {
for (const auto &element : this->message_->elements)
{
element->addToContainer(*this->container_, _flags);
}
if (this->height_ != this->container_->getHeight()) {
if (this->height_ != this->container_->getHeight())
{
this->deleteBuffer();
}
@@ -122,7 +127,8 @@ void MessageLayout::actuallyLayout(int width, MessageElementFlags _flags)
// collapsed state
this->flags.unset(MessageLayoutFlag::Collapsed);
if (this->container_->isCollapsed()) {
if (this->container_->isCollapsed())
{
this->flags.set(MessageLayoutFlag::Collapsed);
}
}
@@ -136,7 +142,8 @@ void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
QPixmap *pixmap = this->buffer_.get();
// create new buffer if required
if (!pixmap) {
if (!pixmap)
{
#ifdef Q_OS_MACOS
pixmap = new QPixmap(int(width * painter.device()->devicePixelRatioF()),
int(container_->getHeight() *
@@ -152,7 +159,8 @@ void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
DebugCount::increase("message drawing buffers");
}
if (!this->bufferValid_ || !selection.isEmpty()) {
if (!this->bufferValid_ || !selection.isEmpty())
{
this->updateBuffer(pixmap, messageIndex, selection);
}
@@ -165,28 +173,35 @@ void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
this->container_->paintAnimatedElements(painter, y);
// draw disabled
if (this->message_->flags.has(MessageFlag::Disabled)) {
if (this->message_->flags.has(MessageFlag::Disabled))
{
painter.fillRect(0, y, pixmap->width(), pixmap->height(),
app->themes->messages.disabled);
}
// draw selection
if (!selection.isEmpty()) {
if (!selection.isEmpty())
{
this->container_->paintSelection(painter, messageIndex, selection, y);
}
// draw message seperation line
if (getSettings()->separateMessages.getValue()) {
if (getSettings()->separateMessages.getValue())
{
painter.fillRect(0, y, this->container_->getWidth(), 1,
app->themes->splits.messageSeperator);
}
// draw last read message line
if (isLastReadMessage) {
if (isLastReadMessage)
{
QColor color;
if (getSettings()->lastMessageColor != "") {
if (getSettings()->lastMessageColor != "")
{
color = QColor(getSettings()->lastMessageColor.getValue());
} else {
}
else
{
color =
isWindowFocused
? app->themes->tabs.selected.backgrounds.regular.color()
@@ -214,12 +229,17 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/,
// draw background
QColor backgroundColor = app->themes->messages.backgrounds.regular;
if (this->message_->flags.has(MessageFlag::Highlighted) &&
!this->flags.has(MessageLayoutFlag::IgnoreHighlights)) {
!this->flags.has(MessageLayoutFlag::IgnoreHighlights))
{
backgroundColor = app->themes->messages.backgrounds.highlighted;
} else if (this->message_->flags.has(MessageFlag::Subscription)) {
}
else if (this->message_->flags.has(MessageFlag::Subscription))
{
backgroundColor = app->themes->messages.backgrounds.subscription;
} else if (getSettings()->alternateMessageBackground.getValue() &&
this->flags.has(MessageLayoutFlag::AlternateBackground)) {
}
else if (getSettings()->alternateMessageBackground.getValue() &&
this->flags.has(MessageLayoutFlag::AlternateBackground))
{
backgroundColor = app->themes->messages.backgrounds.alternate;
}
@@ -249,7 +269,8 @@ void MessageLayout::invalidateBuffer()
void MessageLayout::deleteBuffer()
{
if (this->buffer_ != nullptr) {
if (this->buffer_ != nullptr)
{
DebugCount::decrease("message drawing buffers");
this->buffer_ = nullptr;
+120 -60
View File
@@ -65,7 +65,8 @@ void MessageLayoutContainer::clear()
void MessageLayoutContainer::addElement(MessageLayoutElement *element)
{
if (!this->fitsInLine(element->getRect().width())) {
if (!this->fitsInLine(element->getRect().width()))
{
this->breakLine();
}
@@ -86,13 +87,15 @@ bool MessageLayoutContainer::canAddElements()
void MessageLayoutContainer::_addElement(MessageLayoutElement *element,
bool forceAdd)
{
if (!this->canAddElements() && !forceAdd) {
if (!this->canAddElements() && !forceAdd)
{
delete element;
return;
}
// top margin
if (this->elements_.size() == 0) {
if (this->elements_.size() == 0)
{
this->currentY_ = this->margin.top * this->scale_;
}
@@ -103,7 +106,8 @@ void MessageLayoutContainer::_addElement(MessageLayoutElement *element,
!this->flags_.has(MessageFlag::DisableCompactEmotes) &&
element->getCreator().getFlags().has(MessageElementFlag::EmoteImages);
if (isCompactEmote) {
if (isCompactEmote)
{
newLineHeight -= COMPACT_EMOTES_OFFSET * this->scale_;
}
@@ -120,7 +124,8 @@ void MessageLayoutContainer::_addElement(MessageLayoutElement *element,
// set current x
this->currentX_ += element->getRect().width();
if (element->hasTrailingSpace()) {
if (element->hasTrailingSpace())
{
this->currentX_ += this->spaceWidth_;
}
}
@@ -129,7 +134,8 @@ void MessageLayoutContainer::breakLine()
{
int xOffset = 0;
if (this->flags_.has(MessageFlag::Centered) && this->elements_.size() > 0) {
if (this->flags_.has(MessageFlag::Centered) && this->elements_.size() > 0)
{
xOffset = (width_ - this->elements_.at(0)->getRect().left() -
this->elements_.at(this->elements_.size() - 1)
->getRect()
@@ -137,7 +143,8 @@ void MessageLayoutContainer::breakLine()
2;
}
for (size_t i = lineStart_; i < this->elements_.size(); i++) {
for (size_t i = lineStart_; i < this->elements_.size(); i++)
{
MessageLayoutElement *element = this->elements_.at(i).get();
bool isCompactEmote =
@@ -146,14 +153,16 @@ void MessageLayoutContainer::breakLine()
MessageElementFlag::EmoteImages);
int yExtra = 0;
if (isCompactEmote) {
if (isCompactEmote)
{
yExtra = (COMPACT_EMOTES_OFFSET / 2) * this->scale_;
}
// if (element->getCreator().getFlags() &
// MessageElementFlag::Badges)
// {
if (element->getRect().height() < this->textLineHeight_) {
if (element->getRect().height() < this->textLineHeight_)
{
yExtra -= (this->textLineHeight_ - element->getRect().height()) / 2;
}
@@ -162,7 +171,8 @@ void MessageLayoutContainer::breakLine()
element->getRect().y() + this->lineHeight_ + yExtra));
}
if (this->lines_.size() != 0) {
if (this->lines_.size() != 0)
{
this->lines_.back().endIndex = this->lineStart_;
this->lines_.back().endCharIndex = this->charIndex_;
}
@@ -170,14 +180,16 @@ void MessageLayoutContainer::breakLine()
{(int)lineStart_, 0, this->charIndex_, 0,
QRect(-100000, this->currentY_, 200000, lineHeight_)});
for (int i = this->lineStart_; i < this->elements_.size(); i++) {
for (int i = this->lineStart_; i < this->elements_.size(); i++)
{
this->charIndex_ += this->elements_[i]->getSelectionIndexCount();
}
this->lineStart_ = this->elements_.size();
// this->currentX = (int)(this->scale * 8);
if (this->canCollapse() && line_ + 1 >= MAX_UNCOLLAPSED_LINES) {
if (this->canCollapse() && line_ + 1 >= MAX_UNCOLLAPSED_LINES)
{
this->canAddMessages_ = false;
return;
}
@@ -204,7 +216,8 @@ bool MessageLayoutContainer::fitsInLine(int _width)
void MessageLayoutContainer::end()
{
if (!this->canAddElements()) {
if (!this->canAddElements())
{
static TextElement dotdotdot("...", MessageElementFlag::Collapsed,
MessageColor::Link);
static QString dotdotdotText("...");
@@ -219,13 +232,15 @@ void MessageLayoutContainer::end()
this->isCollapsed_ = true;
}
if (!this->atStartOfLine()) {
if (!this->atStartOfLine())
{
this->breakLine();
}
this->height_ += this->lineHeight_;
if (this->lines_.size() != 0) {
if (this->lines_.size() != 0)
{
this->lines_[0].rect.setTop(-100000);
this->lines_.back().rect.setBottom(100000);
this->lines_.back().endIndex = this->elements_.size();
@@ -246,8 +261,10 @@ bool MessageLayoutContainer::isCollapsed()
MessageLayoutElement *MessageLayoutContainer::getElementAt(QPoint point)
{
for (std::unique_ptr<MessageLayoutElement> &element : this->elements_) {
if (element->getRect().contains(point)) {
for (std::unique_ptr<MessageLayoutElement> &element : this->elements_)
{
if (element->getRect().contains(point))
{
return element.get();
}
}
@@ -258,8 +275,8 @@ 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());
@@ -272,8 +289,8 @@ 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);
}
}
@@ -286,14 +303,17 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
// don't draw anything
if (selection.selectionMin.messageIndex > messageIndex ||
selection.selectionMax.messageIndex < messageIndex) {
selection.selectionMax.messageIndex < messageIndex)
{
return;
}
// fully selected
if (selection.selectionMin.messageIndex < messageIndex &&
selection.selectionMax.messageIndex > messageIndex) {
for (Line &line : this->lines_) {
selection.selectionMax.messageIndex > messageIndex)
{
for (Line &line : this->lines_)
{
QRect rect = line.rect;
rect.setTop(std::max(0, rect.top()) + yOffset);
@@ -311,8 +331,10 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
int index = 0;
// start in this message
if (selection.selectionMin.messageIndex == messageIndex) {
for (; lineIndex < this->lines_.size(); lineIndex++) {
if (selection.selectionMin.messageIndex == messageIndex)
{
for (; lineIndex < this->lines_.size(); lineIndex++)
{
Line &line = this->lines_[lineIndex];
index = line.startCharIndex;
@@ -321,14 +343,17 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
int x = this->elements_[line.startIndex]->getRect().left();
int r = this->elements_[line.endIndex - 1]->getRect().right();
if (line.endCharIndex <= selection.selectionMin.charIndex) {
if (line.endCharIndex <= selection.selectionMin.charIndex)
{
continue;
}
for (int i = line.startIndex; i < line.endIndex; i++) {
for (int i = line.startIndex; i < line.endIndex; i++)
{
int c = this->elements_[i]->getSelectionIndexCount();
if (index + c > selection.selectionMin.charIndex) {
if (index + c > selection.selectionMin.charIndex)
{
x = this->elements_[i]->getXFromIndex(
selection.selectionMin.charIndex - index);
@@ -339,11 +364,13 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
{
returnAfter = true;
index = line.startCharIndex;
for (int i = line.startIndex; i < line.endIndex; i++) {
for (int i = line.startIndex; i < line.endIndex; i++)
{
int c =
this->elements_[i]->getSelectionIndexCount();
if (index + c > selection.selectionMax.charIndex) {
if (index + c > selection.selectionMax.charIndex)
{
r = this->elements_[i]->getXFromIndex(
selection.selectionMax.charIndex - index);
break;
@@ -353,9 +380,11 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
}
// ends in same line end
if (selection.selectionMax.messageIndex != messageIndex) {
if (selection.selectionMax.messageIndex != messageIndex)
{
int lineIndex2 = lineIndex + 1;
for (; lineIndex2 < this->lines_.size(); lineIndex2++) {
for (; lineIndex2 < this->lines_.size(); lineIndex2++)
{
Line &line = this->lines_[lineIndex2];
QRect rect = line.rect;
@@ -373,7 +402,9 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
painter.fillRect(rect, selectionColor);
}
returnAfter = true;
} else {
}
else
{
lineIndex++;
breakAfter = true;
}
@@ -392,23 +423,27 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
painter.fillRect(rect, selectionColor);
if (returnAfter) {
if (returnAfter)
{
return;
}
if (breakAfter) {
if (breakAfter)
{
break;
}
}
}
// start in this message
for (; lineIndex < this->lines_.size(); lineIndex++) {
for (; lineIndex < this->lines_.size(); lineIndex++)
{
Line &line = this->lines_[lineIndex];
index = line.startCharIndex;
// just draw the garbage
if (line.endCharIndex < /*=*/selection.selectionMax.charIndex) {
if (line.endCharIndex < /*=*/selection.selectionMax.charIndex)
{
QRect rect = line.rect;
rect.setTop(std::max(0, rect.top()) + yOffset);
@@ -423,10 +458,12 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
int r = this->elements_[line.endIndex - 1]->getRect().right();
for (int i = line.startIndex; i < line.endIndex; i++) {
for (int i = line.startIndex; i < line.endIndex; i++)
{
int c = this->elements_[i]->getSelectionIndexCount();
if (index + c > selection.selectionMax.charIndex) {
if (index + c > selection.selectionMax.charIndex)
{
r = this->elements_[i]->getXFromIndex(
selection.selectionMax.charIndex - index);
break;
@@ -450,21 +487,25 @@ 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();
for (; line != this->lines_.end(); line++) {
if (line->rect.contains(point)) {
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()) {
if (line != this->lines_.end())
{
line++;
}
int lineEnd =
@@ -472,20 +513,24 @@ int MessageLayoutContainer::getSelectionIndex(QPoint point)
int index = 0;
for (int i = 0; i < lineEnd; i++) {
for (int i = 0; i < lineEnd; i++)
{
// end of line
if (i == lineEnd) {
if (i == lineEnd)
{
break;
}
// before line
if (i < lineStart) {
if (i < lineStart)
{
index += this->elements_[i]->getSelectionIndexCount();
continue;
}
// this is the word
if (point.x() <= this->elements_[i]->getRect().right()) {
if (point.x() <= this->elements_[i]->getRect().right())
{
index += this->elements_[i]->getMouseOverIndex(point);
break;
}
@@ -499,7 +544,8 @@ 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;
@@ -515,10 +561,14 @@ int MessageLayoutContainer::getFirstMessageCharacterIndex() const
// Get the index of the first character of the real message
// (no badges/timestamps/username)
int index = 0;
for (auto &element : this->elements_) {
if (element->getFlags().hasAny(flags)) {
for (auto &element : this->elements_)
{
if (element->getFlags().hasAny(flags))
{
index += element->getSelectionIndexCount();
} else {
}
else
{
break;
}
}
@@ -531,8 +581,10 @@ void MessageLayoutContainer::addSelectionText(QString &str, int from, int to,
int index = 0;
bool first = true;
for (auto &element : this->elements_) {
if (copymode == CopyMode::OnlyTextAndEmotes) {
for (auto &element : this->elements_)
{
if (copymode == CopyMode::OnlyTextAndEmotes)
{
if (element->getCreator().getFlags().hasAny(
{MessageElementFlag::Timestamp,
MessageElementFlag::Username, MessageElementFlag::Badges}))
@@ -541,20 +593,28 @@ void MessageLayoutContainer::addSelectionText(QString &str, int from, int to,
auto indexCount = element->getSelectionIndexCount();
if (first) {
if (index + indexCount > from) {
if (first)
{
if (index + indexCount > from)
{
element->addCopyTextToString(str, from - index, to - index);
first = false;
if (index + indexCount > to) {
if (index + indexCount > to)
{
break;
}
}
} else {
if (index + indexCount > to) {
}
else
{
if (index + indexCount > to)
{
element->addCopyTextToString(str, 0, to - index);
break;
} else {
}
else
{
element->addCopyTextToString(str);
}
}
+53 -23
View File
@@ -96,9 +96,11 @@ void ImageLayoutElement::addCopyTextToString(QString &str, int from,
{
const auto *emoteElement =
dynamic_cast<EmoteElement *>(&this->getCreator());
if (emoteElement) {
if (emoteElement)
{
str += emoteElement->getEmote()->getCopyString();
if (this->hasTrailingSpace()) {
if (this->hasTrailingSpace())
{
str += " ";
}
}
@@ -111,12 +113,14 @@ int ImageLayoutElement::getSelectionIndexCount() const
void ImageLayoutElement::paint(QPainter &painter)
{
if (this->image_ == nullptr) {
if (this->image_ == nullptr)
{
return;
}
auto pixmap = this->image_->pixmap();
if (pixmap && !this->image_->animated()) {
if (pixmap && !this->image_->animated())
{
// fourtf: make it use qreal values
painter.drawPixmap(QRectF(this->getRect()), *pixmap, QRectF());
}
@@ -124,12 +128,15 @@ void ImageLayoutElement::paint(QPainter &painter)
void ImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
{
if (this->image_ == nullptr) {
if (this->image_ == nullptr)
{
return;
}
if (this->image_->animated()) {
if (auto pixmap = this->image_->pixmap()) {
if (this->image_->animated())
{
if (auto pixmap = this->image_->pixmap())
{
auto rect = this->getRect();
rect.moveTop(rect.y() + yOffset);
painter.drawPixmap(QRectF(rect), *pixmap, QRectF());
@@ -144,12 +151,17 @@ int ImageLayoutElement::getMouseOverIndex(const QPoint &abs) const
int ImageLayoutElement::getXFromIndex(int index)
{
if (index <= 0) {
if (index <= 0)
{
return this->getRect().left();
} else if (index == 1) {
}
else if (index == 1)
{
// fourtf: remove space width
return this->getRect().right();
} else {
}
else
{
return this->getRect().right();
}
}
@@ -174,7 +186,8 @@ void TextLayoutElement::addCopyTextToString(QString &str, int from,
{
str += this->getText().mid(from, to - from);
if (this->hasTrailingSpace()) {
if (this->hasTrailingSpace())
{
str += " ";
}
}
@@ -203,7 +216,8 @@ void TextLayoutElement::paintAnimated(QPainter &, int)
int TextLayoutElement::getMouseOverIndex(const QPoint &abs) const
{
if (abs.x() < this->getRect().left()) {
if (abs.x() < this->getRect().left())
{
return 0;
}
@@ -213,11 +227,13 @@ int TextLayoutElement::getMouseOverIndex(const QPoint &abs) const
int x = this->getRect().left();
for (int i = 0; i < this->getText().size(); i++) {
for (int i = 0; i < this->getText().size(); i++)
{
auto &text = this->getText();
auto width = metrics.width(this->getText()[i]);
if (x + width > abs.x()) {
if (x + width > abs.x())
{
if (text.size() > i + 1 &&
QChar::isLowSurrogate(text[i].unicode())) //
{
@@ -239,15 +255,21 @@ int TextLayoutElement::getXFromIndex(int index)
QFontMetrics metrics = app->fonts->getFontMetrics(this->style, this->scale);
if (index <= 0) {
if (index <= 0)
{
return this->getRect().left();
} else if (index < this->getText().size()) {
}
else if (index < this->getText().size())
{
int x = 0;
for (int i = 0; i < index; i++) {
for (int i = 0; i < index; i++)
{
x += metrics.width(this->getText()[i]);
}
return x + this->getRect().left();
} else {
}
else
{
return this->getRect().right();
}
}
@@ -286,10 +308,13 @@ void TextIconLayoutElement::paint(QPainter &painter)
QTextOption option;
option.setAlignment(Qt::AlignHCenter);
if (this->line2.isEmpty()) {
if (this->line2.isEmpty())
{
QRect _rect(this->getRect());
painter.drawText(_rect, this->line1, option);
} else {
}
else
{
painter.drawText(
QPoint(this->getRect().x(),
this->getRect().y() + this->getRect().height() / 2),
@@ -311,12 +336,17 @@ int TextIconLayoutElement::getMouseOverIndex(const QPoint &abs) const
int TextIconLayoutElement::getXFromIndex(int index)
{
if (index <= 0) {
if (index <= 0)
{
return this->getRect().left();
} else if (index == 1) {
}
else if (index == 1)
{
// fourtf: remove space width
return this->getRect().right();
} else {
}
else
{
return this->getRect().right();
}
}