diff --git a/.clang-format b/.clang-format index eeb9eb929..4f7b191e6 100644 --- a/.clang-format +++ b/.clang-format @@ -4,7 +4,7 @@ AccessModifierOffset: -1 AccessModifierOffset: -4 AlignEscapedNewlinesLeft: true AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: false AlwaysBreakBeforeMultilineStrings: false @@ -12,10 +12,10 @@ BasedOnStyle: Google BraceWrapping: { AfterNamespace: 'false' AfterClass: 'true' - BeforeElse: 'false' - AfterControlStatement: 'false' + BeforeElse: 'true' + AfterControlStatement: 'true' AfterFunction: 'true' - BeforeCatch: 'false' + BeforeCatch: 'true' } BreakBeforeBraces: Custom BreakConstructorInitializersBeforeComma: true diff --git a/src/Application.cpp b/src/Application.cpp index ed657d0c9..25942889e 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -75,7 +75,8 @@ void Application::initialize(Settings &settings, Paths &paths) assert(isAppInitialized == false); isAppInitialized = true; - for (auto &singleton : this->singletons_) { + for (auto &singleton : this->singletons_) + { singleton->initialize(settings, paths); } @@ -98,7 +99,8 @@ int Application::run(QApplication &qtApp) void Application::save() { - for (auto &singleton : this->singletons_) { + for (auto &singleton : this->singletons_) + { singleton->save(); } } @@ -132,7 +134,8 @@ void Application::initPubsub() [this](const auto &action) { auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID); - if (chan->isEmpty()) { + if (chan->isEmpty()) + { return; } @@ -147,7 +150,8 @@ void Application::initPubsub() [this](const auto &action) { auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID); - if (chan->isEmpty()) { + if (chan->isEmpty()) + { return; } @@ -158,7 +162,8 @@ void Application::initPubsub() : "off") .arg(action.getModeName()); - if (action.duration > 0) { + if (action.duration > 0) + { text.append(" (" + QString::number(action.duration) + " seconds)"); } @@ -171,16 +176,20 @@ void Application::initPubsub() [this](const auto &action) { auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID); - if (chan->isEmpty()) { + if (chan->isEmpty()) + { return; } QString text; - if (action.modded) { + if (action.modded) + { text = QString("%1 modded %2") .arg(action.source.name, action.target.name); - } else { + } + else + { text = QString("%1 unmodded %2") .arg(action.source.name, action.target.name); } @@ -194,7 +203,8 @@ void Application::initPubsub() auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID); - if (chan->isEmpty()) { + if (chan->isEmpty()) + { return; } @@ -211,7 +221,8 @@ void Application::initPubsub() auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID); - if (chan->isEmpty()) { + if (chan->isEmpty()) + { return; } diff --git a/src/BrowserExtension.cpp b/src/BrowserExtension.cpp index f12d19b5e..25707e230 100644 --- a/src/BrowserExtension.cpp +++ b/src/BrowserExtension.cpp @@ -27,11 +27,13 @@ namespace { void runLoop(NativeMessagingClient &client) { - while (true) { + while (true) + { char size_c[4]; std::cin.read(size_c, 4); - if (std::cin.eof()) break; + if (std::cin.eof()) + break; auto size = *reinterpret_cast(size_c); @@ -72,7 +74,8 @@ void runBrowserExtensionHost() QTimer timer; QObject::connect(&timer, &QTimer::timeout, [&ping] { - if (!ping.exchange(false)) { + if (!ping.exchange(false)) + { _Exit(0); } }); diff --git a/src/RunGui.cpp b/src/RunGui.cpp index 04cb7985a..4da91a500 100644 --- a/src/RunGui.cpp +++ b/src/RunGui.cpp @@ -80,10 +80,14 @@ namespace { #ifndef C_DISABLE_CRASH_DIALOG LastRunCrashDialog dialog; - switch (dialog.exec()) { - case QDialog::Accepted: { - }; break; - default: { + switch (dialog.exec()) + { + case QDialog::Accepted: + { + }; + break; + default: + { _exit(0); } } @@ -120,9 +124,12 @@ void runGui(QApplication &a, Paths &paths, Settings &settings) auto runningPath = paths.miscDirectory + "/running_" + paths.applicationFilePathHash; - if (QFile::exists(runningPath)) { + if (QFile::exists(runningPath)) + { showLastCrashDialog(); - } else { + } + else + { createRunningFile(runningPath); } @@ -138,7 +145,7 @@ void runGui(QApplication &a, Paths &paths, Settings &settings) chatterino::NetworkManager::deinit(); #ifdef USEWINSDK - // flushing windows clipboard to keep copied messages + // flushing windows clipboard to keep copied messages flushClipboard(); #endif diff --git a/src/autogenerated/ResourcesAutogen.hpp b/src/autogenerated/ResourcesAutogen.hpp index c7af30fc1..075c801eb 100644 --- a/src/autogenerated/ResourcesAutogen.hpp +++ b/src/autogenerated/ResourcesAutogen.hpp @@ -3,7 +3,8 @@ namespace chatterino { -class Resources2 : public Singleton { +class Resources2 : public Singleton +{ public: Resources2(); diff --git a/src/common/Channel.cpp b/src/common/Channel.cpp index ece3d6ac1..3f4047079 100644 --- a/src/common/Channel.cpp +++ b/src/common/Channel.cpp @@ -65,17 +65,20 @@ void Channel::addMessage(MessagePtr message, MessagePtr deleted; const QString &username = message->loginName; - if (!username.isEmpty()) { + if (!username.isEmpty()) + { // TODO: Add recent chatters display name this->addRecentChatter(message); } // FOURTF: change this when adding more providers - if (this->isTwitchChannel()) { + if (this->isTwitchChannel()) + { app->logging->addMessage(this->name_, message); } - if (this->messages_.pushBack(message, deleted)) { + if (this->messages_.pushBack(message, deleted)) + { this->messageRemovedFromStart.invoke(deleted); } @@ -93,15 +96,18 @@ void Channel::addOrReplaceTimeout(MessagePtr message) QTime minimumTime = QTime::currentTime().addSecs(-5); - for (int i = snapshotLength - 1; i >= end; --i) { + for (int i = snapshotLength - 1; i >= end; --i) + { auto &s = snapshot[i]; - if (s->parseTime < minimumTime) { + if (s->parseTime < minimumTime) + { break; } if (s->flags.has(MessageFlag::Untimeout) && - s->timeoutUser == message->timeoutUser) { + s->timeoutUser == message->timeoutUser) + { break; } @@ -139,17 +145,20 @@ void Channel::addOrReplaceTimeout(MessagePtr message) } // disable the messages from the user - for (int i = 0; i < snapshotLength; i++) { + for (int i = 0; i < snapshotLength; i++) + { auto &s = snapshot[i]; if (s->flags.hasNone({MessageFlag::Timeout, MessageFlag::Untimeout}) && - s->loginName == message->timeoutUser) { + s->loginName == message->timeoutUser) + { // FOURTF: disabled for now // PAJLADA: Shitty solution described in Message.hpp s->flags.set(MessageFlag::Disabled); } } - if (addMessage) { + if (addMessage) + { this->addMessage(message); } @@ -161,10 +170,11 @@ void Channel::disableAllMessages() { LimitedQueueSnapshot snapshot = this->getMessageSnapshot(); int snapshotLength = snapshot.getLength(); - for (int i = 0; i < snapshotLength; i++) { + for (int i = 0; i < snapshotLength; i++) + { auto &message = snapshot[i]; - if (message->flags.hasAny( - {MessageFlag::System, MessageFlag::Timeout})) { + if (message->flags.hasAny({MessageFlag::System, MessageFlag::Timeout})) + { continue; } @@ -178,7 +188,8 @@ void Channel::addMessagesAtStart(std::vector &_messages) std::vector addedMessages = this->messages_.pushFront(_messages); - if (addedMessages.size() != 0) { + if (addedMessages.size() != 0) + { this->messagesAddedAtStart.invoke(addedMessages); } } @@ -187,7 +198,8 @@ void Channel::replaceMessage(MessagePtr message, MessagePtr replacement) { int index = this->messages_.replaceItem(message, replacement); - if (index >= 0) { + if (index >= 0) + { this->messageReplaced.invoke((size_t)index, replacement); } } @@ -276,9 +288,12 @@ pajlada::Signals::NoArgSignal &IndirectChannel::getChannelChanged() Channel::Type IndirectChannel::getType() { - if (this->data_->type == Channel::Type::Direct) { + if (this->data_->type == Channel::Type::Direct) + { return this->get()->getType(); - } else { + } + else + { return this->data_->type; } } diff --git a/src/common/CompletionModel.cpp b/src/common/CompletionModel.cpp index 3669ef268..11cb682cf 100644 --- a/src/common/CompletionModel.cpp +++ b/src/common/CompletionModel.cpp @@ -33,14 +33,16 @@ bool CompletionModel::TaggedString::isEmote() const bool CompletionModel::TaggedString::operator<(const TaggedString &that) const { - if (this->isEmote() != that.isEmote()) { + if (this->isEmote() != that.isEmote()) + { return this->isEmote(); } // try comparing insensitively, if they are the same then senstively // (fixes order of LuL and LUL) int k = QString::compare(this->string, that.string, Qt::CaseInsensitive); - if (k == 0) return this->string > that.string; + if (k == 0) + return this->string > that.string; return k < 0; } @@ -79,17 +81,21 @@ void CompletionModel::refresh(const QString &prefix) std::lock_guard guard(this->itemsMutex_); this->items_.clear(); - if (prefix.length() < 2) return; + if (prefix.length() < 2) + return; auto addString = [&](const QString &str, TaggedString::Type type) { if (str.startsWith(prefix, Qt::CaseInsensitive)) this->items_.emplace(str + " ", type); }; - if (auto channel = dynamic_cast(&this->channel_)) { + if (auto channel = dynamic_cast(&this->channel_)) + { // account emotes - if (auto account = getApp()->accounts->twitch.getCurrent()) { - for (const auto &emote : account->accessEmotes()->allEmoteNames) { + if (auto account = getApp()->accounts->twitch.getCurrent()) + { + for (const auto &emote : account->accessEmotes()->allEmoteNames) + { // XXX: No way to discern between a twitch global emote and sub // emote right now addString(emote.string, TaggedString::Type::TwitchGlobalEmote); @@ -97,60 +103,73 @@ void CompletionModel::refresh(const QString &prefix) } // Usernames - if (prefix.length() >= UsernameSet::PrefixLength) { + if (prefix.length() >= UsernameSet::PrefixLength) + { auto usernames = channel->accessChatters(); QString usernamePrefix = prefix; - if (usernamePrefix.startsWith("@")) { + if (usernamePrefix.startsWith("@")) + { usernamePrefix.remove(0, 1); for (const auto &name : - usernames->subrange(Prefix(usernamePrefix))) { + usernames->subrange(Prefix(usernamePrefix))) + { addString("@" + name, TaggedString::Type::Username); } - } else { + } + else + { for (const auto &name : - usernames->subrange(Prefix(usernamePrefix))) { + usernames->subrange(Prefix(usernamePrefix))) + { addString(name, TaggedString::Type::Username); } } } // Bttv Global - for (auto &emote : *channel->globalBttv().emotes()) { + for (auto &emote : *channel->globalBttv().emotes()) + { addString(emote.first.string, TaggedString::Type::BTTVChannelEmote); } // Ffz Global - for (auto &emote : *channel->globalFfz().emotes()) { + for (auto &emote : *channel->globalFfz().emotes()) + { addString(emote.first.string, TaggedString::Type::FFZChannelEmote); } // Bttv Channel - for (auto &emote : *channel->bttvEmotes()) { + for (auto &emote : *channel->bttvEmotes()) + { addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote); } // Ffz Channel - for (auto &emote : *channel->ffzEmotes()) { + for (auto &emote : *channel->ffzEmotes()) + { addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote); } // Emojis - if (prefix.startsWith(":")) { + if (prefix.startsWith(":")) + { const auto &emojiShortCodes = getApp()->emotes->emojis.shortCodes; - for (auto &m : emojiShortCodes) { + for (auto &m : emojiShortCodes) + { addString(":" + m + ":", TaggedString::Type::Emoji); } } // Commands - for (auto &command : getApp()->commands->items.getVector()) { + for (auto &command : getApp()->commands->items.getVector()) + { addString(command.name, TaggedString::Command); } - for (auto &command : - getApp()->commands->getDefaultTwitchCommandList()) { + for (auto &command : getApp()->commands->getDefaultTwitchCommandList()) + { addString(command, TaggedString::Command); } } diff --git a/src/common/ConcurrentMap.hpp b/src/common/ConcurrentMap.hpp index 0b5cbeb0e..6f385559b 100644 --- a/src/common/ConcurrentMap.hpp +++ b/src/common/ConcurrentMap.hpp @@ -21,7 +21,8 @@ public: QMutexLocker lock(&this->mutex); auto a = this->data.find(name); - if (a == this->data.end()) { + if (a == this->data.end()) + { return false; } @@ -35,7 +36,8 @@ public: QMutexLocker lock(&this->mutex); auto a = this->data.find(name); - if (a == this->data.end()) { + if (a == this->data.end()) + { TValue value = addLambda(); this->data.insert(name, value); return value; @@ -72,7 +74,8 @@ public: QMapIterator it(this->data); - while (it.hasNext()) { + while (it.hasNext()) + { it.next(); func(it.key(), it.value()); } @@ -84,7 +87,8 @@ public: QMutableMapIterator it(this->data); - while (it.hasNext()) { + while (it.hasNext()) + { it.next(); func(it.key(), it.value()); } diff --git a/src/common/DownloadManager.cpp b/src/common/DownloadManager.cpp index d762b7f14..286150a7c 100644 --- a/src/common/DownloadManager.cpp +++ b/src/common/DownloadManager.cpp @@ -48,16 +48,21 @@ void DownloadManager::onDownloadProgress(qint64 bytesRead, qint64 bytesTotal) void DownloadManager::onFinished(QNetworkReply *reply) { - switch (reply->error()) { - case QNetworkReply::NoError: { + switch (reply->error()) + { + case QNetworkReply::NoError: + { qDebug("file is downloaded successfully."); - } break; - default: { + } + break; + default: + { qDebug() << reply->errorString().toLatin1(); }; } - if (file->isOpen()) { + if (file->isOpen()) + { file->close(); file->deleteLater(); } @@ -71,7 +76,8 @@ void DownloadManager::onReadyRead() void DownloadManager::onReplyFinished() { - if (file->isOpen()) { + if (file->isOpen()) + { file->close(); file->deleteLater(); } diff --git a/src/common/FlagsEnum.hpp b/src/common/FlagsEnum.hpp index c5be885e5..1a393e9c6 100644 --- a/src/common/FlagsEnum.hpp +++ b/src/common/FlagsEnum.hpp @@ -20,7 +20,8 @@ public: FlagsEnum(std::initializer_list flags) { - for (auto flag : flags) { + for (auto flag : flags) + { this->set(flag); } } diff --git a/src/common/NetworkData.cpp b/src/common/NetworkData.cpp index a58ec7076..95229ebee 100644 --- a/src/common/NetworkData.cpp +++ b/src/common/NetworkData.cpp @@ -20,12 +20,14 @@ NetworkData::~NetworkData() QString NetworkData::getHash() { - if (this->hash_.isEmpty()) { + if (this->hash_.isEmpty()) + { QByteArray bytes; bytes.append(this->request_.url().toString()); - for (const auto &header : this->request_.rawHeaderList()) { + for (const auto &header : this->request_.rawHeaderList()) + { bytes.append(header); } @@ -40,10 +42,12 @@ QString NetworkData::getHash() void NetworkData::writeToCache(const QByteArray &bytes) { - if (this->useQuickLoadCache_) { + if (this->useQuickLoadCache_) + { QFile cachedFile(getPaths()->cacheDirectory() + "/" + this->getHash()); - if (cachedFile.open(QIODevice::WriteOnly)) { + if (cachedFile.open(QIODevice::WriteOnly)) + { cachedFile.write(bytes); cachedFile.close(); diff --git a/src/common/NetworkRequest.cpp b/src/common/NetworkRequest.cpp index 3fbfa7d97..524693c17 100644 --- a/src/common/NetworkRequest.cpp +++ b/src/common/NetworkRequest.cpp @@ -93,7 +93,8 @@ void NetworkRequest::makeAuthorizedV5(const QString &clientID, { this->setRawHeader("Client-ID", clientID); this->setRawHeader("Accept", "application/vnd.twitchtv.v5+json"); - if (!oauthToken.isEmpty()) { + if (!oauthToken.isEmpty()) + { this->setRawHeader("Authorization", "OAuth " + oauthToken); } } @@ -112,34 +113,45 @@ void NetworkRequest::execute() { this->executed_ = true; - switch (this->data->requestType_) { - case NetworkRequestType::Get: { + switch (this->data->requestType_) + { + case NetworkRequestType::Get: + { // Get requests try to load from cache, then perform the request - if (this->data->useQuickLoadCache_) { - if (this->tryLoadCachedFile()) { + if (this->data->useQuickLoadCache_) + { + if (this->tryLoadCachedFile()) + { // Successfully loaded from cache return; } } this->doRequest(); - } break; + } + break; - case NetworkRequestType::Put: { + case NetworkRequestType::Put: + { // Put requests cannot be cached, therefore the request is called // immediately this->doRequest(); - } break; + } + break; - case NetworkRequestType::Delete: { + case NetworkRequestType::Delete: + { // Delete requests cannot be cached, therefore the request is called // immediately this->doRequest(); - } break; + } + break; - default: { + default: + { log("[Execute] Unhandled request type"); - } break; + } + break; } } @@ -153,12 +165,14 @@ Outcome NetworkRequest::tryLoadCachedFile() QFile cachedFile(getPaths()->cacheDirectory() + "/" + this->data->getHash()); - if (!cachedFile.exists()) { + if (!cachedFile.exists()) + { // File didn't exist return Failure; } - if (!cachedFile.open(QIODevice::ReadOnly)) { + if (!cachedFile.open(QIODevice::ReadOnly)) + { // File could not be opened return Failure; } @@ -190,7 +204,8 @@ void NetworkRequest::doRequest() auto onUrlRequested = [data = this->data, timer = this->timer, worker]() mutable { auto reply = [&]() -> QNetworkReply * { - switch (data->requestType_) { + switch (data->requestType_) + { case NetworkRequestType::Get: return NetworkManager::accessManager.get(data->request_); @@ -207,29 +222,35 @@ void NetworkRequest::doRequest() } }(); - if (reply == nullptr) { + if (reply == nullptr) + { log("Unhandled request type"); return; } - if (timer->isStarted()) { + if (timer->isStarted()) + { timer->onTimeout(worker, [reply, data]() { log("Aborted!"); reply->abort(); - if (data->onError_) { + if (data->onError_) + { data->onError_(-2); } }); } - if (data->onReplyCreated_) { + if (data->onReplyCreated_) + { data->onReplyCreated_(reply); } auto handleReply = [data, timer, reply]() mutable { // TODO(pajlada): A reply was received, kill the timeout timer - if (reply->error() != QNetworkReply::NetworkError::NoError) { - if (data->onError_) { + if (reply->error() != QNetworkReply::NetworkError::NoError) + { + if (data->onError_) + { data->onError_(reply->error()); } return; @@ -242,7 +263,8 @@ void NetworkRequest::doRequest() DebugCount::increase("http request success"); // log("starting {}", data->request_.url().toString()); - if (data->onSuccess_) { + if (data->onSuccess_) + { if (data->executeConcurrently) QtConcurrent::run( [onSuccess = std::move(data->onSuccess_), @@ -255,7 +277,8 @@ void NetworkRequest::doRequest() reply->deleteLater(); }; - if (data->caller_ != nullptr) { + if (data->caller_ != nullptr) + { QObject::connect(worker, &NetworkWorker::doneUrl, data->caller_, handleReply); QObject::connect(reply, &QNetworkReply::finished, worker, @@ -264,7 +287,9 @@ void NetworkRequest::doRequest() delete worker; }); - } else { + } + else + { QObject::connect(reply, &QNetworkReply::finished, worker, [handleReply, worker]() mutable { handleReply(); diff --git a/src/common/NetworkResult.cpp b/src/common/NetworkResult.cpp index 78884a421..4051b4f9e 100644 --- a/src/common/NetworkResult.cpp +++ b/src/common/NetworkResult.cpp @@ -16,7 +16,8 @@ NetworkResult::NetworkResult(const QByteArray &data) QJsonObject NetworkResult::parseJson() const { QJsonDocument jsonDoc(QJsonDocument::fromJson(this->data_)); - if (jsonDoc.isNull()) { + if (jsonDoc.isNull()) + { return QJsonObject{}; } @@ -30,7 +31,8 @@ rapidjson::Document NetworkResult::parseRapidJson() const rapidjson::ParseResult result = ret.Parse(this->data_.data(), this->data_.length()); - if (result.Code() != rapidjson::kParseErrorNone) { + if (result.Code() != rapidjson::kParseErrorNone) + { log("JSON parse error: {} ({})", rapidjson::GetParseError_En(result.Code()), result.Offset()); return ret; diff --git a/src/common/NetworkTimer.cpp b/src/common/NetworkTimer.cpp index 858378b17..d8112571f 100644 --- a/src/common/NetworkTimer.cpp +++ b/src/common/NetworkTimer.cpp @@ -10,7 +10,8 @@ namespace chatterino { void NetworkTimer::start() { - if (this->timeoutMS_ <= 0) { + if (this->timeoutMS_ <= 0) + { return; } diff --git a/src/common/SignalVector.hpp b/src/common/SignalVector.hpp index 1ddf2c13a..262718d0f 100644 --- a/src/common/SignalVector.hpp +++ b/src/common/SignalVector.hpp @@ -45,7 +45,8 @@ public: { assertInGuiThread(); - if (!this->itemsChangedTimer_.isActive()) { + if (!this->itemsChangedTimer_.isActive()) + { this->itemsChangedTimer_.start(); } } @@ -92,9 +93,12 @@ public: void *caller = nullptr) override { assertInGuiThread(); - if (index == -1) { + if (index == -1) + { index = this->vector_.size(); - } else { + } + else + { assert(index >= 0 && index <= this->vector_.size()); } diff --git a/src/common/SignalVectorModel.hpp b/src/common/SignalVectorModel.hpp index 4a56913b4..187356dea 100644 --- a/src/common/SignalVectorModel.hpp +++ b/src/common/SignalVectorModel.hpp @@ -19,7 +19,8 @@ public: : QAbstractTableModel(parent) , columnCount_(columnCount) { - for (int i = 0; i < columnCount; i++) { + for (int i = 0; i < columnCount; i++) + { this->headerData_.emplace_back(); } } @@ -29,7 +30,8 @@ public: this->vector_ = vec; auto insert = [this](const SignalVectorItemArgs &args) { - if (args.caller == this) { + if (args.caller == this) + { return; } // get row index @@ -50,7 +52,8 @@ public: }; int i = 0; - for (const TVectorItem &item : vec->getVector()) { + for (const TVectorItem &item : vec->getVector()) + { SignalVectorItemArgs args{item, i++, 0}; insert(args); @@ -59,7 +62,8 @@ public: this->managedConnect(vec->itemInserted, insert); this->managedConnect(vec->itemRemoved, [this](auto args) { - if (args.caller == this) { + if (args.caller == this) + { return; } @@ -76,7 +80,8 @@ public: this->afterRemoved(args.item, items, row); - for (QStandardItem *item : items) { + for (QStandardItem *item : items) + { delete item; } }); @@ -86,8 +91,10 @@ public: virtual ~SignalVectorModel() { - for (Row &row : this->rows_) { - for (QStandardItem *item : row.items) { + for (Row &row : this->rows_) + { + for (QStandardItem *item : row.items) + { delete item; } } @@ -123,9 +130,12 @@ public: rowItem.items[column]->setData(value, role); - if (rowItem.isCustomRow) { + if (rowItem.isCustomRow) + { this->customRowSetData(rowItem.items, column, value, role, row); - } else { + } + else + { int vecRow = this->getVectorIndexFromModelIndex(row); this->vector_->removeItem(vecRow, this); @@ -141,14 +151,18 @@ public: QVariant headerData(int section, Qt::Orientation orientation, int role) const override { - if (orientation != Qt::Horizontal) { + if (orientation != Qt::Horizontal) + { return QVariant(); } auto it = this->headerData_[section].find(role); - if (it == this->headerData_[section].end()) { + if (it == this->headerData_[section].end()) + { return QVariant(); - } else { + } + else + { return it.value(); } } @@ -157,7 +171,8 @@ public: const QVariant &value, int role = Qt::DisplayRole) override { - if (orientation != Qt::Horizontal) { + if (orientation != Qt::Horizontal) + { return false; } @@ -192,7 +207,8 @@ public: bool removeRows(int row, int count, const QModelIndex &parent) override { - if (count != 1) { + if (count != 1) + { return false; } @@ -258,7 +274,8 @@ protected: std::vector createRow() { std::vector row; - for (int i = 0; i < this->columnCount_; i++) { + for (int i = 0; i < this->columnCount_; i++) + { row.push_back(new QStandardItem()); } return row; @@ -296,13 +313,16 @@ private: { int i = 0; - for (auto &row : this->rows_) { - if (row.isCustomRow) { + for (auto &row : this->rows_) + { + if (row.isCustomRow) + { index--; continue; } - if (i == index) { + if (i == index) + { return i; } i++; @@ -316,12 +336,15 @@ private: { int i = 0; - for (auto &row : this->rows_) { - if (row.isCustomRow) { + for (auto &row : this->rows_) + { + if (row.isCustomRow) + { index++; } - if (i == index) { + if (i == index) + { return i; } i++; diff --git a/src/common/UniqueAccess.hpp b/src/common/UniqueAccess.hpp index 30d6bee32..1b9685c2e 100644 --- a/src/common/UniqueAccess.hpp +++ b/src/common/UniqueAccess.hpp @@ -32,7 +32,8 @@ public: ~AccessGuard() { - if (this->isValid_) this->mutex_->unlock(); + if (this->isValid_) + this->mutex_->unlock(); } T *operator->() const diff --git a/src/common/UsernameSet.cpp b/src/common/UsernameSet.cpp index 064b6cf54..8e0a53af7 100644 --- a/src/common/UsernameSet.cpp +++ b/src/common/UsernameSet.cpp @@ -21,11 +21,13 @@ UsernameSet::ConstIterator UsernameSet::end() const UsernameSet::Range UsernameSet::subrange(const Prefix &prefix) const { auto it = this->firstKeyForPrefix.find(prefix); - if (it != this->firstKeyForPrefix.end()) { + if (it != this->firstKeyForPrefix.end()) + { auto start = this->items.find(it->second); auto end = start; - while (end != this->items.end() && prefix.isStartOf(*end)) { + while (end != this->items.end() && prefix.isStartOf(*end)) + { end++; } return {start, end}; @@ -57,7 +59,8 @@ void UsernameSet::insertPrefix(const QString &value) { auto &string = this->firstKeyForPrefix[Prefix(value)]; - if (string.isNull() || value < string) string = value; + if (string.isNull() || value < string) + string = value; } // @@ -98,12 +101,17 @@ bool Prefix::operator==(const Prefix &other) const bool Prefix::isStartOf(const QString &string) const { - if (string.size() == 0) { + if (string.size() == 0) + { return this->first == QChar('\0') && this->second == QChar('\0'); - } else if (string.size() == 1) { + } + else if (string.size() == 1) + { return this->first == string[0].toLower() && this->second == QChar('\0'); - } else { + } + else + { return this->first == string[0].toLower() && this->second == string[1].toLower(); } diff --git a/src/controllers/accounts/Account.cpp b/src/controllers/accounts/Account.cpp index 234723946..63761aff2 100644 --- a/src/controllers/accounts/Account.cpp +++ b/src/controllers/accounts/Account.cpp @@ -10,7 +10,8 @@ Account::Account(ProviderId providerId) static QString twitch("Twitch"); this->category_ = [&]() { - switch (providerId) { + switch (providerId) + { case ProviderId::Twitch: return twitch; } diff --git a/src/controllers/accounts/AccountController.cpp b/src/controllers/accounts/AccountController.cpp index 7d2c84266..468f7433e 100644 --- a/src/controllers/accounts/AccountController.cpp +++ b/src/controllers/accounts/AccountController.cpp @@ -14,7 +14,8 @@ AccountController::AccountController() }); this->twitch.accounts.itemRemoved.connect([this](const auto &args) { - if (args.caller != this) { + if (args.caller != this) + { auto &accs = this->twitch.accounts.getVector(); auto it = std::find(accs.begin(), accs.end(), args.item); assert(it != accs.end()); @@ -24,14 +25,17 @@ AccountController::AccountController() }); this->accounts_.itemRemoved.connect([this](const auto &args) { - switch (args.item->getProviderId()) { - case ProviderId::Twitch: { + switch (args.item->getProviderId()) + { + case ProviderId::Twitch: + { auto &accs = this->twitch.accounts.getVector(); auto it = std::find(accs.begin(), accs.end(), args.item); assert(it != accs.end()); this->twitch.accounts.removeItem(it - accs.begin(), this); - } break; + } + break; } }); } diff --git a/src/controllers/accounts/AccountModel.cpp b/src/controllers/accounts/AccountModel.cpp index 23ded2881..6e1d2a5df 100644 --- a/src/controllers/accounts/AccountModel.cpp +++ b/src/controllers/accounts/AccountModel.cpp @@ -29,7 +29,8 @@ int AccountModel::beforeInsert(const std::shared_ptr &item, std::vector &row, int proposedIndex) { - if (this->categoryCount_[item->getCategory()]++ == 0) { + if (this->categoryCount_[item->getCategory()]++ == 0) + { auto row = this->createRow(); setStringItem(row[0], item->getCategory(), false, false); @@ -49,10 +50,13 @@ void AccountModel::afterRemoved(const std::shared_ptr &item, auto it = this->categoryCount_.find(item->getCategory()); assert(it != this->categoryCount_.end()); - if (it->second <= 1) { + if (it->second <= 1) + { this->categoryCount_.erase(it); this->removeCustomRow(index - 1); - } else { + } + else + { it->second--; } } diff --git a/src/controllers/commands/Command.cpp b/src/controllers/commands/Command.cpp index e76b16f18..113ed2a86 100644 --- a/src/controllers/commands/Command.cpp +++ b/src/controllers/commands/Command.cpp @@ -7,7 +7,8 @@ Command::Command(const QString &_text) { int index = _text.indexOf(' '); - if (index == -1) { + if (index == -1) + { this->name = _text; return; } diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index f931aa073..3c13d5c94 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -37,8 +37,10 @@ CommandController::CommandController() auto addFirstMatchToMap = [this](auto args) { this->commandsMap_.remove(args.item.name); - for (const Command &cmd : this->items.getVector()) { - if (cmd.name == args.item.name) { + for (const Command &cmd : this->items.getVector()) + { + if (cmd.name == args.item.name) + { this->commandsMap_[cmd.name] = cmd; break; } @@ -59,15 +61,18 @@ void CommandController::load(Paths &paths) this->filePath_ = combinePath(paths.settingsDirectory, "commands.txt"); QFile textFile(this->filePath_); - if (!textFile.open(QIODevice::ReadOnly)) { + if (!textFile.open(QIODevice::ReadOnly)) + { // No commands file created yet return; } QList test = textFile.readAll().split('\n'); - for (const auto &command : test) { - if (command.isEmpty()) { + for (const auto &command : test) + { + if (command.isEmpty()) + { continue; } @@ -80,13 +85,15 @@ void CommandController::load(Paths &paths) void CommandController::save() { QFile textFile(this->filePath_); - if (!textFile.open(QIODevice::WriteOnly)) { + if (!textFile.open(QIODevice::WriteOnly)) + { log("[CommandController::saveCommands] Unable to open {} for writing", this->filePath_); return; } - for (const Command &cmd : this->items.getVector()) { + for (const Command &cmd : this->items.getVector()) + { textFile.write((cmd.toString() + "\n").toUtf8()); } @@ -110,16 +117,20 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, { std::lock_guard lock(this->mutex_); - if (words.length() == 0) { + if (words.length() == 0) + { return text; } QString commandName = words[0]; // works in a valid twitch channel and /whispers, etc... - if (!dryRun && channel->isTwitchChannel()) { - if (commandName == "/w") { - if (words.length() <= 2) { + if (!dryRun && channel->isTwitchChannel()) + { + if (commandName == "/w") + { + if (words.length() <= 2) + { return ""; } @@ -139,7 +150,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, QString rest = ""; - for (int i = 2; i < words.length(); i++) { + for (int i = 2; i < words.length(); i++) + { rest += words[i] + " "; } @@ -151,7 +163,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, app->twitch.server->sendMessage("jtv", text); - if (getSettings()->inlineWhispers) { + if (getSettings()->inlineWhispers) + { app->twitch.server->forEachChannel( [&messagexD](ChannelPtr _channel) { _channel->addMessage(messagexD); @@ -166,14 +179,18 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, auto *twitchChannel = dynamic_cast(channel.get()); // works only in a valid twitch channel - if (!dryRun && twitchChannel != nullptr) { - if (commandName == "/debug-args") { + if (!dryRun && twitchChannel != nullptr) + { + if (commandName == "/debug-args") + { QString msg = QApplication::instance()->arguments().join(' '); channel->addMessage(makeSystemMessage(msg)); return ""; - } else if (commandName == "/uptime") { + } + else if (commandName == "/uptime") + { const auto &streamStatus = twitchChannel->accessStreamStatus(); QString messageText = streamStatus->live @@ -183,8 +200,11 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, channel->addMessage(makeSystemMessage(messageText)); return ""; - } else if (commandName == "/ignore") { - if (words.size() < 2) { + } + else if (commandName == "/ignore") + { + if (words.size() < 2) + { channel->addMessage( makeSystemMessage("Usage: /ignore [user]")); return ""; @@ -194,7 +214,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, auto user = app->accounts->twitch.getCurrent(); auto target = words.at(1); - if (user->isAnon()) { + if (user->isAnon()) + { channel->addMessage(makeSystemMessage( "You must be logged in to ignore someone")); return ""; @@ -206,8 +227,11 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, }); return ""; - } else if (commandName == "/unignore") { - if (words.size() < 2) { + } + else if (commandName == "/unignore") + { + if (words.size() < 2) + { channel->addMessage( makeSystemMessage("Usage: /unignore [user]")); return ""; @@ -217,7 +241,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, auto user = app->accounts->twitch.getCurrent(); auto target = words.at(1); - if (user->isAnon()) { + if (user->isAnon()) + { channel->addMessage(makeSystemMessage( "You must be logged in to ignore someone")); return ""; @@ -229,8 +254,11 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, }); return ""; - } else if (commandName == "/follow") { - if (words.size() < 2) { + } + else if (commandName == "/follow") + { + if (words.size() < 2) + { channel->addMessage( makeSystemMessage("Usage: /follow [user]")); return ""; @@ -240,7 +268,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, auto user = app->accounts->twitch.getCurrent(); auto target = words.at(1); - if (user->isAnon()) { + if (user->isAnon()) + { channel->addMessage(makeSystemMessage( "You must be logged in to follow someone")); return ""; @@ -248,7 +277,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, TwitchApi::findUserId( target, [user, channel, target](QString userId) { - if (userId.isEmpty()) { + if (userId.isEmpty()) + { channel->addMessage(makeSystemMessage( "User " + target + " could not be followed!")); return; @@ -260,8 +290,11 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, }); return ""; - } else if (commandName == "/unfollow") { - if (words.size() < 2) { + } + else if (commandName == "/unfollow") + { + if (words.size() < 2) + { channel->addMessage( makeSystemMessage("Usage: /unfollow [user]")); return ""; @@ -271,7 +304,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, auto user = app->accounts->twitch.getCurrent(); auto target = words.at(1); - if (user->isAnon()) { + if (user->isAnon()) + { channel->addMessage(makeSystemMessage( "You must be logged in to follow someone")); return ""; @@ -279,7 +313,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, TwitchApi::findUserId( target, [user, channel, target](QString userId) { - if (userId.isEmpty()) { + if (userId.isEmpty()) + { channel->addMessage(makeSystemMessage( "User " + target + " could not be followed!")); return; @@ -291,8 +326,11 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, }); return ""; - } else if (commandName == "/logs") { - if (words.size() < 2) { + } + else if (commandName == "/logs") + { + if (words.size() < 2) + { channel->addMessage( makeSystemMessage("Usage: /logs [user] (channel)")); return ""; @@ -302,24 +340,34 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, auto logs = new LogsPopup(); QString target; - if (words.at(1).at(0) == "@") { + if (words.at(1).at(0) == "@") + { target = words.at(1).mid(1); - } else { + } + else + { target = words.at(1); } - if (words.size() == 3) { + if (words.size() == 3) + { QString channelName = words.at(2); - if (words.at(2).at(0) == "#") { + if (words.at(2).at(0) == "#") + { channelName = words.at(2).mid(1); } auto logsChannel = app->twitch.server->getChannelOrEmpty(channelName); - if (logsChannel == nullptr) { - } else { + if (logsChannel == nullptr) + { + } + else + { logs->setInfo(logsChannel, target); } - } else { + } + else + { logs->setInfo(channel, target); } logs->setAttribute(Qt::WA_DeleteOnClose); @@ -330,7 +378,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, // check if custom command exists auto it = this->commandsMap_.find(commandName); - if (it == this->commandsMap_.end()) { + if (it == this->commandsMap_.end()) + { return text; } @@ -352,11 +401,13 @@ QString CommandController::execCustomCommand(const QStringList &words, auto globalMatch = parseCommand.globalMatch(command.func); int matchOffset = 0; - while (true) { + while (true) + { QRegularExpressionMatch match = parseCommand.match(command.func, matchOffset); - if (!match.hasMatch()) { + if (!match.hasMatch()) + { break; } @@ -373,32 +424,40 @@ QString CommandController::execCustomCommand(const QStringList &words, bool ok; int wordIndex = wordIndexMatch.replace("=", "").toInt(&ok); - if (!ok || wordIndex == 0) { + if (!ok || wordIndex == 0) + { result += "{" + match.captured(3) + "}"; continue; } - if (words.length() <= wordIndex) { + if (words.length() <= wordIndex) + { continue; } - if (plus) { + if (plus) + { bool first = true; - for (int i = wordIndex; i < words.length(); i++) { - if (!first) { + for (int i = wordIndex; i < words.length(); i++) + { + if (!first) + { result += " "; } result += words[i]; first = false; } - } else { + } + else + { result += words[wordIndex]; } } result += command.func.mid(lastCaptureEnd); - if (result.size() > 0 && result.at(0) == '{') { + if (result.size() > 0 && result.at(0) == '{') + { result = result.mid(1); } diff --git a/src/controllers/highlights/HighlightBlacklistUser.hpp b/src/controllers/highlights/HighlightBlacklistUser.hpp index b2e3e4a06..0e97b719f 100644 --- a/src/controllers/highlights/HighlightBlacklistUser.hpp +++ b/src/controllers/highlights/HighlightBlacklistUser.hpp @@ -46,8 +46,10 @@ public: bool isMatch(const QString &subject) const { - if (this->isRegex()) { - if (this->isValidRegex()) { + if (this->isRegex()) + { + if (this->isValidRegex()) + { return this->regex_.match(subject).hasMatch(); } @@ -91,7 +93,8 @@ namespace Settings { QString pattern; bool isRegex = false; - if (!value.IsObject()) { + if (!value.IsObject()) + { return chatterino::HighlightBlacklistUser(pattern, isRegex); } diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index bd78b65ac..436f1b6b5 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -17,7 +17,8 @@ void HighlightController::initialize(Settings &settings, Paths &paths) assert(!this->initialized_); this->initialized_ = true; - for (const HighlightPhrase &phrase : this->highlightsSetting_.getValue()) { + for (const HighlightPhrase &phrase : this->highlightsSetting_.getValue()) + { this->phrases.appendItem(phrase); } @@ -26,7 +27,8 @@ void HighlightController::initialize(Settings &settings, Paths &paths) }); for (const HighlightBlacklistUser &blacklistedUser : - this->blacklistSetting_.getValue()) { + this->blacklistSetting_.getValue()) + { this->blacklistedUsers.appendItem(blacklistedUser); } @@ -54,8 +56,10 @@ UserHighlightModel *HighlightController::createUserModel(QObject *parent) bool HighlightController::isHighlightedUser(const QString &username) { const auto &userItems = this->highlightedUsers.getVector(); - for (const auto &highlightedUser : userItems) { - if (highlightedUser.isMatch(username)) { + for (const auto &highlightedUser : userItems) + { + if (highlightedUser.isMatch(username)) + { return true; } } @@ -76,8 +80,10 @@ bool HighlightController::blacklistContains(const QString &username) { std::vector blacklistItems = this->blacklistedUsers.getVector(); - for (const auto &blacklistedUser : blacklistItems) { - if (blacklistedUser.isMatch(username)) { + for (const auto &blacklistedUser : blacklistItems) + { + if (blacklistedUser.isMatch(username)) + { return true; } } diff --git a/src/controllers/highlights/HighlightModel.cpp b/src/controllers/highlights/HighlightModel.cpp index 0ba232b37..676369169 100644 --- a/src/controllers/highlights/HighlightModel.cpp +++ b/src/controllers/highlights/HighlightModel.cpp @@ -66,42 +66,63 @@ void HighlightModel::customRowSetData(const std::vector &row, int column, const QVariant &value, int role, int rowIndex) { - switch (column) { - case 0: { - if (role == Qt::CheckStateRole) { - if (rowIndex == 0) { + switch (column) + { + case 0: + { + if (role == Qt::CheckStateRole) + { + if (rowIndex == 0) + { getSettings()->enableSelfHighlight.setValue(value.toBool()); - } else if (rowIndex == 1) { + } + else if (rowIndex == 1) + { getSettings()->enableWhisperHighlight.setValue( value.toBool()); } } - } break; - case 1: { - if (role == Qt::CheckStateRole) { - if (rowIndex == 0) { + } + break; + case 1: + { + if (role == Qt::CheckStateRole) + { + if (rowIndex == 0) + { getSettings()->enableSelfHighlightTaskbar.setValue( value.toBool()); - } else if (rowIndex == 1) { + } + else if (rowIndex == 1) + { getSettings()->enableWhisperHighlightTaskbar.setValue( value.toBool()); } } - } break; - case 2: { - if (role == Qt::CheckStateRole) { - if (rowIndex == 0) { + } + break; + case 2: + { + if (role == Qt::CheckStateRole) + { + if (rowIndex == 0) + { getSettings()->enableSelfHighlightSound.setValue( value.toBool()); - } else if (rowIndex == 1) { + } + else if (rowIndex == 1) + { getSettings()->enableWhisperHighlightSound.setValue( value.toBool()); } } - } break; - case 3: { + } + break; + case 3: + { // empty element - } break; + } + break; } } diff --git a/src/controllers/highlights/HighlightPhrase.hpp b/src/controllers/highlights/HighlightPhrase.hpp index cfbee6588..d5fc5b884 100644 --- a/src/controllers/highlights/HighlightPhrase.hpp +++ b/src/controllers/highlights/HighlightPhrase.hpp @@ -92,7 +92,8 @@ namespace Settings { struct Deserialize { static chatterino::HighlightPhrase get(const rapidjson::Value &value) { - if (!value.IsObject()) { + if (!value.IsObject()) + { return chatterino::HighlightPhrase(QString(), true, false, false); } diff --git a/src/controllers/ignores/IgnoreController.cpp b/src/controllers/ignores/IgnoreController.cpp index 819779eff..5548ee5d4 100644 --- a/src/controllers/ignores/IgnoreController.cpp +++ b/src/controllers/ignores/IgnoreController.cpp @@ -12,7 +12,8 @@ void IgnoreController::initialize(Settings &, Paths &) assert(!this->initialized_); this->initialized_ = true; - for (const IgnorePhrase &phrase : this->ignoresSetting_.getValue()) { + for (const IgnorePhrase &phrase : this->ignoresSetting_.getValue()) + { this->phrases.appendItem(phrase); } diff --git a/src/controllers/ignores/IgnorePhrase.hpp b/src/controllers/ignores/IgnorePhrase.hpp index 7ec644383..10a943b89 100644 --- a/src/controllers/ignores/IgnorePhrase.hpp +++ b/src/controllers/ignores/IgnorePhrase.hpp @@ -35,10 +35,13 @@ public: , replace_(replace) , isCaseSensitive_(isCaseSensitive) { - if (this->isCaseSensitive_) { + if (this->isCaseSensitive_) + { regex_.setPatternOptions( QRegularExpression::UseUnicodePropertiesOption); - } else { + } + else + { regex_.setPatternOptions( QRegularExpression::CaseInsensitiveOption | QRegularExpression::UseUnicodePropertiesOption); @@ -101,14 +104,18 @@ public: bool containsEmote() const { - if (!this->emotesChecked_) { + if (!this->emotesChecked_) + { const auto &accvec = getApp()->accounts->twitch.accounts.getVector(); - for (const auto &acc : accvec) { + for (const auto &acc : accvec) + { const auto &accemotes = *acc->accessEmotes(); - for (const auto &emote : accemotes.emotes) { + for (const auto &emote : accemotes.emotes) + { if (this->replace_.contains(emote.first.string, - Qt::CaseSensitive)) { + Qt::CaseSensitive)) + { this->emotes_.emplace(emote.first, emote.second); } } @@ -154,7 +161,8 @@ namespace Settings { struct Deserialize { static chatterino::IgnorePhrase get(const rapidjson::Value &value) { - if (!value.IsObject()) { + if (!value.IsObject()) + { return chatterino::IgnorePhrase( QString(), false, false, ::chatterino::getSettings() diff --git a/src/controllers/moderationactions/ModerationAction.cpp b/src/controllers/moderationactions/ModerationAction.cpp index cc2b8463e..0b6418a57 100644 --- a/src/controllers/moderationactions/ModerationAction.cpp +++ b/src/controllers/moderationactions/ModerationAction.cpp @@ -33,23 +33,31 @@ ModerationAction::ModerationAction(const QString &action) auto timeoutMatch = timeoutRegex.match(action); - if (timeoutMatch.hasMatch()) { + if (timeoutMatch.hasMatch()) + { // if (multipleTimeouts > 1) { // QString line1; // QString line2; int amount = timeoutMatch.captured(1).toInt(); - if (amount < 60) { + if (amount < 60) + { this->line1_ = QString::number(amount); this->line2_ = "s"; - } else if (amount < 60 * 60) { + } + else if (amount < 60 * 60) + { this->line1_ = QString::number(amount / 60); this->line2_ = "m"; - } else if (amount < 60 * 60 * 24) { + } + else if (amount < 60 * 60 * 24) + { this->line1_ = QString::number(amount / 60 / 60); this->line2_ = "h"; - } else { + } + else + { this->line1_ = QString::number(amount / 60 / 60 / 24); this->line2_ = "d"; } @@ -60,9 +68,13 @@ ModerationAction::ModerationAction(const QString &action) // this->_moderationActions.emplace_back(app->resources->buttonTimeout, // str); // } - } else if (action.startsWith("/ban ")) { + } + else if (action.startsWith("/ban ")) + { this->image_ = Image::fromPixmap(getApp()->resources->buttons.ban); - } else { + } + else + { QString xD = action; xD.replace(replaceRegex, ""); diff --git a/src/controllers/moderationactions/ModerationAction.hpp b/src/controllers/moderationactions/ModerationAction.hpp index 8dbdba93f..6b1399c1b 100644 --- a/src/controllers/moderationactions/ModerationAction.hpp +++ b/src/controllers/moderationactions/ModerationAction.hpp @@ -53,7 +53,8 @@ namespace Settings { struct Deserialize { static chatterino::ModerationAction get(const rapidjson::Value &value) { - if (!value.IsObject()) { + if (!value.IsObject()) + { return chatterino::ModerationAction(QString()); } diff --git a/src/controllers/moderationactions/ModerationActions.cpp b/src/controllers/moderationactions/ModerationActions.cpp index 27cd5de30..bcefacdef 100644 --- a/src/controllers/moderationactions/ModerationActions.cpp +++ b/src/controllers/moderationactions/ModerationActions.cpp @@ -21,7 +21,8 @@ void ModerationActions::initialize(Settings &settings, Paths &paths) std::make_unique>>( "/moderation/actions"); - for (auto &val : this->setting_->getValue()) { + for (auto &val : this->setting_->getValue()) + { this->items.insertItem(val); } diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index 277e5ac6c..395de1974 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -25,7 +25,8 @@ namespace chatterino { void NotificationController::initialize(Settings &settings, Paths &paths) { this->initialized_ = true; - for (const QString &channelName : this->twitchSetting_.getValue()) { + for (const QString &channelName : this->twitchSetting_.getValue()) + { this->channelMap[Platform::Twitch].appendItem(channelName); } @@ -55,9 +56,12 @@ void NotificationController::initialize(Settings &settings, Paths &paths) void NotificationController::updateChannelNotification( const QString &channelName, Platform p) { - if (isChannelNotified(channelName, p)) { + if (isChannelNotified(channelName, p)) + { removeChannelNotification(channelName, p); - } else { + } + else + { addChannelNotification(channelName, p); } } @@ -65,8 +69,10 @@ void NotificationController::updateChannelNotification( bool NotificationController::isChannelNotified(const QString &channelName, Platform p) { - for (const auto &channel : this->channelMap[p].getVector()) { - if (channelName.toLower() == channel.toLower()) { + for (const auto &channel : this->channelMap[p].getVector()) + { + if (channelName.toLower() == channel.toLower()) + { return true; } } @@ -83,8 +89,10 @@ void NotificationController::removeChannelNotification( const QString &channelName, Platform p) { for (std::vector::size_type i = 0; - i != channelMap[p].getVector().size(); i++) { - if (channelMap[p].getVector()[i].toLower() == channelName.toLower()) { + i != channelMap[p].getVector().size(); i++) + { + if (channelMap[p].getVector()[i].toLower() == channelName.toLower()) + { channelMap[p].removeItem(i); i--; } @@ -96,13 +104,17 @@ void NotificationController::playSound() static QUrl currentPlayerUrl; QUrl highlightSoundUrl; - if (getSettings()->notificationCustomSound) { + if (getSettings()->notificationCustomSound) + { highlightSoundUrl = QUrl::fromLocalFile( getSettings()->notificationPathSound.getValue()); - } else { + } + else + { highlightSoundUrl = QUrl("qrc:/sounds/ping2.wav"); } - if (currentPlayerUrl != highlightSoundUrl) { + if (currentPlayerUrl != highlightSoundUrl) + { player->setMedia(highlightSoundUrl); currentPlayerUrl = highlightSoundUrl; @@ -121,10 +133,12 @@ NotificationModel *NotificationController::createModel(QObject *parent, void NotificationController::fetchFakeChannels() { for (std::vector::size_type i = 0; - i != channelMap[Platform::Twitch].getVector().size(); i++) { + i != channelMap[Platform::Twitch].getVector().size(); i++) + { auto chan = getApp()->twitch.server->getChannelOrEmpty( channelMap[Platform::Twitch].getVector()[i]); - if (chan->isEmpty()) { + if (chan->isEmpty()) + { getFakeTwitchChannelLiveStatus( channelMap[Platform::Twitch].getVector()[i]); } @@ -135,7 +149,8 @@ void NotificationController::getFakeTwitchChannelLiveStatus( const QString &channelName) { TwitchApi::findUserId(channelName, [channelName, this](QString roomID) { - if (roomID.isEmpty()) { + if (roomID.isEmpty()) + { log("[TwitchChannel:{}] Refreshing live status (Missing ID)", channelName); removeFakeChannel(channelName); @@ -149,19 +164,22 @@ void NotificationController::getFakeTwitchChannelLiveStatus( request.onSuccess([this, channelName](auto result) -> Outcome { rapidjson::Document document = result.parseRapidJson(); - if (!document.IsObject()) { + if (!document.IsObject()) + { log("[TwitchChannel:refreshLiveStatus]root is not an object"); return Failure; } - if (!document.HasMember("stream")) { + if (!document.HasMember("stream")) + { log("[TwitchChannel:refreshLiveStatus] Missing stream in root"); return Failure; } const auto &stream = document["stream"]; - if (!stream.IsObject()) { + if (!stream.IsObject()) + { // Stream is offline (stream is most likely null) // removeFakeChannel(channelName); return Failure; @@ -170,16 +188,20 @@ void NotificationController::getFakeTwitchChannelLiveStatus( auto i = std::find(fakeTwitchChannels.begin(), fakeTwitchChannels.end(), channelName); - if (!(i != fakeTwitchChannels.end())) { + if (!(i != fakeTwitchChannels.end())) + { fakeTwitchChannels.push_back(channelName); - if (Toasts::isEnabled()) { + if (Toasts::isEnabled()) + { getApp()->toasts->sendChannelNotification(channelName, Platform::Twitch); } - if (getSettings()->notificationPlaySound) { + if (getSettings()->notificationPlaySound) + { getApp()->notifications->playSound(); } - if (getSettings()->notificationFlashTaskbar) { + if (getSettings()->notificationFlashTaskbar) + { getApp()->windows->sendAlert(); } } @@ -194,7 +216,8 @@ void NotificationController::removeFakeChannel(const QString channelName) { auto i = std::find(fakeTwitchChannels.begin(), fakeTwitchChannels.end(), channelName); - if (i != fakeTwitchChannels.end()) { + if (i != fakeTwitchChannels.end()) + { fakeTwitchChannels.erase(i); } } diff --git a/src/main.cpp b/src/main.cpp index 0bff94e0c..52049b0c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,9 +20,12 @@ int main(int argc, char **argv) [&](auto s) { return s; }); // run in gui mode or browser extension host mode - if (shouldRunBrowserExtensionHost(args)) { + if (shouldRunBrowserExtensionHost(args)) + { runBrowserExtensionHost(); - } else { + } + else + { Paths paths; Settings settings(paths); diff --git a/src/messages/Emote.cpp b/src/messages/Emote.cpp index 318e2d300..7c0f5e821 100644 --- a/src/messages/Emote.cpp +++ b/src/messages/Emote.cpp @@ -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(std::move(emote)); } @@ -32,10 +33,13 @@ EmotePtr cachedOrMakeEmotePtr( std::lock_guard 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(std::move(emote)); cache[id] = shared; return shared; diff --git a/src/messages/Image.cpp b/src/messages/Image.cpp index 567765005..70693b3c1 100644 --- a/src/messages/Image.cpp +++ b/src/messages/Image.cpp @@ -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 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 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> 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 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 Image::pixmap() const { assertInGuiThread(); - if (this->shouldLoad_) { + if (this->shouldLoad_) + { const_cast(this)->shouldLoad_ = false; const_cast(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; } diff --git a/src/messages/ImageSet.cpp b/src/messages/ImageSet.cpp index b952e8ee3..3925dc1e7 100644 --- a/src/messages/ImageSet.cpp +++ b/src/messages/ImageSet.cpp @@ -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_; } diff --git a/src/messages/LimitedQueue.hpp b/src/messages/LimitedQueue.hpp index c52d4a35c..3142d8eca 100644 --- a/src/messages/LimitedQueue.hpp +++ b/src/messages/LimitedQueue.hpp @@ -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>>>(); // copy chunks - for (Chunk &chunk : *this->chunks_) { + for (Chunk &chunk : *this->chunks_) + { newVector->push_back(chunk); } @@ -91,7 +93,8 @@ public: { std::vector acceptedItems; - if (this->space() > 0) { + if (this->space() > 0) + { std::lock_guard 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(items.size())); + size_t offset = + std::min(this->space(), static_cast(items.size())); Chunk newFirstChunk = std::make_shared>(); 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>(); 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>(); 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>>>(); // 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; diff --git a/src/messages/LimitedQueueSnapshot.hpp b/src/messages/LimitedQueueSnapshot.hpp index ce78dad94..6a5905c1e 100644 --- a/src/messages/LimitedQueueSnapshot.hpp +++ b/src/messages/LimitedQueueSnapshot.hpp @@ -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(); diff --git a/src/messages/Message.cpp b/src/messages/Message.cpp index 8fa860353..ac7f63eae 100644 --- a/src/messages/Message.cpp +++ b/src/messages/Message.cpp @@ -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(); diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index ec4917b6c..23d7c727b 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -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://"); } diff --git a/src/messages/MessageColor.cpp b/src/messages/MessageColor.cpp index fe793b30e..bd784197a 100644 --- a/src/messages/MessageColor.cpp +++ b/src/messages/MessageColor.cpp @@ -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: diff --git a/src/messages/MessageElement.cpp b/src/messages/MessageElement.cpp index 4412f9de4..fc2f3c54e 100644 --- a/src/messages/MessageElement.cpp +++ b/src/messages/MessageElement.cpp @@ -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(), diff --git a/src/messages/Selection.hpp b/src/messages/Selection.hpp index 435ce6f26..c1ada456a 100644 --- a/src/messages/Selection.hpp +++ b/src/messages/Selection.hpp @@ -59,7 +59,8 @@ struct Selection { , selectionMin(start) , selectionMax(end) { - if (selectionMin > selectionMax) { + if (selectionMin > selectionMax) + { std::swap(this->selectionMin, this->selectionMax); } } diff --git a/src/messages/layouts/MessageLayout.cpp b/src/messages/layouts/MessageLayout.cpp index 4e7343136..ed79a93c4 100644 --- a/src/messages/layouts/MessageLayout.cpp +++ b/src/messages/layouts/MessageLayout.cpp @@ -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; diff --git a/src/messages/layouts/MessageLayoutContainer.cpp b/src/messages/layouts/MessageLayoutContainer.cpp index e4e80f0d9..4652cd654 100644 --- a/src/messages/layouts/MessageLayoutContainer.cpp +++ b/src/messages/layouts/MessageLayoutContainer.cpp @@ -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 &element : this->elements_) { - if (element->getRect().contains(point)) { + for (std::unique_ptr &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 &element : - this->elements_) { + for (const std::unique_ptr &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 &element : - this->elements_) { + for (const std::unique_ptr &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); } } diff --git a/src/messages/layouts/MessageLayoutElement.cpp b/src/messages/layouts/MessageLayoutElement.cpp index b9324aee0..570324fd8 100644 --- a/src/messages/layouts/MessageLayoutElement.cpp +++ b/src/messages/layouts/MessageLayoutElement.cpp @@ -96,9 +96,11 @@ void ImageLayoutElement::addCopyTextToString(QString &str, int from, { const auto *emoteElement = dynamic_cast(&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(); } } diff --git a/src/providers/LinkResolver.cpp b/src/providers/LinkResolver.cpp index 6697e6872..069dba691 100644 --- a/src/providers/LinkResolver.cpp +++ b/src/providers/LinkResolver.cpp @@ -23,12 +23,16 @@ void LinkResolver::getLinkInfo( auto statusCode = root.value("status").toInt(); QString response = QString(); QString linkString = url; - if (statusCode == 200) { + if (statusCode == 200) + { response = root.value("tooltip").toString(); - if (getSettings()->enableUnshortLinks) { + if (getSettings()->enableUnshortLinks) + { linkString = root.value("link").toString(); } - } else { + } + else + { response = root.value("message").toString(); } successCallback(QUrl::fromPercentEncoding(response.toUtf8()), diff --git a/src/providers/LinkResolver.hpp b/src/providers/LinkResolver.hpp index 919f0c3bf..9905bfed4 100644 --- a/src/providers/LinkResolver.hpp +++ b/src/providers/LinkResolver.hpp @@ -11,7 +11,7 @@ class LinkResolver { public: static void getLinkInfo(const QString url, - std::function callback); + std::function callback); private: }; diff --git a/src/providers/bttv/BttvEmotes.cpp b/src/providers/bttv/BttvEmotes.cpp index 2efe00d64..ae279412e 100644 --- a/src/providers/bttv/BttvEmotes.cpp +++ b/src/providers/bttv/BttvEmotes.cpp @@ -29,7 +29,8 @@ namespace { auto urlTemplate = qS("https:") + jsonRoot.value("urlTemplate").toString(); - for (auto jsonEmote : jsonEmotes) { + for (auto jsonEmote : jsonEmotes) + { auto id = EmoteId{jsonEmote.toObject().value("id").toString()}; auto name = EmoteName{jsonEmote.toObject().value("code").toString()}; @@ -62,7 +63,8 @@ namespace { auto jsonEmotes = jsonRoot.value("emotes").toArray(); auto urlTemplate = "https:" + jsonRoot.value("urlTemplate").toString(); - for (auto jsonEmote_ : jsonEmotes) { + for (auto jsonEmote_ : jsonEmotes) + { auto jsonEmote = jsonEmote_.toObject(); auto id = EmoteId{jsonEmote.value("id").toString()}; @@ -103,7 +105,8 @@ boost::optional BttvEmotes::emote(const EmoteName &name) const auto emotes = this->global_.get(); auto it = emotes->find(name); - if (it == emotes->end()) return boost::none; + if (it == emotes->end()) + return boost::none; return it->second; } @@ -137,7 +140,8 @@ void BttvEmotes::loadChannel(const QString &channelName, request.onSuccess([callback = std::move(callback)](auto result) -> Outcome { auto pair = parseChannelEmotes(result.parseJson()); - if (pair.first) callback(std::move(pair.second)); + if (pair.first) + callback(std::move(pair.second)); return pair.first; }); diff --git a/src/providers/chatterino/ChatterinoBadges.cpp b/src/providers/chatterino/ChatterinoBadges.cpp index 28bb57f3e..37db25c13 100644 --- a/src/providers/chatterino/ChatterinoBadges.cpp +++ b/src/providers/chatterino/ChatterinoBadges.cpp @@ -25,7 +25,8 @@ ChatterinoBadges::ChatterinoBadges() boost::optional ChatterinoBadges::getBadge(const UserName &username) { auto it = badgeMap.find(username.string); - if (it != badgeMap.end()) { + if (it != badgeMap.end()) + { return emotes[it->second]; } return boost::none; @@ -41,7 +42,8 @@ void ChatterinoBadges::loadChatterinoBadges() req.onSuccess([this](auto result) -> Outcome { auto jsonRoot = result.parseJson(); int index = 0; - for (const auto &jsonBadge_ : jsonRoot.value("badges").toArray()) { + for (const auto &jsonBadge_ : jsonRoot.value("badges").toArray()) + { auto jsonBadge = jsonBadge_.toObject(); auto emote = Emote{ EmoteName{}, ImageSet{Url{jsonBadge.value("image").toString()}}, @@ -49,7 +51,8 @@ void ChatterinoBadges::loadChatterinoBadges() emotes.push_back(std::make_shared(std::move(emote))); - for (const auto &user : jsonBadge.value("users").toArray()) { + for (const auto &user : jsonBadge.value("users").toArray()) + { badgeMap[user.toString()] = index; } ++index; diff --git a/src/providers/emoji/Emojis.cpp b/src/providers/emoji/Emojis.cpp index 25bc4f6c8..a219cceba 100644 --- a/src/providers/emoji/Emojis.cpp +++ b/src/providers/emoji/Emojis.cpp @@ -29,11 +29,15 @@ namespace { bool messenger; } capabilities; - if (!shortCode.isEmpty()) { + if (!shortCode.isEmpty()) + { emojiData->shortCodes.push_back(shortCode); - } else { + } + else + { const auto &shortCodes = unparsedEmoji["short_names"]; - for (const auto &shortCode : shortCodes.GetArray()) { + for (const auto &shortCode : shortCodes.GetArray()) + { emojiData->shortCodes.emplace_back(shortCode.GetString()); } } @@ -49,39 +53,50 @@ namespace { rj::getSafe(unparsedEmoji, "has_img_facebook", capabilities.facebook); rj::getSafe(unparsedEmoji, "has_img_messenger", capabilities.messenger); - if (capabilities.apple) { + if (capabilities.apple) + { emojiData->capabilities.insert("Apple"); } - if (capabilities.google) { + if (capabilities.google) + { emojiData->capabilities.insert("Google"); } - if (capabilities.twitter) { + if (capabilities.twitter) + { emojiData->capabilities.insert("Twitter"); } - if (capabilities.emojione) { + if (capabilities.emojione) + { emojiData->capabilities.insert("EmojiOne 3"); } - if (capabilities.facebook) { + if (capabilities.facebook) + { emojiData->capabilities.insert("Facebook"); } - if (capabilities.messenger) { + if (capabilities.messenger) + { emojiData->capabilities.insert("Messenger"); } QStringList unicodeCharacters; - if (!emojiData->nonQualifiedCode.isEmpty()) { + if (!emojiData->nonQualifiedCode.isEmpty()) + { unicodeCharacters = emojiData->nonQualifiedCode.toLower().split('-'); - } else { + } + else + { unicodeCharacters = emojiData->unifiedCode.toLower().split('-'); } - if (unicodeCharacters.length() < 1) { + if (unicodeCharacters.length() < 1) + { return; } int numUnicodeBytes = 0; - for (const QString &unicodeCharacter : unicodeCharacters) { + for (const QString &unicodeCharacter : unicodeCharacters) + { unicodeBytes[numUnicodeBytes++] = QString(unicodeCharacter).toUInt(nullptr, 16); } @@ -115,17 +130,20 @@ void Emojis::loadEmojis() rapidjson::Document root; rapidjson::ParseResult result = root.Parse(data.toUtf8(), data.length()); - if (result.Code() != rapidjson::kParseErrorNone) { + if (result.Code() != rapidjson::kParseErrorNone) + { log("JSON parse error: {} ({})", rapidjson::GetParseError_En(result.Code()), result.Offset()); return; } - for (const auto &unparsedEmoji : root.GetArray()) { + for (const auto &unparsedEmoji : root.GetArray()) + { auto emojiData = std::make_shared(); parseEmoji(emojiData, unparsedEmoji); - for (const auto &shortCode : emojiData->shortCodes) { + for (const auto &shortCode : emojiData->shortCodes) + { this->emojiShortCodeToEmoji_.insert(shortCode, emojiData); this->shortCodes.emplace_back(shortCode); } @@ -134,16 +152,19 @@ void Emojis::loadEmojis() this->emojis.insert(emojiData->unifiedCode, emojiData); - if (unparsedEmoji.HasMember("skin_variations")) { + if (unparsedEmoji.HasMember("skin_variations")) + { for (const auto &skinVariation : - unparsedEmoji["skin_variations"].GetObject()) { + unparsedEmoji["skin_variations"].GetObject()) + { std::string tone = skinVariation.name.GetString(); const auto &variation = skinVariation.value; auto variationEmojiData = std::make_shared(); auto toneNameIt = toneNames.find(tone); - if (toneNameIt == toneNames.end()) { + if (toneNameIt == toneNames.end()) + { log("Tone with key {} does not exist in tone names map", tone); continue; @@ -172,24 +193,28 @@ void Emojis::loadEmojiOne2Capabilities() file.open(QFile::ReadOnly); QTextStream in(&file); - while (!in.atEnd()) { + while (!in.atEnd()) + { // Line example: sunglasses 1f60e QString line = in.readLine(); - if (line.at(0) == '#') { + if (line.at(0) == '#') + { // Ignore lines starting with # (comments) continue; } QStringList parts = line.split(' '); - if (parts.length() < 2) { + if (parts.length() < 2) + { continue; } QString shortCode = parts[0]; auto emojiIt = this->emojiShortCodeToEmoji_.find(shortCode); - if (emojiIt != this->emojiShortCodeToEmoji_.end()) { + if (emojiIt != this->emojiShortCodeToEmoji_.end()) + { std::shared_ptr emoji = *emojiIt; emoji->capabilities.insert("EmojiOne 2"); continue; @@ -199,7 +224,8 @@ void Emojis::loadEmojiOne2Capabilities() void Emojis::sortEmojis() { - for (auto &p : this->emojiFirstByte_) { + for (auto &p : this->emojiFirstByte_) + { std::stable_sort(p.begin(), p.end(), [](const auto &lhs, const auto &rhs) { return lhs->value.length() > rhs->value.length(); @@ -239,13 +265,16 @@ void Emojis::loadEmojiSet() }; // clang-format on - if (emoji->capabilities.count(emojiSetToUse) == 0) { + if (emoji->capabilities.count(emojiSetToUse) == 0) + { emojiSetToUse = "EmojiOne 3"; } QString code = emoji->unifiedCode; - if (emojiSetToUse == "EmojiOne 2") { - if (!emoji->nonQualifiedCode.isEmpty()) { + if (emojiSetToUse == "EmojiOne 2") + { + if (!emoji->nonQualifiedCode.isEmpty()) + { code = emoji->nonQualifiedCode; } } @@ -253,7 +282,8 @@ void Emojis::loadEmojiSet() QString urlPrefix = "https://cdnjs.cloudflare.com/ajax/libs/" "emojione/2.2.6/assets/png/"; auto it = emojiSets.find(emojiSetToUse); - if (it != emojiSets.end()) { + if (it != emojiSets.end()) + { urlPrefix = it->second; } QString url = urlPrefix + code + ".png"; @@ -270,15 +300,18 @@ std::vector> Emojis::parse( auto result = std::vector>(); int lastParsedEmojiEndIndex = 0; - for (auto i = 0; i < text.length(); ++i) { + for (auto i = 0; i < text.length(); ++i) + { const QChar character = text.at(i); - if (character.isLowSurrogate()) { + if (character.isLowSurrogate()) + { continue; } auto it = this->emojiFirstByte_.find(character); - if (it == this->emojiFirstByte_.end()) { + if (it == this->emojiFirstByte_.end()) + { // No emoji starts with this character continue; } @@ -291,24 +324,29 @@ std::vector> Emojis::parse( int matchedEmojiLength = 0; - for (const std::shared_ptr &emoji : possibleEmojis) { + for (const std::shared_ptr &emoji : possibleEmojis) + { int emojiExtraCharacters = emoji->value.length() - 1; - if (emojiExtraCharacters > remainingCharacters) { + if (emojiExtraCharacters > remainingCharacters) + { // It cannot be this emoji, there's not enough space for it continue; } bool match = true; - for (int j = 1; j < emoji->value.length(); ++j) { - if (text.at(i + j) != emoji->value.at(j)) { + for (int j = 1; j < emoji->value.length(); ++j) + { + if (text.at(i + j) != emoji->value.at(j)) + { match = false; break; } } - if (match) { + if (match) + { matchedEmoji = emoji; matchedEmojiLength = emoji->value.length(); @@ -316,7 +354,8 @@ std::vector> Emojis::parse( } } - if (matchedEmojiLength == 0) { + if (matchedEmojiLength == 0) + { continue; } @@ -326,7 +365,8 @@ std::vector> Emojis::parse( int charactersFromLastParsedEmoji = currentParsedEmojiFirstIndex - lastParsedEmojiEndIndex; - if (charactersFromLastParsedEmoji > 0) { + if (charactersFromLastParsedEmoji > 0) + { // Add characters inbetween emojis result.emplace_back(text.mid(lastParsedEmojiEndIndex, charactersFromLastParsedEmoji)); @@ -340,7 +380,8 @@ std::vector> Emojis::parse( i += matchedEmojiLength - 1; } - if (lastParsedEmojiEndIndex < text.length()) { + if (lastParsedEmojiEndIndex < text.length()) + { // Add remaining characters result.emplace_back(text.mid(lastParsedEmojiEndIndex)); } @@ -355,7 +396,8 @@ QString Emojis::replaceShortCodes(const QString &text) int32_t offset = 0; - while (it.hasNext()) { + while (it.hasNext()) + { auto match = it.next(); auto capturedString = match.captured(); @@ -365,7 +407,8 @@ QString Emojis::replaceShortCodes(const QString &text) auto emojiIt = this->emojiShortCodeToEmoji_.constFind(matchString); - if (emojiIt == this->emojiShortCodeToEmoji_.constEnd()) { + if (emojiIt == this->emojiShortCodeToEmoji_.constEnd()) + { continue; } diff --git a/src/providers/ffz/FfzEmotes.cpp b/src/providers/ffz/FfzEmotes.cpp index 54efde13e..c43564037 100644 --- a/src/providers/ffz/FfzEmotes.cpp +++ b/src/providers/ffz/FfzEmotes.cpp @@ -13,7 +13,8 @@ namespace { Url getEmoteLink(const QJsonObject &urls, const QString &emoteScale) { auto emote = urls.value(emoteScale); - if (emote.isUndefined()) { + if (emote.isUndefined()) + { return {""}; } @@ -48,10 +49,12 @@ namespace { auto jsonSets = jsonRoot.value("sets").toObject(); auto emotes = EmoteMap(); - for (auto jsonSet : jsonSets) { + for (auto jsonSet : jsonSets) + { auto jsonEmotes = jsonSet.toObject().value("emoticons").toArray(); - for (auto jsonEmoteValue : jsonEmotes) { + for (auto jsonEmoteValue : jsonEmotes) + { auto jsonEmote = jsonEmoteValue.toObject(); auto name = EmoteName{jsonEmote.value("name").toString()}; @@ -78,10 +81,12 @@ namespace { auto jsonSets = jsonRoot.value("sets").toObject(); auto emotes = EmoteMap(); - for (auto jsonSet : jsonSets) { + for (auto jsonSet : jsonSets) + { auto jsonEmotes = jsonSet.toObject().value("emoticons").toArray(); - for (auto _jsonEmote : jsonEmotes) { + for (auto _jsonEmote : jsonEmotes) + { auto jsonEmote = _jsonEmote.toObject(); // margins @@ -120,7 +125,8 @@ boost::optional FfzEmotes::emote(const EmoteName &name) const { auto emotes = this->global_.get(); auto it = emotes->find(name); - if (it != emotes->end()) return it->second; + if (it != emotes->end()) + return it->second; return boost::none; } @@ -156,17 +162,20 @@ void FfzEmotes::loadChannel(const QString &channelName, request.onSuccess([callback = std::move(callback)](auto result) -> Outcome { auto pair = parseChannelEmotes(result.parseJson()); - if (pair.first) callback(std::move(pair.second)); + if (pair.first) + callback(std::move(pair.second)); return pair.first; }); request.onError([channelName](int result) { - if (result == 203) { + if (result == 203) + { // User does not have any FFZ emotes return true; } - if (result == -2) { + if (result == -2) + { // TODO: Auto retry in case of a timeout, with a delay log("Fetching FFZ emotes for channel {} failed due to timeout", channelName); diff --git a/src/providers/irc/AbstractIrcServer.cpp b/src/providers/irc/AbstractIrcServer.cpp index e884dc327..11c4e917b 100644 --- a/src/providers/irc/AbstractIrcServer.cpp +++ b/src/providers/irc/AbstractIrcServer.cpp @@ -60,7 +60,8 @@ AbstractIrcServer::AbstractIrcServer() this->falloffCounter_ = std::min(MAX_FALLOFF_COUNTER, this->falloffCounter_ + 1); - if (!this->readConnection_->isConnected()) { + if (!this->readConnection_->isConnected()) + { log("Trying to reconnect... {}", this->falloffCounter_); this->connect(); } @@ -73,10 +74,13 @@ void AbstractIrcServer::connect() bool separateWriteConnection = this->hasSeparateWriteConnection(); - if (separateWriteConnection) { + if (separateWriteConnection) + { this->initializeConnection(this->writeConnection_.get(), false, true); this->initializeConnection(this->readConnection_.get(), true, false); - } else { + } + else + { this->initializeConnection(this->readConnection_.get(), true, true); } @@ -85,8 +89,10 @@ void AbstractIrcServer::connect() std::lock_guard lock1(this->connectionMutex_); std::lock_guard lock2(this->channelMutex); - for (std::weak_ptr &weak : this->channels.values()) { - if (auto channel = std::shared_ptr(weak.lock())) { + for (std::weak_ptr &weak : this->channels.values()) + { + if (auto channel = std::shared_ptr(weak.lock())) + { this->readConnection_->sendRaw("JOIN #" + channel->getName()); } } @@ -117,9 +123,12 @@ void AbstractIrcServer::sendRawMessage(const QString &rawMessage) { std::lock_guard locker(this->connectionMutex_); - if (this->hasSeparateWriteConnection()) { + if (this->hasSeparateWriteConnection()) + { this->writeConnection_->sendRaw(rawMessage); - } else { + } + else + { this->readConnection_->sendRaw(rawMessage); } } @@ -136,7 +145,8 @@ std::shared_ptr AbstractIrcServer::getOrAddChannel( // try get channel ChannelPtr chan = this->getChannelOrEmpty(channelName); - if (chan != Channel::getEmpty()) { + if (chan != Channel::getEmpty()) + { return chan; } @@ -144,7 +154,8 @@ std::shared_ptr AbstractIrcServer::getOrAddChannel( // value doesn't exist chan = this->createChannel(channelName); - if (!chan) { + if (!chan) + { return Channel::getEmpty(); } @@ -158,11 +169,13 @@ std::shared_ptr AbstractIrcServer::getOrAddChannel( clojuresInCppAreShit); this->channels.remove(clojuresInCppAreShit); - if (this->readConnection_) { + if (this->readConnection_) + { this->readConnection_->sendRaw("PART #" + clojuresInCppAreShit); } - if (this->writeConnection_) { + if (this->writeConnection_) + { this->writeConnection_->sendRaw("PART #" + clojuresInCppAreShit); } }); @@ -171,11 +184,13 @@ std::shared_ptr AbstractIrcServer::getOrAddChannel( { std::lock_guard lock2(this->connectionMutex_); - if (this->readConnection_) { + if (this->readConnection_) + { this->readConnection_->sendRaw("JOIN #" + channelName); } - if (this->writeConnection_) { + if (this->writeConnection_) + { this->writeConnection_->sendRaw("JOIN #" + channelName); } } @@ -192,16 +207,19 @@ std::shared_ptr AbstractIrcServer::getChannelOrEmpty( // try get special channel ChannelPtr chan = this->getCustomChannel(channelName); - if (chan) { + if (chan) + { return chan; } // value exists auto it = this->channels.find(channelName); - if (it != this->channels.end()) { + if (it != this->channels.end()) + { chan = it.value().lock(); - if (chan) { + if (chan) + { return chan; } } @@ -216,9 +234,11 @@ void AbstractIrcServer::onConnected() auto connected = makeSystemMessage("connected to chat"); auto reconnected = makeSystemMessage("reconnected to chat"); - for (std::weak_ptr &weak : this->channels.values()) { + for (std::weak_ptr &weak : this->channels.values()) + { std::shared_ptr chan = weak.lock(); - if (!chan) { + if (!chan) + { continue; } @@ -228,7 +248,8 @@ void AbstractIrcServer::onConnected() snapshot[snapshot.getLength() - 1]->flags.has( MessageFlag::DisconnectedMessage); - if (replaceMessage) { + if (replaceMessage) + { chan->replaceMessage(snapshot[snapshot.getLength() - 1], reconnected); continue; @@ -248,9 +269,11 @@ void AbstractIrcServer::onDisconnected() b->flags.set(MessageFlag::DisconnectedMessage); auto disconnected = b.release(); - for (std::weak_ptr &weak : this->channels.values()) { + for (std::weak_ptr &weak : this->channels.values()) + { std::shared_ptr chan = weak.lock(); - if (!chan) { + if (!chan) + { continue; } @@ -279,10 +302,13 @@ void AbstractIrcServer::addFakeMessage(const QString &data) auto fakeMessage = Communi::IrcMessage::fromData( data.toUtf8(), this->readConnection_.get()); - if (fakeMessage->command() == "PRIVMSG") { + if (fakeMessage->command() == "PRIVMSG") + { this->privateMessageReceived( static_cast(fakeMessage)); - } else { + } + else + { this->messageReceived(fakeMessage); } } @@ -300,9 +326,11 @@ void AbstractIrcServer::forEachChannel(std::function func) { std::lock_guard lock(this->channelMutex); - for (std::weak_ptr &weak : this->channels.values()) { + for (std::weak_ptr &weak : this->channels.values()) + { std::shared_ptr chan = weak.lock(); - if (!chan) { + if (!chan) + { continue; } diff --git a/src/providers/irc/IrcConnection2.cpp b/src/providers/irc/IrcConnection2.cpp index 4739739aa..c6065f8bc 100644 --- a/src/providers/irc/IrcConnection2.cpp +++ b/src/providers/irc/IrcConnection2.cpp @@ -9,8 +9,10 @@ IrcConnection::IrcConnection(QObject *parent) this->pingTimer_.setInterval(5000); this->pingTimer_.start(); QObject::connect(&this->pingTimer_, &QTimer::timeout, [this] { - if (this->isConnected()) { - if (!this->recentlyReceivedMessage_.load()) { + if (this->isConnected()) + { + if (!this->recentlyReceivedMessage_.load()) + { this->sendRaw("PING"); this->reconnectTimer_.start(); } @@ -22,7 +24,8 @@ IrcConnection::IrcConnection(QObject *parent) this->reconnectTimer_.setInterval(5000); this->reconnectTimer_.setSingleShot(true); QObject::connect(&this->reconnectTimer_, &QTimer::timeout, [this] { - if (this->isConnected()) { + if (this->isConnected()) + { reconnectRequested.invoke(); } }); @@ -31,7 +34,8 @@ IrcConnection::IrcConnection(QObject *parent) [this](Communi::IrcMessage *) { this->recentlyReceivedMessage_ = true; - if (this->reconnectTimer_.isActive()) { + if (this->reconnectTimer_.isActive()) + { this->reconnectTimer_.stop(); } }); diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index 8b1b3fa03..a23ffa70d 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -39,29 +39,35 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *_message, bool isSub, bool isAction) { QString channelName; - if (!trimChannelName(target, channelName)) { + if (!trimChannelName(target, channelName)) + { return; } auto chan = server.getChannelOrEmpty(channelName); - if (chan->isEmpty()) { + if (chan->isEmpty()) + { return; } MessageParseArgs args; - if (isSub) { + if (isSub) + { args.trimSubscriberUsername = true; } - if (chan->isBroadcaster()) { + if (chan->isBroadcaster()) + { args.isStaffOrBroadcaster = true; } TwitchMessageBuilder builder(chan.get(), _message, args, content, isAction); - if (isSub || !builder.isIgnored()) { - if (isSub) { + if (isSub || !builder.isIgnored()) + { + if (isSub) + { builder->flags.set(MessageFlag::Subscription); builder->flags.unset(MessageFlag::Highlighted); } @@ -69,8 +75,10 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *_message, auto msg = builder.build(); auto highlighted = msg->flags.has(MessageFlag::Highlighted); - if (!isSub) { - if (highlighted) { + if (!isSub) + { + if (highlighted) + { server.mentionsChannel->addMessage(msg); getApp()->highlights->addHighlight(msg); } @@ -87,16 +95,19 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message) // get twitch channel QString chanName; - if (!trimChannelName(message->parameter(0), chanName)) { + if (!trimChannelName(message->parameter(0), chanName)) + { return; } auto chan = app->twitch.server->getChannelOrEmpty(chanName); - if (auto *twitchChannel = dynamic_cast(chan.get())) { + if (auto *twitchChannel = dynamic_cast(chan.get())) + { // room-id decltype(tags.find("xD")) it; - if ((it = tags.find("room-id")) != tags.end()) { + if ((it = tags.find("room-id")) != tags.end()) + { auto roomId = it.value().toString(); twitchChannel->setRoomId(roomId); @@ -106,19 +117,24 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message) { auto roomModes = *twitchChannel->accessRoomModes(); - if ((it = tags.find("emote-only")) != tags.end()) { + if ((it = tags.find("emote-only")) != tags.end()) + { roomModes.emoteOnly = it.value() == "1"; } - if ((it = tags.find("subs-only")) != tags.end()) { + if ((it = tags.find("subs-only")) != tags.end()) + { roomModes.submode = it.value() == "1"; } - if ((it = tags.find("slow")) != tags.end()) { + if ((it = tags.find("slow")) != tags.end()) + { roomModes.slowMode = it.value().toInt(); } - if ((it = tags.find("r9k")) != tags.end()) { + if ((it = tags.find("r9k")) != tags.end()) + { roomModes.r9k = it.value() == "1"; } - if ((it = tags.find("broadcaster-lang")) != tags.end()) { + if ((it = tags.find("broadcaster-lang")) != tags.end()) + { roomModes.broadcasterLang = it.value().toString(); } twitchChannel->setRoomModes(roomModes); @@ -131,12 +147,14 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message) void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message) { // check parameter count - if (message->parameters().length() < 1) { + if (message->parameters().length() < 1) + { return; } QString chanName; - if (!trimChannelName(message->parameter(0), chanName)) { + if (!trimChannelName(message->parameter(0), chanName)) + { return; } @@ -145,7 +163,8 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message) // get channel auto chan = app->twitch.server->getChannelOrEmpty(chanName); - if (chan->isEmpty()) { + if (chan->isEmpty()) + { log("[IrcMessageHandler:handleClearChatMessage] Twitch channel {} not " "found", chanName); @@ -153,7 +172,8 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message) } // check if the chat has been cleared by a moderator - if (message->parameters().length() == 1) { + if (message->parameters().length() == 1) + { chan->disableAllMessages(); chan->addMessage( makeSystemMessage("Chat has been cleared by a moderator.")); @@ -165,12 +185,14 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message) QString username = message->parameter(1); QString durationInSeconds, reason; QVariant v = message->tag("ban-duration"); - if (v.isValid()) { + if (v.isValid()) + { durationInSeconds = v.toString(); } v = message->tag("ban-reason"); - if (v.isValid()) { + if (v.isValid()) + { reason = v.toString(); } @@ -187,21 +209,25 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message) { QVariant _mod = message->tag("mod"); - if (_mod.isValid()) { + if (_mod.isValid()) + { auto app = getApp(); QString channelName; - if (!trimChannelName(message->parameter(0), channelName)) { + if (!trimChannelName(message->parameter(0), channelName)) + { return; } auto c = app->twitch.server->getChannelOrEmpty(channelName); - if (c->isEmpty()) { + if (c->isEmpty()) + { return; } TwitchChannel *tc = dynamic_cast(c.get()); - if (tc != nullptr) { + if (tc != nullptr) + { tc->setMod(_mod == "1"); } } @@ -220,12 +246,14 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message) TwitchMessageBuilder builder(c, message, args, message->parameter(1), false); - if (!builder.isIgnored()) { + if (!builder.isIgnored()) + { MessagePtr _message = builder.build(); app->twitch.server->lastUserThatWhisperedMe.set(builder.userName); - if (_message->flags.has(MessageFlag::Highlighted)) { + if (_message->flags.has(MessageFlag::Highlighted)) + { app->twitch.server->mentionsChannel->addMessage(_message); } @@ -234,7 +262,8 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message) auto overrideFlags = boost::optional(_message->flags); overrideFlags->set(MessageFlag::DoNotTriggerNotification); - if (getSettings()->inlineWhispers) { + if (getSettings()->inlineWhispers) + { app->twitch.server->forEachChannel( [_message, overrideFlags](ChannelPtr channel) { channel->addMessage(_message, overrideFlags); // @@ -254,21 +283,25 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message, auto target = parameters[0]; QString msgType = tags.value("msg-id", "").toString(); QString content; - if (parameters.size() >= 2) { + if (parameters.size() >= 2) + { content = parameters[1]; } - if (msgType == "sub" || msgType == "resub" || msgType == "subgift") { + if (msgType == "sub" || msgType == "resub" || msgType == "subgift") + { // Sub-specific message. I think it's only allowed for "resub" messages // atm - if (!content.isEmpty()) { + if (!content.isEmpty()) + { this->addMessage(message, target, content, server, true, false); } } auto it = tags.find("system-msg"); - if (it != tags.end()) { + if (it != tags.end()) + { auto b = MessageBuilder(systemMessage, parseTagString(it.value().toString())); @@ -277,17 +310,20 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message, QString channelName; - if (message->parameters().size() < 1) { + if (message->parameters().size() < 1) + { return; } - if (!trimChannelName(message->parameter(0), channelName)) { + if (!trimChannelName(message->parameter(0), channelName)) + { return; } auto chan = server.getChannelOrEmpty(channelName); - if (!chan->isEmpty()) { + if (!chan->isEmpty()) + { chan->addMessage(newMessage); } } @@ -300,13 +336,17 @@ void IrcMessageHandler::handleModeMessage(Communi::IrcMessage *message) auto channel = app->twitch.server->getChannelOrEmpty( message->parameter(0).remove(0, 1)); - if (channel->isEmpty()) { + if (channel->isEmpty()) + { return; } - if (message->parameter(1) == "+o") { + if (message->parameter(1) == "+o") + { channel->modList.append(message->parameter(2)); - } else if (message->parameter(1) == "-o") { + } + else if (message->parameter(1) == "-o") + { channel->modList.append(message->parameter(2)); } } @@ -317,7 +357,8 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) MessagePtr msg = makeSystemMessage(message->content()); QString channelName; - if (!trimChannelName(message->target(), channelName)) { + if (!trimChannelName(message->target(), channelName)) + { // Notice wasn't targeted at a single channel, send to all twitch // channels app->twitch.server->forEachChannelAndSpecialChannels( @@ -330,7 +371,8 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) auto channel = app->twitch.server->getChannelOrEmpty(channelName); - if (channel->isEmpty()) { + if (channel->isEmpty()) + { log("[IrcManager:handleNoticeMessage] Channel {} not found in channel " "manager ", channelName); @@ -367,10 +409,12 @@ void IrcMessageHandler::handleWriteConnectionNoticeMessage( }; QVariant v = message->tag("msg-id"); - if (v.isValid()) { + if (v.isValid()) + { std::string msgID = v.toString().toStdString(); - if (readConnectionOnlyIDs.find(msgID) != readConnectionOnlyIDs.end()) { + if (readConnectionOnlyIDs.find(msgID) != readConnectionOnlyIDs.end()) + { return; } @@ -388,7 +432,8 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message) message->parameter(0).remove(0, 1)); if (TwitchChannel *twitchChannel = - dynamic_cast(channel.get())) { + dynamic_cast(channel.get())) + { twitchChannel->addJoinedUser(message->nick()); } } @@ -400,7 +445,8 @@ void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message) message->parameter(0).remove(0, 1)); if (TwitchChannel *twitchChannel = - dynamic_cast(channel.get())) { + dynamic_cast(channel.get())) + { twitchChannel->addPartedUser(message->nick()); } } diff --git a/src/providers/twitch/PartialTwitchUser.cpp b/src/providers/twitch/PartialTwitchUser.cpp index 6aca624b1..157274bf0 100644 --- a/src/providers/twitch/PartialTwitchUser.cpp +++ b/src/providers/twitch/PartialTwitchUser.cpp @@ -31,7 +31,8 @@ void PartialTwitchUser::getId(std::function successCallback, { assert(!this->username_.isEmpty()); - if (caller == nullptr) { + if (caller == nullptr) + { caller = QThread::currentThread(); } @@ -42,23 +43,27 @@ void PartialTwitchUser::getId(std::function successCallback, request.onSuccess([successCallback](auto result) -> Outcome { auto root = result.parseJson(); - if (!root.value("users").isArray()) { + if (!root.value("users").isArray()) + { log("API Error while getting user id, users is not an array"); return Failure; } auto users = root.value("users").toArray(); - if (users.size() != 1) { + if (users.size() != 1) + { log("API Error while getting user id, users array size is not 1"); return Failure; } - if (!users[0].isObject()) { + if (!users[0].isObject()) + { log("API Error while getting user id, first user is not an object"); return Failure; } auto firstUser = users[0].toObject(); auto id = firstUser.value("_id"); - if (!id.isString()) { + if (!id.isString()) + { log("API Error: while getting user id, first user object `_id` key " "is not a " "string"); diff --git a/src/providers/twitch/PubsubActions.hpp b/src/providers/twitch/PubsubActions.hpp index 688468f0e..8b2bfecfb 100644 --- a/src/providers/twitch/PubsubActions.hpp +++ b/src/providers/twitch/PubsubActions.hpp @@ -44,7 +44,8 @@ struct ModeChangedAction : PubSubAction { const char *getModeName() const { - switch (this->mode) { + switch (this->mode) + { case Mode::Slow: return "slow"; case Mode::R9K: diff --git a/src/providers/twitch/PubsubClient.cpp b/src/providers/twitch/PubsubClient.cpp index 77b6ba1d4..6bc866700 100644 --- a/src/providers/twitch/PubsubClient.cpp +++ b/src/providers/twitch/PubsubClient.cpp @@ -51,14 +51,16 @@ namespace detail { { int numRequestedListens = message["data"]["topics"].Size(); - if (this->numListens_ + numRequestedListens > MAX_PUBSUB_LISTENS) { + if (this->numListens_ + numRequestedListens > MAX_PUBSUB_LISTENS) + { // This PubSubClient is already at its peak listens return false; } this->numListens_ += numRequestedListens; - for (const auto &topic : message["data"]["topics"].GetArray()) { + for (const auto &topic : message["data"]["topics"].GetArray()) + { this->listeners_.emplace_back( Listener{topic.GetString(), false, false, false}); } @@ -79,18 +81,22 @@ namespace detail { { std::vector topics; - for (auto it = this->listeners_.begin(); - it != this->listeners_.end();) { + for (auto it = this->listeners_.begin(); it != this->listeners_.end();) + { const auto &listener = *it; - if (listener.topic.find(prefix) == 0) { + if (listener.topic.find(prefix) == 0) + { topics.push_back(listener.topic); it = this->listeners_.erase(it); - } else { + } + else + { ++it; } } - if (topics.empty()) { + if (topics.empty()) + { return; } @@ -117,8 +123,10 @@ namespace detail { bool PubSubClient::isListeningToTopic(const std::string &payload) { - for (const auto &listener : this->listeners_) { - if (listener.topic == payload) { + for (const auto &listener : this->listeners_) + { + if (listener.topic == payload) + { return true; } } @@ -130,7 +138,8 @@ namespace detail { { assert(this->started_); - if (!this->send(pingPayload)) { + if (!this->send(pingPayload)) + { return; } @@ -140,11 +149,13 @@ namespace detail { runAfter(this->websocketClient_.get_io_service(), std::chrono::seconds(15), [self](auto timer) { - if (!self->started_) { + if (!self->started_) + { return; } - if (self->awaitingPong_) { + if (self->awaitingPong_) + { log("No pong respnose, disconnect!"); // TODO(pajlada): Label this connection as "disconnect // me" @@ -153,7 +164,8 @@ namespace detail { runAfter(this->websocketClient_.get_io_service(), std::chrono::minutes(5), [self](auto timer) { - if (!self->started_) { + if (!self->started_) + { return; } @@ -167,7 +179,8 @@ namespace detail { this->websocketClient_.send(this->handle_, payload, websocketpp::frame::opcode::text, ec); - if (ec) { + if (ec) + { log("Error sending message {}: {}", payload, ec.message()); // TODO(pajlada): Check which error code happened and maybe // gracefully handle it @@ -208,26 +221,30 @@ PubSub::PubSub() action.mode = ModeChangedAction::Mode::Slow; action.state = ModeChangedAction::State::On; - if (!data.HasMember("args")) { + if (!data.HasMember("args")) + { log("Missing required args member"); return; } const auto &args = data["args"]; - if (!args.IsArray()) { + if (!args.IsArray()) + { log("args member must be an array"); return; } - if (args.Size() == 0) { + if (args.Size() == 0) + { log("Missing duration argument in slowmode on"); return; } const auto &durationArg = args[0]; - if (!durationArg.IsString()) { + if (!durationArg.IsString()) + { log("Duration arg must be a string"); return; } @@ -305,17 +322,22 @@ PubSub::PubSub() getTargetUser(data, action.target); - try { + try + { const auto &args = getArgs(data); - if (args.Size() < 1) { + if (args.Size() < 1) + { return; } - if (!rj::getSafe(args[0], action.target.name)) { + if (!rj::getSafe(args[0], action.target.name)) + { return; } - } catch (const std::runtime_error &ex) { + } + catch (const std::runtime_error &ex) + { log("Error parsing moderation action: {}", ex.what()); } @@ -330,17 +352,22 @@ PubSub::PubSub() getTargetUser(data, action.target); - try { + try + { const auto &args = getArgs(data); - if (args.Size() < 1) { + if (args.Size() < 1) + { return; } - if (!rj::getSafe(args[0], action.target.name)) { + if (!rj::getSafe(args[0], action.target.name)) + { return; } - } catch (const std::runtime_error &ex) { + } + catch (const std::runtime_error &ex) + { log("Error parsing moderation action: {}", ex.what()); } @@ -356,32 +383,40 @@ PubSub::PubSub() getCreatedByUser(data, action.source); getTargetUser(data, action.target); - try { + try + { const auto &args = getArgs(data); - if (args.Size() < 2) { + if (args.Size() < 2) + { return; } - if (!rj::getSafe(args[0], action.target.name)) { + if (!rj::getSafe(args[0], action.target.name)) + { return; } QString durationString; - if (!rj::getSafe(args[1], durationString)) { + if (!rj::getSafe(args[1], durationString)) + { return; } bool ok; action.duration = durationString.toUInt(&ok, 10); - if (args.Size() >= 3) { - if (!rj::getSafe(args[2], action.reason)) { + if (args.Size() >= 3) + { + if (!rj::getSafe(args[2], action.reason)) + { return; } } this->signals_.moderation.userBanned.invoke(action); - } catch (const std::runtime_error &ex) { + } + catch (const std::runtime_error &ex) + { log("Error parsing moderation action: {}", ex.what()); } }; @@ -393,25 +428,32 @@ PubSub::PubSub() getCreatedByUser(data, action.source); getTargetUser(data, action.target); - try { + try + { const auto &args = getArgs(data); - if (args.Size() < 1) { + if (args.Size() < 1) + { return; } - if (!rj::getSafe(args[0], action.target.name)) { + if (!rj::getSafe(args[0], action.target.name)) + { return; } - if (args.Size() >= 2) { - if (!rj::getSafe(args[1], action.reason)) { + if (args.Size() >= 2) + { + if (!rj::getSafe(args[1], action.reason)) + { return; } } this->signals_.moderation.userBanned.invoke(action); - } catch (const std::runtime_error &ex) { + } + catch (const std::runtime_error &ex) + { log("Error parsing moderation action: {}", ex.what()); } }; @@ -425,19 +467,24 @@ PubSub::PubSub() action.previousState = UnbanAction::Banned; - try { + try + { const auto &args = getArgs(data); - if (args.Size() < 1) { + if (args.Size() < 1) + { return; } - if (!rj::getSafe(args[0], action.target.name)) { + if (!rj::getSafe(args[0], action.target.name)) + { return; } this->signals_.moderation.userUnbanned.invoke(action); - } catch (const std::runtime_error &ex) { + } + catch (const std::runtime_error &ex) + { log("Error parsing moderation action: {}", ex.what()); } }; @@ -451,19 +498,24 @@ PubSub::PubSub() action.previousState = UnbanAction::TimedOut; - try { + try + { const auto &args = getArgs(data); - if (args.Size() < 1) { + if (args.Size() < 1) + { return; } - if (!rj::getSafe(args[0], action.target.name)) { + if (!rj::getSafe(args[0], action.target.name)) + { return; } this->signals_.moderation.userUnbanned.invoke(action); - } catch (const std::runtime_error &ex) { + } + catch (const std::runtime_error &ex) + { log("Error parsing moderation action: {}", ex.what()); } }; @@ -494,7 +546,8 @@ void PubSub::addClient() websocketpp::lib::error_code ec; auto con = this->websocketClient.get_connection(TWITCH_PUBSUB_URL, ec); - if (ec) { + if (ec) + { log("Unable to establish connection: {}", ec.message()); return; } @@ -521,7 +574,8 @@ void PubSub::listenToWhispers(std::shared_ptr account) this->listen(createListenMessage(topics, account)); - if (ec) { + if (ec) + { log("Unable to send message to websocket server: {}", ec.message()); return; } @@ -529,7 +583,8 @@ void PubSub::listenToWhispers(std::shared_ptr account) void PubSub::unlistenAllModerationActions() { - for (const auto &p : this->clients) { + for (const auto &p : this->clients) + { const auto &client = p.second; client->unlistenPrefix("chat_moderator_actions."); } @@ -541,11 +596,13 @@ void PubSub::listenToChannelModerationActions( assert(!channelID.isEmpty()); assert(account != nullptr); QString userID = account->getUserId(); - if (userID.isEmpty()) return; + if (userID.isEmpty()) + return; std::string topic(fS("chat_moderator_actions.{}.{}", userID, channelID)); - if (this->isListeningToTopic(topic)) { + if (this->isListeningToTopic(topic)) + { log("We are already listening to topic {}", topic); return; } @@ -565,7 +622,8 @@ void PubSub::listenToTopic(const std::string &topic, void PubSub::listen(rapidjson::Document &&msg) { - if (this->tryListen(msg)) { + if (this->tryListen(msg)) + { log("Successfully listened!"); return; } @@ -578,9 +636,11 @@ void PubSub::listen(rapidjson::Document &&msg) bool PubSub::tryListen(rapidjson::Document &msg) { log("tryListen with {} clients", this->clients.size()); - for (const auto &p : this->clients) { + for (const auto &p : this->clients) + { const auto &client = p.second; - if (client->listen(msg)) { + if (client->listen(msg)) + { return true; } } @@ -590,9 +650,11 @@ bool PubSub::tryListen(rapidjson::Document &msg) bool PubSub::isListeningToTopic(const std::string &topic) { - for (const auto &p : this->clients) { + for (const auto &p : this->clients) + { const auto &client = p.second; - if (client->isListeningToTopic(topic)) { + if (client->isListeningToTopic(topic)) + { return true; } } @@ -609,13 +671,15 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl, rapidjson::ParseResult res = msg.Parse(payload.c_str()); - if (!res) { + if (!res) + { log("Error parsing message '{}' from PubSub: {}", payload, rapidjson::GetParseError_En(res.Code())); return; } - if (!msg.IsObject()) { + if (!msg.IsObject()) + { log("Error parsing message '{}' from PubSub. Root object is not an " "object", payload); @@ -624,28 +688,36 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl, std::string type; - if (!rj::getSafe(msg, "type", type)) { + if (!rj::getSafe(msg, "type", type)) + { log("Missing required string member `type` in message root"); return; } - if (type == "RESPONSE") { + if (type == "RESPONSE") + { this->handleListenResponse(msg); - } else if (type == "MESSAGE") { - if (!msg.HasMember("data")) { + } + else if (type == "MESSAGE") + { + if (!msg.HasMember("data")) + { log("Missing required object member `data` in message root"); return; } const auto &data = msg["data"]; - if (!data.IsObject()) { + if (!data.IsObject()) + { log("Member `data` must be an object"); return; } this->handleMessageResponse(data); - } else if (type == "PONG") { + } + else if (type == "PONG") + { auto clientIt = this->clients.find(hdl); // If this assert goes off, there's something wrong with the connection @@ -655,7 +727,9 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl, auto &client = *clientIt; client.second->handlePong(); - } else { + } + else + { log("Unknown message type: {}", type); } } @@ -696,11 +770,14 @@ PubSub::WebsocketContextPtr PubSub::onTLSInit(websocketpp::connection_hdl hdl) WebsocketContextPtr ctx( new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1)); - try { + try + { ctx->set_options(boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 | boost::asio::ssl::context::single_dh_use); - } catch (const std::exception &e) { + } + catch (const std::exception &e) + { log("Exception caught in OnTLSInit: {}", e.what()); } @@ -711,11 +788,13 @@ void PubSub::handleListenResponse(const rapidjson::Document &msg) { std::string error; - if (rj::getSafe(msg, "error", error)) { + if (rj::getSafe(msg, "error", error)) + { std::string nonce; rj::getSafe(msg, "nonce", nonce); - if (error.empty()) { + if (error.empty()) + { log("Successfully listened to nonce {}", nonce); // Nothing went wrong return; @@ -730,14 +809,16 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData) { QString topic; - if (!rj::getSafe(outerData, "topic", topic)) { + if (!rj::getSafe(outerData, "topic", topic)) + { log("Missing required string member `topic` in outerData"); return; } std::string payload; - if (!rj::getSafe(outerData, "message", payload)) { + if (!rj::getSafe(outerData, "message", payload)) + { log("Expected string message in outerData"); return; } @@ -746,53 +827,69 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData) rapidjson::ParseResult res = msg.Parse(payload.c_str()); - if (!res) { + if (!res) + { log("Error parsing message '{}' from PubSub: {}", payload, rapidjson::GetParseError_En(res.Code())); return; } - if (topic.startsWith("whispers.")) { + if (topic.startsWith("whispers.")) + { std::string whisperType; - if (!rj::getSafe(msg, "type", whisperType)) { + if (!rj::getSafe(msg, "type", whisperType)) + { log("Bad whisper data"); return; } - if (whisperType == "whisper_received") { + if (whisperType == "whisper_received") + { this->signals_.whisper.received.invoke(msg); - } else if (whisperType == "whisper_sent") { + } + else if (whisperType == "whisper_sent") + { this->signals_.whisper.sent.invoke(msg); - } else if (whisperType == "thread") { + } + else if (whisperType == "thread") + { // Handle thread? - } else { + } + else + { log("Invalid whisper type: {}", whisperType); assert(false); return; } - } else if (topic.startsWith("chat_moderator_actions.")) { + } + else if (topic.startsWith("chat_moderator_actions.")) + { auto topicParts = topic.split("."); assert(topicParts.length() == 3); const auto &data = msg["data"]; std::string moderationAction; - if (!rj::getSafe(data, "moderation_action", moderationAction)) { + if (!rj::getSafe(data, "moderation_action", moderationAction)) + { log("Missing moderation action in data: {}", rj::stringify(data)); return; } auto handlerIt = this->moderationActionHandlers.find(moderationAction); - if (handlerIt == this->moderationActionHandlers.end()) { + if (handlerIt == this->moderationActionHandlers.end()) + { log("No handler found for moderation action {}", moderationAction); return; } // Invoke handler function handlerIt->second(data, topicParts[2]); - } else { + } + else + { log("Unknown topic: {}", topic); return; } diff --git a/src/providers/twitch/PubsubHelpers.cpp b/src/providers/twitch/PubsubHelpers.cpp index f9b4e784a..cda4b8788 100644 --- a/src/providers/twitch/PubsubHelpers.cpp +++ b/src/providers/twitch/PubsubHelpers.cpp @@ -8,13 +8,15 @@ namespace chatterino { const rapidjson::Value &getArgs(const rapidjson::Value &data) { - if (!data.HasMember("args")) { + if (!data.HasMember("args")) + { throw std::runtime_error("Missing member args"); } const auto &args = data["args"]; - if (!args.IsArray()) { + if (!args.IsArray()) + { throw std::runtime_error("args must be an array"); } @@ -43,12 +45,14 @@ rapidjson::Document createListenMessage( rapidjson::Value data(rapidjson::kObjectType); - if (account) { + if (account) + { rj::set(data, "auth_token", account->getOAuthToken(), a); } rapidjson::Value topics(rapidjson::kArrayType); - for (const auto &topic : topicsVec) { + for (const auto &topic : topicsVec) + { rj::add(topics, topic, a); } @@ -70,7 +74,8 @@ rapidjson::Document createUnlistenMessage( rapidjson::Value data(rapidjson::kObjectType); rapidjson::Value topics(rapidjson::kArrayType); - for (const auto &topic : topicsVec) { + for (const auto &topic : topicsVec) + { rj::add(topics, topic, a); } diff --git a/src/providers/twitch/PubsubHelpers.hpp b/src/providers/twitch/PubsubHelpers.hpp index c478ed437..7ea540ad8 100644 --- a/src/providers/twitch/PubsubHelpers.hpp +++ b/src/providers/twitch/PubsubHelpers.hpp @@ -32,7 +32,8 @@ void runAfter(boost::asio::io_service &ioService, Duration duration, timer->expires_from_now(duration); timer->async_wait([timer, cb](const boost::system::error_code &ec) { - if (ec) { + if (ec) + { log("Error in runAfter: {}", ec.message()); return; } @@ -49,7 +50,8 @@ void runAfter(std::shared_ptr timer, timer->expires_from_now(duration); timer->async_wait([timer, cb](const boost::system::error_code &ec) { - if (ec) { + if (ec) + { log("Error in runAfter: {}", ec.message()); return; } diff --git a/src/providers/twitch/TwitchAccount.cpp b/src/providers/twitch/TwitchAccount.cpp index 3e7ea237d..abc95efd0 100644 --- a/src/providers/twitch/TwitchAccount.cpp +++ b/src/providers/twitch/TwitchAccount.cpp @@ -31,7 +31,8 @@ namespace { }; auto it = emoteNameReplacements.find(dirtyEmoteCode.string); - if (it != emoteNameReplacements.end()) { + if (it != emoteNameReplacements.end()) + { cleanCode = it.value(); } @@ -91,7 +92,8 @@ void TwitchAccount::setColor(QColor color) bool TwitchAccount::setOAuthClient(const QString &newClientID) { - if (this->oauthClient_.compare(newClientID) == 0) { + if (this->oauthClient_.compare(newClientID) == 0) + { return false; } @@ -102,7 +104,8 @@ bool TwitchAccount::setOAuthClient(const QString &newClientID) bool TwitchAccount::setOAuthToken(const QString &newOAuthToken) { - if (this->oauthToken_.compare(newOAuthToken) == 0) { + if (this->oauthToken_.compare(newOAuthToken) == 0) + { return false; } @@ -126,17 +129,20 @@ void TwitchAccount::loadIgnores() req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken()); req.onSuccess([=](auto result) -> Outcome { auto document = result.parseRapidJson(); - if (!document.IsObject()) { + if (!document.IsObject()) + { return Failure; } auto blocksIt = document.FindMember("blocks"); - if (blocksIt == document.MemberEnd()) { + if (blocksIt == document.MemberEnd()) + { return Failure; } const auto &blocks = blocksIt->value; - if (!blocks.IsArray()) { + if (!blocks.IsArray()) + { return Failure; } @@ -144,16 +150,20 @@ void TwitchAccount::loadIgnores() std::lock_guard lock(this->ignoresMutex_); this->ignores_.clear(); - for (const auto &block : blocks.GetArray()) { - if (!block.IsObject()) { + for (const auto &block : blocks.GetArray()) + { + if (!block.IsObject()) + { continue; } auto userIt = block.FindMember("user"); - if (userIt == block.MemberEnd()) { + if (userIt == block.MemberEnd()) + { continue; } TwitchUser ignoredUser; - if (!rj::getSafe(userIt->value, ignoredUser)) { + if (!rj::getSafe(userIt->value, ignoredUser)) + { log("Error parsing twitch user JSON {}", rj::stringify(userIt->value)); continue; @@ -201,14 +211,16 @@ void TwitchAccount::ignoreByID( req.onSuccess([=](auto result) -> Outcome { auto document = result.parseRapidJson(); - if (!document.IsObject()) { + if (!document.IsObject()) + { onFinished(IgnoreResult_Failed, "Bad JSON data while ignoring user " + targetName); return Failure; } auto userIt = document.FindMember("user"); - if (userIt == document.MemberEnd()) { + if (userIt == document.MemberEnd()) + { onFinished(IgnoreResult_Failed, "Bad JSON data while ignoring user (missing user) " + targetName); @@ -216,7 +228,8 @@ void TwitchAccount::ignoreByID( } TwitchUser ignoredUser; - if (!rj::getSafe(userIt->value, ignoredUser)) { + if (!rj::getSafe(userIt->value, ignoredUser)) + { onFinished(IgnoreResult_Failed, "Bad JSON data while ignoring user (invalid user) " + targetName); @@ -226,7 +239,8 @@ void TwitchAccount::ignoreByID( std::lock_guard lock(this->ignoresMutex_); auto res = this->ignores_.insert(ignoredUser); - if (!res.second) { + if (!res.second) + { const TwitchUser &existingUser = *(res.first); existingUser.update(ignoredUser); onFinished(IgnoreResult_AlreadyIgnored, @@ -303,9 +317,12 @@ void TwitchAccount::checkFollow(const QString targetUserID, req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken()); req.onError([=](int errorCode) { - if (errorCode == 203) { + if (errorCode == 203) + { onFinished(FollowResult_NotFollowing); - } else { + } + else + { onFinished(FollowResult_Failed); } @@ -354,7 +371,8 @@ void TwitchAccount::unfollowUser(const QString userID, request.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken()); request.onError([successCallback](int code) { - if (code >= 200 && code <= 299) { + if (code >= 200 && code <= 299) + { successCallback(); } @@ -384,7 +402,8 @@ void TwitchAccount::loadEmotes() const auto &clientID = this->getOAuthClient(); const auto &oauthToken = this->getOAuthToken(); - if (clientID.isEmpty() || oauthToken.isEmpty()) { + if (clientID.isEmpty() || oauthToken.isEmpty()) + { log("Missing Client ID or OAuth token"); return; } @@ -398,9 +417,12 @@ void TwitchAccount::loadEmotes() req.onError([=](int errorCode) { log("[TwitchAccount::loadEmotes] Error {}", errorCode); - if (errorCode == 203) { + if (errorCode == 203) + { // onFinished(FollowResult_NotFollowing); - } else { + } + else + { // onFinished(FollowResult_Failed); } @@ -430,33 +452,38 @@ void TwitchAccount::parseEmotes(const rapidjson::Document &root) emoteData->allEmoteNames.clear(); auto emoticonSets = root.FindMember("emoticon_sets"); - if (emoticonSets == root.MemberEnd() || !emoticonSets->value.IsObject()) { + if (emoticonSets == root.MemberEnd() || !emoticonSets->value.IsObject()) + { log("No emoticon_sets in load emotes response"); return; } - for (const auto &emoteSetJSON : emoticonSets->value.GetObject()) { + for (const auto &emoteSetJSON : emoticonSets->value.GetObject()) + { auto emoteSet = std::make_shared(); emoteSet->key = emoteSetJSON.name.GetString(); this->loadEmoteSetData(emoteSet); - for (const rapidjson::Value &emoteJSON : - emoteSetJSON.value.GetArray()) { - if (!emoteJSON.IsObject()) { + for (const rapidjson::Value &emoteJSON : emoteSetJSON.value.GetArray()) + { + if (!emoteJSON.IsObject()) + { log("Emote value was invalid"); return; } uint64_t idNumber; - if (!rj::getSafe(emoteJSON, "id", idNumber)) { + if (!rj::getSafe(emoteJSON, "id", idNumber)) + { log("No ID key found in Emote value"); return; } QString _code; - if (!rj::getSafe(emoteJSON, "code", _code)) { + if (!rj::getSafe(emoteJSON, "code", _code)) + { log("No code key found in Emote value"); return; } @@ -478,13 +505,15 @@ void TwitchAccount::parseEmotes(const rapidjson::Document &root) void TwitchAccount::loadEmoteSetData(std::shared_ptr emoteSet) { - if (!emoteSet) { + if (!emoteSet) + { log("null emote set sent"); return; } auto staticSetIt = this->staticEmoteSets.find(emoteSet->key); - if (staticSetIt != this->staticEmoteSets.end()) { + if (staticSetIt != this->staticEmoteSets.end()) + { const auto &staticSet = staticSetIt->second; emoteSet->channelName = staticSet.channelName; emoteSet->text = staticSet.text; @@ -503,18 +532,21 @@ void TwitchAccount::loadEmoteSetData(std::shared_ptr emoteSet) req.onSuccess([emoteSet](auto result) -> Outcome { auto root = result.parseRapidJson(); - if (!root.IsObject()) { + if (!root.IsObject()) + { return Failure; } std::string emoteSetID; QString channelName; QString type; - if (!rj::getSafe(root, "channel_name", channelName)) { + if (!rj::getSafe(root, "channel_name", channelName)) + { return Failure; } - if (!rj::getSafe(root, "type", type)) { + if (!rj::getSafe(root, "type", type)) + { return Failure; } diff --git a/src/providers/twitch/TwitchAccountManager.cpp b/src/providers/twitch/TwitchAccountManager.cpp index 097aa89ea..a386d15d1 100644 --- a/src/providers/twitch/TwitchAccountManager.cpp +++ b/src/providers/twitch/TwitchAccountManager.cpp @@ -21,7 +21,8 @@ TwitchAccountManager::TwitchAccountManager() std::shared_ptr TwitchAccountManager::getCurrent() { - if (!this->currentUser_) { + if (!this->currentUser_) + { return this->anonymousUser_; } @@ -34,7 +35,8 @@ std::vector TwitchAccountManager::getUsernames() const std::lock_guard lock(this->mutex_); - for (const auto &user : this->accounts.getVector()) { + for (const auto &user : this->accounts.getVector()) + { userNames.push_back(user->getUserName()); } @@ -46,8 +48,10 @@ std::shared_ptr TwitchAccountManager::findUserByUsername( { std::lock_guard lock(this->mutex_); - for (const auto &user : this->accounts.getVector()) { - if (username.compare(user->getUserName(), Qt::CaseInsensitive) == 0) { + for (const auto &user : this->accounts.getVector()) + { + if (username.compare(user->getUserName(), Qt::CaseInsensitive) == 0) + { return user; } } @@ -68,8 +72,10 @@ void TwitchAccountManager::reloadUsers() bool listUpdated = false; - for (const auto &uid : keys) { - if (uid == "current") { + for (const auto &uid : keys) + { + if (uid == "current") + { continue; } @@ -83,7 +89,8 @@ void TwitchAccountManager::reloadUsers() "/accounts/" + uid + "/oauthToken"); if (username.empty() || userID.empty() || clientID.empty() || - oauthToken.empty()) { + oauthToken.empty()) + { continue; } @@ -92,28 +99,37 @@ void TwitchAccountManager::reloadUsers() userData.clientID = qS(clientID).trimmed(); userData.oauthToken = qS(oauthToken).trimmed(); - switch (this->addUser(userData)) { - case AddUserResponse::UserAlreadyExists: { + switch (this->addUser(userData)) + { + case AddUserResponse::UserAlreadyExists: + { log("User {} already exists", userData.username); // Do nothing - } break; - case AddUserResponse::UserValuesUpdated: { + } + break; + case AddUserResponse::UserValuesUpdated: + { log("User {} already exists, and values updated!", userData.username); - if (userData.username == this->getCurrent()->getUserName()) { + if (userData.username == this->getCurrent()->getUserName()) + { log("It was the current user, so we need to reconnect " "stuff!"); this->currentUserChanged.invoke(); } - } break; - case AddUserResponse::UserAdded: { + } + break; + case AddUserResponse::UserAdded: + { log("Added user {}", userData.username); listUpdated = true; - } break; + } + break; } } - if (listUpdated) { + if (listUpdated) + { this->userListUpdated.invoke(); } } @@ -125,12 +141,15 @@ void TwitchAccountManager::load() this->currentUsername.connect([this](const auto &newValue, auto) { QString newUsername(QString::fromStdString(newValue)); auto user = this->findUserByUsername(newUsername); - if (user) { + if (user) + { log("[AccountManager:currentUsernameChanged] User successfully " "updated to {}", newUsername); this->currentUser_ = user; - } else { + } + else + { log("[AccountManager:currentUsernameChanged] User successfully " "updated to anonymous"); this->currentUser_ = this->anonymousUser_; @@ -142,7 +161,8 @@ void TwitchAccountManager::load() bool TwitchAccountManager::isLoggedIn() const { - if (!this->currentUser_) { + if (!this->currentUser_) + { return false; } @@ -156,12 +176,14 @@ bool TwitchAccountManager::removeUser(TwitchAccount *account) const auto &accs = this->accounts.getVector(); std::string userID(account->getUserId().toStdString()); - if (!userID.empty()) { + if (!userID.empty()) + { pajlada::Settings::SettingManager::removeSetting("/accounts/uid" + userID); } - if (account->getUserName() == qS(this->currentUsername.getValue())) { + if (account->getUserName() == qS(this->currentUsername.getValue())) + { // The user that was removed is the current user, log into the anonymous // user this->currentUsername = ""; @@ -176,20 +198,26 @@ TwitchAccountManager::AddUserResponse TwitchAccountManager::addUser( const TwitchAccountManager::UserData &userData) { auto previousUser = this->findUserByUsername(userData.username); - if (previousUser) { + if (previousUser) + { bool userUpdated = false; - if (previousUser->setOAuthClient(userData.clientID)) { + if (previousUser->setOAuthClient(userData.clientID)) + { userUpdated = true; } - if (previousUser->setOAuthToken(userData.oauthToken)) { + if (previousUser->setOAuthToken(userData.oauthToken)) + { userUpdated = true; } - if (userUpdated) { + if (userUpdated) + { return AddUserResponse::UserValuesUpdated; - } else { + } + else + { return AddUserResponse::UserAlreadyExists; } } diff --git a/src/providers/twitch/TwitchApi.cpp b/src/providers/twitch/TwitchApi.cpp index eb4ddb0cf..f06cb1173 100644 --- a/src/providers/twitch/TwitchApi.cpp +++ b/src/providers/twitch/TwitchApi.cpp @@ -21,25 +21,29 @@ void TwitchApi::findUserId(const QString user, request.setTimeout(30000); request.onSuccess([successCallback](auto result) mutable -> Outcome { auto root = result.parseJson(); - if (!root.value("users").isArray()) { + if (!root.value("users").isArray()) + { log("API Error while getting user id, users is not an array"); successCallback(""); return Failure; } auto users = root.value("users").toArray(); - if (users.size() != 1) { + if (users.size() != 1) + { log("API Error while getting user id, users array size is not 1"); successCallback(""); return Failure; } - if (!users[0].isObject()) { + if (!users[0].isObject()) + { log("API Error while getting user id, first user is not an object"); successCallback(""); return Failure; } auto firstUser = users[0].toObject(); auto id = firstUser.value("_id"); - if (!id.isString()) { + if (!id.isString()) + { log("API Error: while getting user id, first user object `_id` key " "is not a " "string"); diff --git a/src/providers/twitch/TwitchBadges.cpp b/src/providers/twitch/TwitchBadges.cpp index 4bd1bd771..9313fdc02 100644 --- a/src/providers/twitch/TwitchBadges.cpp +++ b/src/providers/twitch/TwitchBadges.cpp @@ -24,11 +24,13 @@ void TwitchBadges::loadTwitchBadges() auto badgeSets = this->badgeSets_.access(); auto jsonSets = root.value("badge_sets").toObject(); - for (auto sIt = jsonSets.begin(); sIt != jsonSets.end(); ++sIt) { + for (auto sIt = jsonSets.begin(); sIt != jsonSets.end(); ++sIt) + { auto key = sIt.key(); auto versions = sIt.value().toObject().value("versions").toObject(); - for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt) { + for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt) + { auto versionObj = vIt.value().toObject(); auto emote = Emote{ @@ -61,9 +63,11 @@ boost::optional TwitchBadges::badge(const QString &set, { auto badgeSets = this->badgeSets_.access(); auto it = badgeSets->find(set); - if (it != badgeSets->end()) { + if (it != badgeSets->end()) + { auto it2 = it->second.find(version); - if (it2 != it->second.end()) { + if (it2 != it->second.end()) + { return it2->second; } } diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index a75c1b8f2..3b8756ecb 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -34,9 +34,11 @@ namespace { QJsonArray jsonMessages = jsonRoot.value("messages").toArray(); std::vector messages; - if (jsonMessages.empty()) return messages; + if (jsonMessages.empty()) + return messages; - for (const auto jsonMessage : jsonMessages) { + for (const auto jsonMessage : jsonMessages) + { auto content = jsonMessage.toString().toUtf8(); // passing nullptr as the channel makes the message invalid but we // don't check for that anyways @@ -46,7 +48,8 @@ namespace { MessageParseArgs args; TwitchMessageBuilder builder(channel.get(), privMsg, args); - if (!builder.isIgnored()) { + if (!builder.isIgnored()) + { messages.push_back(builder.build()); } } @@ -63,8 +66,10 @@ namespace { // parse json QJsonObject jsonCategories = jsonRoot.value("chatters").toObject(); - for (const auto &category : categories) { - for (auto jsonCategory : jsonCategories.value(category).toArray()) { + for (const auto &category : categories) + { + for (auto jsonCategory : jsonCategories.value(category).toArray()) + { usernames.insert(jsonCategory.toString()); } } @@ -90,7 +95,8 @@ TwitchChannel::TwitchChannel(const QString &name, log("[TwitchChannel:{}] Opened", name); this->liveStatusChanged.connect([this]() { - if (this->isLive() == 1) { + if (this->isLive() == 1) + { } }); @@ -168,7 +174,8 @@ void TwitchChannel::sendMessage(const QString &message) { auto app = getApp(); - if (!app->accounts->twitch.isLoggedIn()) { + if (!app->accounts->twitch.isLoggedIn()) + { // XXX: It would be nice if we could add a link here somehow that opened // the "account manager" dialog this->addMessage( @@ -184,13 +191,17 @@ void TwitchChannel::sendMessage(const QString &message) parsedMessage = parsedMessage.trimmed(); - if (parsedMessage.isEmpty()) { + if (parsedMessage.isEmpty()) + { return; } - if (!this->hasModRights()) { - if (getSettings()->allowDuplicateMessages) { - if (parsedMessage == this->lastSentMessage_) { + if (!this->hasModRights()) + { + if (getSettings()->allowDuplicateMessages) + { + if (parsedMessage == this->lastSentMessage_) + { parsedMessage.append(this->messageSuffix_); } } @@ -199,7 +210,8 @@ void TwitchChannel::sendMessage(const QString &message) bool messageSent = false; this->sendMessageSignal.invoke(this->getName(), parsedMessage, messageSent); - if (messageSent) { + if (messageSent) + { qDebug() << "sent"; this->lastSentMessage_ = parsedMessage; } @@ -212,7 +224,8 @@ bool TwitchChannel::isMod() const void TwitchChannel::setMod(bool value) { - if (this->mod_ != value) { + if (this->mod_ != value) + { this->mod_ = value; this->userStateChanged.invoke(); @@ -235,14 +248,16 @@ void TwitchChannel::addJoinedUser(const QString &user) { auto app = getApp(); if (user == app->accounts->twitch.getCurrent()->getUserName() || - !getSettings()->showJoins.getValue()) { + !getSettings()->showJoins.getValue()) + { return; } auto joinedUsers = this->joinedUsers_.access(); joinedUsers->append(user); - if (!this->joinedUsersMergeQueued_) { + if (!this->joinedUsersMergeQueued_) + { this->joinedUsersMergeQueued_ = true; QTimer::singleShot(500, &this->lifetimeGuard_, [this] { @@ -263,14 +278,16 @@ void TwitchChannel::addPartedUser(const QString &user) auto app = getApp(); if (user == app->accounts->twitch.getCurrent()->getUserName() || - !getSettings()->showJoins.getValue()) { + !getSettings()->showJoins.getValue()) + { return; } auto partedUsers = this->partedUsers_.access(); partedUsers->append(user); - if (!this->partedUsersMergeQueued_) { + if (!this->partedUsersMergeQueued_) + { this->partedUsersMergeQueued_ = true; QTimer::singleShot(500, &this->lifetimeGuard_, [this] { @@ -294,7 +311,8 @@ QString TwitchChannel::roomId() const void TwitchChannel::setRoomId(const QString &id) { - if (*this->roomID_.accessConst() != id) { + if (*this->roomID_.accessConst() != id) + { *this->roomID_.access() = id; this->roomIdChanged.invoke(); this->loadRecentMessages(); @@ -350,7 +368,8 @@ boost::optional TwitchChannel::bttvEmote(const EmoteName &name) const auto emotes = this->bttvEmotes_.get(); auto it = emotes->find(name); - if (it == emotes->end()) return boost::none; + if (it == emotes->end()) + return boost::none; return it->second; } @@ -359,7 +378,8 @@ boost::optional TwitchChannel::ffzEmote(const EmoteName &name) const auto emotes = this->ffzEmotes_.get(); auto it = emotes->find(name); - if (it == emotes->end()) return boost::none; + if (it == emotes->end()) + return boost::none; return it->second; } @@ -393,25 +413,33 @@ void TwitchChannel::setLive(bool newLiveStatus) bool gotNewLiveStatus = false; { auto guard = this->streamStatus_.access(); - if (guard->live != newLiveStatus) { + if (guard->live != newLiveStatus) + { gotNewLiveStatus = true; - if (newLiveStatus) { + if (newLiveStatus) + { if (getApp()->notifications->isChannelNotified( - this->getName(), Platform::Twitch)) { - if (Toasts::isEnabled()) { + this->getName(), Platform::Twitch)) + { + if (Toasts::isEnabled()) + { getApp()->toasts->sendChannelNotification( this->getName(), Platform::Twitch); } - if (getSettings()->notificationPlaySound) { + if (getSettings()->notificationPlaySound) + { getApp()->notifications->playSound(); } - if (getSettings()->notificationFlashTaskbar) { + if (getSettings()->notificationFlashTaskbar) + { getApp()->windows->sendAlert(); } } auto live = makeSystemMessage(this->getName() + " is live"); this->addMessage(live); - } else { + } + else + { auto offline = makeSystemMessage(this->getName() + " is offline"); this->addMessage(offline); @@ -420,7 +448,8 @@ void TwitchChannel::setLive(bool newLiveStatus) } } - if (gotNewLiveStatus) { + if (gotNewLiveStatus) + { this->liveStatusChanged.invoke(); } } @@ -429,7 +458,8 @@ void TwitchChannel::refreshLiveStatus() { auto roomID = this->roomId(); - if (roomID.isEmpty()) { + if (roomID.isEmpty()) + { log("[TwitchChannel:{}] Refreshing live status (Missing ID)", this->getName()); this->setLive(false); @@ -450,7 +480,8 @@ void TwitchChannel::refreshLiveStatus() request.onSuccess( [this, weak = weakOf(this)](auto result) -> Outcome { ChannelPtr shared = weak.lock(); - if (!shared) return Failure; + if (!shared) + return Failure; return this->parseLiveStatus(result.parseRapidJson()); }); @@ -460,26 +491,30 @@ void TwitchChannel::refreshLiveStatus() Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document) { - if (!document.IsObject()) { + if (!document.IsObject()) + { log("[TwitchChannel:refreshLiveStatus] root is not an object"); return Failure; } - if (!document.HasMember("stream")) { + if (!document.HasMember("stream")) + { log("[TwitchChannel:refreshLiveStatus] Missing stream in root"); return Failure; } const auto &stream = document["stream"]; - if (!stream.IsObject()) { + if (!stream.IsObject()) + { // Stream is offline (stream is most likely null) this->setLive(false); return Failure; } if (!stream.HasMember("viewers") || !stream.HasMember("game") || - !stream.HasMember("channel") || !stream.HasMember("created_at")) { + !stream.HasMember("channel") || !stream.HasMember("created_at")) + { log("[TwitchChannel:refreshLiveStatus] Missing members in stream"); this->setLive(false); return Failure; @@ -487,7 +522,8 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document) const rapidjson::Value &streamChannel = stream["channel"]; - if (!streamChannel.IsObject() || !streamChannel.HasMember("status")) { + if (!streamChannel.IsObject() || !streamChannel.HasMember("status")) + { log("[TwitchChannel:refreshLiveStatus] Missing member \"status\" in " "channel"); return Failure; @@ -507,19 +543,25 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document) QString::number(diff % 3600 / 60) + "m"; status->rerun = false; - if (stream.HasMember("stream_type")) { + if (stream.HasMember("stream_type")) + { status->streamType = stream["stream_type"].GetString(); - } else { + } + else + { status->streamType = QString(); } - if (stream.HasMember("broadcast_platform")) { + if (stream.HasMember("broadcast_platform")) + { const auto &broadcastPlatformValue = stream["broadcast_platform"]; - if (broadcastPlatformValue.IsString()) { + if (broadcastPlatformValue.IsString()) + { const char *broadcastPlatform = stream["broadcast_platform"].GetString(); - if (strcmp(broadcastPlatform, "rerun") == 0) { + if (strcmp(broadcastPlatform, "rerun") == 0) + { status->rerun = true; } } @@ -546,7 +588,8 @@ void TwitchChannel::loadRecentMessages() request.onSuccess([weak = weakOf(this)](auto result) -> Outcome { auto shared = weak.lock(); - if (!shared) return Failure; + if (!shared) + return Failure; auto messages = parseRecentMessages(result.parseJson(), shared); @@ -561,9 +604,11 @@ void TwitchChannel::loadRecentMessages() void TwitchChannel::refreshPubsub() { // listen to moderation actions - if (!this->hasModRights()) return; + if (!this->hasModRights()) + return; auto roomId = this->roomId(); - if (roomId.isEmpty()) return; + if (roomId.isEmpty()) + return; auto account = getApp()->accounts->twitch.getCurrent(); getApp()->twitch2->pubsub->listenToChannelModerationActions(roomId, @@ -575,9 +620,11 @@ void TwitchChannel::refreshChatters() // setting? const auto streamStatus = this->accessStreamStatus(); - if (getSettings()->onlyFetchChattersForSmallerStreamers) { + if (getSettings()->onlyFetchChattersForSmallerStreamers) + { if (streamStatus->live && - streamStatus->viewerCount > getSettings()->smallStreamerLimit) { + streamStatus->viewerCount > getSettings()->smallStreamerLimit) + { return; } } @@ -591,10 +638,12 @@ void TwitchChannel::refreshChatters() [this, weak = weakOf(this)](auto result) -> Outcome { // channel still exists? auto shared = weak.lock(); - if (!shared) return Failure; + if (!shared) + return Failure; auto pair = parseChatters(result.parseJson()); - if (pair.first) { + if (pair.first) + { *this->chatters_.access() = std::move(pair.second); } @@ -613,7 +662,8 @@ void TwitchChannel::refreshBadges() req.onSuccess([this, weak = weakOf(this)](auto result) -> Outcome { auto shared = weak.lock(); - if (!shared) return Failure; + if (!shared) + return Failure; auto badgeSets = this->badgeSets_.access(); @@ -621,12 +671,14 @@ void TwitchChannel::refreshBadges() auto _ = jsonRoot["badge_sets"].toObject(); for (auto jsonBadgeSet = _.begin(); jsonBadgeSet != _.end(); - jsonBadgeSet++) { + jsonBadgeSet++) + { auto &versions = (*badgeSets)[jsonBadgeSet.key()]; auto _ = jsonBadgeSet->toObject()["versions"].toObject(); for (auto jsonVersion_ = _.begin(); jsonVersion_ != _.end(); - jsonVersion_++) { + jsonVersion_++) + { auto jsonVersion = jsonVersion_->toObject(); auto emote = std::make_shared(Emote{ EmoteName{}, @@ -719,9 +771,11 @@ boost::optional TwitchChannel::twitchBadge( { auto badgeSets = this->badgeSets_.access(); auto it = badgeSets->find(set); - if (it != badgeSets->end()) { + if (it != badgeSets->end()) + { auto it2 = it->second.find(version); - if (it2 != it->second.end()) { + if (it2 != it->second.end()) + { return it2->second; } } diff --git a/src/providers/twitch/TwitchEmotes.cpp b/src/providers/twitch/TwitchEmotes.cpp index 80a249b71..4f757d456 100644 --- a/src/providers/twitch/TwitchEmotes.cpp +++ b/src/providers/twitch/TwitchEmotes.cpp @@ -37,7 +37,8 @@ EmotePtr TwitchEmotes::getOrCreateEmote(const EmoteId &id, // replace regexes auto it = replacements.find(name); - if (it != replacements.end()) { + if (it != replacements.end()) + { name = it.value(); } @@ -45,7 +46,8 @@ EmotePtr TwitchEmotes::getOrCreateEmote(const EmoteId &id, auto cache = this->twitchEmotesCache_.access(); auto shared = (*cache)[id].lock(); - if (!shared) { + if (!shared) + { (*cache)[id] = shared = std::make_shared( Emote{EmoteName{name}, ImageSet{ diff --git a/src/providers/twitch/TwitchHelpers.cpp b/src/providers/twitch/TwitchHelpers.cpp index 32317c940..4189cea0c 100644 --- a/src/providers/twitch/TwitchHelpers.cpp +++ b/src/providers/twitch/TwitchHelpers.cpp @@ -5,7 +5,8 @@ namespace chatterino { bool trimChannelName(const QString &channelName, QString &outChannelName) { - if (channelName.length() < 2) { + if (channelName.length() < 2) + { log("channel name length below 2"); return false; } diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 5cf704664..e24cd6493 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -59,8 +59,10 @@ bool TwitchMessageBuilder::isIgnored() const auto app = getApp(); // TODO(pajlada): Do we need to check if the phrase is valid first? - for (const auto &phrase : app->ignores->phrases.getVector()) { - if (phrase.isBlock() && phrase.isMatch(this->originalMessage_)) { + for (const auto &phrase : app->ignores->phrases.getVector()) + { + if (phrase.isBlock() && phrase.isMatch(this->originalMessage_)) + { log("Blocking message because it contains ignored phrase {}", phrase.getPattern()); return true; @@ -68,12 +70,15 @@ bool TwitchMessageBuilder::isIgnored() const } if (getSettings()->enableTwitchIgnoredUsers && - this->tags.contains("user-id")) { + this->tags.contains("user-id")) + { auto sourceUserID = this->tags.value("user-id").toString(); for (const auto &user : - app->accounts->twitch.getCurrent()->getIgnores()) { - if (sourceUserID == user.id) { + app->accounts->twitch.getCurrent()->getIgnores()) + { + if (sourceUserID == user.id) + { log("Blocking message because it's from blocked user {}", user.name); return true; @@ -89,7 +94,8 @@ MessagePtr TwitchMessageBuilder::build() // PARSING this->parseUsername(); - if (this->userName == this->channel->getName()) { + if (this->userName == this->channel->getName()) + { this->senderIsBroadcaster = true; } @@ -104,32 +110,42 @@ MessagePtr TwitchMessageBuilder::build() // timestamp bool isPastMsg = this->tags.contains("historical"); - if (isPastMsg) { + if (isPastMsg) + { // This may be architecture dependent(datatype) qint64 ts = this->tags.value("tmi-sent-ts").toLongLong(); QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(ts); this->emplace(dateTime.time()); - } else { + } + else + { this->emplace(); } bool addModerationElement = true; - if (this->senderIsBroadcaster) { + if (this->senderIsBroadcaster) + { addModerationElement = false; - } else { + } + else + { bool hasUserType = this->tags.contains("user-type"); - if (hasUserType) { + if (hasUserType) + { QString userType = this->tags.value("user-type").toString(); - if (userType == "mod") { - if (!args.isStaffOrBroadcaster) { + if (userType == "mod") + { + if (!args.isStaffOrBroadcaster) + { addModerationElement = false; } } } } - if (addModerationElement) { + if (addModerationElement) + { this->emplace(); } @@ -144,7 +160,8 @@ MessagePtr TwitchMessageBuilder::build() // QString bits; auto iterator = this->tags.find("bits"); - if (iterator != this->tags.end()) { + if (iterator != this->tags.end()) + { this->hasBits_ = true; // bits = iterator.value().toString(); } @@ -153,10 +170,12 @@ MessagePtr TwitchMessageBuilder::build() std::vector> twitchEmotes; iterator = this->tags.find("emotes"); - if (iterator != this->tags.end()) { + if (iterator != this->tags.end()) + { QStringList emoteString = iterator.value().toString().split('/'); - for (QString emote : emoteString) { + for (QString emote : emoteString) + { this->appendTwitchEmote(emote, twitchEmotes); } } @@ -172,8 +191,10 @@ MessagePtr TwitchMessageBuilder::build() return !((std::get<0>(item) >= pos) && std::get<0>(item) < (pos + len)); }); - for (auto copy = it; copy != twitchEmotes.end(); ++copy) { - if (std::get<1>(*copy) == nullptr) { + for (auto copy = it; copy != twitchEmotes.end(); ++copy) + { + if (std::get<1>(*copy) == nullptr) + { log("remem nullptr {}", std::get<2>(*copy).string); } } @@ -184,9 +205,11 @@ MessagePtr TwitchMessageBuilder::build() }; auto shiftIndicesAfter = [&twitchEmotes](int pos, int by) mutable { - for (auto &item : twitchEmotes) { + for (auto &item : twitchEmotes) + { auto &index = std::get<0>(item); - if (index >= pos) { + if (index >= pos) + { index += by; } } @@ -195,16 +218,21 @@ MessagePtr TwitchMessageBuilder::build() auto addReplEmotes = [&twitchEmotes](const IgnorePhrase &phrase, const QStringRef &midrepl, int startIndex) mutable { - if (!phrase.containsEmote()) { + if (!phrase.containsEmote()) + { return; } QVector words = midrepl.split(' '); int pos = 0; - for (const auto &word : words) { - for (const auto &emote : phrase.getEmotes()) { - if (word == emote.first.string) { - if (emote.second == nullptr) { + for (const auto &word : words) + { + for (const auto &emote : phrase.getEmotes()) + { + if (word == emote.first.string) + { + if (emote.second == nullptr) + { log("emote null {}", emote.first.string); } twitchEmotes.push_back(std::tuple{ @@ -215,19 +243,24 @@ MessagePtr TwitchMessageBuilder::build() } }; - for (const auto &phrase : phrases) { - if (phrase.isBlock()) { + for (const auto &phrase : phrases) + { + if (phrase.isBlock()) + { continue; } - if (phrase.isRegex()) { + if (phrase.isRegex()) + { const auto ®ex = phrase.getRegex(); - if (!regex.isValid()) { + if (!regex.isValid()) + { continue; } QRegularExpressionMatch match; int from = 0; while ((from = this->originalMessage_.indexOf(regex, from, - &match)) != -1) { + &match)) != -1) + { int len = match.capturedLength(); auto vret = removeEmotesInRange(from, len, twitchEmotes); auto mid = this->originalMessage_.mid(from, len); @@ -236,15 +269,19 @@ MessagePtr TwitchMessageBuilder::build() int midsize = mid.size(); this->originalMessage_.replace(from, len, mid); int pos1 = from; - while (pos1 > 0) { - if (this->originalMessage_[pos1 - 1] == ' ') { + while (pos1 > 0) + { + if (this->originalMessage_[pos1 - 1] == ' ') + { break; } --pos1; } int pos2 = from + midsize; - while (pos2 < this->originalMessage_.length()) { - if (this->originalMessage_[pos2] == ' ') { + while (pos2 < this->originalMessage_.length()) + { + if (this->originalMessage_[pos2] == ' ') + { break; } ++pos2; @@ -255,8 +292,10 @@ MessagePtr TwitchMessageBuilder::build() auto midExtendedRef = this->originalMessage_.midRef(pos1, pos2 - pos1); - for (auto &tup : vret) { - if (std::get<1>(tup) == nullptr) { + for (auto &tup : vret) + { + if (std::get<1>(tup) == nullptr) + { log("v nullptr {}", std::get<2>(tup).string); continue; } @@ -264,9 +303,11 @@ MessagePtr TwitchMessageBuilder::build() "\\b" + std::get<2>(tup).string + "\\b", QRegularExpression::UseUnicodePropertiesOption); auto match = emoteregex.match(midExtendedRef); - if (match.hasMatch()) { + if (match.hasMatch()) + { int last = match.lastCapturedIndex(); - for (int i = 0; i <= last; ++i) { + for (int i = 0; i <= last; ++i) + { std::get<0>(tup) = from + match.capturedStart(); twitchEmotes.push_back(std::move(tup)); } @@ -277,14 +318,18 @@ MessagePtr TwitchMessageBuilder::build() from += midsize; } - } else { + } + else + { const auto &pattern = phrase.getPattern(); - if (pattern.isEmpty()) { + if (pattern.isEmpty()) + { continue; } int from = 0; while ((from = this->originalMessage_.indexOf( - pattern, from, phrase.caseSensitivity())) != -1) { + pattern, from, phrase.caseSensitivity())) != -1) + { int len = pattern.size(); auto vret = removeEmotesInRange(from, len, twitchEmotes); auto replace = phrase.getReplace(); @@ -293,15 +338,19 @@ MessagePtr TwitchMessageBuilder::build() this->originalMessage_.replace(from, len, replace); int pos1 = from; - while (pos1 > 0) { - if (this->originalMessage_[pos1 - 1] == ' ') { + while (pos1 > 0) + { + if (this->originalMessage_[pos1 - 1] == ' ') + { break; } --pos1; } int pos2 = from + replacesize; - while (pos2 < this->originalMessage_.length()) { - if (this->originalMessage_[pos2] == ' ') { + while (pos2 < this->originalMessage_.length()) + { + if (this->originalMessage_[pos2] == ' ') + { break; } ++pos2; @@ -312,8 +361,10 @@ MessagePtr TwitchMessageBuilder::build() auto midExtendedRef = this->originalMessage_.midRef(pos1, pos2 - pos1); - for (auto &tup : vret) { - if (std::get<1>(tup) == nullptr) { + for (auto &tup : vret) + { + if (std::get<1>(tup) == nullptr) + { log("v nullptr {}", std::get<2>(tup).string); continue; } @@ -321,9 +372,11 @@ MessagePtr TwitchMessageBuilder::build() "\\b" + std::get<2>(tup).string + "\\b", QRegularExpression::UseUnicodePropertiesOption); auto match = emoteregex.match(midExtendedRef); - if (match.hasMatch()) { + if (match.hasMatch()) + { int last = match.lastCapturedIndex(); - for (int i = 0; i <= last; ++i) { + for (int i = 0; i <= last; ++i) + { std::get<0>(tup) = from + match.capturedStart(); twitchEmotes.push_back(std::move(tup)); } @@ -365,16 +418,20 @@ void TwitchMessageBuilder::addWords( auto i = int(); auto currentTwitchEmote = twitchEmotes.begin(); - for (const auto &word : words) { + for (const auto &word : words) + { // check if it's a twitch emote twitch emote while (currentTwitchEmote != twitchEmotes.end() && - std::get<0>(*currentTwitchEmote) < i) { + std::get<0>(*currentTwitchEmote) < i) + { ++currentTwitchEmote; } if (currentTwitchEmote != twitchEmotes.end() && - std::get<0>(*currentTwitchEmote) == i) { + std::get<0>(*currentTwitchEmote) == i) + { auto emoteImage = std::get<1>(*currentTwitchEmote); - if (emoteImage == nullptr) { + if (emoteImage == nullptr) + { log("emoteImage nullptr {}", std::get<2>(*currentTwitchEmote).string); } @@ -388,15 +445,18 @@ void TwitchMessageBuilder::addWords( } // split words - for (auto &variant : getApp()->emotes->emojis.parse(word)) { + for (auto &variant : getApp()->emotes->emojis.parse(word)) + { boost::apply_visitor([&](auto &&arg) { this->addTextOrEmoji(arg); }, variant); } - for (int j = 0; j < word.size(); j++) { + for (int j = 0; j < word.size(); j++) + { i++; - if (word.at(j).isHighSurrogate()) { + if (word.at(j).isHighSurrogate()) + { j++; } } @@ -414,7 +474,8 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) { auto string = QString(string_); - if (this->hasBits_ && this->tryParseCheermote(string)) { + if (this->hasBits_ && this->tryParseCheermote(string)) + { // This string was parsed as a cheermote return; } @@ -424,7 +485,8 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) // Emote name: "forsenPuke" - if string in ignoredEmotes // Will match emote regardless of source (i.e. bttv, ffz) // Emote source + name: "bttv:nyanPls" - if (this->tryAppendEmote({string})) { + if (this->tryAppendEmote({string})) + { // Successfully appended an emote return; } @@ -435,28 +497,37 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) auto textColor = this->action_ ? MessageColor(this->usernameColor_) : MessageColor(MessageColor::Text); - if (linkString.isEmpty()) { - if (string.startsWith('@')) { + if (linkString.isEmpty()) + { + if (string.startsWith('@')) + { this->emplace(string, MessageElementFlag::BoldUsername, textColor, FontStyle::ChatMediumBold); this->emplace( string, MessageElementFlag::NonBoldUsername, textColor); - } else { + } + else + { this->emplace(string, MessageElementFlag::Text, textColor); } - } else { + } + else + { static QRegularExpression domainRegex( R"(^(?:(?:ftp|http)s?:\/\/)?([^\/]+)(?:\/.*)?$)", QRegularExpression::CaseInsensitiveOption); QString lowercaseLinkString; auto match = domainRegex.match(string); - if (match.isValid()) { + if (match.isValid()) + { lowercaseLinkString = string.mid(0, match.capturedStart(1)) + match.captured(1).toLower() + string.mid(match.capturedEnd(1)); - } else { + } + else + { lowercaseLinkString = string; } link = Link(Link::Url, linkString); @@ -475,12 +546,14 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) LinkResolver::getLinkInfo( linkString, [linkMELowercase, linkMEOriginal, linkString]( QString tooltipText, Link originalLink) { - if (!tooltipText.isEmpty()) { + if (!tooltipText.isEmpty()) + { linkMELowercase->setTooltip(tooltipText); linkMEOriginal->setTooltip(tooltipText); } if (originalLink.value != linkString && - !originalLink.value.isEmpty()) { + !originalLink.value.isEmpty()) + { linkMELowercase->setLink(originalLink)->updateLink(); linkMEOriginal->setLink(originalLink)->updateLink(); } @@ -526,23 +599,27 @@ void TwitchMessageBuilder::parseMessageID() { auto iterator = this->tags.find("id"); - if (iterator != this->tags.end()) { + if (iterator != this->tags.end()) + { this->messageID = iterator.value().toString(); } } void TwitchMessageBuilder::parseRoomID() { - if (this->twitchChannel == nullptr) { + if (this->twitchChannel == nullptr) + { return; } auto iterator = this->tags.find("room-id"); - if (iterator != std::end(this->tags)) { + if (iterator != std::end(this->tags)) + { this->roomID_ = iterator.value().toString(); - if (this->twitchChannel->roomId().isEmpty()) { + if (this->twitchChannel->roomId().isEmpty()) + { this->twitchChannel->setRoomId(this->roomID_); } } @@ -561,14 +638,16 @@ void TwitchMessageBuilder::appendChannelName() void TwitchMessageBuilder::parseUsername() { auto iterator = this->tags.find("color"); - if (iterator != this->tags.end()) { + if (iterator != this->tags.end()) + { this->usernameColor_ = QColor(iterator.value().toString()); } // username this->userName = this->ircMessage->nick(); - if (this->userName.isEmpty() || this->args.trimSubscriberUsername) { + if (this->userName.isEmpty() || this->args.trimSubscriberUsername) + { this->userName = this->tags.value(QLatin1String("login")).toString(); } @@ -591,16 +670,20 @@ void TwitchMessageBuilder::appendUsername() QString localizedName; auto iterator = this->tags.find("display-name"); - if (iterator != this->tags.end()) { + if (iterator != this->tags.end()) + { QString displayName = parseTagString(iterator.value().toString()).trimmed(); if (QString::compare(displayName, this->userName, - Qt::CaseInsensitive) == 0) { + Qt::CaseInsensitive) == 0) + { username = displayName; this->message().displayName = displayName; - } else { + } + else + { localizedName = displayName; this->message().displayName = username; @@ -617,34 +700,50 @@ void TwitchMessageBuilder::appendUsername() "/appearance/messages/usernameDisplayMode", UsernameDisplayMode::UsernameAndLocalizedName); - switch (usernameDisplayMode.getValue()) { - case UsernameDisplayMode::Username: { + switch (usernameDisplayMode.getValue()) + { + case UsernameDisplayMode::Username: + { usernameText = username; - } break; + } + break; - case UsernameDisplayMode::LocalizedName: { - if (hasLocalizedName) { + case UsernameDisplayMode::LocalizedName: + { + if (hasLocalizedName) + { usernameText = localizedName; - } else { + } + else + { usernameText = username; } - } break; + } + break; default: - case UsernameDisplayMode::UsernameAndLocalizedName: { - if (hasLocalizedName) { + case UsernameDisplayMode::UsernameAndLocalizedName: + { + if (hasLocalizedName) + { usernameText = username + "(" + localizedName + ")"; - } else { + } + else + { usernameText = username; } - } break; + } + break; } - if (this->args.isSentWhisper) { + if (this->args.isSentWhisper) + { // TODO(pajlada): Re-implement // userDisplayString += // IrcManager::getInstance().getUser().getUserName(); - } else if (this->args.isReceivedWhisper) { + } + else if (this->args.isReceivedWhisper) + { // Sender username this->emplace(usernameText, MessageElementFlag::Username, this->usernameColor_, @@ -659,7 +758,8 @@ void TwitchMessageBuilder::appendUsername() FontStyle::ChatMedium); QColor selfColor = currentUser->color(); - if (!selfColor.isValid()) { + if (!selfColor.isValid()) + { selfColor = app->themes->messages.textColors.system; } @@ -667,8 +767,11 @@ void TwitchMessageBuilder::appendUsername() this->emplace(currentUser->getUserName() + ":", MessageElementFlag::Username, selfColor, FontStyle::ChatMediumBold); - } else { - if (!this->action_) { + } + else + { + if (!this->action_) + { usernameText += ":"; } @@ -690,7 +793,8 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg) QString currentUsername = currentUser->getUserName(); - if (this->ircMessage->nick() == currentUsername) { + if (this->ircMessage->nick() == currentUsername) + { currentUser->setColor(this->usernameColor_); // Do nothing. Highlights cannot be triggered by yourself return; @@ -698,14 +802,18 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg) // update the media player url if necessary QUrl highlightSoundUrl; - if (getSettings()->customHighlightSound) { + if (getSettings()->customHighlightSound) + { highlightSoundUrl = QUrl::fromLocalFile(getSettings()->pathHighlightSound.getValue()); - } else { + } + else + { highlightSoundUrl = QUrl("qrc:/sounds/ping2.wav"); } - if (currentPlayerUrl != highlightSoundUrl) { + if (currentPlayerUrl != highlightSoundUrl) + { player->setMedia(highlightSoundUrl); currentPlayerUrl = highlightSoundUrl; @@ -718,7 +826,8 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg) std::vector userHighlights = app->highlights->highlightedUsers.getVector(); - if (getSettings()->enableSelfHighlight && currentUsername.size() > 0) { + if (getSettings()->enableSelfHighlight && currentUsername.size() > 0) + { HighlightPhrase selfHighlight( currentUsername, getSettings()->enableSelfHighlightTaskbar, getSettings()->enableSelfHighlightSound, false); @@ -731,22 +840,28 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg) bool hasFocus = (QApplication::focusWidget() != nullptr); - if (!app->highlights->blacklistContains(this->ircMessage->nick())) { - for (const HighlightPhrase &highlight : activeHighlights) { - if (highlight.isMatch(this->originalMessage_)) { + if (!app->highlights->blacklistContains(this->ircMessage->nick())) + { + for (const HighlightPhrase &highlight : activeHighlights) + { + if (highlight.isMatch(this->originalMessage_)) + { log("Highlight because {} matches {}", this->originalMessage_, highlight.getPattern()); doHighlight = true; - if (highlight.getAlert()) { + if (highlight.getAlert()) + { doAlert = true; } - if (highlight.getSound()) { + if (highlight.getSound()) + { playSound = true; } - if (playSound && doAlert) { + if (playSound && doAlert) + { // Break if no further action can be taken from other // highlights This might change if highlights can have // custom colors/sounds/actions @@ -754,21 +869,26 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg) } } } - for (const HighlightPhrase &userHighlight : userHighlights) { - if (userHighlight.isMatch(this->ircMessage->nick())) { + for (const HighlightPhrase &userHighlight : userHighlights) + { + if (userHighlight.isMatch(this->ircMessage->nick())) + { log("Highlight because user {} sent a message", this->ircMessage->nick()); doHighlight = true; - if (userHighlight.getAlert()) { + if (userHighlight.getAlert()) + { doAlert = true; } - if (userHighlight.getSound()) { + if (userHighlight.getSound()) + { playSound = true; } - if (playSound && doAlert) { + if (playSound && doAlert) + { // Break if no further action can be taken from other // usernames Mostly used for regex stuff break; @@ -776,24 +896,30 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg) } } if (this->args.isReceivedWhisper && - getSettings()->enableWhisperHighlight) { - if (getSettings()->enableWhisperHighlightTaskbar) { + getSettings()->enableWhisperHighlight) + { + if (getSettings()->enableWhisperHighlightTaskbar) + { doAlert = true; } - if (getSettings()->enableWhisperHighlightSound) { + if (getSettings()->enableWhisperHighlightSound) + { playSound = true; } } this->message().flags.set(MessageFlag::Highlighted, doHighlight); - if (!isPastMsg) { + if (!isPastMsg) + { if (playSound && - (!hasFocus || getSettings()->highlightAlwaysPlaySound)) { + (!hasFocus || getSettings()->highlightAlwaysPlaySound)) + { player->play(); } - if (doAlert) { + if (doAlert) + { getApp()->windows->sendAlert(); } } @@ -805,13 +931,15 @@ void TwitchMessageBuilder::appendTwitchEmote( std::vector> &vec) { auto app = getApp(); - if (!emote.contains(':')) { + if (!emote.contains(':')) + { return; } auto parameters = emote.split(':'); - if (parameters.length() < 2) { + if (parameters.length() < 2) + { return; } @@ -819,18 +947,20 @@ void TwitchMessageBuilder::appendTwitchEmote( auto occurences = parameters.at(1).split(','); - for (QString occurence : occurences) { + for (QString occurence : occurences) + { auto coords = occurence.split('-'); - if (coords.length() < 2) { + if (coords.length() < 2) + { return; } auto start = coords.at(0).toInt(); auto end = coords.at(1).toInt(); - if (start >= end || start < 0 || - end > this->originalMessage_.length()) { + if (start >= end || start < 0 || end > this->originalMessage_.length()) + { return; } @@ -838,7 +968,8 @@ void TwitchMessageBuilder::appendTwitchEmote( EmoteName{this->originalMessage_.mid(start, end - start + 1)}; auto tup = std::tuple{ start, app->emotes->twitch.getOrCreateEmote(id, name), name}; - if (std::get<1>(tup) == nullptr) { + if (std::get<1>(tup) == nullptr) + { log("nullptr {}", std::get<2>(tup).string); } vec.push_back(std::move(tup)); @@ -849,24 +980,33 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) { // Special channels, like /whispers and /channels return here // This means they will not render any BTTV or FFZ emotes - if (this->twitchChannel == nullptr) { + if (this->twitchChannel == nullptr) + { return Failure; } auto flags = MessageElementFlags(); auto emote = boost::optional{}; - if ((emote = this->twitchChannel->globalBttv().emote(name))) { + if ((emote = this->twitchChannel->globalBttv().emote(name))) + { flags = MessageElementFlag::BttvEmote; - } else if ((emote = this->twitchChannel->bttvEmote(name))) { + } + else if ((emote = this->twitchChannel->bttvEmote(name))) + { flags = MessageElementFlag::BttvEmote; - } else if ((emote = this->twitchChannel->globalFfz().emote(name))) { + } + else if ((emote = this->twitchChannel->globalFfz().emote(name))) + { flags = MessageElementFlag::FfzEmote; - } else if ((emote = this->twitchChannel->ffzEmote(name))) { + } + else if ((emote = this->twitchChannel->ffzEmote(name))) + { flags = MessageElementFlag::FfzEmote; } - if (emote) { + if (emote) + { this->emplace(emote.get(), flags); return Success; } @@ -877,96 +1017,129 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) // fourtf: this is ugly void TwitchMessageBuilder::appendTwitchBadges() { - if (this->twitchChannel == nullptr) { + if (this->twitchChannel == nullptr) + { return; } auto app = getApp(); auto iterator = this->tags.find("badges"); - if (iterator == this->tags.end()) return; + if (iterator == this->tags.end()) + return; - for (QString badge : iterator.value().toString().split(',')) { - if (badge.startsWith("bits/")) { + for (QString badge : iterator.value().toString().split(',')) + { + if (badge.startsWith("bits/")) + { QString cheerAmount = badge.mid(5); QString tooltip = QString("Twitch cheer ") + cheerAmount; // Try to fetch channel-specific bit badge - try { + try + { if (twitchChannel) if (const auto &badge = this->twitchChannel->twitchBadge( - "bits", cheerAmount)) { + "bits", cheerAmount)) + { this->emplace( badge.get(), MessageElementFlag::BadgeVanity) ->setTooltip(tooltip); continue; } - } catch (const std::out_of_range &) { + } + catch (const std::out_of_range &) + { // Channel does not contain a special bit badge for this version } // Use default bit badge if (auto badge = this->twitchChannel->globalTwitchBadges().badge( - "bits", cheerAmount)) { + "bits", cheerAmount)) + { this->emplace(badge.get(), MessageElementFlag::BadgeVanity) ->setTooltip(tooltip); } - } else if (badge == "staff/1") { + } + else if (badge == "staff/1") + { this->emplace( Image::fromPixmap(app->resources->twitch.staff), MessageElementFlag::BadgeGlobalAuthority) ->setTooltip("Twitch Staff"); - } else if (badge == "admin/1") { + } + else if (badge == "admin/1") + { this->emplace( Image::fromPixmap(app->resources->twitch.admin), MessageElementFlag::BadgeGlobalAuthority) ->setTooltip("Twitch Admin"); - } else if (badge == "global_mod/1") { + } + else if (badge == "global_mod/1") + { this->emplace( Image::fromPixmap(app->resources->twitch.globalmod), MessageElementFlag::BadgeGlobalAuthority) ->setTooltip("Twitch Global Moderator"); - } else if (badge == "moderator/1") { + } + else if (badge == "moderator/1") + { // TODO: Implement custom FFZ moderator badge this->emplace( Image::fromPixmap(app->resources->twitch.moderator), MessageElementFlag::BadgeChannelAuthority) ->setTooltip("Twitch Channel Moderator"); - } else if (badge == "turbo/1") { + } + else if (badge == "turbo/1") + { this->emplace( Image::fromPixmap(app->resources->twitch.turbo), MessageElementFlag::BadgeGlobalAuthority) ->setTooltip("Twitch Turbo Subscriber"); - } else if (badge == "broadcaster/1") { + } + else if (badge == "broadcaster/1") + { this->emplace( Image::fromPixmap(app->resources->twitch.broadcaster), MessageElementFlag::BadgeChannelAuthority) ->setTooltip("Twitch Broadcaster"); - } else if (badge == "premium/1") { + } + else if (badge == "premium/1") + { this->emplace( Image::fromPixmap(app->resources->twitch.prime), MessageElementFlag::BadgeVanity) ->setTooltip("Twitch Prime Subscriber"); - } else if (badge.startsWith("partner/")) { + } + else if (badge.startsWith("partner/")) + { int index = badge.midRef(8).toInt(); - switch (index) { - case 1: { + switch (index) + { + case 1: + { this->emplace( Image::fromPixmap(app->resources->twitch.verified, 0.25), MessageElementFlag::BadgeVanity) ->setTooltip("Twitch Verified"); - } break; - default: { + } + break; + default: + { printf("[TwitchMessageBuilder] Unhandled partner badge " "index: %d\n", index); - } break; + } + break; } - } else if (badge.startsWith("subscriber/")) { + } + else if (badge.startsWith("subscriber/")) + { if (auto badgeEmote = this->twitchChannel->twitchBadge( - "subscriber", badge.mid(11))) { + "subscriber", badge.mid(11))) + { this->emplace( badgeEmote.get(), MessageElementFlag::BadgeSubscription) ->setTooltip((*badgeEmote)->tooltip.string); @@ -978,12 +1151,16 @@ void TwitchMessageBuilder::appendTwitchBadges() Image::fromPixmap(app->resources->twitch.subscriber, 0.25), MessageElementFlag::BadgeSubscription) ->setTooltip("Twitch Subscriber"); - } else { + } + else + { auto splits = badge.split('/'); - if (splits.size() != 2) continue; + if (splits.size() != 2) + continue; if (auto badgeEmote = - this->twitchChannel->twitchBadge(splits[0], splits[1])) { + this->twitchChannel->twitchBadge(splits[0], splits[1])) + { this->emplace(badgeEmote.get(), MessageElementFlag::BadgeVanity) ->setTooltip((*badgeEmote)->tooltip.string); @@ -997,7 +1174,8 @@ void TwitchMessageBuilder::appendChatterinoBadges() { auto chatterinoBadgePtr = getApp()->chatterinoBadges->getBadge({this->userName}); - if (chatterinoBadgePtr) { + if (chatterinoBadgePtr) + { this->emplace(*chatterinoBadgePtr, MessageElementFlag::BadgeChatterino); } diff --git a/src/providers/twitch/TwitchParseCheerEmotes.cpp b/src/providers/twitch/TwitchParseCheerEmotes.cpp index 65eca1fa3..5258baf9a 100644 --- a/src/providers/twitch/TwitchParseCheerEmotes.cpp +++ b/src/providers/twitch/TwitchParseCheerEmotes.cpp @@ -12,13 +12,15 @@ namespace { inline bool ReadValue(const rapidjson::Value &object, const char *key, Type &out) { - if (!object.HasMember(key)) { + if (!object.HasMember(key)) + { return false; } const auto &value = object[key]; - if (!value.Is()) { + if (!value.Is()) + { return false; } @@ -31,13 +33,15 @@ namespace { inline bool ReadValue(const rapidjson::Value &object, const char *key, QString &out) { - if (!object.HasMember(key)) { + if (!object.HasMember(key)) + { return false; } const auto &value = object[key]; - if (!value.IsString()) { + if (!value.IsString()) + { return false; } @@ -51,18 +55,22 @@ namespace { const char *key, std::vector &out) { - if (!object.HasMember(key)) { + if (!object.HasMember(key)) + { return false; } const auto &value = object[key]; - if (!value.IsArray()) { + if (!value.IsArray()) + { return false; } - for (const rapidjson::Value &innerValue : value.GetArray()) { - if (!innerValue.IsString()) { + for (const rapidjson::Value &innerValue : value.GetArray()) + { + if (!innerValue.IsString()) + { return false; } @@ -76,141 +84,173 @@ namespace { inline bool ParseSingleCheermoteSet(JSONCheermoteSet &set, const rapidjson::Value &action) { - if (!action.IsObject()) { + if (!action.IsObject()) + { return false; } - if (!ReadValue(action, "prefix", set.prefix)) { + if (!ReadValue(action, "prefix", set.prefix)) + { return false; } - if (!ReadValue(action, "scales", set.scales)) { + if (!ReadValue(action, "scales", set.scales)) + { return false; } - if (!ReadValue(action, "backgrounds", set.backgrounds)) { + if (!ReadValue(action, "backgrounds", set.backgrounds)) + { return false; } - if (!ReadValue(action, "states", set.states)) { + if (!ReadValue(action, "states", set.states)) + { return false; } - if (!ReadValue(action, "type", set.type)) { + if (!ReadValue(action, "type", set.type)) + { return false; } - if (!ReadValue(action, "updated_at", set.updatedAt)) { + if (!ReadValue(action, "updated_at", set.updatedAt)) + { return false; } - if (!ReadValue(action, "priority", set.priority)) { + if (!ReadValue(action, "priority", set.priority)) + { return false; } // Tiers - if (!action.HasMember("tiers")) { + if (!action.HasMember("tiers")) + { return false; } const auto &tiersValue = action["tiers"]; - if (!tiersValue.IsArray()) { + if (!tiersValue.IsArray()) + { return false; } - for (const rapidjson::Value &tierValue : tiersValue.GetArray()) { + for (const rapidjson::Value &tierValue : tiersValue.GetArray()) + { JSONCheermoteSet::CheermoteTier tier; - if (!tierValue.IsObject()) { + if (!tierValue.IsObject()) + { return false; } - if (!ReadValue(tierValue, "min_bits", tier.minBits)) { + if (!ReadValue(tierValue, "min_bits", tier.minBits)) + { return false; } - if (!ReadValue(tierValue, "id", tier.id)) { + if (!ReadValue(tierValue, "id", tier.id)) + { return false; } - if (!ReadValue(tierValue, "color", tier.color)) { + if (!ReadValue(tierValue, "color", tier.color)) + { return false; } // Images - if (!tierValue.HasMember("images")) { + if (!tierValue.HasMember("images")) + { return false; } const auto &imagesValue = tierValue["images"]; - if (!imagesValue.IsObject()) { + if (!imagesValue.IsObject()) + { return false; } // Read images object - for (const auto &imageBackgroundValue : imagesValue.GetObject()) { + for (const auto &imageBackgroundValue : imagesValue.GetObject()) + { QString background = imageBackgroundValue.name.GetString(); bool backgroundExists = false; - for (const auto &bg : set.backgrounds) { - if (background == bg) { + for (const auto &bg : set.backgrounds) + { + if (background == bg) + { backgroundExists = true; break; } } - if (!backgroundExists) { + if (!backgroundExists) + { continue; } const rapidjson::Value &imageBackgroundStates = imageBackgroundValue.value; - if (!imageBackgroundStates.IsObject()) { + if (!imageBackgroundStates.IsObject()) + { continue; } // Read each key which represents a background for (const auto &imageBackgroundState : - imageBackgroundStates.GetObject()) { + imageBackgroundStates.GetObject()) + { QString state = imageBackgroundState.name.GetString(); bool stateExists = false; - for (const auto &_state : set.states) { - if (state == _state) { + for (const auto &_state : set.states) + { + if (state == _state) + { stateExists = true; break; } } - if (!stateExists) { + if (!stateExists) + { continue; } const rapidjson::Value &imageScalesValue = imageBackgroundState.value; - if (!imageScalesValue.IsObject()) { + if (!imageScalesValue.IsObject()) + { continue; } // Read each key which represents a scale for (const auto &imageScaleValue : - imageScalesValue.GetObject()) { + imageScalesValue.GetObject()) + { QString scale = imageScaleValue.name.GetString(); bool scaleExists = false; - for (const auto &_scale : set.scales) { - if (scale == _scale) { + for (const auto &_scale : set.scales) + { + if (scale == _scale) + { scaleExists = true; break; } } - if (!scaleExists) { + if (!scaleExists) + { continue; } const rapidjson::Value &imageScaleURLValue = imageScaleValue.value; - if (!imageScaleURLValue.IsString()) { + if (!imageScaleURLValue.IsString()) + { continue; } @@ -218,7 +258,8 @@ namespace { bool ok = false; qreal scaleNumber = scale.toFloat(&ok); - if (!ok) { + if (!ok) + { continue; } @@ -246,25 +287,30 @@ std::vector ParseCheermoteSets(const rapidjson::Document &d) { std::vector sets; - if (!d.IsObject()) { + if (!d.IsObject()) + { return sets; } - if (!d.HasMember("actions")) { + if (!d.HasMember("actions")) + { return sets; } const auto &actionsValue = d["actions"]; - if (!actionsValue.IsArray()) { + if (!actionsValue.IsArray()) + { return sets; } - for (const auto &action : actionsValue.GetArray()) { + for (const auto &action : actionsValue.GetArray()) + { JSONCheermoteSet set; bool res = ParseSingleCheermoteSet(set, action); - if (res) { + if (res) + { sets.emplace_back(set); } } diff --git a/src/providers/twitch/TwitchServer.cpp b/src/providers/twitch/TwitchServer.cpp index d1e03b63b..c8b3427e2 100644 --- a/src/providers/twitch/TwitchServer.cpp +++ b/src/providers/twitch/TwitchServer.cpp @@ -58,7 +58,8 @@ void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead, QString username = account->getUserName(); QString oauthToken = account->getOAuthToken(); - if (!oauthToken.startsWith("oauth:")) { + if (!oauthToken.startsWith("oauth:")) + { oauthToken.prepend("oauth:"); } @@ -66,7 +67,8 @@ void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead, connection->setNickName(username); connection->setRealName(username); - if (!account->isAnon()) { + if (!account->isAnon()) + { connection->setPassword(oauthToken); } @@ -103,7 +105,8 @@ void TwitchServer::privateMessageReceived(Communi::IrcPrivateMessage *message) void TwitchServer::messageReceived(Communi::IrcMessage *message) { // this->readConnection - if (message->type() == Communi::IrcMessage::Type::Private) { + if (message->type() == Communi::IrcMessage::Type::Private) + { // We already have a handler for private messages return; } @@ -112,35 +115,55 @@ void TwitchServer::messageReceived(Communi::IrcMessage *message) auto &handler = IrcMessageHandler::getInstance(); - if (command == "ROOMSTATE") { + if (command == "ROOMSTATE") + { handler.handleRoomStateMessage(message); - } else if (command == "CLEARCHAT") { + } + else if (command == "CLEARCHAT") + { handler.handleClearChatMessage(message); - } else if (command == "USERSTATE") { + } + else if (command == "USERSTATE") + { handler.handleUserStateMessage(message); - } else if (command == "WHISPER") { + } + else if (command == "WHISPER") + { handler.handleWhisperMessage(message); - } else if (command == "USERNOTICE") { + } + else if (command == "USERNOTICE") + { handler.handleUserNoticeMessage(message, *this); - } else if (command == "MODE") { + } + else if (command == "MODE") + { handler.handleModeMessage(message); - } else if (command == "NOTICE") { + } + else if (command == "NOTICE") + { handler.handleNoticeMessage( static_cast(message)); - } else if (command == "JOIN") { + } + else if (command == "JOIN") + { handler.handleJoinMessage(message); - } else if (command == "PART") { + } + else if (command == "PART") + { handler.handlePartMessage(message); } } void TwitchServer::writeConnectionMessageReceived(Communi::IrcMessage *message) { - switch (message->type()) { - case Communi::IrcMessage::Type::Notice: { + switch (message->type()) + { + case Communi::IrcMessage::Type::Notice: + { IrcMessageHandler::getInstance().handleWriteConnectionNoticeMessage( static_cast(message)); - } break; + } + break; default:; } @@ -149,11 +172,13 @@ void TwitchServer::writeConnectionMessageReceived(Communi::IrcMessage *message) std::shared_ptr TwitchServer::getCustomChannel( const QString &channelName) { - if (channelName == "/whispers") { + if (channelName == "/whispers") + { return this->whispersChannel; } - if (channelName == "/mentions") { + if (channelName == "/mentions") + { return this->mentionsChannel; } @@ -174,14 +199,18 @@ std::shared_ptr TwitchServer::getChannelOrEmptyByID( { std::lock_guard lock(this->channelMutex); - for (const auto &weakChannel : this->channels) { + for (const auto &weakChannel : this->channels) + { auto channel = weakChannel.lock(); - if (!channel) continue; + if (!channel) + continue; auto twitchChannel = std::dynamic_pointer_cast(channel); - if (!twitchChannel) continue; + if (!twitchChannel) + continue; - if (twitchChannel->roomId() == channelId) { + if (twitchChannel->roomId() == channelId) + { return twitchChannel; } } @@ -217,9 +246,10 @@ void TwitchServer::onMessageSendRequested(TwitchChannel *channel, auto now = std::chrono::steady_clock::now(); // check if you are sending messages too fast - if (!lastMessage.empty() && - lastMessage.back() + minMessageOffset > now) { - if (this->lastErrorTimeSpeed_ + 30s < now) { + if (!lastMessage.empty() && lastMessage.back() + minMessageOffset > now) + { + if (this->lastErrorTimeSpeed_ + 30s < now) + { auto errorMessage = makeSystemMessage("sending messages too fast"); @@ -231,13 +261,16 @@ void TwitchServer::onMessageSendRequested(TwitchChannel *channel, } // remove messages older than 30 seconds - while (!lastMessage.empty() && lastMessage.front() + 32s < now) { + while (!lastMessage.empty() && lastMessage.front() + 32s < now) + { lastMessage.pop(); } // check if you are sending too many messages - if (lastMessage.size() >= maxMessageCount) { - if (this->lastErrorTimeAmount_ + 30s < now) { + if (lastMessage.size() >= maxMessageCount) + { + if (this->lastErrorTimeAmount_ + 30s < now) + { auto errorMessage = makeSystemMessage("sending too many messages"); diff --git a/src/providers/twitch/TwitchUser.hpp b/src/providers/twitch/TwitchUser.hpp index 27539386d..6b68bec50 100644 --- a/src/providers/twitch/TwitchUser.hpp +++ b/src/providers/twitch/TwitchUser.hpp @@ -43,26 +43,30 @@ namespace Settings { TwitchUser user; - if (!value.IsObject()) { + if (!value.IsObject()) + { PAJLADA_REPORT_ERROR(error) PAJLADA_THROW_EXCEPTION( "Deserialized rapidjson::Value is wrong type"); return user; } - if (!rj::getSafe(value, "_id", user.id)) { + if (!rj::getSafe(value, "_id", user.id)) + { PAJLADA_REPORT_ERROR(error) PAJLADA_THROW_EXCEPTION("Missing ID key"); return user; } - if (!rj::getSafe(value, "name", user.name)) { + if (!rj::getSafe(value, "name", user.name)) + { PAJLADA_REPORT_ERROR(error) PAJLADA_THROW_EXCEPTION("Missing name key"); return user; } - if (!rj::getSafe(value, "display_name", user.displayName)) { + if (!rj::getSafe(value, "display_name", user.displayName)) + { PAJLADA_REPORT_ERROR(error) PAJLADA_THROW_EXCEPTION("Missing display name key"); return user; diff --git a/src/singletons/Fonts.cpp b/src/singletons/Fonts.cpp index 991646acd..1700f43b1 100644 --- a/src/singletons/Fonts.cpp +++ b/src/singletons/Fonts.cpp @@ -35,7 +35,8 @@ void Fonts::initialize(Settings &, Paths &) this->chatFontFamily.connect([this](const std::string &, auto) { assertInGuiThread(); - for (auto &map : this->fontsByType_) { + for (auto &map : this->fontsByType_) + { map.clear(); } this->fontChanged.invoke(); @@ -44,7 +45,8 @@ void Fonts::initialize(Settings &, Paths &) this->chatFontSize.connect([this](const int &, auto) { assertInGuiThread(); - for (auto &map : this->fontsByType_) { + for (auto &map : this->fontsByType_) + { map.clear(); } this->fontChanged.invoke(); @@ -55,7 +57,8 @@ void Fonts::initialize(Settings &, Paths &) getApp()->windows->incGeneration(); - for (auto &map : this->fontsByType_) { + for (auto &map : this->fontsByType_) + { map.clear(); } this->fontChanged.invoke(); @@ -82,7 +85,8 @@ Fonts::FontData &Fonts::getOrCreateFontData(FontStyle type, float scale) // find element auto it = map.find(scale); - if (it != map.end()) { + if (it != map.end()) + { // return if found return it->second; @@ -98,7 +102,8 @@ Fonts::FontData &Fonts::getOrCreateFontData(FontStyle type, float scale) Fonts::FontData Fonts::createFontData(FontStyle type, float scale) { // check if it's a chat (scale the setting) - if (type >= FontStyle::ChatStart && type <= FontStyle::ChatEnd) { + if (type >= FontStyle::ChatStart && type <= FontStyle::ChatEnd) + { static std::unordered_map sizeScale{ {FontStyle::ChatSmall, {0.6f, false, QFont::Normal}}, {FontStyle::ChatMediumSmall, {0.8f, false, QFont::Normal}}, diff --git a/src/singletons/Logging.cpp b/src/singletons/Logging.cpp index 9d5823564..0d4d59ed2 100644 --- a/src/singletons/Logging.cpp +++ b/src/singletons/Logging.cpp @@ -18,17 +18,21 @@ void Logging::initialize(Settings &settings, Paths &paths) void Logging::addMessage(const QString &channelName, MessagePtr message) { - if (!getSettings()->enableLogging) { + if (!getSettings()->enableLogging) + { return; } auto it = this->loggingChannels_.find(channelName); - if (it == this->loggingChannels_.end()) { + if (it == this->loggingChannels_.end()) + { auto channel = new LoggingChannel(channelName); channel->addMessage(message); this->loggingChannels_.emplace( channelName, std::unique_ptr(std::move(channel))); - } else { + } + else + { it->second->addMessage(message); } } diff --git a/src/singletons/NativeMessaging.cpp b/src/singletons/NativeMessaging.cpp index dc79afddc..54fbf8bf2 100644 --- a/src/singletons/NativeMessaging.cpp +++ b/src/singletons/NativeMessaging.cpp @@ -37,7 +37,8 @@ void registerNmManifest(Paths &paths, const QString &manifestFilename, void registerNmHost(Paths &paths) { - if (paths.isPortable()) return; + if (paths.isPortable()) + return; auto getBaseDocument = [&] { QJsonObject obj; @@ -112,11 +113,14 @@ std::string &getNmQueueName(Paths &paths) void NativeMessagingClient::sendMessage(const QByteArray &array) { - try { + try + { ipc::message_queue messageQueue(ipc::open_only, "chatterino_gui"); messageQueue.try_send(array.data(), array.size(), 1); - } catch (ipc::interprocess_exception &ex) { + } + catch (ipc::interprocess_exception &ex) + { qDebug() << "send to gui process:" << ex.what(); } } @@ -144,8 +148,10 @@ void NativeMessagingServer::ReceiverThread::run() ipc::message_queue messageQueue(ipc::open_or_create, "chatterino_gui", 100, MESSAGE_SIZE); - while (true) { - try { + while (true) + { + try + { auto buf = std::make_unique(MESSAGE_SIZE); auto retSize = ipc::message_queue::size_type(); auto priority = static_cast(0); @@ -156,7 +162,9 @@ void NativeMessagingServer::ReceiverThread::run() QByteArray::fromRawData(buf.get(), retSize)); this->handleMessage(document.object()); - } catch (ipc::interprocess_exception &ex) { + } + catch (ipc::interprocess_exception &ex) + { qDebug() << "received from gui process:" << ex.what(); } } @@ -169,12 +177,14 @@ void NativeMessagingServer::ReceiverThread::handleMessage( QString action = root.value("action").toString(); - if (action.isNull()) { + if (action.isNull()) + { qDebug() << "NM action was null"; return; } - if (action == "select") { + if (action == "select") + { QString _type = root.value("type").toString(); bool attach = root.value("attach").toBool(); QString name = root.value("name").toString(); @@ -188,26 +198,31 @@ void NativeMessagingServer::ReceiverThread::handleMessage( args.width = root.value("size").toObject().value("width").toInt(-1); args.height = root.value("size").toObject().value("height").toInt(-1); - if (_type.isNull() || args.winId.isNull()) { + if (_type.isNull() || args.winId.isNull()) + { qDebug() << "NM type, name or winId missing"; attach = false; return; } #endif - if (_type == "twitch") { + if (_type == "twitch") + { postToThread([=] { - if (!name.isEmpty()) { + if (!name.isEmpty()) + { app->twitch.server->watchingChannel.reset( app->twitch.server->getOrAddChannel(name)); } - if (attach) { + if (attach) + { #ifdef USEWINSDK // if (args.height != -1) { auto *window = AttachedWindow::get(::GetForegroundWindow(), args); - if (!name.isEmpty()) { + if (!name.isEmpty()) + { window->setChannel( app->twitch.server->getOrAddChannel(name)); } @@ -216,14 +231,18 @@ void NativeMessagingServer::ReceiverThread::handleMessage( #endif } }); - - } else { + } + else + { qDebug() << "NM unknown channel type"; } - } else if (action == "detach") { + } + else if (action == "detach") + { QString winId = root.value("winId").toString(); - if (winId.isNull()) { + if (winId.isNull()) + { qDebug() << "NM winId missing"; return; } @@ -234,7 +253,9 @@ void NativeMessagingServer::ReceiverThread::handleMessage( AttachedWindow::detach(winId); }); #endif - } else { + } + else + { qDebug() << "NM unknown action " + action; } } diff --git a/src/singletons/Paths.cpp b/src/singletons/Paths.cpp index 2fd8cef85..3114cf2d6 100644 --- a/src/singletons/Paths.cpp +++ b/src/singletons/Paths.cpp @@ -49,7 +49,8 @@ QString Paths::cacheDirectory() auto path = cachePathSetting.getValue(); - if (path == "") { + if (path == "") + { return this->cacheDirectory_; } @@ -83,14 +84,16 @@ void Paths::initAppDataDirectory() this->rootAppDataDirectory = [&]() -> QString { // portable - if (this->isPortable()) { + if (this->isPortable()) + { return QCoreApplication::applicationDirPath(); } // permanent installation QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); - if (path.isEmpty()) { + if (path.isEmpty()) + { throw std::runtime_error( "Error finding writable location for settings"); } @@ -117,7 +120,8 @@ void Paths::initSubDirectories() auto path = combinePath(this->rootAppDataDirectory, QString::fromStdString(name)); - if (!QDir().mkpath(path)) { + if (!QDir().mkpath(path)) + { throw std::runtime_error( "Error creating appdata path %appdata%/chatterino/" + name); } diff --git a/src/singletons/Settings.cpp b/src/singletons/Settings.cpp index ea5318ab3..0cb2bef67 100644 --- a/src/singletons/Settings.cpp +++ b/src/singletons/Settings.cpp @@ -37,9 +37,11 @@ void Settings::saveSnapshot() rapidjson::Document *d = new rapidjson::Document(rapidjson::kObjectType); rapidjson::Document::AllocatorType &a = d->GetAllocator(); - for (const auto &weakSetting : _settings) { + for (const auto &weakSetting : _settings) + { auto setting = weakSetting.lock(); - if (!setting) { + if (!setting) + { continue; } @@ -55,22 +57,26 @@ void Settings::saveSnapshot() void Settings::restoreSnapshot() { - if (!this->snapshot_) { + if (!this->snapshot_) + { return; } const auto &snapshotObject = this->snapshot_->GetObject(); - for (const auto &weakSetting : _settings) { + for (const auto &weakSetting : _settings) + { auto setting = weakSetting.lock(); - if (!setting) { + if (!setting) + { log("Error stage 1 of loading"); continue; } const char *path = setting->getPath().c_str(); - if (!snapshotObject.HasMember(path)) { + if (!snapshotObject.HasMember(path)) + { log("Error stage 2 of loading"); continue; } diff --git a/src/singletons/Theme.cpp b/src/singletons/Theme.cpp index 6a4d937a4..38dd6f257 100644 --- a/src/singletons/Theme.cpp +++ b/src/singletons/Theme.cpp @@ -12,13 +12,20 @@ namespace detail { double getMultiplierByTheme(const QString &themeName) { - if (themeName == "Light") { + if (themeName == "Light") + { return 0.8; - } else if (themeName == "White") { + } + else if (themeName == "White") + { return 1.0; - } else if (themeName == "Black") { + } + else if (themeName == "Black") + { return -1.0; - } else if (themeName == "Dark") { + } + else if (themeName == "Dark") + { return -0.8; } @@ -88,7 +95,8 @@ void Theme::actuallyUpdate(double hue, double multiplier) QColor highlighted = lightWin ? QColor("#ff0000") : QColor("#ee6166"); /// TABS - if (lightWin) { + if (lightWin) + { this->tabs.regular = { QColor("#444"), {QColor("#fff"), QColor("#eee"), QColor("#fff")}, @@ -105,7 +113,9 @@ void Theme::actuallyUpdate(double hue, double multiplier) QColor("#000"), {QColor("#b4d7ff"), QColor("#b4d7ff"), QColor("#b4d7ff")}, {QColor("#00aeef"), QColor("#00aeef"), QColor("#00aeef")}}; - } else { + } + else + { this->tabs.regular = { QColor("#aaa"), {QColor("#252525"), QColor("#252525"), QColor("#252525")}, @@ -161,13 +171,16 @@ void Theme::actuallyUpdate(double hue, double multiplier) this->splits.dropPreview = QColor(0, 148, 255, 0x30); this->splits.dropPreviewBorder = QColor(0, 148, 255, 0xff); - if (isLight_) { + if (isLight_) + { this->splits.dropTargetRect = QColor(255, 255, 255, 0x00); this->splits.dropTargetRectBorder = QColor(0, 148, 255, 0x00); this->splits.resizeHandle = QColor(0, 148, 255, 0xff); this->splits.resizeHandleBackground = QColor(0, 148, 255, 0x50); - } else { + } + else + { this->splits.dropTargetRect = QColor(0, 148, 255, 0x00); this->splits.dropTargetRectBorder = QColor(0, 148, 255, 0x00); @@ -200,10 +213,13 @@ void Theme::actuallyUpdate(double hue, double multiplier) this->messages.backgrounds.regular = splits.background; this->messages.backgrounds.alternate = getColor(0, sat, 0.93); - if (isLight_) { + if (isLight_) + { this->messages.backgrounds.highlighted = blendColors(themeColor, this->messages.backgrounds.regular, 0.8); - } else { + } + else + { this->messages.backgrounds.highlighted = QColor(getSettings()->highlightColor); } @@ -247,25 +263,32 @@ QColor Theme::blendColors(const QColor &color1, const QColor &color2, void Theme::normalizeColor(QColor &color) { - if (this->isLight_) { - if (color.lightnessF() > 0.5) { + if (this->isLight_) + { + if (color.lightnessF() > 0.5) + { color.setHslF(color.hueF(), color.saturationF(), 0.5); } if (color.lightnessF() > 0.4 && color.hueF() > 0.1 && - color.hueF() < 0.33333) { + color.hueF() < 0.33333) + { color.setHslF(color.hueF(), color.saturationF(), color.lightnessF() - sin((color.hueF() - 0.1) / (0.3333 - 0.1) * 3.14159) * color.saturationF() * 0.4); } - } else { - if (color.lightnessF() < 0.5) { + } + else + { + if (color.lightnessF() < 0.5) + { color.setHslF(color.hueF(), color.saturationF(), 0.5); } if (color.lightnessF() < 0.6 && color.hueF() > 0.54444 && - color.hueF() < 0.83333) { + color.hueF() < 0.83333) + { color.setHslF( color.hueF(), color.saturationF(), color.lightnessF() + sin((color.hueF() - 0.54444) / diff --git a/src/singletons/Toasts.cpp b/src/singletons/Toasts.cpp index f331e3b01..36f46d7ad 100644 --- a/src/singletons/Toasts.cpp +++ b/src/singletons/Toasts.cpp @@ -45,12 +45,16 @@ void Toasts::sendChannelNotification(const QString &channelName, Platform p) }; #endif // Fetch user profile avatar - if (p == Platform::Twitch) { + if (p == Platform::Twitch) + { QFileInfo check_file(getPaths()->twitchProfileAvatars + "/twitch/" + channelName + ".png"); - if (check_file.exists() && check_file.isFile()) { + if (check_file.exists() && check_file.isFile()) + { sendChannelNotification(); - } else { + } + else + { this->fetchChannelAvatar( channelName, [channelName, sendChannelNotification](QString avatarLink) { @@ -81,7 +85,8 @@ public: void toastActivated() const { QString link; - if (platform_ == Platform::Twitch) { + if (platform_ == Platform::Twitch) + { link = "http://www.twitch.tv/" + channelName_; } QDesktopServices::openUrl(QUrl(link)); @@ -112,14 +117,16 @@ void Toasts::sendWindowsNotification(const QString &channelName, Platform p) templ.setTextField(L"Click here to open in browser", WinToastLib::WinToastTemplate::SecondLine); QString Path; - if (p == Platform::Twitch) { + if (p == Platform::Twitch) + { Path = getPaths()->twitchProfileAvatars + "/twitch/" + channelName + ".png"; } std::string temp_Utf8 = Path.toUtf8().constData(); std::wstring imagePath = std::wstring(temp_Utf8.begin(), temp_Utf8.end()); templ.setImagePath(imagePath); - if (getSettings()->notificationPlaySound) { + if (getSettings()->notificationPlaySound) + { templ.setAudioOption( WinToastLib::WinToastTemplate::AudioOption::Silent); } @@ -151,19 +158,22 @@ void Toasts::fetchChannelAvatar(const QString channelName, request.setTimeout(30000); request.onSuccess([successCallback](auto result) mutable -> Outcome { auto root = result.parseJson(); - if (!root.value("users").isArray()) { + if (!root.value("users").isArray()) + { // log("API Error while getting user id, users is not an array"); successCallback(""); return Failure; } auto users = root.value("users").toArray(); - if (users.size() != 1) { + if (users.size() != 1) + { // log("API Error while getting user id, users array size is not // 1"); successCallback(""); return Failure; } - if (!users[0].isObject()) { + if (!users[0].isObject()) + { // log("API Error while getting user id, first user is not an // object"); successCallback(""); @@ -171,7 +181,8 @@ void Toasts::fetchChannelAvatar(const QString channelName, } auto firstUser = users[0].toObject(); auto avatar = firstUser.value("logo"); - if (!avatar.isString()) { + if (!avatar.isString()) + { // log("API Error: while getting user avatar, first user object " // "`avatar` key " // "is not a " diff --git a/src/singletons/Updates.cpp b/src/singletons/Updates.cpp index 5782b4bea..ff32e88dd 100644 --- a/src/singletons/Updates.cpp +++ b/src/singletons/Updates.cpp @@ -39,7 +39,8 @@ const QString &Updates::getOnlineVersion() const void Updates::installUpdates() { - if (this->status_ != UpdateAvailable) { + if (this->status_ != UpdateAvailable) + { assert(false); return; } @@ -77,7 +78,8 @@ void Updates::installUpdates() QFile file(filename); file.open(QIODevice::Truncate | QIODevice::WriteOnly); - if (file.write(object) == -1) { + if (file.write(object) == -1) + { this->setStatus_(WriteFileFailed); return Failure; } @@ -109,7 +111,8 @@ void Updates::checkForUpdates() QJsonValue version_val = object.value("version"); QJsonValue update_val = object.value("update"); - if (!version_val.isString() || !update_val.isString()) { + if (!version_val.isString() || !update_val.isString()) + { this->setStatus_(SearchFailed); qDebug() << "error updating"; @@ -129,7 +132,8 @@ void Updates::checkForUpdates() this->onlineVersion_ = version_val.toString(); this->updateUrl_ = update_val.toString(); - if (this->currentVersion_ != this->onlineVersion_) { + if (this->currentVersion_ != this->onlineVersion_) + { this->setStatus_(UpdateAvailable); postToThread([this] { QMessageBox *box = new QMessageBox( @@ -140,11 +144,14 @@ void Updates::checkForUpdates() box->setAttribute(Qt::WA_DeleteOnClose); box->show(); box->raise(); - if (box->exec() == QMessageBox::Yes) { + if (box->exec() == QMessageBox::Yes) + { this->installUpdates(); } }); - } else { + } + else + { this->setStatus_(NoUpdateAvailable); } return Failure; @@ -161,7 +168,8 @@ Updates::Status Updates::getStatus() const bool Updates::shouldShowUpdateButton() const { - switch (this->getStatus()) { + switch (this->getStatus()) + { case UpdateAvailable: case SearchFailed: case Downloading: @@ -176,7 +184,8 @@ bool Updates::shouldShowUpdateButton() const bool Updates::isError() const { - switch (this->getStatus()) { + switch (this->getStatus()) + { case SearchFailed: case DownloadFailed: case WriteFileFailed: @@ -189,7 +198,8 @@ bool Updates::isError() const void Updates::setStatus_(Status status) { - if (this->status_ != status) { + if (this->status_ != status) + { this->status_ = status; postToThread([this, status] { this->statusUpdated.invoke(status); }); } diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index e75b0278c..55854ebea 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -45,7 +45,8 @@ void WindowManager::showAccountSelectPopup(QPoint point) // static QWidget *lastFocusedWidget = nullptr; static AccountSwitchPopupWidget *w = new AccountSwitchPopupWidget(); - if (w->hasFocus()) { + if (w->hasFocus()) + { w->hide(); // if (lastFocusedWidget) { // lastFocusedWidget->setFocus(); @@ -109,7 +110,8 @@ void WindowManager::updateWordTypeMask() auto flags = MessageElementFlags(MEF::Text); // timestamp - if (settings->showTimestamps) { + if (settings->showTimestamps) + { flags.set(MEF::Timestamp); } @@ -152,7 +154,8 @@ void WindowManager::updateWordTypeMask() // update flags MessageElementFlags newFlags = static_cast(flags); - if (newFlags != this->wordFlags_) { + if (newFlags != this->wordFlags_) + { this->wordFlags_ = newFlags; this->wordFlagsChanged.invoke(); @@ -172,7 +175,8 @@ void WindowManager::forceLayoutChannelViews() void WindowManager::repaintVisibleChatWidgets(Channel *channel) { - if (this->mainWindow_ != nullptr) { + if (this->mainWindow_ != nullptr) + { this->mainWindow_->repaintVisibleChatWidgets(channel); } } @@ -211,13 +215,16 @@ Window &WindowManager::createWindow(WindowType type) this->windows_.push_back(window); window->show(); - if (type != WindowType::Main) { + if (type != WindowType::Main) + { window->setAttribute(Qt::WA_DeleteOnClose); QObject::connect(window, &QWidget::destroyed, [this, window] { for (auto it = this->windows_.begin(); it != this->windows_.end(); - it++) { - if (*it == window) { + it++) + { + if (*it == window) + { this->windows_.erase(it); break; } @@ -237,7 +244,8 @@ Window *WindowManager::windowAt(int index) { assertInGuiThread(); - if (index < 0 || (size_t)index >= this->windows_.size()) { + if (index < 0 || (size_t)index >= this->windows_.size()) + { return nullptr; } log("getting window at bad index {}", index); @@ -263,7 +271,8 @@ void WindowManager::initialize(Settings &settings, Paths &paths) QJsonArray windows_arr = document.object().value("windows").toArray(); // "deserialize" - for (QJsonValue window_val : windows_arr) { + for (QJsonValue window_val : windows_arr) + { QJsonObject window_obj = window_val.toObject(); // get type @@ -271,13 +280,15 @@ void WindowManager::initialize(Settings &settings, Paths &paths) WindowType type = type_val == "main" ? WindowType::Main : WindowType::Popup; - if (type == WindowType::Main && mainWindow_ != nullptr) { + if (type == WindowType::Main && mainWindow_ != nullptr) + { type = WindowType::Popup; } Window &window = createWindow(type); - if (type == WindowType::Main) { + if (type == WindowType::Main) + { mainWindow_ = &window; } @@ -288,7 +299,8 @@ void WindowManager::initialize(Settings &settings, Paths &paths) int width = window_obj.value("width").toInt(-1); int height = window_obj.value("height").toInt(-1); - if (x != -1 && y != -1 && width != -1 && height != -1) { + if (x != -1 && y != -1 && width != -1 && height != -1) + { // Have to offset x by one because qt moves the window 1px too // far to the left window.setGeometry(x + 1, y, width, height); @@ -297,19 +309,22 @@ void WindowManager::initialize(Settings &settings, Paths &paths) // load tabs QJsonArray tabs = window_obj.value("tabs").toArray(); - for (QJsonValue tab_val : tabs) { + for (QJsonValue tab_val : tabs) + { SplitContainer *page = window.getNotebook().addPage(false); QJsonObject tab_obj = tab_val.toObject(); // set custom title QJsonValue title_val = tab_obj.value("title"); - if (title_val.isString()) { + if (title_val.isString()) + { page->getTab()->setCustomTitle(title_val.toString()); } // selected - if (tab_obj.value("selected").toBool(false)) { + if (tab_obj.value("selected").toBool(false)) + { window.getNotebook().select(page); } @@ -320,7 +335,8 @@ void WindowManager::initialize(Settings &settings, Paths &paths) // load splits QJsonObject splitRoot = tab_obj.value("splits2").toObject(); - if (!splitRoot.isEmpty()) { + if (!splitRoot.isEmpty()) + { page->decodeFromJson(splitRoot); continue; @@ -328,8 +344,10 @@ void WindowManager::initialize(Settings &settings, Paths &paths) // fallback load splits (old) int colNr = 0; - for (QJsonValue column_val : tab_obj.value("splits").toArray()) { - for (QJsonValue split_val : column_val.toArray()) { + for (QJsonValue column_val : tab_obj.value("splits").toArray()) + { + for (QJsonValue split_val : column_val.toArray()) + { Split *split = new Split(page); QJsonObject split_obj = split_val.toObject(); @@ -342,7 +360,8 @@ void WindowManager::initialize(Settings &settings, Paths &paths) } } - if (mainWindow_ == nullptr) { + if (mainWindow_ == nullptr) + { mainWindow_ = &createWindow(WindowType::Main); mainWindow_->getNotebook().addPage(true); } @@ -376,11 +395,13 @@ void WindowManager::save() // "serialize" QJsonArray window_arr; - for (Window *window : this->windows_) { + for (Window *window : this->windows_) + { QJsonObject window_obj; // window type - switch (window->getType()) { + switch (window->getType()) + { case WindowType::Main: window_obj.insert("type", "main"); break; @@ -402,19 +423,22 @@ void WindowManager::save() QJsonArray tabs_arr; for (int tab_i = 0; tab_i < window->getNotebook().getPageCount(); - tab_i++) { + tab_i++) + { QJsonObject tab_obj; SplitContainer *tab = dynamic_cast( window->getNotebook().getPageAt(tab_i)); assert(tab != nullptr); // custom tab title - if (tab->getTab()->hasCustomTitle()) { + if (tab->getTab()->hasCustomTitle()) + { tab_obj.insert("title", tab->getTab()->getCustomTitle()); } // selected - if (window->getNotebook().getSelectedPage() == tab) { + if (window->getNotebook().getSelectedPage() == tab) + { tab_obj.insert("selected", true); } @@ -459,7 +483,8 @@ void WindowManager::save() void WindowManager::sendAlert() { int flashDuration = 2500; - if (getSettings()->longAlerts) { + if (getSettings()->longAlerts) + { flashDuration = 0; } QApplication::alert(this->getMainWindow().window(), flashDuration); @@ -474,29 +499,35 @@ void WindowManager::queueSave() void WindowManager::encodeNodeRecusively(SplitNode *node, QJsonObject &obj) { - switch (node->getType()) { - case SplitNode::_Split: { + switch (node->getType()) + { + case SplitNode::_Split: + { obj.insert("type", "split"); QJsonObject split; encodeChannel(node->getSplit()->getIndirectChannel(), split); obj.insert("data", split); obj.insert("flexh", node->getHorizontalFlex()); obj.insert("flexv", node->getVerticalFlex()); - } break; + } + break; case SplitNode::HorizontalContainer: - case SplitNode::VerticalContainer: { + case SplitNode::VerticalContainer: + { obj.insert("type", node->getType() == SplitNode::HorizontalContainer ? "horizontal" : "vertical"); QJsonArray items_arr; - for (const std::unique_ptr &n : node->getChildren()) { + for (const std::unique_ptr &n : node->getChildren()) + { QJsonObject subObj; this->encodeNodeRecusively(n.get(), subObj); items_arr.append(subObj); } obj.insert("items", items_arr); - } break; + } + break; } } @@ -504,20 +535,29 @@ void WindowManager::encodeChannel(IndirectChannel channel, QJsonObject &obj) { assertInGuiThread(); - switch (channel.getType()) { - case Channel::Type::Twitch: { + switch (channel.getType()) + { + case Channel::Type::Twitch: + { obj.insert("type", "twitch"); obj.insert("name", channel.get()->getName()); - } break; - case Channel::Type::TwitchMentions: { + } + break; + case Channel::Type::TwitchMentions: + { obj.insert("type", "mentions"); - } break; - case Channel::Type::TwitchWatching: { + } + break; + case Channel::Type::TwitchWatching: + { obj.insert("type", "watching"); - } break; - case Channel::Type::TwitchWhispers: { + } + break; + case Channel::Type::TwitchWhispers: + { obj.insert("type", "whispers"); - } break; + } + break; } } @@ -528,14 +568,21 @@ IndirectChannel WindowManager::decodeChannel(const QJsonObject &obj) auto app = getApp(); QString type = obj.value("type").toString(); - if (type == "twitch") { + if (type == "twitch") + { return app->twitch.server->getOrAddChannel( obj.value("name").toString()); - } else if (type == "mentions") { + } + else if (type == "mentions") + { return app->twitch.server->mentionsChannel; - } else if (type == "watching") { + } + else if (type == "watching") + { return app->twitch.server->watchingChannel; - } else if (type == "whispers") { + } + else if (type == "whispers") + { return app->twitch.server->whispersChannel; } @@ -546,7 +593,8 @@ void WindowManager::closeAll() { assertInGuiThread(); - for (Window *window : windows_) { + for (Window *window : windows_) + { window->close(); } } @@ -573,7 +621,8 @@ float WindowManager::getUiScaleValue() float WindowManager::getUiScaleValue(int scale) { - switch (clampUiScale(scale)) { + switch (clampUiScale(scale)) + { case -5: return 0.5f; case -4: diff --git a/src/singletons/helper/LoggingChannel.cpp b/src/singletons/helper/LoggingChannel.cpp index c9081d2a6..74b4ebe30 100644 --- a/src/singletons/helper/LoggingChannel.cpp +++ b/src/singletons/helper/LoggingChannel.cpp @@ -16,11 +16,16 @@ QByteArray endline("\n"); LoggingChannel::LoggingChannel(const QString &_channelName) : channelName(_channelName) { - if (this->channelName.startsWith("/whispers")) { + if (this->channelName.startsWith("/whispers")) + { this->subDirectory = "Whispers"; - } else if (channelName.startsWith("/mentions")) { + } + else if (channelName.startsWith("/mentions")) + { this->subDirectory = "Mentions"; - } else { + } + else + { this->subDirectory = QStringLiteral("Channels") + QDir::separator() + channelName; } @@ -33,9 +38,12 @@ LoggingChannel::LoggingChannel(const QString &_channelName) getSettings()->logPath.connect([this](const QString &logPath, auto) { auto app = getApp(); - if (logPath.isEmpty()) { + if (logPath.isEmpty()) + { this->baseDirectory = getPaths()->messageLogDirectory; - } else { + } + else + { this->baseDirectory = logPath; } @@ -54,7 +62,8 @@ void LoggingChannel::openLogFile() QDateTime now = QDateTime::currentDateTime(); this->dateString = this->generateDateString(now); - if (this->fileHandle.isOpen()) { + if (this->fileHandle.isOpen()) + { this->fileHandle.flush(); this->fileHandle.close(); } @@ -64,7 +73,8 @@ void LoggingChannel::openLogFile() QString directory = this->baseDirectory + QDir::separator() + this->subDirectory; - if (!QDir().mkpath(directory)) { + if (!QDir().mkpath(directory)) + { log("Unable to create logging path"); return; } @@ -84,7 +94,8 @@ void LoggingChannel::addMessage(MessagePtr message) QDateTime now = QDateTime::currentDateTime(); QString messageDateString = this->generateDateString(now); - if (messageDateString != this->dateString) { + if (messageDateString != this->dateString) + { this->dateString = messageDateString; this->openLogFile(); } diff --git a/src/util/ConcurrentMap.hpp b/src/util/ConcurrentMap.hpp index 281f3ce46..0346bcae6 100644 --- a/src/util/ConcurrentMap.hpp +++ b/src/util/ConcurrentMap.hpp @@ -21,7 +21,8 @@ public: QMutexLocker lock(&this->mutex_); auto a = this->data_.find(name); - if (a == this->data_.end()) { + if (a == this->data_.end()) + { return false; } @@ -35,7 +36,8 @@ public: QMutexLocker lock(&this->mutex_); auto a = this->data_.find(name); - if (a == this->data_.end()) { + if (a == this->data_.end()) + { TValue value = addLambda(); this->data_.insert(name, value); return value; @@ -72,7 +74,8 @@ public: QMapIterator it(this->data_); - while (it.hasNext()) { + while (it.hasNext()) + { it.next(); func(it.key(), it.value()); } @@ -84,7 +87,8 @@ public: QMutableMapIterator it(this->data_); - while (it.hasNext()) { + while (it.hasNext()) + { it.next(); func(it.key(), it.value()); } diff --git a/src/util/DebugCount.hpp b/src/util/DebugCount.hpp index 46bfb83a1..c0eea3772 100644 --- a/src/util/DebugCount.hpp +++ b/src/util/DebugCount.hpp @@ -18,9 +18,12 @@ public: auto counts = counts_.access(); auto it = counts->find(name); - if (it == counts->end()) { + if (it == counts->end()) + { counts->insert(name, 1); - } else { + } + else + { reinterpret_cast(it.value())++; } } @@ -30,9 +33,12 @@ public: auto counts = counts_.access(); auto it = counts->find(name); - if (it == counts->end()) { + if (it == counts->end()) + { counts->insert(name, -1); - } else { + } + else + { reinterpret_cast(it.value())--; } } @@ -42,7 +48,8 @@ public: auto counts = counts_.access(); QString text; - for (auto it = counts->begin(); it != counts->end(); it++) { + for (auto it = counts->begin(); it != counts->end(); it++) + { text += it.key() + ": " + QString::number(it.value()) + "\n"; } return text; diff --git a/src/util/FormatTime.cpp b/src/util/FormatTime.cpp index 63b2e3c6b..318c08a49 100644 --- a/src/util/FormatTime.cpp +++ b/src/util/FormatTime.cpp @@ -19,23 +19,30 @@ QString formatTime(int totalSeconds) int timeoutHours = timeoutMinutes / 60; int hours = timeoutHours % 24; int days = timeoutHours / 24; - if (days > 0) { + if (days > 0) + { appendDuration(days, 'd', res); } - if (hours > 0) { - if (!res.isEmpty()) { + if (hours > 0) + { + if (!res.isEmpty()) + { res.append(" "); } appendDuration(hours, 'h', res); } - if (minutes > 0) { - if (!res.isEmpty()) { + if (minutes > 0) + { + if (!res.isEmpty()) + { res.append(" "); } appendDuration(minutes, 'm', res); } - if (seconds > 0) { - if (!res.isEmpty()) { + if (seconds > 0) + { + if (!res.isEmpty()) + { res.append(" "); } appendDuration(seconds, 's', res); diff --git a/src/util/Helpers.hpp b/src/util/Helpers.hpp index bb6c742a2..dfb91b783 100644 --- a/src/util/Helpers.hpp +++ b/src/util/Helpers.hpp @@ -19,7 +19,8 @@ static QString CreateUUID() static QString createLink(const QString &url, bool file = false) { - if (file) { + if (file) + { return QString("" + url + ""); @@ -29,9 +30,11 @@ static QString createLink(const QString &url, bool file = false) url + ""); } -static QString createNamedLink(const QString &url, const QString &name, bool file = false) +static QString createNamedLink(const QString &url, const QString &name, + bool file = false) { - if (file) { + if (file) + { return QString("" + name + ""); @@ -43,7 +46,8 @@ static QString createNamedLink(const QString &url, const QString &name, bool fil static QString shortenString(const QString &str, unsigned maxWidth = 50) { - if (str.size() <= maxWidth) { + if (str.size() <= maxWidth) + { return str; } diff --git a/src/util/IncognitoBrowser.cpp b/src/util/IncognitoBrowser.cpp index 2b6cdc222..09b4e8c8e 100644 --- a/src/util/IncognitoBrowser.cpp +++ b/src/util/IncognitoBrowser.cpp @@ -21,7 +21,8 @@ namespace { // transform into regex and replacement string std::vector> replacers; - for (const auto &switch_ : switches) { + for (const auto &switch_ : switches) + { replacers.emplace_back( QRegularExpression("(" + switch_.first + "\\.exe\"?).*", QRegularExpression::CaseInsensitiveOption), @@ -29,8 +30,10 @@ namespace { } // try to find matching regex and apply it - for (const auto &replacement : replacers) { - if (replacement.first.match(command).hasMatch()) { + for (const auto &replacement : replacers) + { + if (replacement.first.match(command).hasMatch()) + { command.replace(replacement.first, replacement.second); return command; } @@ -57,13 +60,15 @@ namespace { QSettings::NativeFormat) .value("Default") .toString(); - if (command.isNull()) return QString(); + if (command.isNull()) + return QString(); log(command); // inject switch to enable private browsing command = injectPrivateSwitch(command); - if (command.isNull()) return QString(); + if (command.isNull()) + return QString(); // link command += " " + link; diff --git a/src/util/InitUpdateButton.cpp b/src/util/InitUpdateButton.cpp index 54f06976d..202a722e3 100644 --- a/src/util/InitUpdateButton.cpp +++ b/src/util/InitUpdateButton.cpp @@ -20,13 +20,18 @@ void initUpdateButton(Button &button, dialog->raise(); dialog->buttonClicked.connect([&button](auto buttonType) { - switch (buttonType) { - case UpdateDialog::Dismiss: { + switch (buttonType) + { + case UpdateDialog::Dismiss: + { button.hide(); - } break; - case UpdateDialog::Install: { + } + break; + case UpdateDialog::Install: + { Updates::getInstance().installUpdates(); - } break; + } + break; } }); diff --git a/src/util/IrcHelpers.hpp b/src/util/IrcHelpers.hpp index 6ae09d94b..1c605c941 100644 --- a/src/util/IrcHelpers.hpp +++ b/src/util/IrcHelpers.hpp @@ -11,34 +11,49 @@ inline QString parseTagString(const QString &input) auto length = output.length(); - for (int i = 0; i < length - 1; i++) { - if (output[i] == '\\') { + for (int i = 0; i < length - 1; i++) + { + if (output[i] == '\\') + { QChar c = output[i + 1]; - switch (c.cell()) { - case 'n': { + switch (c.cell()) + { + case 'n': + { output.replace(i, 2, '\n'); - } break; + } + break; - case 'r': { + case 'r': + { output.replace(i, 2, '\r'); - } break; + } + break; - case 's': { + case 's': + { output.replace(i, 2, ' '); - } break; + } + break; - case '\\': { + case '\\': + { output.replace(i, 2, '\\'); - } break; + } + break; - case ':': { + case ':': + { output.replace(i, 2, ';'); - } break; + } + break; - default: { + default: + { output.remove(i, 1); - } break; + } + break; } i++; diff --git a/src/util/LayoutCreator.hpp b/src/util/LayoutCreator.hpp index c519b7659..bd137a43b 100644 --- a/src/util/LayoutCreator.hpp +++ b/src/util/LayoutCreator.hpp @@ -153,7 +153,8 @@ private: int>::type = 0> QLayout *getOrCreateLayout() { - if (!this->item_->layout()) { + if (!this->item_->layout()) + { this->item_->setLayout(new QHBoxLayout()); } diff --git a/src/util/LayoutHelper.hpp b/src/util/LayoutHelper.hpp index b996aa084..f66fbef87 100644 --- a/src/util/LayoutHelper.hpp +++ b/src/util/LayoutHelper.hpp @@ -13,8 +13,10 @@ T *makeLayout(std::initializer_list items) { auto t = new T; - for (auto &item : items) { - switch (item.which()) { + for (auto &item : items) + { + switch (item.which()) + { case 0: t->addItem(new QWidgetItem(boost::get(item))); break; diff --git a/src/util/RapidJsonSerializeQString.hpp b/src/util/RapidJsonSerializeQString.hpp index 0d34a256b..de6812c70 100644 --- a/src/util/RapidJsonSerializeQString.hpp +++ b/src/util/RapidJsonSerializeQString.hpp @@ -19,19 +19,25 @@ namespace Settings { struct Deserialize { static QString get(const rapidjson::Value &value, bool *error = nullptr) { - if (!value.IsString()) { + if (!value.IsString()) + { PAJLADA_REPORT_ERROR(error) PAJLADA_THROW_EXCEPTION( "Deserialized rapidjson::Value is not a string"); return QString{}; } - try { + try + { return QString::fromUtf8(value.GetString(), value.GetStringLength()); - } catch (const std::exception &) { + } + catch (const std::exception &) + { // int x = 5; - } catch (...) { + } + catch (...) + { // int y = 5; } diff --git a/src/util/RapidjsonHelpers.hpp b/src/util/RapidjsonHelpers.hpp index d3e73e8f9..85b0ba971 100644 --- a/src/util/RapidjsonHelpers.hpp +++ b/src/util/RapidjsonHelpers.hpp @@ -72,15 +72,18 @@ namespace rj { template bool getSafe(const rapidjson::Value &obj, const char *key, Type &out) { - if (!obj.IsObject()) { + if (!obj.IsObject()) + { return false; } - if (!obj.HasMember(key)) { + if (!obj.HasMember(key)) + { return false; } - if (obj.IsNull()) { + if (obj.IsNull()) + { return false; } diff --git a/src/util/StreamLink.cpp b/src/util/StreamLink.cpp index 972c47f59..31b2d2fda 100644 --- a/src/util/StreamLink.cpp +++ b/src/util/StreamLink.cpp @@ -38,9 +38,12 @@ namespace { { auto app = getApp(); - if (getSettings()->streamlinkUseCustomPath) { + if (getSettings()->streamlinkUseCustomPath) + { return getSettings()->streamlinkPath + "/" + getBinaryName(); - } else { + } + else + { return getBinaryName(); } } @@ -49,7 +52,8 @@ namespace { { QFileInfo fileinfo(path); - if (!fileinfo.exists()) { + if (!fileinfo.exists()) + { return false; // throw Exception(fS("Streamlink path ({}) is invalid, file does // not exist", path)); @@ -63,13 +67,16 @@ namespace { static QErrorMessage *msg = new QErrorMessage; auto app = getApp(); - if (getSettings()->streamlinkUseCustomPath) { + if (getSettings()->streamlinkUseCustomPath) + { msg->showMessage( "Unable to find Streamlink executable\nMake sure your custom " "path " "is pointing " "to the DIRECTORY where the streamlink executable is located"); - } else { + } + else + { msg->showMessage( "Unable to find Streamlink executable.\nIf you have Streamlink " "installed, you might need to enable the custom path option"); @@ -82,9 +89,12 @@ namespace { p->setProgram(getStreamlinkProgram()); QObject::connect(p, &QProcess::errorOccurred, [=](auto err) { - if (err == QProcess::FailedToStart) { + if (err == QProcess::FailedToStart) + { showStreamlinkNotFoundError(); - } else { + } + else + { log("Error occured {}", err); } @@ -110,20 +120,24 @@ void getStreamQualities(const QString &channelURL, QObject::connect( p, static_cast(&QProcess::finished), [=](int res) { - if (res != 0) { + if (res != 0) + { log("Got error code {}", res); // return; } QString lastLine = QString(p->readAllStandardOutput()); lastLine = lastLine.trimmed().split('\n').last().trimmed(); - if (lastLine.startsWith("Available streams: ")) { + if (lastLine.startsWith("Available streams: ")) + { QStringList options; QStringList split = lastLine.right(lastLine.length() - 19).split(", "); - for (int i = split.length() - 1; i >= 0; i--) { + for (int i = split.length() - 1; i >= 0; i--) + { QString option = split.at(i); - if (option == "best)") { + if (option == "best)") + { // As it turns out, sometimes, one quality option can // be the best and worst quality at the same time. // Since we start loop from the end, we can check @@ -131,11 +145,17 @@ void getStreamQualities(const QString &channelURL, option = split.at(--i); // "900p60 (worst" options << option.left(option.length() - 7); - } else if (option.endsWith(" (worst)")) { + } + else if (option.endsWith(" (worst)")) + { options << option.left(option.length() - 8); - } else if (option.endsWith(" (best)")) { + } + else if (option.endsWith(" (best)")) + { options << option.left(option.length() - 7); - } else { + } + else + { options << option; } } @@ -157,7 +177,8 @@ void openStreamlink(const QString &channelURL, const QString &quality, QStringList arguments; QString additionalOptions = getSettings()->streamlinkOpts.getValue(); - if (!additionalOptions.isEmpty()) { + if (!additionalOptions.isEmpty()) + { arguments << getSettings()->streamlinkOpts; } @@ -165,14 +186,16 @@ void openStreamlink(const QString &channelURL, const QString &quality, arguments << channelURL; - if (!quality.isEmpty()) { + if (!quality.isEmpty()) + { arguments << quality; } bool res = QProcess::startDetached(getStreamlinkProgram() + " " + QString(arguments.join(' '))); - if (!res) { + if (!res) + { showStreamlinkNotFoundError(); } } @@ -186,7 +209,8 @@ void openStreamlinkForChannel(const QString &channel) QString preferredQuality = getSettings()->preferredQuality; preferredQuality = preferredQuality.toLower(); - if (preferredQuality == "choose") { + if (preferredQuality == "choose") + { getStreamQualities(channelURL, [=](QStringList qualityOptions) { QualityPopup::showDialog(channel, qualityOptions); }); @@ -201,21 +225,31 @@ void openStreamlinkForChannel(const QString &channel) // Streamlink qualities to exclude QString exclude; - if (preferredQuality == "high") { + if (preferredQuality == "high") + { exclude = ">720p30"; quality = "high,best"; - } else if (preferredQuality == "medium") { + } + else if (preferredQuality == "medium") + { exclude = ">540p30"; quality = "medium,best"; - } else if (preferredQuality == "low") { + } + else if (preferredQuality == "low") + { exclude = ">360p30"; quality = "low,best"; - } else if (preferredQuality == "audio only") { + } + else if (preferredQuality == "audio only") + { quality = "audio,audio_only"; - } else { + } + else + { quality = "best"; } - if (!exclude.isEmpty()) { + if (!exclude.isEmpty()) + { args << "--stream-sorting-excludes" << exclude; } diff --git a/src/util/WindowsHelper.cpp b/src/util/WindowsHelper.cpp index c87d31561..7e497c744 100644 --- a/src/util/WindowsHelper.cpp +++ b/src/util/WindowsHelper.cpp @@ -17,9 +17,11 @@ typedef HRESULT(CALLBACK *GetDpiForMonitor_)(HMONITOR, MONITOR_DPI_TYPE, UINT *, boost::optional getWindowDpi(HWND hwnd) { static HINSTANCE shcore = LoadLibrary(L"Shcore.dll"); - if (shcore != nullptr) { + if (shcore != nullptr) + { if (auto getDpiForMonitor = - GetDpiForMonitor_(GetProcAddress(shcore, "GetDpiForMonitor"))) { + GetDpiForMonitor_(GetProcAddress(shcore, "GetDpiForMonitor"))) + { HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); @@ -39,8 +41,11 @@ typedef HRESULT(CALLBACK *OleFlushClipboard_)(); void flushClipboard() { static HINSTANCE ole32 = LoadLibrary(L"Ole32.dll"); - if (ole32 != nullptr) { - if (auto oleFlushClipboard = OleFlushClipboard_(GetProcAddress(ole32, "OleFlushClipboard"))) { + if (ole32 != nullptr) + { + if (auto oleFlushClipboard = + OleFlushClipboard_(GetProcAddress(ole32, "OleFlushClipboard"))) + { oleFlushClipboard(); } } diff --git a/src/util/WindowsHelper.hpp b/src/util/WindowsHelper.hpp index 6e20b1e73..ab604cf66 100644 --- a/src/util/WindowsHelper.hpp +++ b/src/util/WindowsHelper.hpp @@ -10,7 +10,6 @@ namespace chatterino { boost::optional getWindowDpi(HWND hwnd); void flushClipboard(); - } // namespace chatterino #endif diff --git a/src/util/rangealgorithm.hpp b/src/util/rangealgorithm.hpp index e5c0527b7..4dd270ade 100644 --- a/src/util/rangealgorithm.hpp +++ b/src/util/rangealgorithm.hpp @@ -5,17 +5,18 @@ namespace chatterino { namespace util { -template -typename Container::iterator find_if(Container &container, UnaryPredicate pred) -{ - return std::find_if(container.begin(), container.end(), pred); -} + template + typename Container::iterator find_if(Container &container, + UnaryPredicate pred) + { + return std::find_if(container.begin(), container.end(), pred); + } -template -bool any_of(Container &container, UnaryPredicate pred) -{ - return std::any_of(container.begin(), container.end(), pred); -} + template + bool any_of(Container &container, UnaryPredicate pred) + { + return std::any_of(container.begin(), container.end(), pred); + } } // namespace util } // namespace chatterino diff --git a/src/widgets/AccountSwitchWidget.cpp b/src/widgets/AccountSwitchWidget.cpp index 3e201ded3..9b4a920fd 100644 --- a/src/widgets/AccountSwitchWidget.cpp +++ b/src/widgets/AccountSwitchWidget.cpp @@ -15,7 +15,8 @@ AccountSwitchWidget::AccountSwitchWidget(QWidget *parent) this->addItem(ANONYMOUS_USERNAME_LABEL); - for (const auto &userName : app->accounts->twitch.getUsernames()) { + for (const auto &userName : app->accounts->twitch.getUsernames()) + { this->addItem(userName); } @@ -26,7 +27,8 @@ AccountSwitchWidget::AccountSwitchWidget(QWidget *parent) this->addItem(ANONYMOUS_USERNAME_LABEL); - for (const auto &userName : app->accounts->twitch.getUsernames()) { + for (const auto &userName : app->accounts->twitch.getUsernames()) + { this->addItem(userName); } @@ -38,12 +40,16 @@ AccountSwitchWidget::AccountSwitchWidget(QWidget *parent) this->refreshSelection(); QObject::connect(this, &QListWidget::clicked, [=] { - if (!this->selectedItems().isEmpty()) { + if (!this->selectedItems().isEmpty()) + { QString newUsername = this->currentItem()->text(); if (newUsername.compare(ANONYMOUS_USERNAME_LABEL, - Qt::CaseInsensitive) == 0) { + Qt::CaseInsensitive) == 0) + { app->accounts->twitch.currentUsername = ""; - } else { + } + else + { app->accounts->twitch.currentUsername = newUsername.toStdString(); } @@ -61,20 +67,25 @@ void AccountSwitchWidget::refreshSelection() this->blockSignals(true); // Select the currently logged in user - if (this->count() > 0) { + if (this->count() > 0) + { auto app = getApp(); auto currentUser = app->accounts->twitch.getCurrent(); - if (currentUser->isAnon()) { + if (currentUser->isAnon()) + { this->setCurrentRow(0); - } else { + } + else + { const QString ¤tUsername = currentUser->getUserName(); - for (int i = 0; i < this->count(); ++i) { + for (int i = 0; i < this->count(); ++i) + { QString itemText = this->item(i)->text(); - if (itemText.compare(currentUsername, Qt::CaseInsensitive) == - 0) { + if (itemText.compare(currentUsername, Qt::CaseInsensitive) == 0) + { this->setCurrentRow(i); break; } diff --git a/src/widgets/AttachedWindow.cpp b/src/widgets/AttachedWindow.cpp index fee940591..1c0152a76 100644 --- a/src/widgets/AttachedWindow.cpp +++ b/src/widgets/AttachedWindow.cpp @@ -37,8 +37,10 @@ AttachedWindow::AttachedWindow(void *_target, int _yOffset) AttachedWindow::~AttachedWindow() { - for (auto it = items.begin(); it != items.end(); it++) { - if (it->window == this) { + for (auto it = items.begin(); it != items.end(); it++) + { + if (it->window == this) + { items.erase(it); break; } @@ -50,8 +52,10 @@ AttachedWindow::~AttachedWindow() AttachedWindow *AttachedWindow::get(void *target, const GetArgs &args) { AttachedWindow *window = [&]() { - for (Item &item : items) { - if (item.hwnd == target) { + for (Item &item : items) + { + if (item.hwnd == target) + { return item.window; } } @@ -64,26 +68,35 @@ AttachedWindow *AttachedWindow::get(void *target, const GetArgs &args) bool show = true; QSize size = window->size(); - if (args.height != -1) { - if (args.height == 0) { + if (args.height != -1) + { + if (args.height == 0) + { window->hide(); show = false; - } else { + } + else + { window->height_ = args.height; size.setHeight(args.height); } } - if (args.width != -1) { - if (args.width == 0) { + if (args.width != -1) + { + if (args.width == 0) + { window->hide(); show = false; - } else { + } + else + { window->width_ = args.width; size.setWidth(args.width); } } - if (show) { + if (show) + { window->updateWindowRect(window->target_); window->show(); } @@ -93,8 +106,10 @@ AttachedWindow *AttachedWindow::get(void *target, const GetArgs &args) void AttachedWindow::detach(const QString &winId) { - for (Item &item : items) { - if (item.winId == winId) { + for (Item &item : items) + { + if (item.winId == winId) + { item.window->deleteLater(); } } @@ -113,7 +128,8 @@ void AttachedWindow::showEvent(QShowEvent *) void AttachedWindow::attachToHwnd(void *_attachedPtr) { #ifdef USEWINSDK - if (this->attached_) { + if (this->attached_) + { return; } @@ -125,7 +141,8 @@ void AttachedWindow::attachToHwnd(void *_attachedPtr) QObject::connect(&this->timer_, &QTimer::timeout, [this, hwnd, attached] { // check process id - if (!this->validProcessName_) { + if (!this->validProcessName_) + { DWORD processId; ::GetWindowThreadProcessId(attached, &processId); @@ -139,7 +156,8 @@ void AttachedWindow::attachToHwnd(void *_attachedPtr) QString::fromWCharArray(filename.get(), filenameLength); if (!qfilename.endsWith("chrome.exe") && - !qfilename.endsWith("firefox.exe")) { + !qfilename.endsWith("firefox.exe")) + { qDebug() << "NM Illegal caller" << qfilename; this->timer_.stop(); this->deleteLater(); @@ -167,7 +185,8 @@ void AttachedWindow::updateWindowRect(void *_attachedPtr) RECT rect; ::GetWindowRect(attached, &rect); - if (::GetLastError() != 0) { + if (::GetLastError() != 0) + { qDebug() << "NM GetLastError()" << ::GetLastError(); this->timer_.stop(); @@ -182,7 +201,8 @@ void AttachedWindow::updateWindowRect(void *_attachedPtr) SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); float scale = 1.f; - if (auto dpi = getWindowDpi(attached)) { + if (auto dpi = getWindowDpi(attached)) + { scale = dpi.get() / 96.f; // for (auto w : this->ui_.split->findChildren()) { @@ -191,12 +211,15 @@ void AttachedWindow::updateWindowRect(void *_attachedPtr) // this->ui_.split->setOverrideScale(scale); } - if (this->height_ == -1) { + if (this->height_ == -1) + { // ::MoveWindow(hwnd, rect.right - this->width_ - 8, rect.top + // this->yOffset_ - 8, // this->width_, rect.bottom - rect.top - this->yOffset_, // false); - } else { + } + else + { ::MoveWindow(hwnd, // int(rect.right - this->width_ * scale - 8), // int(rect.bottom - this->height_ * scale - 8), // diff --git a/src/widgets/BaseWidget.cpp b/src/widgets/BaseWidget.cpp index 278fe9248..7437f48d5 100644 --- a/src/widgets/BaseWidget.cpp +++ b/src/widgets/BaseWidget.cpp @@ -28,13 +28,15 @@ BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f) float BaseWidget::getScale() const { - if (this->overrideScale_) { + if (this->overrideScale_) + { return this->overrideScale_.get(); } BaseWidget *baseWidget = dynamic_cast(this->window()); - if (baseWidget == nullptr) { + if (baseWidget == nullptr) + { return 1.f; } @@ -87,10 +89,12 @@ void BaseWidget::setScaleIndependantSize(QSize size) { this->scaleIndependantSize_ = size; - if (size.width() > 0) { + if (size.width() > 0) + { this->setFixedWidth((int)(size.width() * this->getScale())); } - if (size.height() > 0) { + if (size.height() > 0) + { this->setFixedHeight((int)(size.height() * this->getScale())); } } @@ -109,16 +113,21 @@ void BaseWidget::setScaleIndependantHeight(int value) void BaseWidget::childEvent(QChildEvent *event) { - if (event->added()) { + if (event->added()) + { BaseWidget *widget = dynamic_cast(event->child()); - if (widget != nullptr) { + if (widget != nullptr) + { this->widgets_.push_back(widget); } - } else if (event->removed()) { - for (auto it = this->widgets_.begin(); it != this->widgets_.end(); - it++) { - if (*it == event->child()) { + } + else if (event->removed()) + { + for (auto it = this->widgets_.begin(); it != this->widgets_.end(); it++) + { + if (*it == event->child()) + { this->widgets_.erase(it); break; } diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index 5c6df9f54..a8714ad34 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -48,7 +48,8 @@ BaseWindow::BaseWindow(QWidget *parent, Flags _flags) , frameless_(_flags & Frameless) , flags_(_flags) { - if (this->frameless_) { + if (this->frameless_) + { this->enableCustomFrame_ = false; this->setWindowFlag(Qt::FramelessWindowHint); } @@ -82,7 +83,8 @@ void BaseWindow::init() this->setWindowIcon(QIcon(":/images/icon.png")); #ifdef USEWINSDK - if (this->hasCustomWindowFrame()) { + if (this->hasCustomWindowFrame()) + { // CUSTOM WINDOW FRAME QVBoxLayout *layout = new QVBoxLayout(); this->ui_.windowLayout = layout; @@ -90,7 +92,8 @@ void BaseWindow::init() layout->setSpacing(0); this->setLayout(layout); { - if (!this->frameless_) { + if (!this->frameless_) + { QHBoxLayout *buttonLayout = this->ui_.titlebarBox = new QHBoxLayout(); buttonLayout->setMargin(0); @@ -161,7 +164,8 @@ void BaseWindow::init() #ifdef USEWINSDK // fourtf: don't ask me why we need to delay this - if (!(this->flags_ & Flags::TopMost)) { + if (!(this->flags_ & Flags::TopMost)) + { QTimer::singleShot(1, this, [this] { getSettings()->windowTopMost.connect( [this](bool topMost, auto) { @@ -204,9 +208,12 @@ BaseWindow::ActionOnFocusLoss BaseWindow::getActionOnFocusLoss() const QWidget *BaseWindow::getLayoutContainer() { - if (this->hasCustomWindowFrame()) { + if (this->hasCustomWindowFrame()) + { return this->ui_.layoutBase; - } else { + } + else + { return this; } } @@ -224,13 +231,15 @@ bool BaseWindow::hasCustomWindowFrame() void BaseWindow::themeChangedEvent() { - if (this->hasCustomWindowFrame()) { + if (this->hasCustomWindowFrame()) + { QPalette palette; palette.setColor(QPalette::Background, QColor(0, 0, 0, 0)); palette.setColor(QPalette::Foreground, this->theme->window.text); this->setPalette(palette); - if (this->ui_.titleLabel) { + if (this->ui_.titleLabel) + { QPalette palette_title; palette_title.setColor( QPalette::Foreground, @@ -238,10 +247,13 @@ void BaseWindow::themeChangedEvent() this->ui_.titleLabel->setPalette(palette_title); } - for (Button *button : this->ui_.buttons) { + for (Button *button : this->ui_.buttons) + { button->setMouseEffectColor(this->theme->window.text); } - } else { + } + else + { QPalette palette; palette.setColor(QPalette::Background, this->theme->window.background); palette.setColor(QPalette::Foreground, this->theme->window.text); @@ -252,7 +264,8 @@ void BaseWindow::themeChangedEvent() bool BaseWindow::event(QEvent *event) { if (event->type() == - QEvent::WindowDeactivate /*|| event->type() == QEvent::FocusOut*/) { + QEvent::WindowDeactivate /*|| event->type() == QEvent::FocusOut*/) + { this->onFocusLost(); } @@ -261,15 +274,20 @@ bool BaseWindow::event(QEvent *event) void BaseWindow::wheelEvent(QWheelEvent *event) { - if (event->orientation() != Qt::Vertical) { + if (event->orientation() != Qt::Vertical) + { return; } - if (event->modifiers() & Qt::ControlModifier) { - if (event->delta() > 0) { + if (event->modifiers() & Qt::ControlModifier) + { + if (event->delta() > 0) + { getSettings()->uiScale.setValue(WindowManager::clampUiScale( getSettings()->uiScale.getValue() + 1)); - } else { + } + else + { getSettings()->uiScale.setValue(WindowManager::clampUiScale( getSettings()->uiScale.getValue() - 1)); } @@ -278,18 +296,25 @@ void BaseWindow::wheelEvent(QWheelEvent *event) void BaseWindow::onFocusLost() { - switch (this->getActionOnFocusLoss()) { - case Delete: { + switch (this->getActionOnFocusLoss()) + { + case Delete: + { this->deleteLater(); - } break; + } + break; - case Close: { + case Close: + { this->close(); - } break; + } + break; - case Hide: { + case Hide: + { this->hide(); - } break; + } + break; default:; } @@ -298,24 +323,29 @@ void BaseWindow::onFocusLost() void BaseWindow::mousePressEvent(QMouseEvent *event) { #ifndef Q_OS_WIN - if (this->flags_ & FramelessDraggable) { + if (this->flags_ & FramelessDraggable) + { this->movingRelativePos = event->localPos(); if (auto widget = - this->childAt(event->localPos().x(), event->localPos().y())) { + this->childAt(event->localPos().x(), event->localPos().y())) + { std::function recursiveCheckMouseTracking; recursiveCheckMouseTracking = [&](QWidget *widget) { - if (widget == nullptr) { + if (widget == nullptr) + { return false; } - if (widget->hasMouseTracking()) { + if (widget->hasMouseTracking()) + { return true; } return recursiveCheckMouseTracking(widget->parentWidget()); }; - if (!recursiveCheckMouseTracking(widget)) { + if (!recursiveCheckMouseTracking(widget)) + { log("Start moving"); this->moving = true; } @@ -329,8 +359,10 @@ void BaseWindow::mousePressEvent(QMouseEvent *event) void BaseWindow::mouseReleaseEvent(QMouseEvent *event) { #ifndef Q_OS_WIN - if (this->flags_ & FramelessDraggable) { - if (this->moving) { + if (this->flags_ & FramelessDraggable) + { + if (this->moving) + { log("Stop moving"); this->moving = false; } @@ -343,8 +375,10 @@ void BaseWindow::mouseReleaseEvent(QMouseEvent *event) void BaseWindow::mouseMoveEvent(QMouseEvent *event) { #ifndef Q_OS_WIN - if (this->flags_ & FramelessDraggable) { - if (this->moving) { + if (this->flags_ & FramelessDraggable) + { + if (this->moving) + { const auto &newPos = event->screenPos() - this->movingRelativePos; this->move(newPos.x(), newPos.y()); } @@ -389,7 +423,8 @@ void BaseWindow::changeEvent(QEvent *) TooltipWidget::getInstance()->hide(); #ifdef USEWINSDK - if (this->ui_.maxButton) { + if (this->ui_.maxButton) + { this->ui_.maxButton->setButtonStyle( this->windowState() & Qt::WindowMaximized ? TitleBarButtonStyle::Unmaximize @@ -409,7 +444,8 @@ void BaseWindow::leaveEvent(QEvent *) void BaseWindow::moveTo(QWidget *parent, QPoint point, bool offset) { - if (offset) { + if (offset) + { point.rx() += 16; point.ry() += 16; } @@ -443,7 +479,8 @@ void BaseWindow::closeEvent(QCloseEvent *) void BaseWindow::moveIntoDesktopRect(QWidget *parent) { - if (!this->stayInScreenRect_) return; + if (!this->stayInScreenRect_) + return; // move the widget into the screen geometry if it's not already in there QDesktopWidget *desktop = QApplication::desktop(); @@ -451,20 +488,25 @@ void BaseWindow::moveIntoDesktopRect(QWidget *parent) QRect s = desktop->availableGeometry(parent); QPoint p = this->pos(); - if (p.x() < s.left()) { + if (p.x() < s.left()) + { p.setX(s.left()); } - if (p.y() < s.top()) { + if (p.y() < s.top()) + { p.setY(s.top()); } - if (p.x() + this->width() > s.right()) { + if (p.x() + this->width() > s.right()) + { p.setX(s.right() - this->width()); } - if (p.y() + this->height() > s.bottom()) { + if (p.y() + this->height() > s.bottom()) + { p.setY(s.bottom() - this->height()); } - if (p != this->pos()) this->move(p); + if (p != this->pos()) + this->move(p); } bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, @@ -479,7 +521,8 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, bool returnValue = false; - switch (msg->message) { + switch (msg->message) + { case WM_DPICHANGED: returnValue = handleDPICHANGED(msg); break; @@ -523,7 +566,8 @@ void BaseWindow::paintEvent(QPaintEvent *) { QPainter painter(this); - if (this->frameless_) { + if (this->frameless_) + { painter.setPen(QColor("#999")); painter.drawRect(0, 0, this->width() - 1, this->height() - 1); } @@ -539,25 +583,30 @@ void BaseWindow::updateScale() : getApp()->windows->getUiScaleValue()); this->setScale(scale); - for (auto child : this->findChildren()) { + for (auto child : this->findChildren()) + { child->setScale(scale); } } void BaseWindow::calcButtonsSizes() { - if (!this->shown_) { + if (!this->shown_) + { return; } - if ((this->width() / this->getScale()) < 300) { + if ((this->width() / this->getScale()) < 300) + { if (this->ui_.minButton) this->ui_.minButton->setScaleIndependantSize(30, 30); if (this->ui_.maxButton) this->ui_.maxButton->setScaleIndependantSize(30, 30); if (this->ui_.exitButton) this->ui_.exitButton->setScaleIndependantSize(30, 30); - } else { + } + else + { if (this->ui_.minButton) this->ui_.minButton->setScaleIndependantSize(46, 30); if (this->ui_.maxButton) @@ -570,7 +619,8 @@ void BaseWindow::calcButtonsSizes() void BaseWindow::drawCustomWindowFrame(QPainter &painter) { #ifdef USEWINSDK - if (this->hasCustomWindowFrame()) { + if (this->hasCustomWindowFrame()) + { QPainter painter(this); QColor bg = this->overrideBackgroundColor_.value_or( @@ -591,7 +641,8 @@ bool BaseWindow::handleDPICHANGED(MSG *msg) static bool firstResize = true; - if (!firstResize) { + if (!firstResize) + { auto *prcNewWindow = reinterpret_cast(msg->lParam); SetWindowPos(msg->hwnd, nullptr, prcNewWindow->left, prcNewWindow->top, prcNewWindow->right - prcNewWindow->left, @@ -612,12 +663,14 @@ bool BaseWindow::handleDPICHANGED(MSG *msg) bool BaseWindow::handleSHOWWINDOW(MSG *msg) { #ifdef USEWINSDK - if (auto dpi = getWindowDpi(msg->hwnd)) { + if (auto dpi = getWindowDpi(msg->hwnd)) + { this->nativeScale_ = dpi.get() / 96.f; this->updateScale(); } - if (!this->shown_ && this->isVisible() && this->hasCustomWindowFrame()) { + if (!this->shown_ && this->isVisible() && this->hasCustomWindowFrame()) + { this->shown_ = true; const MARGINS shadow = {8, 8, 8, 8}; @@ -635,11 +688,13 @@ bool BaseWindow::handleSHOWWINDOW(MSG *msg) bool BaseWindow::handleNCCALCSIZE(MSG *msg, long *result) { #ifdef USEWINSDK - if (this->hasCustomWindowFrame()) { + if (this->hasCustomWindowFrame()) + { // int cx = GetSystemMetrics(SM_CXSIZEFRAME); // int cy = GetSystemMetrics(SM_CYSIZEFRAME); - if (msg->wParam == TRUE) { + if (msg->wParam == TRUE) + { NCCALCSIZE_PARAMS *ncp = (reinterpret_cast(msg->lParam)); ncp->lppos->flags |= SWP_NOREDRAW; @@ -663,16 +718,23 @@ bool BaseWindow::handleNCCALCSIZE(MSG *msg, long *result) bool BaseWindow::handleSIZE(MSG *msg) { #ifdef USEWINSDK - if (this->ui_.windowLayout) { - if (this->frameless_) { + if (this->ui_.windowLayout) + { + if (this->frameless_) + { // - } else if (this->hasCustomWindowFrame()) { - if (msg->wParam == SIZE_MAXIMIZED) { + } + else if (this->hasCustomWindowFrame()) + { + if (msg->wParam == SIZE_MAXIMIZED) + { auto offset = int(this->getScale() * 8); this->ui_.windowLayout->setContentsMargins(offset, offset, offset, offset); - } else { + } + else + { this->ui_.windowLayout->setContentsMargins(0, 1, 0, 0); } } @@ -695,102 +757,130 @@ bool BaseWindow::handleNCHITTEST(MSG *msg, long *result) QPoint point(x - winrect.left, y - winrect.top); - if (this->hasCustomWindowFrame()) { + if (this->hasCustomWindowFrame()) + { *result = 0; bool resizeWidth = minimumWidth() != maximumWidth(); bool resizeHeight = minimumHeight() != maximumHeight(); - if (resizeWidth) { + if (resizeWidth) + { // left border - if (x < winrect.left + border_width) { + if (x < winrect.left + border_width) + { *result = HTLEFT; } // right border - if (x >= winrect.right - border_width) { + if (x >= winrect.right - border_width) + { *result = HTRIGHT; } } - if (resizeHeight) { + if (resizeHeight) + { // bottom border - if (y >= winrect.bottom - border_width) { + if (y >= winrect.bottom - border_width) + { *result = HTBOTTOM; } // top border - if (y < winrect.top + border_width) { + if (y < winrect.top + border_width) + { *result = HTTOP; } } - if (resizeWidth && resizeHeight) { + if (resizeWidth && resizeHeight) + { // bottom left corner if (x >= winrect.left && x < winrect.left + border_width && - y < winrect.bottom && y >= winrect.bottom - border_width) { + y < winrect.bottom && y >= winrect.bottom - border_width) + { *result = HTBOTTOMLEFT; } // bottom right corner if (x < winrect.right && x >= winrect.right - border_width && - y < winrect.bottom && y >= winrect.bottom - border_width) { + y < winrect.bottom && y >= winrect.bottom - border_width) + { *result = HTBOTTOMRIGHT; } // top left corner if (x >= winrect.left && x < winrect.left + border_width && - y >= winrect.top && y < winrect.top + border_width) { + y >= winrect.top && y < winrect.top + border_width) + { *result = HTTOPLEFT; } // top right corner if (x < winrect.right && x >= winrect.right - border_width && - y >= winrect.top && y < winrect.top + border_width) { + y >= winrect.top && y < winrect.top + border_width) + { *result = HTTOPRIGHT; } } - if (*result == 0) { + if (*result == 0) + { bool client = false; - for (QWidget *widget : this->ui_.buttons) { - if (widget->geometry().contains(point)) { + for (QWidget *widget : this->ui_.buttons) + { + if (widget->geometry().contains(point)) + { client = true; } } - if (this->ui_.layoutBase->geometry().contains(point)) { + if (this->ui_.layoutBase->geometry().contains(point)) + { client = true; } - if (client) { + if (client) + { *result = HTCLIENT; - } else { + } + else + { *result = HTCAPTION; } } return true; - } else if (this->flags_ & FramelessDraggable) { + } + else if (this->flags_ & FramelessDraggable) + { *result = 0; bool client = false; - if (auto widget = this->childAt(point)) { + if (auto widget = this->childAt(point)) + { std::function recursiveCheckMouseTracking; recursiveCheckMouseTracking = [&](QWidget *widget) { - if (widget == nullptr) { + if (widget == nullptr) + { return false; } - if (widget->hasMouseTracking()) { + if (widget->hasMouseTracking()) + { return true; } return recursiveCheckMouseTracking(widget->parentWidget()); }; - if (recursiveCheckMouseTracking(widget)) { + if (recursiveCheckMouseTracking(widget)) + { client = true; } } - if (client) { + if (client) + { *result = HTCLIENT; - } else { + } + else + { *result = HTCAPTION; } diff --git a/src/widgets/Label.cpp b/src/widgets/Label.cpp index aefe07d49..4106e4dee 100644 --- a/src/widgets/Label.cpp +++ b/src/widgets/Label.cpp @@ -29,7 +29,8 @@ const QString &Label::getText() const void Label::setText(const QString &text) { - if (this->text_ != text) { + if (this->text_ != text) + { this->text_ = text; this->updateSize(); this->update(); diff --git a/src/widgets/Notebook.cpp b/src/widgets/Notebook.cpp index 5df9d4af6..5dba0f28f 100644 --- a/src/widgets/Notebook.cpp +++ b/src/widgets/Notebook.cpp @@ -63,7 +63,8 @@ NotebookTab *Notebook::addPage(QWidget *page, QString title, bool select) page->hide(); page->setParent(this); - if (select || this->items_.count() == 1) { + if (select || this->items_.count() == 1) + { this->select(page); } @@ -79,13 +80,20 @@ void Notebook::removePage(QWidget *page) // Queue up save because: Tab removed getApp()->windows->queueSave(); - for (int i = 0; i < this->items_.count(); i++) { - if (this->items_[i].page == page) { - if (this->items_.count() == 1) { + for (int i = 0; i < this->items_.count(); i++) + { + if (this->items_[i].page == page) + { + if (this->items_.count() == 1) + { this->select(nullptr); - } else if (i == this->items_.count() - 1) { + } + else if (i == this->items_.count() - 1) + { this->select(this->items_[i - 1].page); - } else { + } + else + { this->select(this->items_[i + 1].page); } @@ -106,15 +114,18 @@ void Notebook::removePage(QWidget *page) void Notebook::removeCurrentPage() { - if (this->selectedPage_ != nullptr) { + if (this->selectedPage_ != nullptr) + { this->removePage(this->selectedPage_); } } int Notebook::indexOf(QWidget *page) const { - for (int i = 0; i < this->items_.count(); i++) { - if (this->items_[i].page == page) { + for (int i = 0; i < this->items_.count(); i++) + { + if (this->items_[i].page == page) + { return i; } } @@ -124,11 +135,13 @@ int Notebook::indexOf(QWidget *page) const void Notebook::select(QWidget *page) { - if (page == this->selectedPage_) { + if (page == this->selectedPage_) + { return; } - if (page != nullptr) { + if (page != nullptr) + { page->setHidden(false); assert(this->containsPage(page)); @@ -137,20 +150,27 @@ void Notebook::select(QWidget *page) item.tab->setSelected(true); item.tab->raise(); - if (item.selectedWidget == nullptr) { + if (item.selectedWidget == nullptr) + { item.page->setFocus(); - } else { - if (containsChild(page, item.selectedWidget)) { + } + else + { + if (containsChild(page, item.selectedWidget)) + { qDebug() << item.selectedWidget; item.selectedWidget->setFocus(Qt::MouseFocusReason); - } else { + } + else + { qDebug() << "Notebook: selected child of page doesn't exist anymore"; } } } - if (this->selectedPage_ != nullptr) { + if (this->selectedPage_ != nullptr) + { this->selectedPage_->setHidden(true); Item &item = this->findItem(selectedPage_); @@ -187,7 +207,8 @@ bool Notebook::containsChild(const QObject *obj, const QObject *child) { return std::any_of(obj->children().begin(), obj->children().end(), [child](const QObject *o) { - if (o == child) { + if (o == child) + { return true; } @@ -197,7 +218,8 @@ bool Notebook::containsChild(const QObject *obj, const QObject *child) void Notebook::selectIndex(int index) { - if (index < 0 || this->items_.count() <= index) { + if (index < 0 || this->items_.count() <= index) + { return; } @@ -206,7 +228,8 @@ void Notebook::selectIndex(int index) void Notebook::selectNextTab() { - if (this->items_.size() <= 1) { + if (this->items_.size() <= 1) + { return; } @@ -218,13 +241,15 @@ void Notebook::selectNextTab() void Notebook::selectPreviousTab() { - if (this->items_.size() <= 1) { + if (this->items_.size() <= 1) + { return; } int index = this->indexOf(this->selectedPage_) - 1; - if (index < 0) { + if (index < 0) + { index += this->items_.count(); } @@ -255,13 +280,15 @@ QWidget *Notebook::tabAt(QPoint point, int &index, int maxWidth) { auto i = 0; - for (auto &item : this->items_) { + for (auto &item : this->items_) + { auto rect = item.tab->getDesiredRect(); rect.setHeight(int(this->getScale() * 24)); rect.setWidth(std::min(maxWidth, rect.width())); - if (rect.contains(point)) { + if (rect.contains(point)) + { index = i; return item.page; } @@ -311,7 +338,8 @@ void Notebook::scaleChangedEvent(float scale) this->addButton_->setFixedSize(h, h); - for (auto &i : this->items_) { + for (auto &i : this->items_) + { i.tab->updateSize(); } } @@ -332,8 +360,10 @@ void Notebook::performLayout(bool animated) auto y = 0; // set size of custom buttons (settings, user, ...) - for (auto *btn : this->customButtons_) { - if (!btn->isVisible()) { + for (auto *btn : this->customButtons_) + { + if (!btn->isVisible()) + { continue; } @@ -347,7 +377,8 @@ void Notebook::performLayout(bool animated) auto firstInBottomRow = this->items_.size() ? &this->items_.front() : nullptr; - for (auto &item : this->items_) { + for (auto &item : this->items_) + { /// Break line if element doesn't fit. auto isFirst = &item == &this->items_.front(); auto isLast = &item == &this->items_.back(); @@ -355,7 +386,8 @@ void Notebook::performLayout(bool animated) auto fitsInLine = ((isLast ? addButtonWidth : 0) + x + item.tab->width()) <= width(); - if (!isFirst && !fitsInLine) { + if (!isFirst && !fitsInLine) + { y += item.tab->height(); x = left; firstInBottomRow = &item; @@ -368,19 +400,23 @@ void Notebook::performLayout(bool animated) /// Update which tabs are in the last row auto inLastRow = false; - for (const auto &item : this->items_) { - if (&item == firstInBottomRow) { + for (const auto &item : this->items_) + { + if (&item == firstInBottomRow) + { inLastRow = true; } item.tab->setInLastRow(inLastRow); } // move misc buttons - if (this->showAddButton_) { + if (this->showAddButton_) + { this->addButton_->move(x, y); } - if (this->lineY_ != y + tabHeight) { + if (this->lineY_ != y + tabHeight) + { this->lineY_ = y + tabHeight; this->update(); } @@ -389,16 +425,19 @@ void Notebook::performLayout(bool animated) y += int(2 * scale); // raise elements - for (auto &i : this->items_) { + for (auto &i : this->items_) + { i.tab->raise(); } - if (this->showAddButton_) { + if (this->showAddButton_) + { this->addButton_->raise(); } // set page bounds - if (this->selectedPage_ != nullptr) { + if (this->selectedPage_ != nullptr) + { this->selectedPage_->move(0, y + tabHeight); this->selectedPage_->resize(width(), height() - y - tabHeight); this->selectedPage_->raise(); @@ -431,8 +470,10 @@ NotebookButton *Notebook::addCustomButton() NotebookTab *Notebook::getTabFromPage(QWidget *page) { - for (auto &it : this->items_) { - if (it.page == page) { + for (auto &it : this->items_) + { + if (it.page == page) + { return it.tab; } } @@ -448,7 +489,8 @@ SplitNotebook::SplitNotebook(Window *parent) }); // add custom buttons if they are not in the parent window frame - if (!parent->hasCustomWindowFrame()) { + if (!parent->hasCustomWindowFrame()) + { this->addCustomButtons(); } } @@ -508,10 +550,12 @@ SplitContainer *SplitNotebook::getOrAddSelectedPage() void SplitNotebook::select(QWidget *page) { - if (auto selectedPage = this->getSelectedPage()) { - if (auto splitContainer = - dynamic_cast(selectedPage)) { - for (auto split : splitContainer->getSplits()) { + if (auto selectedPage = this->getSelectedPage()) + { + if (auto splitContainer = dynamic_cast(selectedPage)) + { + for (auto split : splitContainer->getSplits()) + { split->updateLastReadMessage(); } } diff --git a/src/widgets/Scrollbar.cpp b/src/widgets/Scrollbar.cpp index e412d9e25..c288dff3b 100644 --- a/src/widgets/Scrollbar.cpp +++ b/src/widgets/Scrollbar.cpp @@ -62,7 +62,8 @@ void Scrollbar::clearHighlights() LimitedQueueSnapshot Scrollbar::getHighlightSnapshot() { - if (!this->highlightsPaused_) { + if (!this->highlightsPaused_) + { this->highlightSnapshot_ = this->highlights_.getSnapshot(); } @@ -114,8 +115,10 @@ void Scrollbar::setDesiredValue(qreal value, bool animated) std::min(this->maximum_ - this->largeChange_, value)); if (std::abs(this->desiredValue_ + this->smoothScrollingOffset_ - value) > - 0.0001) { - if (animated) { + 0.0001) + { + if (animated) + { this->currentValueAnimation_.stop(); this->currentValueAnimation_.setStartValue( this->currentValue_ + this->smoothScrollingOffset_); @@ -130,9 +133,12 @@ void Scrollbar::setDesiredValue(qreal value, bool animated) this->atBottom_ = ((this->getMaximum() - this->getLargeChange()) - value) <= 0.0001; this->currentValueAnimation_.start(); - } else { + } + else + { if (this->currentValueAnimation_.state() != - QPropertyAnimation::Running) { + QPropertyAnimation::Running) + { this->smoothScrollingOffset_ = 0; this->desiredValue_ = value; this->currentValueAnimation_.stop(); @@ -182,9 +188,12 @@ qreal Scrollbar::getCurrentValue() const void Scrollbar::offset(qreal value) { - if (this->currentValueAnimation_.state() == QPropertyAnimation::Running) { + if (this->currentValueAnimation_.state() == QPropertyAnimation::Running) + { this->smoothScrollingOffset_ += value; - } else { + } + else + { this->setDesiredValue(this->getDesiredValue() + value); } } @@ -205,7 +214,8 @@ void Scrollbar::setCurrentValue(qreal value) std::min(this->maximum_ - this->largeChange_, value + this->smoothScrollingOffset_)); - if (std::abs(this->currentValue_ - value) > 0.0001) { + if (std::abs(this->currentValue_ - value) > 0.0001) + { this->currentValue_ = value; this->updateScroll(); @@ -241,12 +251,14 @@ void Scrollbar::paintEvent(QPaintEvent *) this->thumbRect_.setX(xOffset); // mouse over thumb - if (this->mouseDownIndex_ == 2) { + if (this->mouseDownIndex_ == 2) + { painter.fillRect(this->thumbRect_, this->theme->scrollbars.thumbSelected); } // mouse not over thumb - else { + else + { painter.fillRect(this->thumbRect_, this->theme->scrollbars.thumb); } @@ -254,7 +266,8 @@ void Scrollbar::paintEvent(QPaintEvent *) auto snapshot = this->getHighlightSnapshot(); size_t snapshotLength = snapshot.getLength(); - if (snapshotLength == 0) { + if (snapshotLength == 0) + { return; } @@ -263,12 +276,15 @@ void Scrollbar::paintEvent(QPaintEvent *) float dY = float(this->height()) / float(snapshotLength); int highlightHeight = int(std::ceil(dY)); - for (size_t i = 0; i < snapshotLength; i++) { + for (size_t i = 0; i < snapshotLength; i++) + { ScrollbarHighlight const &highlight = snapshot[i]; - if (!highlight.isNull()) { + if (!highlight.isNull()) + { QColor color = [&] { - switch (highlight.getColor()) { + switch (highlight.getColor()) + { case ScrollbarHighlight::Highlight: return getApp() ->themes->scrollbars.highlights.highlight; @@ -279,15 +295,20 @@ void Scrollbar::paintEvent(QPaintEvent *) return QColor(); }(); - switch (highlight.getStyle()) { - case ScrollbarHighlight::Default: { + switch (highlight.getStyle()) + { + case ScrollbarHighlight::Default: + { painter.fillRect(w / 8 * 3, int(y), w / 4, highlightHeight, color); - } break; + } + break; - case ScrollbarHighlight::Line: { + case ScrollbarHighlight::Line: + { painter.fillRect(0, int(y), w, 1, color); - } break; + } + break; case ScrollbarHighlight::None:; } @@ -304,27 +325,40 @@ void Scrollbar::resizeEvent(QResizeEvent *) void Scrollbar::mouseMoveEvent(QMouseEvent *event) { - if (this->mouseDownIndex_ == -1) { + if (this->mouseDownIndex_ == -1) + { int y = event->pos().y(); auto oldIndex = this->mouseOverIndex_; - if (y < this->buttonHeight_) { + if (y < this->buttonHeight_) + { this->mouseOverIndex_ = 0; - } else if (y < this->thumbRect_.y()) { + } + else if (y < this->thumbRect_.y()) + { this->mouseOverIndex_ = 1; - } else if (this->thumbRect_.contains(2, y)) { + } + else if (this->thumbRect_.contains(2, y)) + { this->mouseOverIndex_ = 2; - } else if (y < height() - this->buttonHeight_) { + } + else if (y < height() - this->buttonHeight_) + { this->mouseOverIndex_ = 3; - } else { + } + else + { this->mouseOverIndex_ = 4; } - if (oldIndex != this->mouseOverIndex_) { + if (oldIndex != this->mouseOverIndex_) + { update(); } - } else if (this->mouseDownIndex_ == 2) { + } + else if (this->mouseDownIndex_ == 2) + { int delta = event->pos().y() - this->lastMousePosition_.y(); setDesiredValue(this->desiredValue_ + @@ -338,15 +372,24 @@ void Scrollbar::mousePressEvent(QMouseEvent *event) { int y = event->pos().y(); - if (y < this->buttonHeight_) { + if (y < this->buttonHeight_) + { this->mouseDownIndex_ = 0; - } else if (y < this->thumbRect_.y()) { + } + else if (y < this->thumbRect_.y()) + { this->mouseDownIndex_ = 1; - } else if (this->thumbRect_.contains(2, y)) { + } + else if (this->thumbRect_.contains(2, y)) + { this->mouseDownIndex_ = 2; - } else if (y < height() - this->buttonHeight_) { + } + else if (y < height() - this->buttonHeight_) + { this->mouseDownIndex_ = 3; - } else { + } + else + { this->mouseDownIndex_ = 4; } } @@ -355,22 +398,35 @@ void Scrollbar::mouseReleaseEvent(QMouseEvent *event) { int y = event->pos().y(); - if (y < this->buttonHeight_) { - if (this->mouseDownIndex_ == 0) { + if (y < this->buttonHeight_) + { + if (this->mouseDownIndex_ == 0) + { setDesiredValue(this->desiredValue_ - this->smallChange_, true); } - } else if (y < this->thumbRect_.y()) { - if (this->mouseDownIndex_ == 1) { + } + else if (y < this->thumbRect_.y()) + { + if (this->mouseDownIndex_ == 1) + { setDesiredValue(this->desiredValue_ - this->smallChange_, true); } - } else if (this->thumbRect_.contains(2, y)) { + } + else if (this->thumbRect_.contains(2, y)) + { // do nothing - } else if (y < height() - this->buttonHeight_) { - if (this->mouseDownIndex_ == 3) { + } + else if (y < height() - this->buttonHeight_) + { + if (this->mouseDownIndex_ == 3) + { setDesiredValue(this->desiredValue_ + this->smallChange_, true); } - } else { - if (this->mouseDownIndex_ == 4) { + } + else + { + if (this->mouseDownIndex_ == 4) + { setDesiredValue(this->desiredValue_ + this->smallChange_, true); } } diff --git a/src/widgets/TooltipWidget.cpp b/src/widgets/TooltipWidget.cpp index 5ee0b1daf..2d528c4d8 100644 --- a/src/widgets/TooltipWidget.cpp +++ b/src/widgets/TooltipWidget.cpp @@ -18,7 +18,8 @@ namespace chatterino { TooltipWidget *TooltipWidget::getInstance() { static TooltipWidget *tooltipWidget = nullptr; - if (tooltipWidget == nullptr) { + if (tooltipWidget == nullptr) + { tooltipWidget = new TooltipWidget(); } return tooltipWidget; diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index 0257bb63e..8eac74391 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -48,9 +48,12 @@ Window::Window(WindowType type) [this] { this->onAccountSelected(); }); this->onAccountSelected(); - if (type == WindowType::Main) { + if (type == WindowType::Main) + { this->resize(int(600 * this->getScale()), int(500 * this->getScale())); - } else { + } + else + { this->resize(int(300 * this->getScale()), int(500 * this->getScale())); } } @@ -69,8 +72,10 @@ void Window::repaintVisibleChatWidgets(Channel *channel) { auto page = this->notebook_->getOrAddSelectedPage(); - for (const auto &split : page->getSplits()) { - if (channel == nullptr || channel == split->getChannel().get()) { + for (const auto &split : page->getSplits()) + { + if (channel == nullptr || channel == split->getChannel().get()) + { split->layoutMessages(); } } @@ -78,26 +83,32 @@ void Window::repaintVisibleChatWidgets(Channel *channel) bool Window::event(QEvent *event) { - switch (event->type()) { + switch (event->type()) + { case QEvent::WindowActivate: break; - case QEvent::WindowDeactivate: { + case QEvent::WindowDeactivate: + { auto page = this->notebook_->getOrAddSelectedPage(); - if (page != nullptr) { + if (page != nullptr) + { std::vector splits = page->getSplits(); - for (Split *split : splits) { + for (Split *split : splits) + { split->updateLastReadMessage(); } } if (SplitContainer *container = - dynamic_cast(page)) { + dynamic_cast(page)) + { container->hideResizeHandles(); } - } break; + } + break; default:; }; @@ -108,7 +119,8 @@ bool Window::event(QEvent *event) void Window::showEvent(QShowEvent *event) { // Startup notification - if (getSettings()->startUpNotification.getValue() < 1) { + if (getSettings()->startUpNotification.getValue() < 1) + { getSettings()->startUpNotification = 1; auto box = new QMessageBox( @@ -122,12 +134,14 @@ void Window::showEvent(QShowEvent *event) // Show changelog if (getSettings()->currentVersion.getValue() != "" && - getSettings()->currentVersion.getValue() != CHATTERINO_VERSION) { + getSettings()->currentVersion.getValue() != CHATTERINO_VERSION) + { auto box = new QMessageBox(QMessageBox::Information, "Chatterino 2 Beta", "Show changelog?", QMessageBox::Yes | QMessageBox::No); box->setAttribute(Qt::WA_DeleteOnClose); - if (box->exec() == QMessageBox::Yes) { + if (box->exec() == QMessageBox::Yes) + { QDesktopServices::openUrl( QUrl("https://fourtf.com/chatterino-changelog/")); } @@ -141,7 +155,8 @@ void Window::showEvent(QShowEvent *event) void Window::closeEvent(QCloseEvent *) { - if (this->type_ == WindowType::Main) { + if (this->type_ == WindowType::Main) + { auto app = getApp(); app->windows->save(); app->windows->closeAll(); @@ -149,7 +164,8 @@ void Window::closeEvent(QCloseEvent *) this->closed.invoke(); - if (this->type_ == WindowType::Main) { + if (this->type_ == WindowType::Main) + { QApplication::exit(); } } @@ -170,8 +186,10 @@ void Window::addLayout() void Window::addCustomTitlebarButtons() { - if (!this->hasCustomWindowFrame()) return; - if (this->type_ != WindowType::Main) return; + if (!this->hasCustomWindowFrame()) + return; + if (this->type_ != WindowType::Main) + return; // settings this->addTitleBarButton(TitleBarButtonStyle::Settings, @@ -309,15 +327,18 @@ void Window::addShortcuts() // Reopen last closed split createWindowShortcut(this, "CTRL+G", [this] { - if (ClosedSplits::empty()) { + if (ClosedSplits::empty()) + { return; } ClosedSplits::SplitInfo si = ClosedSplits::pop(); SplitContainer *splitContainer{nullptr}; - if (si.tab) { + if (si.tab) + { splitContainer = dynamic_cast(si.tab->page); } - if (!splitContainer) { + if (!splitContainer) + { splitContainer = this->notebook_->getOrAddSelectedPage(); } this->notebook_->select(splitContainer); @@ -345,12 +366,17 @@ void Window::onAccountSelected() this->setWindowTitle(windowTitleEnd); - if (user->isAnon()) { - if (this->userLabel_) { + if (user->isAnon()) + { + if (this->userLabel_) + { this->userLabel_->getLabel().setText("anonymous"); } - } else { - if (this->userLabel_) { + } + else + { + if (this->userLabel_) + { this->userLabel_->getLabel().setText(user->getUserName()); } } diff --git a/src/widgets/dialogs/EmotePopup.cpp b/src/widgets/dialogs/EmotePopup.cpp index 227493050..0d9c22eac 100644 --- a/src/widgets/dialogs/EmotePopup.cpp +++ b/src/widgets/dialogs/EmotePopup.cpp @@ -29,14 +29,18 @@ namespace { builder->flags.set(MessageFlag::Centered); builder->flags.set(MessageFlag::DisableCompactEmotes); - if (!map.empty()) { - for (const auto &emote : map) { + if (!map.empty()) + { + for (const auto &emote : map) + { builder .emplace(emote.second, MessageElementFlag::AlwaysShow) ->setLink(Link(Link::InsertText, emote.first.string)); } - } else { + } + else + { builder.emplace("no emotes available", MessageElementFlag::Text, MessageColor::System); @@ -50,7 +54,8 @@ namespace { { QMap>> mapOfSets; - for (const auto &set : sets) { + for (const auto &set : sets) + { // TITLE auto channelName = set->channelName; auto text = @@ -62,13 +67,15 @@ namespace { builder->flags.set(MessageFlag::DisableCompactEmotes); // If value of map is empty, create init pair and add title. - if (mapOfSets.find(channelName) == mapOfSets.end()) { + if (mapOfSets.find(channelName) == mapOfSets.end()) + { std::vector b; b.push_back(makeTitleMessage(text)); mapOfSets[channelName] = qMakePair(set->key == "0", b); } - for (const auto &emote : set->emotes) { + for (const auto &emote : set->emotes) + { builder .emplace( getApp()->emotes->twitch.getOrCreateEmote(emote.id, @@ -82,9 +89,11 @@ namespace { // Output to channel all created messages, // That contain title or emotes. - foreach (auto pair, mapOfSets) { + foreach (auto pair, mapOfSets) + { auto &channel = pair.first ? globalChannel : subChannel; - for (auto message : pair.second) { + for (auto message : pair.second) + { channel.addMessage(message); } } @@ -131,7 +140,8 @@ void EmotePopup::loadChannel(ChannelPtr _channel) this->setWindowTitle("Emotes in #" + _channel->getName()); auto twitchChannel = dynamic_cast(_channel.get()); - if (twitchChannel == nullptr) return; + if (twitchChannel == nullptr) + return; auto addEmotes = [&](Channel &channel, const EmoteMap &map, const QString &title) { @@ -162,7 +172,8 @@ void EmotePopup::loadChannel(ChannelPtr _channel) this->subEmotesView_->setChannel(subChannel); this->channelEmotesView_->setChannel(channelChannel); - if (subChannel->getMessageSnapshot().getLength() == 0) { + if (subChannel->getMessageSnapshot().getLength() == 0) + { MessageBuilder builder; builder->flags.set(MessageFlag::Centered); builder->flags.set(MessageFlag::DisableCompactEmotes); diff --git a/src/widgets/dialogs/LoginDialog.cpp b/src/widgets/dialogs/LoginDialog.cpp index 35c18c7d6..146557ee9 100644 --- a/src/widgets/dialogs/LoginDialog.cpp +++ b/src/widgets/dialogs/LoginDialog.cpp @@ -28,20 +28,25 @@ namespace { { QStringList errors; - if (userID.empty()) { + if (userID.empty()) + { errors.append("Missing user ID"); } - if (username.empty()) { + if (username.empty()) + { errors.append("Missing username"); } - if (clientID.empty()) { + if (clientID.empty()) + { errors.append("Missing Client ID"); } - if (oauthToken.empty()) { + if (oauthToken.empty()) + { errors.append("Missing OAuth Token"); } - if (errors.length() > 0) { + if (errors.length() > 0) + { QMessageBox messageBox; messageBox.setIcon(QMessageBox::Critical); messageBox.setText(errors.join("
")); @@ -96,23 +101,34 @@ BasicLoginWidget::BasicLoginWidget() std::string oauthToken, clientID, username, userID; - for (const auto ¶m : parameters) { + for (const auto ¶m : parameters) + { QStringList kvParameters = param.split('='); - if (kvParameters.size() != 2) { + if (kvParameters.size() != 2) + { continue; } QString key = kvParameters[0]; QString value = kvParameters[1]; - if (key == "oauth_token") { + if (key == "oauth_token") + { oauthToken = value.toStdString(); - } else if (key == "client_id") { + } + else if (key == "client_id") + { clientID = value.toStdString(); - } else if (key == "username") { + } + else if (key == "username") + { username = value.toStdString(); - } else if (key == "user_id") { + } + else if (key == "user_id") + { userID = value.toStdString(); - } else { + } + else + { qDebug() << "Unknown key in code: " << key; } } @@ -212,9 +228,12 @@ void AdvancedLoginWidget::refreshButtons() if (this->ui_.userIDInput.text().isEmpty() || this->ui_.usernameInput.text().isEmpty() || this->ui_.clientIDInput.text().isEmpty() || - this->ui_.oauthTokenInput.text().isEmpty()) { + this->ui_.oauthTokenInput.text().isEmpty()) + { this->ui_.buttonUpperRow.addUserButton.setEnabled(false); - } else { + } + else + { this->ui_.buttonUpperRow.addUserButton.setEnabled(true); } } diff --git a/src/widgets/dialogs/LoginDialog.hpp b/src/widgets/dialogs/LoginDialog.hpp index c2efa926c..a6819e3af 100644 --- a/src/widgets/dialogs/LoginDialog.hpp +++ b/src/widgets/dialogs/LoginDialog.hpp @@ -2,7 +2,6 @@ #include "widgets/BaseWidget.hpp" -#include #include #include #include @@ -16,6 +15,7 @@ #include #include #include +#include namespace chatterino { diff --git a/src/widgets/dialogs/LogsPopup.cpp b/src/widgets/dialogs/LogsPopup.cpp index be799be53..66db3cf82 100644 --- a/src/widgets/dialogs/LogsPopup.cpp +++ b/src/widgets/dialogs/LogsPopup.cpp @@ -54,7 +54,8 @@ void LogsPopup::getRoomID() { TwitchChannel *twitchChannel = dynamic_cast(this->channel_.get()); - if (twitchChannel == nullptr) { + if (twitchChannel == nullptr) + { return; } @@ -84,7 +85,8 @@ void LogsPopup::getLogviewerLogs() { TwitchChannel *twitchChannel = dynamic_cast(this->channel_.get()); - if (twitchChannel == nullptr) { + if (twitchChannel == nullptr) + { return; } @@ -107,7 +109,8 @@ void LogsPopup::getLogviewerLogs() QJsonValue before = data.value("before"); - for (auto i : before.toArray()) { + for (auto i : before.toArray()) + { auto messageObject = i.toObject(); QString message = messageObject.value("text").toString(); @@ -137,7 +140,8 @@ void LogsPopup::getOverrustleLogs() { TwitchChannel *twitchChannel = dynamic_cast(this->channel_.get()); - if (twitchChannel == nullptr) { + if (twitchChannel == nullptr) + { return; } @@ -164,9 +168,11 @@ void LogsPopup::getOverrustleLogs() req.onSuccess([this, channelName](auto result) -> Outcome { auto data = result.parseJson(); std::vector messages; - if (data.contains("lines")) { + if (data.contains("lines")) + { QJsonArray dataMessages = data.value("lines").toArray(); - for (auto i : dataMessages) { + for (auto i : dataMessages) + { QJsonObject singleMessage = i.toObject(); QTime timeStamp = QDateTime::fromSecsSinceEpoch( singleMessage.value("timestamp").toInt()) diff --git a/src/widgets/dialogs/NotificationPopup.cpp b/src/widgets/dialogs/NotificationPopup.cpp index fb1822f40..3eb10320d 100644 --- a/src/widgets/dialogs/NotificationPopup.cpp +++ b/src/widgets/dialogs/NotificationPopup.cpp @@ -33,11 +33,14 @@ void NotificationPopup::updatePosition() QDesktopWidget *desktop = QApplication::desktop(); const QRect rect = desktop->availableGeometry(); - switch (location) { - case BottomRight: { + switch (location) + { + case BottomRight: + { this->move(rect.right() - this->width(), rect.bottom() - this->height()); - } break; + } + break; } } diff --git a/src/widgets/dialogs/QualityPopup.cpp b/src/widgets/dialogs/QualityPopup.cpp index 94bbf5594..322741ab8 100644 --- a/src/widgets/dialogs/QualityPopup.cpp +++ b/src/widgets/dialogs/QualityPopup.cpp @@ -44,9 +44,12 @@ void QualityPopup::okButtonClicked() { QString channelURL = "twitch.tv/" + this->channelName_; - try { + try + { openStreamlink(channelURL, this->ui_.selector.currentText()); - } catch (const Exception &ex) { + } + catch (const Exception &ex) + { log("Exception caught trying to open streamlink: {}", ex.what()); } diff --git a/src/widgets/dialogs/SelectChannelDialog.cpp b/src/widgets/dialogs/SelectChannelDialog.cpp index 3a8faaf7c..2d8218e69 100644 --- a/src/widgets/dialogs/SelectChannelDialog.cpp +++ b/src/widgets/dialogs/SelectChannelDialog.cpp @@ -46,7 +46,8 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent) QObject::connect(channel_btn.getElement(), &QRadioButton::toggled, [=](bool enabled) mutable { - if (enabled) { + if (enabled) + { channel_edit->setFocus(); channel_edit->setSelection( 0, channel_edit->text().length()); @@ -176,25 +177,35 @@ void SelectChannelDialog::setSelectedChannel(IndirectChannel _channel) this->selectedChannel_ = channel; - switch (_channel.getType()) { - case Channel::Type::Twitch: { + switch (_channel.getType()) + { + case Channel::Type::Twitch: + { this->ui_.notebook->selectIndex(TAB_TWITCH); this->ui_.twitch.channel->setFocus(); this->ui_.twitch.channelName->setText(channel->getName()); - } break; - case Channel::Type::TwitchWatching: { + } + break; + case Channel::Type::TwitchWatching: + { this->ui_.notebook->selectIndex(TAB_TWITCH); this->ui_.twitch.watching->setFocus(); - } break; - case Channel::Type::TwitchMentions: { + } + break; + case Channel::Type::TwitchMentions: + { this->ui_.notebook->selectIndex(TAB_TWITCH); this->ui_.twitch.mentions->setFocus(); - } break; - case Channel::Type::TwitchWhispers: { + } + break; + case Channel::Type::TwitchWhispers: + { this->ui_.notebook->selectIndex(TAB_TWITCH); this->ui_.twitch.whispers->setFocus(); - } break; - default: { + } + break; + default: + { this->ui_.notebook->selectIndex(TAB_TWITCH); this->ui_.twitch.channel->setFocus(); } @@ -205,22 +216,32 @@ void SelectChannelDialog::setSelectedChannel(IndirectChannel _channel) IndirectChannel SelectChannelDialog::getSelectedChannel() const { - if (!this->hasSelectedChannel_) { + if (!this->hasSelectedChannel_) + { return this->selectedChannel_; } auto app = getApp(); - switch (this->ui_.notebook->getSelectedIndex()) { - case TAB_TWITCH: { - if (this->ui_.twitch.channel->isChecked()) { + switch (this->ui_.notebook->getSelectedIndex()) + { + case TAB_TWITCH: + { + if (this->ui_.twitch.channel->isChecked()) + { return app->twitch.server->getOrAddChannel( this->ui_.twitch.channelName->text().trimmed()); - } else if (this->ui_.twitch.watching->isChecked()) { + } + else if (this->ui_.twitch.watching->isChecked()) + { return app->twitch.server->watchingChannel; - } else if (this->ui_.twitch.mentions->isChecked()) { + } + else if (this->ui_.twitch.mentions->isChecked()) + { return app->twitch.server->mentionsChannel; - } else if (this->ui_.twitch.whispers->isChecked()) { + } + else if (this->ui_.twitch.whispers->isChecked()) + { return app->twitch.server->whispersChannel; } } @@ -239,54 +260,74 @@ bool SelectChannelDialog::EventFilter::eventFilter(QObject *watched, { auto *widget = (QWidget *)watched; - if (event->type() == QEvent::FocusIn) { + if (event->type() == QEvent::FocusIn) + { widget->grabKeyboard(); auto *radio = dynamic_cast(watched); - if (radio) { + if (radio) + { radio->setChecked(true); } return true; - } else if (event->type() == QEvent::FocusOut) { + } + else if (event->type() == QEvent::FocusOut) + { widget->releaseKeyboard(); return false; - } else if (event->type() == QEvent::KeyPress) { + } + else if (event->type() == QEvent::KeyPress) + { QKeyEvent *event_key = static_cast(event); if ((event_key->key() == Qt::Key_Tab || event_key->key() == Qt::Key_Down) && - event_key->modifiers() == Qt::NoModifier) { - if (widget == this->dialog->ui_.twitch.channelName) { + event_key->modifiers() == Qt::NoModifier) + { + if (widget == this->dialog->ui_.twitch.channelName) + { this->dialog->ui_.twitch.whispers->setFocus(); return true; - } else { + } + else + { widget->nextInFocusChain()->setFocus(); } return true; - } else if (((event_key->key() == Qt::Key_Tab || - event_key->key() == Qt::Key_Backtab) && - event_key->modifiers() == Qt::ShiftModifier) || - ((event_key->key() == Qt::Key_Up) && - event_key->modifiers() == Qt::NoModifier)) { - if (widget == this->dialog->ui_.twitch.channelName) { + } + else if (((event_key->key() == Qt::Key_Tab || + event_key->key() == Qt::Key_Backtab) && + event_key->modifiers() == Qt::ShiftModifier) || + ((event_key->key() == Qt::Key_Up) && + event_key->modifiers() == Qt::NoModifier)) + { + if (widget == this->dialog->ui_.twitch.channelName) + { this->dialog->ui_.twitch.watching->setFocus(); return true; - } else if (widget == this->dialog->ui_.twitch.whispers) { + } + else if (widget == this->dialog->ui_.twitch.whispers) + { this->dialog->ui_.twitch.channel->setFocus(); return true; } widget->previousInFocusChain()->setFocus(); return true; - } else { + } + else + { return false; } return true; - } else if (event->type() == QEvent::KeyRelease) { + } + else if (event->type() == QEvent::KeyRelease) + { QKeyEvent *event_key = static_cast(event); if ((event_key->key() == Qt::Key_Backtab || event_key->key() == Qt::Key_Down) && - event_key->modifiers() == Qt::NoModifier) { + event_key->modifiers() == Qt::NoModifier) + { return true; } } @@ -303,10 +344,13 @@ void SelectChannelDialog::themeChangedEvent() { BaseWindow::themeChangedEvent(); - if (this->theme->isLightTheme()) { + if (this->theme->isLightTheme()) + { this->setStyleSheet( "QRadioButton { color: #000 } QLabel { color: #000 }"); - } else { + } + else + { this->setStyleSheet( "QRadioButton { color: #fff } QLabel { color: #fff }"); } diff --git a/src/widgets/dialogs/SettingsDialog.cpp b/src/widgets/dialogs/SettingsDialog.cpp index d21008bd1..ea848a9d5 100644 --- a/src/widgets/dialogs/SettingsDialog.cpp +++ b/src/widgets/dialogs/SettingsDialog.cpp @@ -121,7 +121,8 @@ void SettingsDialog::addTab(SettingsPage *page, Qt::Alignment alignment) this->ui_.tabContainer->addWidget(tab, 0, alignment); this->tabs_.push_back(tab); - if (this->tabs_.size() == 1) { + if (this->tabs_.size() == 1) + { this->selectTab(tab); } } @@ -130,7 +131,8 @@ void SettingsDialog::selectTab(SettingsDialogTab *tab) { this->ui_.pageStack->setCurrentWidget(tab->getSettingsPage()); - if (this->selectedTab_ != nullptr) { + if (this->selectedTab_ != nullptr) + { this->selectedTab_->setSelected(false); this->selectedTab_->setStyleSheet("color: #FFF"); } @@ -145,10 +147,13 @@ void SettingsDialog::showDialog(PreferredTab preferredTab) static SettingsDialog *instance = new SettingsDialog(); instance->refresh(); - switch (preferredTab) { - case SettingsDialog::PreferredTab::Accounts: { + switch (preferredTab) + { + case SettingsDialog::PreferredTab::Accounts: + { instance->selectTab(instance->tabs_.at(0)); - } break; + } + break; } instance->show(); @@ -161,7 +166,8 @@ void SettingsDialog::refresh() { getSettings()->saveSnapshot(); - for (auto *tab : this->tabs_) { + for (auto *tab : this->tabs_) + { tab->getSettingsPage()->onShow(); } } @@ -174,7 +180,8 @@ void SettingsDialog::scaleChangedEvent(float newDpi) styleSheet.replace("", QString::number(int(14 * newDpi))); styleSheet.replace("", QString::number(int(14 * newDpi))); - for (SettingsDialogTab *tab : this->tabs_) { + for (SettingsDialogTab *tab : this->tabs_) + { tab->setFixedHeight(int(30 * newDpi)); } @@ -200,7 +207,8 @@ void SettingsDialog::onOkClicked() void SettingsDialog::onCancelClicked() { - for (auto &tab : this->tabs_) { + for (auto &tab : this->tabs_) + { tab->getSettingsPage()->cancel(); } diff --git a/src/widgets/dialogs/UpdateDialog.cpp b/src/widgets/dialogs/UpdateDialog.cpp index de065283f..7eac073fd 100644 --- a/src/widgets/dialogs/UpdateDialog.cpp +++ b/src/widgets/dialogs/UpdateDialog.cpp @@ -43,31 +43,42 @@ void UpdateDialog::updateStatusChanged(Updates::Status status) { this->ui_.installButton->setVisible(status == Updates::UpdateAvailable); - switch (status) { - case Updates::UpdateAvailable: { + switch (status) + { + case Updates::UpdateAvailable: + { this->ui_.label->setText( QString("An update (%1) is available.\n\nDo you want to " "download and install it?") .arg(Updates::getInstance().getOnlineVersion())); - } break; + } + break; - case Updates::SearchFailed: { + case Updates::SearchFailed: + { this->ui_.label->setText("Failed to load version information."); - } break; + } + break; - case Updates::Downloading: { + case Updates::Downloading: + { this->ui_.label->setText( "Downloading updates.\n\nChatterino will restart " "automatically when the download is done."); - } break; + } + break; - case Updates::DownloadFailed: { + case Updates::DownloadFailed: + { this->ui_.label->setText("Failed to download the update."); - } break; + } + break; - case Updates::WriteFileFailed: { + case Updates::WriteFileFailed: + { this->ui_.label->setText("Failed to save the update to disk."); - } break; + } + break; default:; } diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index 2b7f37f4a..3fac00871 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -113,7 +113,8 @@ UserInfoPopup::UserInfoPopup() TwitchChannel *twitchChannel = dynamic_cast(this->channel_.get()); - if (twitchChannel) { + if (twitchChannel) + { qDebug() << this->userName_; bool isMyself = @@ -140,7 +141,8 @@ UserInfoPopup::UserInfoPopup() TwitchChannel *twitchChannel = dynamic_cast(this->channel_.get()); - if (twitchChannel) { + if (twitchChannel) + { lineMod->setVisible(twitchChannel->hasModRights()); timeout->setVisible(twitchChannel->hasModRights()); } @@ -151,25 +153,35 @@ UserInfoPopup::UserInfoPopup() int arg; std::tie(action, arg) = item; - switch (action) { - case TimeoutWidget::Ban: { - if (this->channel_) { + switch (action) + { + case TimeoutWidget::Ban: + { + if (this->channel_) + { this->channel_->sendMessage("/ban " + this->userName_); } - } break; - case TimeoutWidget::Unban: { - if (this->channel_) { + } + break; + case TimeoutWidget::Unban: + { + if (this->channel_) + { this->channel_->sendMessage("/unban " + this->userName_); } - } break; - case TimeoutWidget::Timeout: { - if (this->channel_) { + } + break; + case TimeoutWidget::Timeout: + { + if (this->channel_) + { this->channel_->sendMessage("/timeout " + this->userName_ + " " + QString::number(arg)); } - } break; + } + break; } }); } @@ -204,9 +216,12 @@ void UserInfoPopup::installEvents() }; this->ui_.follow->setEnabled(false); - if (this->ui_.follow->isChecked()) { + if (this->ui_.follow->isChecked()) + { currentUser->followUser(this->userId_, reenableFollowCheckbox); - } else { + } + else + { currentUser->unfollowUser(this->userId_, reenableFollowCheckbox); } @@ -218,7 +233,8 @@ void UserInfoPopup::installEvents() QObject::connect( this->ui_.ignore, &QCheckBox::stateChanged, [this, ignoreNext, hack](int) mutable { - if (*ignoreNext) { + if (*ignoreNext) + { *ignoreNext = false; return; } @@ -226,24 +242,31 @@ void UserInfoPopup::installEvents() this->ui_.ignore->setEnabled(false); auto currentUser = getApp()->accounts->twitch.getCurrent(); - if (this->ui_.ignore->isChecked()) { + if (this->ui_.ignore->isChecked()) + { currentUser->ignoreByID( this->userId_, this->userName_, [=](auto result, const auto &message) mutable { - if (hack.lock()) { - if (result == IgnoreResult_Failed) { + if (hack.lock()) + { + if (result == IgnoreResult_Failed) + { *ignoreNext = true; this->ui_.ignore->setChecked(false); } this->ui_.ignore->setEnabled(true); } }); - } else { + } + else + { currentUser->unignoreByID( this->userId_, this->userName_, [=](auto result, const auto &message) mutable { - if (hack.lock()) { - if (result == UnignoreResult_Failed) { + if (hack.lock()) + { + if (result == UnignoreResult_Failed) + { *ignoreNext = true; this->ui_.ignore->setChecked(true); } @@ -259,24 +282,32 @@ void UserInfoPopup::installEvents() [this](bool checked) mutable { this->ui_.ignoreHighlights->setEnabled(false); - if (checked) { + if (checked) + { getApp()->highlights->blacklistedUsers.insertItem( HighlightBlacklistUser{this->userName_, false}); this->ui_.ignoreHighlights->setEnabled(true); - } else { + } + else + { const auto &vector = getApp()->highlights->blacklistedUsers.getVector(); - for (int i = 0; i < vector.size(); i++) { - if (this->userName_ == vector[i].getPattern()) { + for (int i = 0; i < vector.size(); i++) + { + if (this->userName_ == vector[i].getPattern()) + { getApp()->highlights->blacklistedUsers.removeItem(i); i--; } } - if (getApp()->highlights->blacklistContains(this->userName_)) { + if (getApp()->highlights->blacklistContains(this->userName_)) + { this->ui_.ignoreHighlights->setToolTip( "Name matched by regex"); - } else { + } + else + { this->ui_.ignoreHighlights->setEnabled(true); } } @@ -329,8 +360,10 @@ void UserInfoPopup::updateUserData() // get follow state currentUser->checkFollow(id, [this, hack](auto result) { - if (hack.lock()) { - if (result != FollowResult_Failed) { + if (hack.lock()) + { + if (result != FollowResult_Failed) + { this->ui_.follow->setEnabled(true); this->ui_.follow->setChecked(result == FollowResult_Following); @@ -340,8 +373,10 @@ void UserInfoPopup::updateUserData() // get ignore state bool isIgnoring = false; - for (const auto &ignoredUser : currentUser->getIgnores()) { - if (id == ignoredUser.id) { + for (const auto &ignoredUser : currentUser->getIgnores()) + { + if (id == ignoredUser.id) + { isIgnoring = true; break; } @@ -350,16 +385,21 @@ void UserInfoPopup::updateUserData() // get ignoreHighlights state bool isIgnoringHighlights = false; const auto &vector = getApp()->highlights->blacklistedUsers.getVector(); - for (int i = 0; i < vector.size(); i++) { - if (this->userName_ == vector[i].getPattern()) { + for (int i = 0; i < vector.size(); i++) + { + if (this->userName_ == vector[i].getPattern()) + { isIgnoringHighlights = true; break; } } if (getApp()->highlights->blacklistContains(this->userName_) && - !isIgnoringHighlights) { + !isIgnoringHighlights) + { this->ui_.ignoreHighlights->setToolTip("Name matched by regex"); - } else { + } + else + { this->ui_.ignoreHighlights->setEnabled(true); } this->ui_.ignore->setEnabled(true); @@ -381,14 +421,17 @@ void UserInfoPopup::loadAvatar(const QUrl &url) auto *reply = manager->get(req); QObject::connect(reply, &QNetworkReply::finished, this, [=] { - if (reply->error() == QNetworkReply::NoError) { + if (reply->error() == QNetworkReply::NoError) + { const auto data = reply->readAll(); // might want to cache the avatar image QPixmap avatar; avatar.loadFromData(data); this->ui_.avatarButton->setPixmap(avatar); - } else { + } + else + { this->ui_.avatarButton->setPixmap(QPixmap()); } }); @@ -454,13 +497,17 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget() auto hbox = vbox.emplace().withoutMargin(); hbox->setSpacing(0); - for (const auto &item : items) { + for (const auto &item : items) + { auto a = hbox.emplace(); a->getLabel().setText(std::get<0>(item)); - if (std::get<0>(item).length() > 1) { + if (std::get<0>(item).length() > 1) + { a->setScaleIndependantSize(buttonWidth2, buttonHeight); - } else { + } + else + { a->setScaleIndependantSize(buttonWidth, buttonHeight); } a->setBorderColor(color1); diff --git a/src/widgets/helper/Button.cpp b/src/widgets/helper/Button.cpp index 948fbc6d2..53d866df8 100644 --- a/src/widgets/helper/Button.cpp +++ b/src/widgets/helper/Button.cpp @@ -97,7 +97,8 @@ void Button::setMenu(std::unique_ptr menu) this->menu_->installEventFilter( new FunctionEventFilter(this, [this](QObject *, QEvent *event) { - if (event->type() == QEvent::Hide) { + if (event->type() == QEvent::Hide) + { QTimer::singleShot(20, this, [this] { this->menuVisible_ = false; }); } @@ -111,8 +112,10 @@ void Button::paintEvent(QPaintEvent *) painter.setRenderHint(QPainter::SmoothPixmapTransform); - if (!this->pixmap_.isNull()) { - if (!this->mouseOver_ && this->dimPixmap_ && this->enabled_) { + if (!this->pixmap_.isNull()) + { + if (!this->mouseOver_ && this->dimPixmap_ && this->enabled_) + { painter.setOpacity(this->getCurrentDimAmount()); } @@ -131,7 +134,8 @@ void Button::paintEvent(QPaintEvent *) this->fancyPaint(painter); - if (this->borderColor_.isValid()) { + if (this->borderColor_.isValid()) + { painter.setRenderHint(QPainter::Antialiasing, false); painter.setPen(this->borderColor_); painter.drawRect(0, 0, this->width() - 1, this->height() - 1); @@ -140,7 +144,8 @@ void Button::paintEvent(QPaintEvent *) void Button::fancyPaint(QPainter &painter) { - if (!this->enabled_) { + if (!this->enabled_) + { return; } @@ -148,14 +153,18 @@ void Button::fancyPaint(QPainter &painter) painter.setRenderHint(QPainter::Antialiasing); QColor c; - if (this->mouseEffectColor_) { + if (this->mouseEffectColor_) + { c = this->mouseEffectColor_.get(); - } else { + } + else + { c = this->theme->isLightTheme() ? QColor(0, 0, 0) : QColor(255, 255, 255); } - if (this->hoverMultiplier_ > 0) { + if (this->hoverMultiplier_ > 0) + { QRadialGradient gradient(QPointF(mousePos_), this->width() / 2); gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(), @@ -166,7 +175,8 @@ void Button::fancyPaint(QPainter &painter) painter.fillRect(this->rect(), gradient); } - for (auto effect : this->clickEffects_) { + for (auto effect : this->clickEffects_) + { QRadialGradient gradient(effect.position.x(), effect.position.y(), effect.progress * qreal(width()) * 2, effect.position.x(), effect.position.y()); @@ -193,11 +203,13 @@ void Button::leaveEvent(QEvent *) void Button::mousePressEvent(QMouseEvent *event) { - if (!this->enabled_) { + if (!this->enabled_) + { return; } - if (event->button() != Qt::LeftButton) { + if (event->button() != Qt::LeftButton) + { return; } @@ -207,7 +219,8 @@ void Button::mousePressEvent(QMouseEvent *event) emit this->leftMousePress(); - if (this->menu_ && !this->menuVisible_) { + if (this->menu_ && !this->menuVisible_) + { QTimer::singleShot(80, this, [this] { this->showMenu(); }); this->mouseDown_ = false; this->mouseOver_ = false; @@ -216,24 +229,28 @@ void Button::mousePressEvent(QMouseEvent *event) void Button::mouseReleaseEvent(QMouseEvent *event) { - if (!this->enabled_) { + if (!this->enabled_) + { return; } - if (event->button() != Qt::LeftButton) { + if (event->button() != Qt::LeftButton) + { return; } this->mouseDown_ = false; - if (this->rect().contains(event->pos())) { + if (this->rect().contains(event->pos())) + { emit clicked(); } } void Button::mouseMoveEvent(QMouseEvent *event) { - if (!this->enabled_) { + if (!this->enabled_) + { return; } @@ -246,49 +263,64 @@ void Button::onMouseEffectTimeout() { bool performUpdate = false; - if (selected_) { - if (this->hoverMultiplier_ != 0) { + if (selected_) + { + if (this->hoverMultiplier_ != 0) + { this->hoverMultiplier_ = std::max(0.0, this->hoverMultiplier_ - 0.1); performUpdate = true; } - } else if (mouseOver_) { - if (this->hoverMultiplier_ != 1) { + } + else if (mouseOver_) + { + if (this->hoverMultiplier_ != 1) + { this->hoverMultiplier_ = std::min(1.0, this->hoverMultiplier_ + 0.5); performUpdate = true; } - } else { - if (this->hoverMultiplier_ != 0) { + } + else + { + if (this->hoverMultiplier_ != 0) + { this->hoverMultiplier_ = std::max(0.0, this->hoverMultiplier_ - 0.3); performUpdate = true; } } - if (this->clickEffects_.size() != 0) { + if (this->clickEffects_.size() != 0) + { performUpdate = true; for (auto it = this->clickEffects_.begin(); - it != this->clickEffects_.end();) { + it != this->clickEffects_.end();) + { it->progress += mouseDown_ ? 0.02 : 0.07; - if (it->progress >= 1.0) { + if (it->progress >= 1.0) + { it = this->clickEffects_.erase(it); - } else { + } + else + { it++; } } } - if (performUpdate) { + if (performUpdate) + { update(); } } void Button::showMenu() { - if (!this->menu_) return; + if (!this->menu_) + return; auto point = [this] { auto bounds = QApplication::desktop()->availableGeometry(this); @@ -296,7 +328,8 @@ void Button::showMenu() auto point = this->mapToGlobal( QPoint(this->width() - this->menu_->width(), this->height())); - if (point.y() + this->menu_->height() > bounds.bottom()) { + if (point.y() + this->menu_->height() > bounds.bottom()) + { point.setY(point.y() - this->menu_->height() - this->height()); } diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 14d77f2d8..cc1fd8999 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -61,7 +61,8 @@ namespace { // Add copy and open links for 1x, 2x, 3x auto addImageLink = [&](const ImagePtr &image, char scale) { - if (!image->isEmpty()) { + if (!image->isEmpty()) + { copyMenu->addAction( QString(scale) + "x link", [url = image->url()] { QApplication::clipboard()->setText(url.string); @@ -92,9 +93,12 @@ namespace { }); }; - if (creatorFlags.has(MessageElementFlag::BttvEmote)) { + if (creatorFlags.has(MessageElementFlag::BttvEmote)) + { addPageLink("BTTV"); - } else if (creatorFlags.has(MessageElementFlag::FfzEmote)) { + } + else if (creatorFlags.has(MessageElementFlag::FfzEmote)) + { addPageLink("FFZ"); } } @@ -221,7 +225,8 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) auto messagesSnapshot = this->getMessagesSnapshot(); - if (messagesSnapshot.getLength() == 0) { + if (messagesSnapshot.getLength() == 0) + { this->scrollBar_->setVisible(false); return; @@ -243,11 +248,13 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) MessageElementFlags flags = this->getFlags(); // layout the visible messages in the view - if (messagesSnapshot.getLength() > start) { + if (messagesSnapshot.getLength() > start) + { int y = int(-(messagesSnapshot[start]->getHeight() * (fmod(this->scrollBar_->getCurrentValue(), 1)))); - for (size_t i = start; i < messagesSnapshot.getLength(); ++i) { + for (size_t i = start; i < messagesSnapshot.getLength(); ++i) + { auto message = messagesSnapshot[i]; redrawRequired |= @@ -255,7 +262,8 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) y += message->getHeight(); - if (y >= this->height()) { + if (y >= this->height()) + { break; } } @@ -264,14 +272,16 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) // layout the messages at the bottom to determine the scrollbar thumb size int h = this->height() - 8; - for (int i = int(messagesSnapshot.getLength()) - 1; i >= 0; i--) { + for (int i = int(messagesSnapshot.getLength()) - 1; i >= 0; i--) + { auto *message = messagesSnapshot[i].get(); message->layout(layoutWidth, this->getScale(), flags); h -= message->getHeight(); - if (h < 0) { + if (h < 0) + { this->scrollBar_->setLargeChange( (messagesSnapshot.getLength() - i) + qreal(h) / message->getHeight()); @@ -284,7 +294,8 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) this->scrollBar_->setVisible(showScrollbar); - if (!showScrollbar && !causedByScrollbar) { + if (!showScrollbar && !causedByScrollbar) + { this->scrollBar_->setDesiredValue(0); } @@ -293,8 +304,10 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) // If we were showing the latest messages and the scrollbar now wants to be // rendered, scroll to bottom if (this->enableScrollingToBottom_ && this->showingLatestMessages_ && - showScrollbar) { - if (!this->isPaused()) { + showScrollbar) + { + if (!this->isPaused()) + { this->scrollBar_->scrollToBottom( // this->messageWasAdded && getSettings()->enableSmoothScrollingNewMessages.getValue()); @@ -302,7 +315,8 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) this->messageWasAdded_ = false; } - if (redrawRequired) { + if (redrawRequired) + { this->queueUpdate(); } } @@ -333,12 +347,14 @@ QString ChannelView::getSelectedText() Selection _selection = this->selection_; - if (_selection.isEmpty()) { + if (_selection.isEmpty()) + { return result; } for (int msg = _selection.selectionMin.messageIndex; - msg <= _selection.selectionMax.messageIndex; msg++) { + msg <= _selection.selectionMax.messageIndex; msg++) + { MessageLayoutPtr layout = messagesSnapshot[msg]; int from = msg == _selection.selectionMin.messageIndex ? _selection.selectionMin.charIndex @@ -390,7 +406,8 @@ const boost::optional &ChannelView::getOverrideFlags() LimitedQueueSnapshot ChannelView::getMessagesSnapshot() { - if (!this->isPaused() /*|| this->scrollBar_->isVisible()*/) { + if (!this->isPaused() /*|| this->scrollBar_->isVisible()*/) + { this->snapshot_ = this->messages.getSnapshot(); } @@ -399,7 +416,8 @@ LimitedQueueSnapshot ChannelView::getMessagesSnapshot() void ChannelView::setChannel(ChannelPtr newChannel) { - if (this->channel_) { + if (this->channel_) + { this->detachChannel(); } @@ -412,47 +430,59 @@ void ChannelView::setChannel(ChannelPtr newChannel) MessageLayoutPtr deleted; auto *messageFlags = &message->flags; - if (overridingFlags) { + if (overridingFlags) + { messageFlags = overridingFlags.get_ptr(); } auto messageRef = new MessageLayout(message); - if (this->lastMessageHasAlternateBackground_) { + if (this->lastMessageHasAlternateBackground_) + { messageRef->flags.set(MessageLayoutFlag::AlternateBackground); } - if (this->channel_->shouldIgnoreHighlights()) { + if (this->channel_->shouldIgnoreHighlights()) + { messageRef->flags.set(MessageLayoutFlag::IgnoreHighlights); } this->lastMessageHasAlternateBackground_ = !this->lastMessageHasAlternateBackground_; - if (this->isPaused()) { + if (this->isPaused()) + { this->messagesAddedSinceSelectionPause_++; } - if (this->messages.pushBack(MessageLayoutPtr(messageRef), - deleted)) { + if (this->messages.pushBack(MessageLayoutPtr(messageRef), deleted)) + { // if (!this->isPaused()) { - if (this->scrollBar_->isAtBottom()) { + if (this->scrollBar_->isAtBottom()) + { this->scrollBar_->scrollToBottom(); - } else { + } + else + { this->scrollBar_->offset(-1); } // } } - if (!messageFlags->has(MessageFlag::DoNotTriggerNotification)) { - if (messageFlags->has(MessageFlag::Highlighted)) { + if (!messageFlags->has(MessageFlag::DoNotTriggerNotification)) + { + if (messageFlags->has(MessageFlag::Highlighted)) + { this->tabHighlightRequested.invoke( HighlightState::Highlighted); - } else { + } + else + { this->tabHighlightRequested.invoke( HighlightState::NewMessage); } } - if (this->channel_->getType() != Channel::Type::TwitchMentions) { + if (this->channel_->getType() != Channel::Type::TwitchMentions) + { this->scrollBar_->addHighlight( message->getScrollBarHighlight()); } @@ -466,16 +496,22 @@ void ChannelView::setChannel(ChannelPtr newChannel) [this](std::vector &messages) { std::vector messageRefs; messageRefs.resize(messages.size()); - for (size_t i = 0; i < messages.size(); i++) { + for (size_t i = 0; i < messages.size(); i++) + { messageRefs.at(i) = MessageLayoutPtr(new MessageLayout(messages.at(i))); } - if (!this->isPaused()) { - if (this->messages.pushFront(messageRefs).size() > 0) { - if (this->scrollBar_->isAtBottom()) { + if (!this->isPaused()) + { + if (this->messages.pushFront(messageRefs).size() > 0) + { + if (this->scrollBar_->isAtBottom()) + { this->scrollBar_->scrollToBottom(); - } else { + } + else + { this->scrollBar_->offset(qreal(messages.size())); } } @@ -483,7 +519,8 @@ void ChannelView::setChannel(ChannelPtr newChannel) std::vector highlights; highlights.reserve(messages.size()); - for (size_t i = 0; i < messages.size(); i++) { + for (size_t i = 0; i < messages.size(); i++) + { highlights.push_back( messages.at(i)->getScrollBarHighlight()); } @@ -508,14 +545,15 @@ void ChannelView::setChannel(ChannelPtr newChannel) // on message replaced this->channelConnections_.push_back(newChannel->messageReplaced.connect( [this](size_t index, MessagePtr replacement) { - if (index >= this->messages.getSnapshot().getLength() || - index < 0) { + if (index >= this->messages.getSnapshot().getLength() || index < 0) + { return; } MessageLayoutPtr newItem(new MessageLayout(replacement)); auto snapshot = this->messages.getSnapshot(); - if (index >= snapshot.getLength()) { + if (index >= snapshot.getLength()) + { log("Tried to replace out of bounds message. Index: {}. " "Length: {}", index, snapshot.getLength()); @@ -523,7 +561,8 @@ void ChannelView::setChannel(ChannelPtr newChannel) } const auto &message = snapshot[index]; - if (message->flags.has(MessageLayoutFlag::AlternateBackground)) { + if (message->flags.has(MessageLayoutFlag::AlternateBackground)) + { newItem->flags.set(MessageLayoutFlag::AlternateBackground); } @@ -536,12 +575,14 @@ void ChannelView::setChannel(ChannelPtr newChannel) auto snapshot = newChannel->getMessageSnapshot(); - for (size_t i = 0; i < snapshot.getLength(); i++) { + for (size_t i = 0; i < snapshot.getLength(); i++) + { MessageLayoutPtr deleted; auto messageRef = new MessageLayout(snapshot[i]); - if (this->lastMessageHasAlternateBackground_) { + if (this->lastMessageHasAlternateBackground_) + { messageRef->flags.set(MessageLayoutFlag::AlternateBackground); } this->lastMessageHasAlternateBackground_ = @@ -556,7 +597,8 @@ void ChannelView::setChannel(ChannelPtr newChannel) this->queueUpdate(); // Notifications - if (auto tc = dynamic_cast(newChannel.get())) { + if (auto tc = dynamic_cast(newChannel.get())) + { tc->liveStatusChanged.connect([this]() { this->liveStatusChanged.invoke(); // }); @@ -573,7 +615,8 @@ void ChannelView::pause(int msecTimeout) this->pausedTemporarily_ = true; this->updatePauseStatus(); - if (this->pauseTimeout_.remainingTime() < msecTimeout) { + if (this->pauseTimeout_.remainingTime() < msecTimeout) + { this->pauseTimeout_.stop(); this->pauseTimeout_.start(msecTimeout); @@ -585,7 +628,8 @@ void ChannelView::updateLastReadMessage() { auto _snapshot = this->getMessagesSnapshot(); - if (_snapshot.getLength() > 0) { + if (_snapshot.getLength() > 0) + { this->lastReadMessage_ = _snapshot[_snapshot.getLength() - 1]; } @@ -610,7 +654,8 @@ void ChannelView::setSelection(const SelectionItem &start, const SelectionItem &end) { // selections - if (!this->selecting_ && start != end) { + if (!this->selecting_ && start != end) + { this->messagesAddedSinceSelectionPause_ = 0; this->selecting_ = true; @@ -626,7 +671,8 @@ MessageElementFlags ChannelView::getFlags() const { auto app = getApp(); - if (this->overrideFlags_) { + if (this->overrideFlags_) + { return this->overrideFlags_.get(); } @@ -634,11 +680,14 @@ MessageElementFlags ChannelView::getFlags() const Split *split = dynamic_cast(this->parentWidget()); - if (split != nullptr) { - if (split->getModerationMode()) { + if (split != nullptr) + { + if (split->getModerationMode()) + { flags.set(MessageElementFlag::ModeratorTools); } - if (this->channel_ == app->twitch.server->mentionsChannel) { + if (this->channel_ == app->twitch.server->mentionsChannel) + { flags.set(MessageElementFlag::ChannelName); } } @@ -655,9 +704,12 @@ bool ChannelView::isPaused() void ChannelView::updatePauseStatus() { - if (this->isPaused()) { + if (this->isPaused()) + { this->scrollBar_->pauseHighlights(); - } else { + } + else + { this->scrollBar_->unpauseHighlights(); } } @@ -682,7 +734,8 @@ void ChannelView::drawMessages(QPainter &painter) size_t start = size_t(this->scrollBar_->getCurrentValue()); - if (start >= messagesSnapshot.getLength()) { + if (start >= messagesSnapshot.getLength()) + { return; } @@ -692,11 +745,13 @@ void ChannelView::drawMessages(QPainter &painter) MessageLayout *end = nullptr; bool windowFocused = this->window() == QApplication::activeWindow(); - for (size_t i = start; i < messagesSnapshot.getLength(); ++i) { + for (size_t i = start; i < messagesSnapshot.getLength(); ++i) + { MessageLayout *layout = messagesSnapshot[i].get(); bool isLastMessage = false; - if (getSettings()->showLastMessageIndicator) { + if (getSettings()->showLastMessageIndicator) + { isLastMessage = this->lastReadMessage_.get() == layout; } @@ -706,38 +761,45 @@ void ChannelView::drawMessages(QPainter &painter) y += layout->getHeight(); end = layout; - if (y > this->height()) { + if (y > this->height()) + { break; } } - if (end == nullptr) { + if (end == nullptr) + { return; } // remove messages that are on screen // the messages that are left at the end get their buffers reset - for (size_t i = start; i < messagesSnapshot.getLength(); ++i) { + for (size_t i = start; i < messagesSnapshot.getLength(); ++i) + { auto it = this->messagesOnScreen_.find(messagesSnapshot[i]); - if (it != this->messagesOnScreen_.end()) { + if (it != this->messagesOnScreen_.end()) + { this->messagesOnScreen_.erase(it); } } // delete the message buffers that aren't on screen - for (const std::shared_ptr &item : this->messagesOnScreen_) { + for (const std::shared_ptr &item : this->messagesOnScreen_) + { item->deleteBuffer(); } this->messagesOnScreen_.clear(); // add all messages on screen to the map - for (size_t i = start; i < messagesSnapshot.getLength(); ++i) { + for (size_t i = start; i < messagesSnapshot.getLength(); ++i) + { std::shared_ptr layout = messagesSnapshot[i]; this->messagesOnScreen_.insert(layout); - if (layout.get() == end) { + if (layout.get() == end) + { break; } } @@ -745,7 +807,8 @@ void ChannelView::drawMessages(QPainter &painter) void ChannelView::wheelEvent(QWheelEvent *event) { - if (event->orientation() != Qt::Vertical) { + if (event->orientation() != Qt::Vertical) + { return; } @@ -753,12 +816,14 @@ void ChannelView::wheelEvent(QWheelEvent *event) this->pausedTemporarily_ = false; this->updatePauseStatus(); - if (event->modifiers() & Qt::ControlModifier) { + if (event->modifiers() & Qt::ControlModifier) + { event->ignore(); return; } - if (this->scrollBar_->isVisible()) { + if (this->scrollBar_->isVisible()) + { float mouseMultiplier = getSettings()->mouseScrollMultiplier; qreal desired = this->scrollBar_->getDesiredValue(); @@ -768,48 +833,65 @@ void ChannelView::wheelEvent(QWheelEvent *event) int snapshotLength = int(snapshot.getLength()); int i = std::min(int(desired), snapshotLength); - if (delta > 0) { + if (delta > 0) + { qreal scrollFactor = fmod(desired, 1); qreal currentScrollLeft = int(scrollFactor * snapshot[i]->getHeight()); - for (; i >= 0; i--) { - if (delta < currentScrollLeft) { + for (; i >= 0; i--) + { + if (delta < currentScrollLeft) + { desired -= scrollFactor * (delta / currentScrollLeft); break; - } else { + } + else + { delta -= currentScrollLeft; desired -= scrollFactor; } - if (i == 0) { + if (i == 0) + { desired = 0; - } else { + } + else + { snapshot[i - 1]->layout(this->getLayoutWidth(), this->getScale(), this->getFlags()); scrollFactor = 1; currentScrollLeft = snapshot[i - 1]->getHeight(); } } - } else { + } + else + { delta = -delta; qreal scrollFactor = 1 - fmod(desired, 1); qreal currentScrollLeft = int(scrollFactor * snapshot[i]->getHeight()); - for (; i < snapshotLength; i++) { - if (delta < currentScrollLeft) { + for (; i < snapshotLength; i++) + { + if (delta < currentScrollLeft) + { desired += scrollFactor * (qreal(delta) / currentScrollLeft); break; - } else { + } + else + { delta -= currentScrollLeft; desired += scrollFactor; } - if (i == snapshotLength - 1) { + if (i == snapshotLength - 1) + { desired = snapshot.getLength(); - } else { + } + else + { snapshot[i + 1]->layout(this->getLayoutWidth(), this->getScale(), this->getFlags()); @@ -837,14 +919,16 @@ void ChannelView::leaveEvent(QEvent *) void ChannelView::mouseMoveEvent(QMouseEvent *event) { - if (event->modifiers() & (Qt::AltModifier | Qt::ControlModifier)) { + if (event->modifiers() & (Qt::AltModifier | Qt::ControlModifier)) + { this->unsetCursor(); event->ignore(); return; } - if (getSettings()->pauseChatHover.getValue()) { + if (getSettings()->pauseChatHover.getValue()) + { this->pause(CHAT_HOVER_PAUSE_DURATION); } @@ -854,14 +938,16 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) int messageIndex; // no message under cursor - if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) { + if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) + { this->setCursor(Qt::ArrowCursor); tooltipWidget->hide(); return; } // is selecting - if (this->isMouseDown_) { + if (this->isMouseDown_) + { this->pause(300); int index = layout->getSelectionIndex(relativePos); @@ -872,7 +958,8 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } // message under cursor is collapsed - if (layout->flags.has(MessageLayoutFlag::Collapsed)) { + if (layout->flags.has(MessageLayoutFlag::Collapsed)) + { this->setCursor(Qt::PointingHandCursor); tooltipWidget->hide(); return; @@ -882,13 +969,15 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) const MessageLayoutElement *hoverLayoutElement = layout->getElementAt(relativePos); - if (hoverLayoutElement == nullptr) { + if (hoverLayoutElement == nullptr) + { this->setCursor(Qt::ArrowCursor); tooltipWidget->hide(); return; } - if (this->isDoubleClick_) { + if (this->isDoubleClick_) + { int wordStart; int wordEnd; this->getWordBounds(layout.get(), hoverLayoutElement, relativePos, @@ -897,91 +986,125 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) SelectionItem newEnd(messageIndex, wordEnd); // Selection changed in same message - if (messageIndex == this->dCSelection_.origMessageIndex) { + if (messageIndex == this->dCSelection_.origMessageIndex) + { // Selecting to the left if (wordStart < this->selection_.start.charIndex && - !this->dCSelection_.selectingRight) { + !this->dCSelection_.selectingRight) + { this->dCSelection_.selectingLeft = true; // Ensure that the original word stays selected(Edge case) - if (wordStart > this->dCSelection_.originalEnd) { + if (wordStart > this->dCSelection_.originalEnd) + { this->setSelection(this->dCSelection_.origStartItem, newEnd); - } else { + } + else + { this->setSelection(newStart, this->selection_.end); } // Selecting to the right - } else if (wordEnd > this->selection_.end.charIndex && - !this->dCSelection_.selectingLeft) { + } + else if (wordEnd > this->selection_.end.charIndex && + !this->dCSelection_.selectingLeft) + { this->dCSelection_.selectingRight = true; // Ensure that the original word stays selected(Edge case) - if (wordEnd < this->dCSelection_.originalStart) { + if (wordEnd < this->dCSelection_.originalStart) + { this->setSelection(newStart, this->dCSelection_.origEndItem); - } else { + } + else + { this->setSelection(this->selection_.start, newEnd); } } // Swapping from selecting left to selecting right if (wordStart > this->selection_.start.charIndex && - !this->dCSelection_.selectingRight) { - if (wordStart > this->dCSelection_.originalEnd) { + !this->dCSelection_.selectingRight) + { + if (wordStart > this->dCSelection_.originalEnd) + { this->dCSelection_.selectingLeft = false; this->dCSelection_.selectingRight = true; this->setSelection(this->dCSelection_.origStartItem, newEnd); - } else { + } + else + { this->setSelection(newStart, this->selection_.end); } // Swapping from selecting right to selecting left - } else if (wordEnd < this->selection_.end.charIndex && - !this->dCSelection_.selectingLeft) { - if (wordEnd < this->dCSelection_.originalStart) { + } + else if (wordEnd < this->selection_.end.charIndex && + !this->dCSelection_.selectingLeft) + { + if (wordEnd < this->dCSelection_.originalStart) + { this->dCSelection_.selectingLeft = true; this->dCSelection_.selectingRight = false; this->setSelection(newStart, this->dCSelection_.origEndItem); - } else { + } + else + { this->setSelection(this->selection_.start, newEnd); } } // Selection changed in a different message - } else { + } + else + { // Message over the original - if (messageIndex < this->selection_.start.messageIndex) { + if (messageIndex < this->selection_.start.messageIndex) + { // Swapping from left to right selecting - if (!this->dCSelection_.selectingLeft) { + if (!this->dCSelection_.selectingLeft) + { this->dCSelection_.selectingLeft = true; this->dCSelection_.selectingRight = false; } if (wordStart < this->selection_.start.charIndex && - !this->dCSelection_.selectingRight) { + !this->dCSelection_.selectingRight) + { this->dCSelection_.selectingLeft = true; } this->setSelection(newStart, this->dCSelection_.origEndItem); // Message under the original - } else if (messageIndex > this->selection_.end.messageIndex) { + } + else if (messageIndex > this->selection_.end.messageIndex) + { // Swapping from right to left selecting - if (!this->dCSelection_.selectingRight) { + if (!this->dCSelection_.selectingRight) + { this->dCSelection_.selectingLeft = false; this->dCSelection_.selectingRight = true; } if (wordEnd > this->selection_.end.charIndex && - !this->dCSelection_.selectingLeft) { + !this->dCSelection_.selectingLeft) + { this->dCSelection_.selectingRight = true; } this->setSelection(this->dCSelection_.origStartItem, newEnd); // Selection changed in non original message - } else { - if (this->dCSelection_.selectingLeft) { + } + else + { + if (this->dCSelection_.selectingLeft) + { this->setSelection(newStart, this->selection_.end); - } else { + } + else + { this->setSelection(this->selection_.start, newEnd); } } } // Reset direction of selection if (wordStart == this->dCSelection_.originalStart && - wordEnd == this->dCSelection_.originalEnd) { + wordEnd == this->dCSelection_.originalEnd) + { this->dCSelection_.selectingLeft = this->dCSelection_.selectingRight = false; } @@ -990,11 +1113,16 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) const auto &tooltip = hoverLayoutElement->getCreator().getTooltip(); bool isLinkValid = hoverLayoutElement->getLink().isValid(); - if (tooltip.isEmpty()) { + if (tooltip.isEmpty()) + { tooltipWidget->hide(); - } else if (isLinkValid && !getSettings()->enableLinkInfoTooltip) { + } + else if (isLinkValid && !getSettings()->enableLinkInfoTooltip) + { tooltipWidget->hide(); - } else { + } + else + { tooltipWidget->moveTo(this, event->globalPos()); tooltipWidget->setWordWrap(isLinkValid); tooltipWidget->setText(tooltip); @@ -1004,9 +1132,12 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } // check if word has a link - if (isLinkValid) { + if (isLinkValid) + { this->setCursor(Qt::PointingHandCursor); - } else { + } + else + { this->setCursor(Qt::ArrowCursor); } } @@ -1019,15 +1150,18 @@ void ChannelView::mousePressEvent(QMouseEvent *event) QPoint relativePos; int messageIndex; - if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) { + if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) + { setCursor(Qt::ArrowCursor); auto messagesSnapshot = this->getMessagesSnapshot(); - if (messagesSnapshot.getLength() == 0) { + if (messagesSnapshot.getLength() == 0) + { return; } // Start selection at the last message at its last index - if (event->button() == Qt::LeftButton) { + if (event->button() == Qt::LeftButton) + { auto lastMessageIndex = messagesSnapshot.getLength() - 1; auto lastMessage = messagesSnapshot[lastMessageIndex]; auto lastCharacterIndex = lastMessage->getLastCharacterIndex(); @@ -1039,28 +1173,35 @@ void ChannelView::mousePressEvent(QMouseEvent *event) } // check if message is collapsed - switch (event->button()) { - case Qt::LeftButton: { + switch (event->button()) + { + case Qt::LeftButton: + { this->lastPressPosition_ = event->screenPos(); this->isMouseDown_ = true; - if (layout->flags.has(MessageLayoutFlag::Collapsed)) { + if (layout->flags.has(MessageLayoutFlag::Collapsed)) + { return; } - if (getSettings()->linksDoubleClickOnly.getValue()) { + if (getSettings()->linksDoubleClickOnly.getValue()) + { this->pause(200); } int index = layout->getSelectionIndex(relativePos); auto selectionItem = SelectionItem(messageIndex, index); this->setSelection(selectionItem, selectionItem); - } break; + } + break; - case Qt::RightButton: { + case Qt::RightButton: + { this->lastRightPressPosition_ = event->screenPos(); this->isRightMouseDown_ = true; - } break; + } + break; default:; } @@ -1071,39 +1212,55 @@ void ChannelView::mousePressEvent(QMouseEvent *event) void ChannelView::mouseReleaseEvent(QMouseEvent *event) { // check if mouse was pressed - if (event->button() == Qt::LeftButton) { + if (event->button() == Qt::LeftButton) + { this->dCSelection_.selectingLeft = this->dCSelection_.selectingRight = false; - if (this->isDoubleClick_) { + if (this->isDoubleClick_) + { this->isDoubleClick_ = false; // Was actually not a wanted triple-click if (fabsf(distanceBetweenPoints(this->lastDClickPosition_, - event->screenPos())) > 10.f) { + event->screenPos())) > 10.f) + { this->clickTimer_->stop(); return; } - } else if (this->isMouseDown_) { + } + else if (this->isMouseDown_) + { this->isMouseDown_ = false; if (fabsf(distanceBetweenPoints(this->lastPressPosition_, - event->screenPos())) > 15.f) { + event->screenPos())) > 15.f) + { return; } - } else { + } + else + { return; } - } else if (event->button() == Qt::RightButton) { - if (this->isRightMouseDown_) { + } + else if (event->button() == Qt::RightButton) + { + if (this->isRightMouseDown_) + { this->isRightMouseDown_ = false; if (fabsf(distanceBetweenPoints(this->lastRightPressPosition_, - event->screenPos())) > 15.f) { + event->screenPos())) > 15.f) + { return; } - } else { + } + else + { return; } - } else { + } + else + { // not left or right button return; } @@ -1115,13 +1272,15 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event) int messageIndex; // no message found - if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) { + if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) + { // No message at clicked position return; } // message under cursor is collapsed - if (layout->flags.has(MessageLayoutFlag::Collapsed)) { + if (layout->flags.has(MessageLayoutFlag::Collapsed)) + { layout->flags.set(MessageLayoutFlag::Expanded); layout->flags.set(MessageLayoutFlag::RequiresLayout); @@ -1132,14 +1291,17 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event) const MessageLayoutElement *hoverLayoutElement = layout->getElementAt(relativePos); // Triple-clicking a message selects the whole message - if (this->clickTimer_->isActive() && this->selecting_) { + if (this->clickTimer_->isActive() && this->selecting_) + { if (fabsf(distanceBetweenPoints(this->lastDClickPosition_, - event->screenPos())) < 10.f) { + event->screenPos())) < 10.f) + { this->selectWholeMessage(layout.get(), messageIndex); } } - if (hoverLayoutElement == nullptr) { + if (hoverLayoutElement == nullptr) + { return; } @@ -1151,11 +1313,15 @@ void ChannelView::handleMouseClick(QMouseEvent *event, const MessageLayoutElement *hoveredElement, MessageLayout *layout) { - switch (event->button()) { - case Qt::LeftButton: { - if (this->selecting_) { + switch (event->button()) + { + case Qt::LeftButton: + { + if (this->selecting_) + { if (this->messagesAddedSinceSelectionPause_ > - SELECTION_RESUME_SCROLLING_MSG_THRESHOLD) { + SELECTION_RESUME_SCROLLING_MSG_THRESHOLD) + { this->showingLatestMessages_ = false; } @@ -1168,31 +1334,42 @@ void ChannelView::handleMouseClick(QMouseEvent *event, } auto &link = hoveredElement->getLink(); - if (!getSettings()->linksDoubleClickOnly) { + if (!getSettings()->linksDoubleClickOnly) + { this->handleLinkClick(event, link, layout); } // Invoke to signal from EmotePopup. - if (link.type == Link::InsertText) { + if (link.type == Link::InsertText) + { this->linkClicked.invoke(link); } - } break; - case Qt::RightButton: { + } + break; + case Qt::RightButton: + { auto insertText = [=](QString text) { - if (auto split = dynamic_cast(this->parentWidget())) { + if (auto split = dynamic_cast(this->parentWidget())) + { split->insertTextToInput(text); } }; auto &link = hoveredElement->getLink(); - if (link.type == Link::UserInfo) { + if (link.type == Link::UserInfo) + { insertText("@" + link.value + ", "); - } else if (link.type == Link::UserWhisper) { + } + else if (link.type == Link::UserWhisper) + { insertText("/w " + link.value + " "); - } else { + } + else + { this->addContextMenuItems(hoveredElement, layout); } - } break; + } + break; default:; } } @@ -1207,8 +1384,9 @@ void ChannelView::addContextMenuItems( menu->clear(); // Emote actions - if (creatorFlags.hasAny({MessageElementFlag::EmoteImages, - MessageElementFlag::EmojiImage})) { + if (creatorFlags.hasAny( + {MessageElementFlag::EmoteImages, MessageElementFlag::EmojiImage})) + { const auto emoteElement = dynamic_cast(&creator); if (emoteElement) addEmoteContextMenuItems(*emoteElement->getEmote(), creatorFlags, @@ -1216,12 +1394,14 @@ void ChannelView::addContextMenuItems( } // add seperator - if (!menu->actions().empty()) { + if (!menu->actions().empty()) + { menu->addSeparator(); } // Link copy - if (hoveredElement->getLink().type == Link::Url) { + if (hoveredElement->getLink().type == Link::Url) + { QString url = hoveredElement->getLink().value; // open link @@ -1234,7 +1414,8 @@ void ChannelView::addContextMenuItems( QDesktopServices::openUrl(QUrl(url)); }); // open link default - if (supportsIncognitoLinks()) { + if (supportsIncognitoLinks()) + { menu->addAction("Open link incognito", [url] { openLinkIncognito(url); }); } @@ -1245,7 +1426,8 @@ void ChannelView::addContextMenuItems( } // Copy actions - if (!this->selection_.isEmpty()) { + if (!this->selection_.isEmpty()) + { menu->addAction("Copy selection", [this] { QGuiApplication::clipboard()->setText(this->getSelectedText()); }); @@ -1267,7 +1449,8 @@ void ChannelView::addContextMenuItems( }); // Open in new split. - if (hoveredElement->getLink().type == Link::Url) { + if (hoveredElement->getLink().type == Link::Url) + { static QRegularExpression twitchChannelRegex( R"(^(?:https?:\/\/)?(?:www\.|go\.)?twitch\.tv\/(?[a-z0-9_]{3,}))", QRegularExpression::CaseInsensitiveOption); @@ -1280,7 +1463,8 @@ void ChannelView::addContextMenuItems( twitchChannelRegex.match(hoveredElement->getLink().value); auto twitchUsername = twitchMatch.captured("username"); if (!twitchUsername.isEmpty() && - !ignoredUsernames.contains(twitchUsername)) { + !ignoredUsernames.contains(twitchUsername)) + { menu->addSeparator(); menu->addAction("Open in new split", [twitchUsername, this] { this->joinToChannel.invoke(twitchUsername); @@ -1300,12 +1484,14 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event) QPoint relativePos; int messageIndex; - if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) { + if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) + { return; } // message under cursor is collapsed - if (layout->flags.has(MessageLayoutFlag::Collapsed)) { + if (layout->flags.has(MessageLayoutFlag::Collapsed)) + { return; } @@ -1313,13 +1499,15 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event) layout->getElementAt(relativePos); this->lastDClickPosition_ = event->screenPos(); - if (hoverLayoutElement == nullptr) { + if (hoverLayoutElement == nullptr) + { // Possibility for triple click which doesn't have to be over an // existing layout element this->clickTimer_->start(); return; } - if (!this->isMouseDown_) { + if (!this->isMouseDown_) + { this->isDoubleClick_ = true; int wordStart; @@ -1341,7 +1529,8 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event) this->setSelection(wordMin, wordMax); } - if (getSettings()->linksDoubleClickOnly) { + if (getSettings()->linksDoubleClickOnly) + { auto &link = hoverLayoutElement->getLink(); this->handleLinkClick(event, link, layout.get()); } @@ -1349,7 +1538,8 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event) void ChannelView::hideEvent(QHideEvent *) { - for (auto &layout : this->messagesOnScreen_) { + for (auto &layout : this->messagesOnScreen_) + { layout->deleteBuffer(); } @@ -1369,27 +1559,35 @@ void ChannelView::showUserInfoPopup(const QString &userName) void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link, MessageLayout *layout) { - if (event->button() != Qt::LeftButton) { + if (event->button() != Qt::LeftButton) + { return; } - switch (link.type) { + switch (link.type) + { case Link::UserWhisper: - case Link::UserInfo: { + case Link::UserInfo: + { auto user = link.value; this->showUserInfoPopup(user); qDebug() << "Clicked " << user << "s message"; - } break; + } + break; - case Link::Url: { + case Link::Url: + { QDesktopServices::openUrl(QUrl(link.value)); - } break; + } + break; - case Link::UserAction: { + case Link::UserAction: + { QString value = link.value; value.replace("{user}", layout->getMessage()->loginName); this->channel_->sendMessage(value); - } break; + } + break; default:; } @@ -1403,17 +1601,20 @@ bool ChannelView::tryGetMessageAt(QPoint p, size_t start = this->scrollBar_->getCurrentValue(); - if (start >= messagesSnapshot.getLength()) { + if (start >= messagesSnapshot.getLength()) + { return false; } int y = -(messagesSnapshot[start]->getHeight() * (fmod(this->scrollBar_->getCurrentValue(), 1))); - for (size_t i = start; i < messagesSnapshot.getLength(); ++i) { + for (size_t i = start; i < messagesSnapshot.getLength(); ++i) + { auto message = messagesSnapshot[i]; - if (p.y() < y + message->getHeight()) { + if (p.y() < y + message->getHeight()) + { relativePos = QPoint(p.x(), p.y() - y); _message = message; index = i; diff --git a/src/widgets/helper/ComboBoxItemDelegate.cpp b/src/widgets/helper/ComboBoxItemDelegate.cpp index 45d2d545e..00bcb9e14 100644 --- a/src/widgets/helper/ComboBoxItemDelegate.cpp +++ b/src/widgets/helper/ComboBoxItemDelegate.cpp @@ -19,7 +19,8 @@ QWidget *ComboBoxItemDelegate::createEditor(QWidget *parent, { QVariant data = index.data(Qt::UserRole + 1); - if (data.type() != QVariant::StringList) { + if (data.type() != QVariant::StringList) + { return QStyledItemDelegate::createEditor(parent, option, index); } @@ -31,17 +32,21 @@ QWidget *ComboBoxItemDelegate::createEditor(QWidget *parent, void ComboBoxItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { - if (QComboBox *cb = qobject_cast(editor)) { + if (QComboBox *cb = qobject_cast(editor)) + { // get the index of the text in the combobox that matches the current // value of the itenm QString currentText = index.data(Qt::EditRole).toString(); int cbIndex = cb->findText(currentText); // if it is valid, adjust the combobox - if (cbIndex >= 0) { + if (cbIndex >= 0) + { cb->setCurrentIndex(cbIndex); } - } else { + } + else + { QStyledItemDelegate::setEditorData(editor, index); } } diff --git a/src/widgets/helper/EditableModelView.cpp b/src/widgets/helper/EditableModelView.cpp index 3118cd3d4..1f01c7ec1 100644 --- a/src/widgets/helper/EditableModelView.cpp +++ b/src/widgets/helper/EditableModelView.cpp @@ -40,7 +40,8 @@ EditableModelView::EditableModelView(QAbstractTableModel *model) QObject::connect(remove, &QPushButton::clicked, [this] { QModelIndexList list; while ((list = this->getTableView()->selectionModel()->selectedRows(0)) - .length() > 0) { + .length() > 0) + { model_->removeRow(list[0].row()); } }); @@ -52,8 +53,10 @@ EditableModelView::EditableModelView(QAbstractTableModel *model) void EditableModelView::setTitles(std::initializer_list titles) { int i = 0; - for (const QString &title : titles) { - if (this->model_->columnCount() == i) { + for (const QString &title : titles) + { + if (this->model_->columnCount() == i) + { break; } diff --git a/src/widgets/helper/Line.hpp b/src/widgets/helper/Line.hpp index 8cb5fce4b..f813e349d 100644 --- a/src/widgets/helper/Line.hpp +++ b/src/widgets/helper/Line.hpp @@ -13,9 +13,12 @@ public: : BaseWidget(nullptr) , vertical_(vertical) { - if (this->vertical_) { + if (this->vertical_) + { this->setScaleIndependantWidth(8); - } else { + } + else + { this->setScaleIndependantHeight(8); } } @@ -26,10 +29,13 @@ public: painter.setPen(QColor("#999")); - if (this->vertical_) { + if (this->vertical_) + { painter.drawLine(this->width() / 2, 0, this->width() / 2, this->height()); - } else { + } + else + { painter.drawLine(0, this->height() / 2, this->width(), this->height() / 2); } diff --git a/src/widgets/helper/NotebookButton.cpp b/src/widgets/helper/NotebookButton.cpp index 97ab85d0e..a27e2293a 100644 --- a/src/widgets/helper/NotebookButton.cpp +++ b/src/widgets/helper/NotebookButton.cpp @@ -45,10 +45,13 @@ void NotebookButton::paintEvent(QPaintEvent *event) QColor background; QColor foreground; - if (mouseDown_ || mouseOver_) { + if (mouseDown_ || mouseOver_) + { background = this->theme->tabs.regular.backgrounds.hover.color(); foreground = this->theme->tabs.regular.text; - } else { + } + else + { background = this->theme->tabs.regular.backgrounds.regular.color(); foreground = this->theme->tabs.regular.text; } @@ -57,13 +60,18 @@ void NotebookButton::paintEvent(QPaintEvent *event) float h = height(), w = width(); - switch (icon_) { - case Plus: { + switch (icon_) + { + case Plus: + { painter.setPen([&] { QColor tmp = foreground; - if (SplitContainer::isDraggingSplit) { + if (SplitContainer::isDraggingSplit) + { tmp = this->theme->tabs.selected.line.regular; - } else if (!this->mouseOver_) { + } + else if (!this->mouseOver_) + { tmp.setAlpha(180); } return tmp; @@ -79,9 +87,11 @@ void NotebookButton::paintEvent(QPaintEvent *event) rect.top() + rect.height() / 2 - (s / 2), rect.left() + rect.width() / 2, rect.top() + rect.height() / 2 + (s / 2)); - } break; + } + break; - case User: { + case User: + { painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::HighQualityAntialiasing); @@ -98,9 +108,11 @@ void NotebookButton::paintEvent(QPaintEvent *event) painter.setBrush(foreground); painter.drawEllipse(2.5 * a, 1.5 * a, 3 * a + 1, 3 * a); - } break; + } + break; - case Settings: { + case Settings: + { painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::HighQualityAntialiasing); @@ -109,7 +121,8 @@ void NotebookButton::paintEvent(QPaintEvent *event) path.arcMoveTo(a, a, 6 * a, 6 * a, 0 - (360 / 32.0)); - for (int i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) + { path.arcTo(a, a, 6 * a, 6 * a, i * (360 / 8.0) - (360 / 32.0), (360 / 32.0)); path.arcTo(2 * a, 2 * a, 4 * a, 4 * a, @@ -120,7 +133,8 @@ void NotebookButton::paintEvent(QPaintEvent *event) painter.setBrush(background); painter.drawEllipse(3 * a, 3 * a, 2 * a, 2 * a); - } break; + } + break; default:; } @@ -130,7 +144,8 @@ void NotebookButton::paintEvent(QPaintEvent *event) void NotebookButton::mouseReleaseEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton) { + if (event->button() == Qt::LeftButton) + { mouseDown_ = false; update(); @@ -143,7 +158,8 @@ void NotebookButton::mouseReleaseEvent(QMouseEvent *event) void NotebookButton::dragEnterEvent(QDragEnterEvent *event) { - if (!event->mimeData()->hasFormat("chatterino/split")) { + if (!event->mimeData()->hasFormat("chatterino/split")) + { return; } @@ -170,12 +186,14 @@ void NotebookButton::dragLeaveEvent(QDragLeaveEvent *) void NotebookButton::dropEvent(QDropEvent *event) { - if (SplitContainer::isDraggingSplit) { + if (SplitContainer::isDraggingSplit) + { event->acceptProposedAction(); Notebook *notebook = dynamic_cast(this->parentWidget()); - if (notebook != nuuls) { + if (notebook != nuuls) + { SplitContainer *page = new SplitContainer(notebook); auto *tab = notebook->addPage(page); page->setTab(tab); diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index bdee3850a..27060a892 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -50,7 +50,8 @@ NotebookTab::NotebookTab(Notebook *notebook) d.setText(this->getCustomTitle()); d.highlightText(); - if (d.exec() == QDialog::Accepted) { + if (d.exec() == QDialog::Accepted) + { QString newTitle = d.getText(); this->setCustomTitle(newTitle); } @@ -86,16 +87,20 @@ void NotebookTab::updateSize() FontStyle::UiTabs, float(qreal(this->getScale()) * this->devicePixelRatioF())); - if (this->hasXButton()) { + if (this->hasXButton()) + { width = (metrics.width(this->getTitle()) + int(32 * scale)); - } else { + } + else + { width = (metrics.width(this->getTitle()) + int(16 * scale)); } width = clamp(width, this->height(), int(150 * scale)); auto height = int(NOTEBOOK_TAB_HEIGHT * scale); - if (this->width() != width || this->height() != height) { + if (this->width() != width || this->height() != height) + { this->resize(width, height); this->notebook_->performLayout(); } @@ -108,7 +113,8 @@ const QString &NotebookTab::getCustomTitle() const void NotebookTab::setCustomTitle(const QString &newTitle) { - if (this->customTitle_ != newTitle) { + if (this->customTitle_ != newTitle) + { this->customTitle_ = newTitle; this->titleUpdated(); } @@ -126,10 +132,12 @@ bool NotebookTab::hasCustomTitle() const void NotebookTab::setDefaultTitle(const QString &title) { - if (this->defaultTitle_ != title) { + if (this->defaultTitle_ != title) + { this->defaultTitle_ = title; - if (this->customTitle_.isEmpty()) { + if (this->customTitle_.isEmpty()) + { this->titleUpdated(); } } @@ -171,7 +179,8 @@ void NotebookTab::setSelected(bool value) void NotebookTab::setInLastRow(bool value) { - if (this->isInLastRow_ != value) { + if (this->isInLastRow_ != value) + { this->isInLastRow_ = value; this->update(); } @@ -179,7 +188,8 @@ void NotebookTab::setInLastRow(bool value) void NotebookTab::setLive(bool isLive) { - if (this->isLive_ != isLive) { + if (this->isLive_ != isLive) + { this->isLive_ = isLive; this->update(); } @@ -187,10 +197,12 @@ void NotebookTab::setLive(bool isLive) void NotebookTab::setHighlightState(HighlightState newHighlightStyle) { - if (this->isSelected() || !this->highlightEnabled_) { + if (this->isSelected() || !this->highlightEnabled_) + { return; } - if (this->highlightState_ != HighlightState::Highlighted) { + if (this->highlightState_ != HighlightState::Highlighted) + { this->highlightState_ = newHighlightStyle; this->update(); @@ -226,14 +238,16 @@ void NotebookTab::moveAnimated(QPoint pos, bool animated) QWidget *w = this->window(); if ((w != nullptr && !w->isVisible()) || !animated || - !this->positionChangedAnimationRunning_) { + !this->positionChangedAnimationRunning_) + { this->move(pos); this->positionChangedAnimationRunning_ = true; return; } - if (this->positionChangedAnimation_.endValue() == pos) { + if (this->positionChangedAnimation_.endValue() == pos) + { return; } @@ -263,13 +277,20 @@ void NotebookTab::paintEvent(QPaintEvent *) Theme::TabColors colors; Theme::TabColors regular = this->theme->tabs.regular; - if (this->selected_) { + if (this->selected_) + { colors = this->theme->tabs.selected; - } else if (this->highlightState_ == HighlightState::Highlighted) { + } + else if (this->highlightState_ == HighlightState::Highlighted) + { colors = this->theme->tabs.highlighted; - } else if (this->highlightState_ == HighlightState::NewMessage) { + } + else if (this->highlightState_ == HighlightState::NewMessage) + { colors = this->theme->tabs.newMessage; - } else { + } + else + { colors = this->theme->tabs.regular; } @@ -295,7 +316,8 @@ void NotebookTab::paintEvent(QPaintEvent *) : (windowFocused ? colors.line.regular : colors.line.unfocused)); // draw live indicator - if (this->isLive_) { + if (this->isLive_) + { painter.setPen(QColor(Qt::GlobalColor::red)); painter.setRenderHint(QPainter::Antialiasing); QBrush b; @@ -321,7 +343,8 @@ void NotebookTab::paintEvent(QPaintEvent *) QRect textRect(offset, this->selected_ ? 1 : 2, this->width() - offset - offset, height); - if (this->shouldDrawXButton()) { + if (this->shouldDrawXButton()) + { textRect.setRight(textRect.right() - this->height() / 2); } @@ -335,17 +358,22 @@ void NotebookTab::paintEvent(QPaintEvent *) painter.drawText(textRect, this->getTitle(), option); // draw close x - if (this->shouldDrawXButton()) { + if (this->shouldDrawXButton()) + { QRect xRect = this->getXRect(); - if (!xRect.isNull()) { - if (this->selected_) xRect.moveTop(xRect.top() - 1); + if (!xRect.isNull()) + { + if (this->selected_) + xRect.moveTop(xRect.top() - 1); painter.setBrush(QColor("#fff")); - if (this->mouseOverX_) { + if (this->mouseOverX_) + { painter.fillRect(xRect, QColor(0, 0, 0, 64)); - if (this->mouseDownX_) { + if (this->mouseDownX_) + { painter.fillRect(xRect, QColor(0, 0, 0, 64)); } } @@ -360,13 +388,15 @@ void NotebookTab::paintEvent(QPaintEvent *) } // draw line at bottom - if (!this->selected_ && this->isInLastRow_) { + if (!this->selected_ && this->isInLastRow_) + { painter.fillRect(0, this->height() - 1, this->width(), 1, app->themes->window.background); } // draw mouse over effect - if (!this->selected_) { + if (!this->selected_) + { this->fancyPaint(painter); } } @@ -384,7 +414,8 @@ bool NotebookTab::shouldDrawXButton() void NotebookTab::mousePressEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton) { + if (event->button() == Qt::LeftButton) + { this->mouseDown_ = true; this->mouseDownX_ = this->getXRect().contains(event->pos()); @@ -393,11 +424,15 @@ void NotebookTab::mousePressEvent(QMouseEvent *event) this->update(); - if (this->notebook_->getAllowUserTabManagement()) { - switch (event->button()) { - case Qt::RightButton: { + if (this->notebook_->getAllowUserTabManagement()) + { + switch (event->button()) + { + case Qt::RightButton: + { this->menu_.popup(event->globalPos()); - } break; + } + break; default:; } } @@ -413,22 +448,30 @@ void NotebookTab::mouseReleaseEvent(QMouseEvent *event) "Are you sure that you want to remove this tab?", QMessageBox::Yes | QMessageBox::Cancel); - if (reply == QMessageBox::Yes) { + if (reply == QMessageBox::Yes) + { this->notebook_->removePage(this->page); } }; - if (event->button() == Qt::MiddleButton) { - if (this->rect().contains(event->pos())) { + if (event->button() == Qt::MiddleButton) + { + if (this->rect().contains(event->pos())) + { removeThisPage(); } - } else { + } + else + { if (this->hasXButton() && this->mouseDownX_ && - this->getXRect().contains(event->pos())) { + this->getXRect().contains(event->pos())) + { this->mouseDownX_ = false; removeThisPage(); - } else { + } + else + { this->update(); } } @@ -455,11 +498,14 @@ void NotebookTab::leaveEvent(QEvent *event) void NotebookTab::dragEnterEvent(QDragEnterEvent *event) { - if (!event->mimeData()->hasFormat("chatterino/split")) return; + if (!event->mimeData()->hasFormat("chatterino/split")) + return; - if (!SplitContainer::isDraggingSplit) return; + if (!SplitContainer::isDraggingSplit) + return; - if (this->notebook_->getAllowUserTabManagement()) { + if (this->notebook_->getAllowUserTabManagement()) + { this->notebook_->select(this->page); } } @@ -473,7 +519,8 @@ void NotebookTab::mouseMoveEvent(QMouseEvent *event) { bool overX = this->getXRect().contains(event->pos()); - if (overX != this->mouseOverX_) { + if (overX != this->mouseOverX_) + { // Over X state has been changed (we either left or entered it; this->mouseOverX_ = overX; @@ -490,7 +537,8 @@ void NotebookTab::mouseMoveEvent(QMouseEvent *event) QWidget *clickedPage = this->notebook_->tabAt(relPoint, index, this->width()); - if (clickedPage != nullptr && clickedPage != this->page) { + if (clickedPage != nullptr && clickedPage != this->page) + { this->notebook_->rearrangePage(this->page, index); } } @@ -500,9 +548,12 @@ void NotebookTab::mouseMoveEvent(QMouseEvent *event) void NotebookTab::wheelEvent(QWheelEvent *event) { - if (event->delta() > 0) { + if (event->delta() > 0) + { this->notebook_->selectPreviousTab(); - } else { + } + else + { this->notebook_->selectNextTab(); } } diff --git a/src/widgets/helper/ResizingTextEdit.cpp b/src/widgets/helper/ResizingTextEdit.cpp index 1a06b1868..b9787c195 100644 --- a/src/widgets/helper/ResizingTextEdit.cpp +++ b/src/widgets/helper/ResizingTextEdit.cpp @@ -44,18 +44,22 @@ QString ResizingTextEdit::textUnderCursor(bool *hadSpace) const auto textUpToCursor = currentText.left(tc.selectionStart()); auto words = textUpToCursor.splitRef(' '); - if (words.size() == 0) { + if (words.size() == 0) + { return QString(); } bool first = true; QString lastWord; - for (auto it = words.crbegin(); it != words.crend(); ++it) { + for (auto it = words.crbegin(); it != words.crend(); ++it) + { auto word = *it; - if (first && word.isEmpty()) { + if (first && word.isEmpty()) + { first = false; - if (hadSpace != nullptr) { + if (hadSpace != nullptr) + { *hadSpace = true; } continue; @@ -65,7 +69,8 @@ QString ResizingTextEdit::textUnderCursor(bool *hadSpace) const break; } - if (lastWord.isEmpty()) { + if (lastWord.isEmpty()) + { return QString(); } @@ -82,23 +87,27 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event) (event->key() == Qt::Key_Tab || event->key() == Qt::Key_Backtab) && (event->modifiers() & Qt::ControlModifier) == Qt::NoModifier; - if (doComplete) { + if (doComplete) + { // check if there is a completer - if (!this->completer_) { + if (!this->completer_) + { return; } QString currentCompletionPrefix = this->textUnderCursor(); // check if there is something to complete - if (!currentCompletionPrefix.size()) { + if (!currentCompletionPrefix.size()) + { return; } auto *completionModel = static_cast(this->completer_->model()); - if (!this->completionInProgress_) { + if (!this->completionInProgress_) + { // First type pressing tab after modifying a message, we refresh our // completion model this->completer_->setModel(completionModel); @@ -110,15 +119,20 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event) } // scrolling through selections - if (event->key() == Qt::Key_Tab) { + if (event->key() == Qt::Key_Tab) + { if (!this->completer_->setCurrentRow( - this->completer_->currentRow() + 1)) { + this->completer_->currentRow() + 1)) + { // wrap over and start again this->completer_->setCurrentRow(0); } - } else { + } + else + { if (!this->completer_->setCurrentRow( - this->completer_->currentRow() - 1)) { + this->completer_->currentRow() - 1)) + { // wrap over and start again this->completer_->setCurrentRow( this->completer_->completionCount() - 1); @@ -136,11 +150,13 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event) // might be a better solution but nobody is gonna bother anyways if (event->key() != Qt::Key_Shift && event->key() != Qt::Key_Control && event->key() != Qt::Key_Alt && event->key() != Qt::Key_Super_L && - event->key() != Qt::Key_Super_R) { + event->key() != Qt::Key_Super_R) + { this->completionInProgress_ = false; } - if (!event->isAccepted()) { + if (!event->isAccepted()) + { QTextEdit::keyPressEvent(event); } } @@ -149,7 +165,8 @@ void ResizingTextEdit::focusInEvent(QFocusEvent *event) { QTextEdit::focusInEvent(event); - if (event->gotFocus()) { + if (event->gotFocus()) + { this->focused.invoke(); } } @@ -158,20 +175,23 @@ void ResizingTextEdit::focusOutEvent(QFocusEvent *event) { QTextEdit::focusOutEvent(event); - if (event->lostFocus()) { + if (event->lostFocus()) + { this->focusLost.invoke(); } } void ResizingTextEdit::setCompleter(QCompleter *c) { - if (this->completer_) { + if (this->completer_) + { QObject::disconnect(this->completer_, nullptr, this, nullptr); } this->completer_ = c; - if (!this->completer_) { + if (!this->completer_) + { return; } @@ -186,7 +206,8 @@ void ResizingTextEdit::setCompleter(QCompleter *c) void ResizingTextEdit::insertCompletion(const QString &completion) { - if (this->completer_->widget() != this) { + if (this->completer_->widget() != this) + { return; } @@ -195,7 +216,8 @@ void ResizingTextEdit::insertCompletion(const QString &completion) int prefixSize = prefix.size(); - if (hadSpace) { + if (hadSpace) + { ++prefixSize; } diff --git a/src/widgets/helper/SearchPopup.cpp b/src/widgets/helper/SearchPopup.cpp index 81439407a..85545e99a 100644 --- a/src/widgets/helper/SearchPopup.cpp +++ b/src/widgets/helper/SearchPopup.cpp @@ -74,12 +74,14 @@ void SearchPopup::performSearch() ChannelPtr channel(new Channel("search", Channel::Type::None)); - for (size_t i = 0; i < this->snapshot_.getLength(); i++) { + for (size_t i = 0; i < this->snapshot_.getLength(); i++) + { MessagePtr message = this->snapshot_[i]; if (text.isEmpty() || message->searchText.indexOf(this->searchInput_->text(), 0, - Qt::CaseInsensitive) != -1) { + Qt::CaseInsensitive) != -1) + { channel->addMessage(message); } } diff --git a/src/widgets/helper/SettingsDialogTab.cpp b/src/widgets/helper/SettingsDialogTab.cpp index 96c5af4dc..1319b6796 100644 --- a/src/widgets/helper/SettingsDialogTab.cpp +++ b/src/widgets/helper/SettingsDialogTab.cpp @@ -23,7 +23,8 @@ SettingsDialogTab::SettingsDialogTab(SettingsDialog *_dialog, void SettingsDialogTab::setSelected(bool _selected) { - if (this->selected_ == _selected) { + if (this->selected_ == _selected) + { return; } @@ -61,7 +62,8 @@ void SettingsDialogTab::paintEvent(QPaintEvent *) void SettingsDialogTab::mousePressEvent(QMouseEvent *event) { - if (event->button() != Qt::LeftButton) { + if (event->button() != Qt::LeftButton) + { return; } diff --git a/src/widgets/helper/SignalLabel.cpp b/src/widgets/helper/SignalLabel.cpp index cbf8bf5b9..46fd0d80c 100644 --- a/src/widgets/helper/SignalLabel.cpp +++ b/src/widgets/helper/SignalLabel.cpp @@ -14,7 +14,8 @@ void SignalLabel::mouseDoubleClickEvent(QMouseEvent *ev) void SignalLabel::mousePressEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton) { + if (event->button() == Qt::LeftButton) + { emit mouseDown(); } @@ -23,7 +24,8 @@ void SignalLabel::mousePressEvent(QMouseEvent *event) void SignalLabel::mouseReleaseEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton) { + if (event->button() == Qt::LeftButton) + { emit mouseUp(); } diff --git a/src/widgets/helper/TitlebarButton.cpp b/src/widgets/helper/TitlebarButton.cpp index d5ab4cc4a..51be6b9a1 100644 --- a/src/widgets/helper/TitlebarButton.cpp +++ b/src/widgets/helper/TitlebarButton.cpp @@ -34,17 +34,21 @@ void TitleBarButton::paintEvent(QPaintEvent *event) painter.setRenderHint(QPainter::Antialiasing, false); - switch (this->style_) { - case TitleBarButtonStyle::Minimize: { + switch (this->style_) + { + case TitleBarButtonStyle::Minimize: + { painter.fillRect(centerX - xD / 2, xD * 3 / 2, xD, 1, color); break; } - case TitleBarButtonStyle::Maximize: { + case TitleBarButtonStyle::Maximize: + { painter.setPen(color); painter.drawRect(centerX - xD / 2, xD, xD - 1, xD - 1); break; } - case TitleBarButtonStyle::Unmaximize: { + case TitleBarButtonStyle::Unmaximize: + { int xD2 = xD * 1 / 5; int xD3 = xD * 4 / 5; @@ -54,7 +58,8 @@ void TitleBarButton::paintEvent(QPaintEvent *event) painter.drawRect(centerX - xD / 2, xD + xD2, xD3, xD3); break; } - case TitleBarButtonStyle::Close: { + case TitleBarButtonStyle::Close: + { QRect rect(centerX - xD / 2, xD, xD - 1, xD - 1); painter.setPen(QPen(color, 1)); @@ -62,7 +67,8 @@ void TitleBarButton::paintEvent(QPaintEvent *event) painter.drawLine(rect.topRight(), rect.bottomLeft()); break; } - case TitleBarButtonStyle::User: { + case TitleBarButtonStyle::User: + { color = "#999"; painter.setRenderHint(QPainter::Antialiasing); @@ -88,7 +94,8 @@ void TitleBarButton::paintEvent(QPaintEvent *event) break; } - case TitleBarButtonStyle::Settings: { + case TitleBarButtonStyle::Settings: + { color = "#999"; painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::HighQualityAntialiasing); @@ -101,7 +108,8 @@ void TitleBarButton::paintEvent(QPaintEvent *event) path.arcMoveTo(a, a, 6 * a, 6 * a, 0 - (360 / 32.0)); - for (int i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) + { path.arcTo(a, a, 6 * a, 6 * a, i * (360 / 8.0) - (360 / 32.0), (360 / 32.0)); path.arcTo(2 * a, 2 * a, 4 * a, 4 * a, diff --git a/src/widgets/settingspages/AboutPage.cpp b/src/widgets/settingspages/AboutPage.cpp index 1fa5dc40c..63a1972eb 100644 --- a/src/widgets/settingspages/AboutPage.cpp +++ b/src/widgets/settingspages/AboutPage.cpp @@ -129,14 +129,17 @@ AboutPage::AboutPage() QString line; - while (stream.readLineInto(&line)) { - if (line.isEmpty() || line.startsWith('#')) { + while (stream.readLineInto(&line)) + { + if (line.isEmpty() || line.startsWith('#')) + { continue; } QStringList contributorParts = line.split("|"); - if (contributorParts.size() != 4) { + if (contributorParts.size() != 4) + { log("Missing parts in line '{}'", line); continue; } @@ -154,7 +157,8 @@ AboutPage::AboutPage() auto contributorBox2 = l.emplace(); const auto addAvatar = [&avatarUrl, &contributorBox2] { - if (!avatarUrl.isEmpty()) { + if (!avatarUrl.isEmpty()) + { QPixmap avatarPixmap; avatarPixmap.load(avatarUrl); diff --git a/src/widgets/settingspages/IgnoresPage.cpp b/src/widgets/settingspages/IgnoresPage.cpp index 6d238be41..62fbe80b0 100644 --- a/src/widgets/settingspages/IgnoresPage.cpp +++ b/src/widgets/settingspages/IgnoresPage.cpp @@ -98,12 +98,14 @@ void IgnoresPage::onShow() auto user = app->accounts->twitch.getCurrent(); - if (user->isAnon()) { + if (user->isAnon()) + { return; } QStringList users; - for (const auto &ignoredUser : user->getIgnores()) { + for (const auto &ignoredUser : user->getIgnores()) + { users << ignoredUser.name; } this->userListModel_.setStringList(users); diff --git a/src/widgets/settingspages/LookPage.cpp b/src/widgets/settingspages/LookPage.cpp index fad32685e..56680cffc 100644 --- a/src/widgets/settingspages/LookPage.cpp +++ b/src/widgets/settingspages/LookPage.cpp @@ -181,7 +181,8 @@ void LookPage::addMessageTab(LayoutCreator layout) const auto currentIndex = []() -> int { auto val = getSettings()->collpseMessagesMinLines.getValue(); - if (val > 0) { + if (val > 0) + { --val; } return val; @@ -332,7 +333,8 @@ void LookPage::addLastReadMessageIndicatorPatternSelector( combo->addItems({"Dotted line", "Solid line"}); const auto currentIndex = []() -> int { - switch (getSettings()->lastMessagePattern.getValue()) { + switch (getSettings()->lastMessagePattern.getValue()) + { case Qt::SolidLine: return 1; case Qt::VerPattern: @@ -347,7 +349,8 @@ void LookPage::addLastReadMessageIndicatorPatternSelector( static_cast(&QComboBox::currentIndexChanged), [](int index) { getSettings()->lastMessagePattern = [&] { - switch (index) { + switch (index) + { case 1: return Qt::SolidPattern; case 0: @@ -386,7 +389,8 @@ void LookPage::addLastReadMessageIndicatorPatternSelector( QObject::connect( button, &QPushButton::clicked, [updatePreviewColor, getCurrentColor]() { QColor newColor = QColorDialog::getColor(getCurrentColor()); - if (newColor.isValid()) { + if (newColor.isValid()) + { updatePreviewColor(newColor); getSettings()->lastMessageColor = newColor.name(); } diff --git a/src/widgets/settingspages/ModerationPage.cpp b/src/widgets/settingspages/ModerationPage.cpp index dbd5a99cd..1a061c922 100644 --- a/src/widgets/settingspages/ModerationPage.cpp +++ b/src/widgets/settingspages/ModerationPage.cpp @@ -32,7 +32,8 @@ qint64 dirSize(QString dirPath) QDir dir(dirPath); // calculate total size of current directories' files QDir::Filters fileFilters = QDir::Files | QDir::System | QDir::Hidden; - for (QString filePath : dir.entryList(fileFilters)) { + for (QString filePath : dir.entryList(fileFilters)) + { QFileInfo fi(dir, filePath); size += fi.size(); } @@ -49,8 +50,10 @@ QString formatSize(qint64 size) QStringList units = {"Bytes", "KB", "MB", "GB", "TB", "PB"}; int i; double outputSize = size; - for (i = 0; i < units.size() - 1; i++) { - if (outputSize < 1024) break; + for (i = 0; i < units.size() - 1; i++) + { + if (outputSize < 1024) + break; outputSize = outputSize / 1024; } return QString("%0 %1").arg(outputSize, 0, 'f', 2).arg(units[i]); @@ -59,9 +62,12 @@ QString formatSize(qint64 size) QString fetchLogDirectorySize() { QString logPathDirectory; - if (getSettings()->logPath == "") { + if (getSettings()->logPath == "") + { logPathDirectory = getPaths()->messageLogDirectory; - } else { + } + else + { logPathDirectory = getSettings()->logPath; } qint64 logsSize = dirSize(logPathDirectory); @@ -93,9 +99,12 @@ ModerationPage::ModerationPage() [logsPathLabel](const QString &logPath, auto) mutable { QString pathOriginal; - if (logPath == "") { + if (logPath == "") + { pathOriginal = getPaths()->messageLogDirectory; - } else { + } + else + { pathOriginal = logPath; } diff --git a/src/widgets/splits/ClosedSplits.cpp b/src/widgets/splits/ClosedSplits.cpp index 2c1d912c9..79f62c226 100644 --- a/src/widgets/splits/ClosedSplits.cpp +++ b/src/widgets/splits/ClosedSplits.cpp @@ -11,7 +11,8 @@ void ClosedSplits::invalidateTab(NotebookTab *const tab) auto it = std::find_if( ClosedSplits::closedSplits_.begin(), ClosedSplits::closedSplits_.end(), [tab](const auto &item) -> bool { return item.tab == tab; }); - if (it == ClosedSplits::closedSplits_.end()) { + if (it == ClosedSplits::closedSplits_.end()) + { return; } it->tab = nullptr; diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index c03100718..9184f43da 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -125,7 +125,8 @@ Split::Split(QWidget *parent) this->giveFocus(Qt::MouseFocusReason); }); this->view_->selectionChanged.connect([this]() { - if (view_->hasSelection()) { + if (view_->hasSelection()) + { this->input_->clearSelection(); } }); @@ -136,22 +137,29 @@ Split::Split(QWidget *parent) }); this->input_->textChanged.connect([=](const QString &newText) { - if (getSettings()->showEmptyInput) { + if (getSettings()->showEmptyInput) + { return; } - if (newText.length() == 0) { + if (newText.length() == 0) + { this->input_->hide(); - } else if (this->input_->isHidden()) { + } + else if (this->input_->isHidden()) + { this->input_->show(); } }); getSettings()->showEmptyInput.connect( [this](const bool &showEmptyInput, auto) { - if (!showEmptyInput && this->input_->getInputText().length() == 0) { + if (!showEmptyInput && this->input_->getInputText().length() == 0) + { this->input_->hide(); - } else { + } + else + { this->input_->show(); } }, @@ -166,9 +174,12 @@ Split::Split(QWidget *parent) this->managedConnect(modifierStatusChanged, [this](Qt::KeyboardModifiers status) { if ((status == showSplitOverlayModifiers /*|| status == showAddSplitRegions*/) && - this->isMouseOver_) { + this->isMouseOver_) + { this->overlay_->show(); - } else { + } + else + { this->overlay_->hide(); } }); @@ -229,7 +240,8 @@ void Split::setChannel(IndirectChannel newChannel) TwitchChannel *tc = dynamic_cast(newChannel.get().get()); - if (tc != nullptr) { + if (tc != nullptr) + { this->usermodeChangedConnection_ = tc->userStateChanged.connect([this] { this->header_->updateModerationModeIcon(); this->header_->updateRoomModes(); @@ -256,7 +268,8 @@ void Split::setChannel(IndirectChannel newChannel) void Split::setModerationMode(bool value) { - if (value != this->moderationMode_) { + if (value != this->moderationMode_) + { this->moderationMode_ = value; this->header_->updateModerationModeIcon(); this->view_->layoutMessages(); @@ -276,22 +289,26 @@ void Split::insertTextToInput(const QString &text) void Split::showChangeChannelPopup(const char *dialogTitle, bool empty, std::function callback) { - if (this->selectChannelDialog_.hasElement()) { + if (this->selectChannelDialog_.hasElement()) + { this->selectChannelDialog_->raise(); return; } SelectChannelDialog *dialog = new SelectChannelDialog(this); - if (!empty) { + if (!empty) + { dialog->setSelectedChannel(this->getIndirectChannel()); } dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); dialog->closed.connect([=] { - if (dialog->hasSeletedChannel()) { + if (dialog->hasSeletedChannel()) + { this->setChannel(dialog->getSelectedChannel()); - if (this->isInContainer()) { + if (this->isInContainer()) + { this->container_->refreshTab(); } } @@ -368,11 +385,14 @@ void Split::enterEvent(QEvent *event) this->handleModifiers(QGuiApplication::queryKeyboardModifiers()); - if (modifierStatus == showSplitOverlayModifiers /*|| modifierStatus == showAddSplitRegions*/) { + if (modifierStatus == + showSplitOverlayModifiers /*|| modifierStatus == showAddSplitRegions*/) + { this->overlay_->show(); } - if (this->container_ != nullptr) { + if (this->container_ != nullptr) + { this->container_->resetMouseStatus(); } } @@ -393,7 +413,8 @@ void Split::focusInEvent(QFocusEvent *event) void Split::handleModifiers(Qt::KeyboardModifiers modifiers) { - if (modifierStatus != modifiers) { + if (modifierStatus != modifiers) + { modifierStatus = modifiers; modifierStatusChanged.invoke(modifiers); } @@ -408,14 +429,16 @@ void Split::setIsTopRightSplit(bool value) /// Slots void Split::addSibling() { - if (this->container_) { + if (this->container_) + { this->container_->appendNewSplit(true); } } void Split::deleteFromContainer() { - if (this->container_) { + if (this->container_) + { this->container_->deleteSplit(this); auto *tab = this->getContainer()->getTab(); tab->connect(tab, &QWidget::destroyed, @@ -429,8 +452,8 @@ void Split::changeChannel() this->showChangeChannelPopup("Change channel", false, [](bool) {}); auto popup = this->findChildren(); - if (popup.size() && popup.at(0)->isVisible() && - !popup.at(0)->isFloating()) { + if (popup.size() && popup.at(0)->isVisible() && !popup.at(0)->isFloating()) + { popup.at(0)->hide(); showViewerList(); } @@ -471,7 +494,8 @@ void Split::openInBrowser() { auto channel = this->getChannel(); - if (auto twitchChannel = dynamic_cast(channel.get())) { + if (auto twitchChannel = dynamic_cast(channel.get())) + { QDesktopServices::openUrl("https://twitch.tv/" + twitchChannel->getName()); } @@ -480,7 +504,8 @@ void Split::openInBrowser() void Split::openBrowserPlayer() { ChannelPtr channel = this->getChannel(); - if (auto twitchChannel = dynamic_cast(channel.get())) { + if (auto twitchChannel = dynamic_cast(channel.get())) + { QDesktopServices::openUrl("https://player.twitch.tv/?channel=" + twitchChannel->getName()); } @@ -488,9 +513,12 @@ void Split::openBrowserPlayer() void Split::openInStreamlink() { - try { + try + { openStreamlinkForChannel(this->getChannel()->getName()); - } catch (const Exception &ex) { + } + catch (const Exception &ex) + { log("Error in doOpenStreamlink: {}", ex.what()); } } @@ -519,7 +547,8 @@ void Split::showViewerList() static QStringList jsonLabels = {"moderators", "staff", "admins", "global_mods", "viewers"}; QList labelList; - for (auto &x : labels) { + for (auto &x : labels) + { auto label = new QListWidgetItem(x); label->setBackgroundColor(this->theme->splits.header.background); labelList.append(label); @@ -536,12 +565,14 @@ void Split::showViewerList() QJsonObject chattersObj = obj.value("chatters").toObject(); loadingLabel->hide(); - for (int i = 0; i < jsonLabels.size(); i++) { + for (int i = 0; i < jsonLabels.size(); i++) + { auto currentCategory = chattersObj.value(jsonLabels.at(i)).toArray(); // If current category of chatters is empty, dont show this // category. - if (currentCategory.empty()) continue; + if (currentCategory.empty()) + continue; chattersList->addItem(labelList.at(i)); foreach (const QJsonValue &v, currentCategory) @@ -556,16 +587,20 @@ void Split::showViewerList() searchBar->setPlaceholderText("Search User..."); QObject::connect(searchBar, &QLineEdit::textEdited, this, [=]() { auto query = searchBar->text(); - if (!query.isEmpty()) { + if (!query.isEmpty()) + { auto results = chattersList->findItems(query, Qt::MatchStartsWith); chattersList->hide(); resultList->clear(); - for (auto &item : results) { + for (auto &item : results) + { if (!labels.contains(item->text())) resultList->addItem(item->text()); } resultList->show(); - } else { + } + else + { resultList->hide(); chattersList->show(); } @@ -575,7 +610,8 @@ void Split::showViewerList() [=]() { viewerDock->setMinimumWidth(300); }); auto listDoubleClick = [=](QString userName) { - if (!labels.contains(userName)) { + if (!labels.contains(userName)) + { this->view_->showUserInfoPopup(userName); } }; @@ -631,7 +667,8 @@ static Iter select_randomly(Iter start, Iter end) void Split::drag() { - if (auto container = dynamic_cast(this->parentWidget())) { + if (auto container = dynamic_cast(this->parentWidget())) + { SplitContainer::isDraggingSplit = true; SplitContainer::draggingSplit = this; @@ -642,7 +679,8 @@ void Split::drag() mimeData->setData("chatterino/split", "xD"); drag->setMimeData(mimeData); - if (drag->exec(Qt::MoveAction) == Qt::IgnoreAction) { + if (drag->exec(Qt::MoveAction) == Qt::IgnoreAction) + { container->insertSplit(this, originalLocation); } diff --git a/src/widgets/splits/SplitContainer.cpp b/src/widgets/splits/SplitContainer.cpp index 1f1a13359..9b18f8047 100644 --- a/src/widgets/splits/SplitContainer.cpp +++ b/src/widgets/splits/SplitContainer.cpp @@ -41,20 +41,28 @@ SplitContainer::SplitContainer(Notebook *parent) this->managedConnect(Split::modifierStatusChanged, [this](auto modifiers) { this->layout(); - if (modifiers == showResizeHandlesModifiers) { - for (auto &handle : this->resizeHandles_) { + if (modifiers == showResizeHandlesModifiers) + { + for (auto &handle : this->resizeHandles_) + { handle->show(); handle->raise(); } - } else { - for (auto &handle : this->resizeHandles_) { + } + else + { + for (auto &handle : this->resizeHandles_) + { handle->hide(); } } - if (modifiers == showSplitOverlayModifiers) { + if (modifiers == showSplitOverlayModifiers) + { this->setCursor(Qt::PointingHandCursor); - } else { + } + else + { this->unsetCursor(); } }); @@ -91,7 +99,8 @@ void SplitContainer::hideResizeHandles() { this->overlay_.hide(); - for (auto &handle : this->resizeHandles_) { + for (auto &handle : this->resizeHandles_) + { handle->hide(); } } @@ -109,9 +118,11 @@ Split *SplitContainer::appendNewSplit(bool openChannelNameDialog) Split *split = new Split(this); this->appendSplit(split); - if (openChannelNameDialog) { + if (openChannelNameDialog) + { split->showChangeChannelPopup("Open channel name", true, [=](bool ok) { - if (!ok) { + if (!ok) + { this->deleteSplit(split); } }); @@ -150,15 +161,23 @@ void SplitContainer::insertSplit(Split *split, Direction direction, split->setContainer(this); - if (relativeTo == nullptr) { - if (this->baseNode_.type_ == Node::EmptyRoot) { + if (relativeTo == nullptr) + { + if (this->baseNode_.type_ == Node::EmptyRoot) + { this->baseNode_.setSplit(split); - } else if (this->baseNode_.type_ == Node::_Split) { + } + else if (this->baseNode_.type_ == Node::_Split) + { this->baseNode_.nestSplitIntoCollection(split, direction); - } else { + } + else + { this->baseNode_.insertSplitRelative(split, direction); } - } else { + } + else + { assert(this->baseNode_.isOrContainsNode(relativeTo)); relativeTo->insertSplitRelative(split, direction); @@ -181,7 +200,8 @@ void SplitContainer::addSplit(Split *split) split->getChannelView().tabHighlightRequested.connect( [this](HighlightState state) { - if (this->tab_ != nullptr) { + if (this->tab_ != nullptr) + { this->tab_->setHighlightState(state); } }); @@ -199,14 +219,16 @@ void SplitContainer::setSelected(Split *split) { this->selected_ = split; - if (Node *node = this->baseNode_.findNodeContainingSplit(split)) { + if (Node *node = this->baseNode_.findNodeContainingSplit(split)) + { this->setPreferedTargetRecursive(node); } } void SplitContainer::setPreferedTargetRecursive(Node *node) { - if (node->parent_ != nullptr) { + if (node->parent_ != nullptr) + { node->parent_->preferedFocusTarget_ = node; this->setPreferedTargetRecursive(node->parent_); @@ -225,10 +247,13 @@ SplitContainer::Position SplitContainer::releaseSplit(Split *split) split->setParent(nullptr); Position position = node->releaseSplit(); this->layout(); - if (splits_.size() == 0) { + if (splits_.size() == 0) + { this->setSelected(nullptr); this->setCursor(Qt::PointingHandCursor); - } else { + } + else + { this->splits_.front()->giveFocus(Qt::MouseFocusReason); } @@ -258,15 +283,18 @@ void SplitContainer::selectNextSplit(Direction direction) { assertInGuiThread(); - if (Node *node = this->baseNode_.findNodeContainingSplit(this->selected_)) { + if (Node *node = this->baseNode_.findNodeContainingSplit(this->selected_)) + { this->selectSplitRecursive(node, direction); } } void SplitContainer::selectSplitRecursive(Node *node, Direction direction) { - if (node->parent_ != nullptr) { - if (node->parent_->type_ == Node::toContainerType(direction)) { + if (node->parent_ != nullptr) + { + if (node->parent_->type_ == Node::toContainerType(direction)) + { auto &siblings = node->parent_->children_; auto it = std::find_if( @@ -274,22 +302,33 @@ void SplitContainer::selectSplitRecursive(Node *node, Direction direction) [node](const auto &other) { return other.get() == node; }); assert(it != siblings.end()); - if (direction == Direction::Left || direction == Direction::Above) { - if (it == siblings.begin()) { + if (direction == Direction::Left || direction == Direction::Above) + { + if (it == siblings.begin()) + { this->selectSplitRecursive(node->parent_, direction); - } else { + } + else + { this->focusSplitRecursive( siblings[it - siblings.begin() - 1].get(), direction); } - } else { - if (it->get() == siblings.back().get()) { + } + else + { + if (it->get() == siblings.back().get()) + { this->selectSplitRecursive(node->parent_, direction); - } else { + } + else + { this->focusSplitRecursive( siblings[it - siblings.begin() + 1].get(), direction); } } - } else { + } + else + { this->selectSplitRecursive(node->parent_, direction); } } @@ -297,13 +336,17 @@ void SplitContainer::selectSplitRecursive(Node *node, Direction direction) void SplitContainer::focusSplitRecursive(Node *node, Direction direction) { - switch (node->type_) { - case Node::_Split: { + switch (node->type_) + { + case Node::_Split: + { node->split_->giveFocus(Qt::OtherFocusReason); - } break; + } + break; case Node::HorizontalContainer: - case Node::VerticalContainer: { + case Node::VerticalContainer: + { auto &children = node->children_; auto it = std::find_if( @@ -311,13 +354,17 @@ void SplitContainer::focusSplitRecursive(Node *node, Direction direction) return node->preferedFocusTarget_ == other.get(); }); - if (it != children.end()) { + if (it != children.end()) + { this->focusSplitRecursive(it->get(), direction); - } else { + } + else + { this->focusSplitRecursive(node->children_.front().get(), direction); } - } break; + } + break; default:; } @@ -325,7 +372,8 @@ void SplitContainer::focusSplitRecursive(Node *node, Direction direction) Split *SplitContainer::getTopRightSplit(Node &node) { - switch (node.getType()) { + switch (node.getType()) + { case Node::_Split: return node.getSplit(); case Node::VerticalContainer: @@ -345,9 +393,11 @@ void SplitContainer::layout() { // update top right split auto topRight = this->getTopRightSplit(this->baseNode_); - if (this->topRight_) this->topRight_->setIsTopRightSplit(false); + if (this->topRight_) + this->topRight_->setIsTopRightSplit(false); this->topRight_ = topRight; - if (topRight) this->topRight_->setIsTopRightSplit(true); + if (topRight) + this->topRight_->setIsTopRightSplit(true); // layout this->baseNode_.geometry_ = this->rect().adjusted(-1, -1, 0, 0); @@ -360,7 +410,8 @@ void SplitContainer::layout() this->dropRects_ = _dropRects; - for (Split *split : this->splits_) { + for (Split *split : this->splits_) + { const QRect &g = split->geometry(); Node *node = this->baseNode_.findNodeContainingSplit(split); @@ -385,7 +436,8 @@ void SplitContainer::layout() Position(node, Direction::Below))); } - if (this->splits_.empty()) { + if (this->splits_.empty()) + { QRect g = this->rect(); _dropRects.push_back( DropRect(QRect(g.left(), g.top(), g.width() - 1, g.height() - 1), @@ -395,24 +447,30 @@ void SplitContainer::layout() this->overlay_.setRects(std::move(_dropRects)); // handle resizeHandles - if (this->resizeHandles_.size() < _resizeRects.size()) { - while (this->resizeHandles_.size() < _resizeRects.size()) { + if (this->resizeHandles_.size() < _resizeRects.size()) + { + while (this->resizeHandles_.size() < _resizeRects.size()) + { this->resizeHandles_.push_back( std::make_unique(this)); } - } else if (this->resizeHandles_.size() > _resizeRects.size()) { + } + else if (this->resizeHandles_.size() > _resizeRects.size()) + { this->resizeHandles_.resize(_resizeRects.size()); } { size_t i = 0; - for (ResizeRect &resizeRect : _resizeRects) { + for (ResizeRect &resizeRect : _resizeRects) + { ResizeHandle *handle = this->resizeHandles_[i].get(); handle->setGeometry(resizeRect.rect); handle->setVertical(resizeRect.vertical); handle->node = resizeRect.node; - if (Split::modifierStatus == showResizeHandlesModifiers) { + if (Split::modifierStatus == showResizeHandlesModifiers) + { handle->show(); handle->raise(); } @@ -434,20 +492,25 @@ void SplitContainer::resizeEvent(QResizeEvent *event) void SplitContainer::mouseReleaseEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton) { - if (this->splits_.size() == 0) { + if (event->button() == Qt::LeftButton) + { + if (this->splits_.size() == 0) + { // "Add Chat" was clicked this->appendNewSplit(true); this->mouseOverPoint_ = QPoint(-10000, -10000); // this->setCursor(QCursor(Qt::ArrowCursor)); - } else { + } + else + { auto it = std::find_if(this->dropRects_.begin(), this->dropRects_.end(), [event](DropRect &rect) { return rect.rect.contains(event->pos()); }); - if (it != this->dropRects_.end()) { + if (it != this->dropRects_.end()) + { this->insertSplit(new Split(this), it->position); } } @@ -458,7 +521,8 @@ void SplitContainer::paintEvent(QPaintEvent *) { QPainter painter(this); - if (this->splits_.size() == 0) { + if (this->splits_.size() == 0) + { painter.fillRect(rect(), this->theme->splits.background); painter.setPen(this->theme->splits.header.text); @@ -467,29 +531,40 @@ void SplitContainer::paintEvent(QPaintEvent *) Notebook *notebook = dynamic_cast(this->parentWidget()); - if (notebook != nullptr) { - if (notebook->getPageCount() > 1) { + if (notebook != nullptr) + { + if (notebook->getPageCount() > 1) + { text += "\n\nAfter adding hold to move or split it."; } } painter.drawText(rect(), text, QTextOption(Qt::AlignCenter)); - } else { - if (getApp()->themes->isLightTheme()) { + } + else + { + if (getApp()->themes->isLightTheme()) + { painter.fillRect(rect(), QColor("#999")); - } else { + } + else + { painter.fillRect(rect(), QColor("#555")); } } - for (DropRect &dropRect : this->dropRects_) { + for (DropRect &dropRect : this->dropRects_) + { QColor border = getApp()->themes->splits.dropTargetRectBorder; QColor background = getApp()->themes->splits.dropTargetRect; - if (!dropRect.rect.contains(this->mouseOverPoint_)) { + if (!dropRect.rect.contains(this->mouseOverPoint_)) + { // border.setAlphaF(0.1); // background.setAlphaF(0.1); - } else { + } + else + { // background.setAlphaF(0.1); border.setAlpha(255); } @@ -504,9 +579,12 @@ void SplitContainer::paintEvent(QPaintEvent *) int s = std::min(dropRect.rect.width(), dropRect.rect.height()) - 12; - if (this->theme->isLightTheme()) { + if (this->theme->isLightTheme()) + { painter.setPen(QColor(0, 0, 0)); - } else { + } + else + { painter.setPen(QColor(255, 255, 255)); } painter.drawLine(rect.left() + rect.width() / 2 - (s / 2), @@ -529,9 +607,11 @@ void SplitContainer::paintEvent(QPaintEvent *) void SplitContainer::dragEnterEvent(QDragEnterEvent *event) { - if (!event->mimeData()->hasFormat("chatterino/split")) return; + if (!event->mimeData()->hasFormat("chatterino/split")) + return; - if (!SplitContainer::isDraggingSplit) return; + if (!SplitContainer::isDraggingSplit) + return; this->isDragging_ = true; this->layout(); @@ -543,7 +623,8 @@ void SplitContainer::dragEnterEvent(QDragEnterEvent *event) void SplitContainer::mouseMoveEvent(QMouseEvent *event) { - if (Split::modifierStatus == showSplitOverlayModifiers) { + if (Split::modifierStatus == showSplitOverlayModifiers) + { this->setCursor(Qt::PointingHandCursor); } @@ -559,12 +640,14 @@ void SplitContainer::leaveEvent(QEvent *) void SplitContainer::focusInEvent(QFocusEvent *) { - if (this->baseNode_.findNodeContainingSplit(this->selected_) != nullptr) { + if (this->baseNode_.findNodeContainingSplit(this->selected_) != nullptr) + { this->selected_->setFocus(); return; } - if (this->splits_.size() != 0) { + if (this->splits_.size() != 0) + { this->splits_.front()->setFocus(); } } @@ -601,13 +684,16 @@ void SplitContainer::decodeNodeRecusively(QJsonObject &obj, Node *node) { QString type = obj.value("type").toString(); - if (type == "split") { + if (type == "split") + { auto *split = new Split(this); split->setChannel( WindowManager::decodeChannel(obj.value("data").toObject())); this->appendSplit(split); - } else if (type == "horizontal" || type == "vertical") { + } + else if (type == "horizontal" || type == "vertical") + { bool vertical = type == "vertical"; Direction direction = vertical ? Direction::Below : Direction::Right; @@ -615,11 +701,13 @@ void SplitContainer::decodeNodeRecusively(QJsonObject &obj, Node *node) node->type_ = vertical ? Node::VerticalContainer : Node::HorizontalContainer; - for (QJsonValue _val : obj.value("items").toArray()) { + for (QJsonValue _val : obj.value("items").toArray()) + { auto _obj = _val.toObject(); auto _type = _obj.value("type"); - if (_type == "split") { + if (_type == "split") + { auto *split = new Split(this); split->setChannel(WindowManager::decodeChannel( _obj.value("data").toObject())); @@ -634,7 +722,9 @@ void SplitContainer::decodeNodeRecusively(QJsonObject &obj, Node *node) node->children_.emplace_back(_node); this->addSplit(split); - } else { + } + else + { Node *_node = new Node(); _node->parent_ = node; node->children_.emplace_back(_node); @@ -642,8 +732,10 @@ void SplitContainer::decodeNodeRecusively(QJsonObject &obj, Node *node) } } - for (int i = 0; i < 2; i++) { - if (node->getChildren().size() < 2) { + for (int i = 0; i < 2; i++) + { + if (node->getChildren().size() < 2) + { auto *split = new Split(this); split->setChannel( WindowManager::decodeChannel(obj.value("data").toObject())); @@ -656,20 +748,24 @@ void SplitContainer::decodeNodeRecusively(QJsonObject &obj, Node *node) void SplitContainer::refreshTabTitle() { - if (this->tab_ == nullptr) { + if (this->tab_ == nullptr) + { return; } QString newTitle = ""; bool first = true; - for (const auto &chatWidget : this->splits_) { + for (const auto &chatWidget : this->splits_) + { auto channelName = chatWidget->getChannel()->getName(); - if (channelName.isEmpty()) { + if (channelName.isEmpty()) + { continue; } - if (!first) { + if (!first) + { newTitle += ", "; } newTitle += channelName; @@ -677,7 +773,8 @@ void SplitContainer::refreshTabTitle() first = false; } - if (newTitle.isEmpty()) { + if (newTitle.isEmpty()) + { newTitle = "empty"; } @@ -686,14 +783,17 @@ void SplitContainer::refreshTabTitle() void SplitContainer::refreshTabLiveStatus() { - if (this->tab_ == nullptr) { + if (this->tab_ == nullptr) + { return; } bool liveStatus = false; - for (const auto &s : this->splits_) { + for (const auto &s : this->splits_) + { auto c = s->getChannel(); - if (c->isLive()) { + if (c->isLive()) + { liveStatus = true; break; } @@ -752,7 +852,8 @@ SplitContainer::Node::Node(Split *_split, Node *_parent) bool SplitContainer::Node::isOrContainsNode(SplitContainer::Node *_node) { - if (this == _node) { + if (this == _node) + { return true; } @@ -765,14 +866,17 @@ bool SplitContainer::Node::isOrContainsNode(SplitContainer::Node *_node) SplitContainer::Node *SplitContainer::Node::findNodeContainingSplit( Split *_split) { - if (this->type_ == Type::_Split && this->split_ == _split) { + if (this->type_ == Type::_Split && this->split_ == _split) + { return this; } - for (std::unique_ptr &node : this->children_) { + for (std::unique_ptr &node : this->children_) + { Node *a = node->findNodeContainingSplit(_split); - if (a != nullptr) { + if (a != nullptr) + { return a; } } @@ -782,29 +886,42 @@ SplitContainer::Node *SplitContainer::Node::findNodeContainingSplit( void SplitContainer::Node::insertSplitRelative(Split *_split, Direction _direction) { - if (this->parent_ == nullptr) { - switch (this->type_) { - case Node::EmptyRoot: { + if (this->parent_ == nullptr) + { + switch (this->type_) + { + case Node::EmptyRoot: + { this->setSplit(_split); - } break; - case Node::_Split: { + } + break; + case Node::_Split: + { this->nestSplitIntoCollection(_split, _direction); - } break; - case Node::HorizontalContainer: { + } + break; + case Node::HorizontalContainer: + { this->nestSplitIntoCollection(_split, _direction); - } break; - case Node::VerticalContainer: { + } + break; + case Node::VerticalContainer: + { this->nestSplitIntoCollection(_split, _direction); - } break; + } + break; } return; } // parent != nullptr - if (parent_->type_ == toContainerType(_direction)) { + if (parent_->type_ == toContainerType(_direction)) + { // hell yeah we'll just insert it next to outselves this->insertNextToThis(_split, _direction); - } else { + } + else + { this->nestSplitIntoCollection(_split, _direction); } } @@ -812,15 +929,19 @@ void SplitContainer::Node::insertSplitRelative(Split *_split, void SplitContainer::Node::nestSplitIntoCollection(Split *_split, Direction _direction) { - if (toContainerType(_direction) == this->type_) { + if (toContainerType(_direction) == this->type_) + { this->children_.emplace_back(new Node(_split, this)); - } else { + } + else + { // we'll need to nest outselves // move all our data into a new node Node *clone = new Node(); clone->type_ = this->type_; clone->children_ = std::move(this->children_); - for (std::unique_ptr &node : clone->children_) { + for (std::unique_ptr &node : clone->children_) + { node->parent_ = clone; } clone->split_ = this->split_; @@ -842,7 +963,8 @@ void SplitContainer::Node::insertNextToThis(Split *_split, Direction _direction) qreal width = this->parent_->geometry_.width() / siblings.size(); qreal height = this->parent_->geometry_.height() / siblings.size(); - if (siblings.size() == 1) { + if (siblings.size() == 1) + { this->geometry_ = QRect(0, 0, int(width), int(height)); } @@ -850,7 +972,8 @@ void SplitContainer::Node::insertNextToThis(Split *_split, Direction _direction) [this](auto &node) { return this == node.get(); }); assert(it != siblings.end()); - if (_direction == Direction::Right || _direction == Direction::Below) { + if (_direction == Direction::Right || _direction == Direction::Below) + { it++; } @@ -872,7 +995,8 @@ SplitContainer::Position SplitContainer::Node::releaseSplit() { assert(this->type_ == Type::_Split); - if (parent_ == nullptr) { + if (parent_ == nullptr) + { this->type_ = Type::EmptyRoot; this->split_ = nullptr; @@ -880,7 +1004,9 @@ SplitContainer::Position SplitContainer::Node::releaseSplit() pos.relativeNode_ = nullptr; pos.direction_ = Direction::Right; return pos; - } else { + } + else + { auto &siblings = this->parent_->children_; auto it = @@ -889,13 +1015,17 @@ SplitContainer::Position SplitContainer::Node::releaseSplit() assert(it != siblings.end()); Position position; - if (siblings.size() == 2) { + if (siblings.size() == 2) + { // delete this and move split to parent position.relativeNode_ = this->parent_; - if (this->parent_->type_ == Type::VerticalContainer) { + if (this->parent_->type_ == Type::VerticalContainer) + { position.direction_ = siblings.begin() == it ? Direction::Above : Direction::Below; - } else { + } + else + { position.direction_ = siblings.begin() == it ? Direction::Left : Direction::Right; } @@ -907,19 +1037,25 @@ SplitContainer::Position SplitContainer::Node::releaseSplit() _parent->split_ = sibling->split_; std::vector> nodes = std::move(sibling->children_); - for (auto &node : nodes) { + for (auto &node : nodes) + { node->parent_ = _parent; } _parent->children_ = std::move(nodes); - } else { - if (this == siblings.back().get()) { + } + else + { + if (this == siblings.back().get()) + { position.direction_ = this->parent_->type_ == Type::VerticalContainer ? Direction::Below : Direction::Right; siblings.erase(it); position.relativeNode_ = siblings.back().get(); - } else { + } + else + { position.relativeNode_ = (it + 1)->get(); position.direction_ = this->parent_->type_ == Type::VerticalContainer @@ -956,19 +1092,26 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, std::vector &dropRects, std::vector &resizeRects) { - for (std::unique_ptr &node : this->children_) { - if (node->flexH_ <= 0) node->flexH_ = 0; - if (node->flexV_ <= 0) node->flexV_ = 0; + for (std::unique_ptr &node : this->children_) + { + if (node->flexH_ <= 0) + node->flexH_ = 0; + if (node->flexV_ <= 0) + node->flexV_ = 0; } - switch (this->type_) { - case Node::_Split: { + switch (this->type_) + { + case Node::_Split: + { QRect rect = this->geometry_.toRect(); this->split_->setGeometry( rect.marginsRemoved(QMargins(1, 1, 0, 0))); - } break; + } + break; case Node::VerticalContainer: - case Node::HorizontalContainer: { + case Node::HorizontalContainer: + { bool isVertical = this->type_ == Node::VerticalContainer; // vars @@ -988,7 +1131,8 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, QRectF childRect = this->geometry_; // add spacing if reqested - if (addSpacing) { + if (addSpacing) + { qreal offset = std::min(this->getSize(!isVertical) * 0.1, qreal(_scale * 24)); @@ -1002,14 +1146,17 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, isVertical ? Direction::Left : Direction::Above)); // droprect right / below - if (isVertical) { + if (isVertical) + { dropRects.emplace_back( QRectF(this->geometry_.right() - offset, this->geometry_.top(), offset, this->geometry_.height()) .toRect(), Position(this, Direction::Right)); - } else { + } + else + { dropRects.emplace_back( QRectF(this->geometry_.left(), this->geometry_.bottom() - offset, @@ -1019,10 +1166,13 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, } // shrink childRect - if (isVertical) { + if (isVertical) + { childRect.setLeft(childRect.left() + offset); childRect.setRight(childRect.right() - offset); - } else { + } + else + { childRect.setTop(childRect.top() + offset); childRect.setBottom(childRect.bottom() - offset); } @@ -1030,17 +1180,21 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, // iterate children auto pos = int(isVertical ? childRect.top() : childRect.left()); - for (std::unique_ptr &child : this->children_) { + for (std::unique_ptr &child : this->children_) + { // set rect QRect rect = childRect.toRect(); - if (isVertical) { + if (isVertical) + { rect.setTop(pos); rect.setHeight( std::max(this->geometry_.height() / totalFlex * child->flexV_, minSize) * sizeMultiplier); - } else { + } + else + { rect.setLeft(pos); rect.setWidth(std::max(this->geometry_.width() / totalFlex * child->flexH_, @@ -1048,7 +1202,8 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, sizeMultiplier); } - if (child == this->children_.back()) { + if (child == this->children_.back()) + { rect.setRight(childRect.right() - 1); rect.setBottom(childRect.bottom() - 1); } @@ -1059,7 +1214,8 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, pos += child->getSize(isVertical); // add resize rect - if (child != this->children_.front()) { + if (child != this->children_.front()) + { QRectF r = isVertical ? QRectF(this->geometry_.left(), child->geometry_.top() - 4, this->geometry_.width(), 8) @@ -1071,17 +1227,21 @@ void SplitContainer::Node::layout(bool addSpacing, float _scale, } // normalize flex - if (isVertical) { + if (isVertical) + { child->flexV_ = child->flexV_ / totalFlex * this->children_.size(); child->flexH_ = 1; - } else { + } + else + { child->flexH_ = child->flexH_ / totalFlex * this->children_.size(); child->flexV_ = 1; } } - } break; + } + break; }; } @@ -1121,12 +1281,16 @@ void SplitContainer::DropOverlay::paintEvent(QPaintEvent *) bool foundMover = false; - for (DropRect &rect : this->rects_) { - if (!foundMover && rect.rect.contains(this->mouseOverPoint_)) { + for (DropRect &rect : this->rects_) + { + if (!foundMover && rect.rect.contains(this->mouseOverPoint_)) + { painter.setBrush(getApp()->themes->splits.dropPreview); painter.setPen(getApp()->themes->splits.dropPreviewBorder); foundMover = true; - } else { + } + else + { painter.setBrush(QColor(0, 0, 0, 0)); painter.setPen(QColor(0, 0, 0, 0)); // painter.setPen(getApp()->themes->splits.dropPreviewBorder); @@ -1159,14 +1323,17 @@ void SplitContainer::DropOverlay::dragLeaveEvent(QDragLeaveEvent *) void SplitContainer::DropOverlay::dropEvent(QDropEvent *event) { Position *position = nullptr; - for (DropRect &rect : this->rects_) { - if (rect.rect.contains(this->mouseOverPoint_)) { + for (DropRect &rect : this->rects_) + { + if (rect.rect.contains(this->mouseOverPoint_)) + { position = &rect.position; break; } } - if (position != nullptr) { + if (position != nullptr) + { this->parent_->insertSplit(SplitContainer::draggingSplit, *position); event->acceptProposedAction(); } @@ -1202,10 +1369,13 @@ void SplitContainer::ResizeHandle::paintEvent(QPaintEvent *) painter.fillRect(this->rect(), getApp()->themes->splits.resizeHandleBackground); - if (this->vertical_) { + if (this->vertical_) + { painter.drawLine(0, this->height() / 2, this->width(), this->height() / 2); - } else { + } + else + { painter.drawLine(this->width() / 2, 0, this->width() / 2, this->height()); } @@ -1215,7 +1385,8 @@ void SplitContainer::ResizeHandle::mousePressEvent(QMouseEvent *event) { this->isMouseDown_ = true; - if (event->button() == Qt::RightButton) { + if (event->button() == Qt::RightButton) + { this->resetFlex(); } } @@ -1227,7 +1398,8 @@ void SplitContainer::ResizeHandle::mouseReleaseEvent(QMouseEvent *) void SplitContainer::ResizeHandle::mouseMoveEvent(QMouseEvent *event) { - if (!this->isMouseDown_) { + if (!this->isMouseDown_) + { return; } @@ -1259,7 +1431,8 @@ void SplitContainer::ResizeHandle::mouseMoveEvent(QMouseEvent *event) QPoint mousePoint(globalX, globalY); - if (this->vertical_) { + if (this->vertical_) + { qreal totalFlexV = this->node->flexV_ + before->flexV_; before->flexV_ = totalFlexV * (mousePoint.y() - topLeft.y()) / (bottomRight.y() - topLeft.y()); @@ -1269,7 +1442,9 @@ void SplitContainer::ResizeHandle::mouseMoveEvent(QMouseEvent *event) // move handle this->move(this->x(), int(before->geometry_.bottom() - 4)); - } else { + } + else + { qreal totalFlexH = this->node->flexH_ + before->flexH_; before->flexH_ = totalFlexH * (mousePoint.x() - topLeft.x()) / (bottomRight.x() - topLeft.x()); @@ -1291,7 +1466,8 @@ void SplitContainer::ResizeHandle::mouseDoubleClickEvent(QMouseEvent *event) void SplitContainer::ResizeHandle::resetFlex() { - for (auto &sibling : this->node->getParent()->getChildren()) { + for (auto &sibling : this->node->getParent()->getChildren()) + { sibling->flexH_ = 1; sibling->flexV_ = 1; } diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index 939418d9b..db2cd63e8 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -39,19 +39,24 @@ namespace { { auto modes = channel.accessRoomModes(); - if (modes->r9k) text += "r9k, "; + if (modes->r9k) + text += "r9k, "; if (modes->slowMode) text += QString("slow(%1), ").arg(QString::number(modes->slowMode)); - if (modes->emoteOnly) text += "emote, "; - if (modes->submode) text += "sub, "; + if (modes->emoteOnly) + text += "emote, "; + if (modes->submode) + text += "sub, "; } - if (text.length() > 2) { + if (text.length() > 2) + { text = text.mid(0, text.size() - 2); } - if (!text.isEmpty()) { + if (!text.isEmpty()) + { static QRegularExpression commaReplacement("^(.+?, .+?,) (.+)$"); auto match = commaReplacement.match(text); @@ -59,7 +64,8 @@ namespace { text = match.captured(1) + '\n' + match.captured(2); } - if (text.isEmpty() && channel.hasModRights()) return "none"; + if (text.isEmpty() && channel.hasModRights()) + return "none"; return text; } @@ -93,11 +99,14 @@ namespace { title += " (live)"; // description - if (settings.showUptime) title += " - " + s.uptime; + if (settings.showUptime) + title += " - " + s.uptime; if (settings.showViewerCount) title += " - " + QString::number(s.viewerCount); - if (settings.showGame) title += " - " + s.game; - if (settings.showTitle) title += " - " + s.title; + if (settings.showGame) + title += " - " + s.game; + if (settings.showTitle) + title += " - " + s.title; return title; } @@ -203,7 +212,8 @@ std::unique_ptr SplitHeader::createMainMenu() ChannelPtr _channel = this->split->getChannel(); TwitchChannel *tc = dynamic_cast(_channel.get()); - if (tc != nullptr) { + if (tc != nullptr) + { StreamView *view = new StreamView( _channel, "https://player.twitch.tv/?channel=" + tc->name); view->setAttribute(Qt::WA_DeleteOnClose, true); @@ -280,7 +290,8 @@ std::unique_ptr SplitHeader::createChatModeMenu() [this, setSub, setEmote, setSlow, setR9k]() { auto twitchChannel = dynamic_cast(this->split_->getChannel().get()); - if (twitchChannel == nullptr) { + if (twitchChannel == nullptr) + { this->modeButton_->hide(); return; } @@ -308,7 +319,8 @@ std::unique_ptr SplitHeader::createChatModeMenu() [setEmote, toggle]() mutable { toggle("/emoteonly", setEmote); }); QObject::connect(setSlow, &QAction::triggered, this, [setSlow, this]() { - if (!setSlow->isChecked()) { + if (!setSlow->isChecked()) + { this->split_->getChannel().get()->sendMessage("/slowoff"); setSlow->setChecked(false); return; @@ -316,10 +328,13 @@ std::unique_ptr SplitHeader::createChatModeMenu() auto ok = bool(); auto seconds = QInputDialog::getInt(this, "", "Seconds:", 10, 0, 500, 1, &ok, Qt::FramelessWindowHint); - if (ok) { + if (ok) + { this->split_->getChannel().get()->sendMessage( QString("/slow %1").arg(seconds)); - } else { + } + else + { setSlow->setChecked(false); } }); @@ -347,7 +362,8 @@ void SplitHeader::initializeModeSignals(EffectLabel &label) // set the label text auto text = formatRoomMode(*twitchChannel); - if (!text.isEmpty()) { + if (!text.isEmpty()) + { label.getLabel().setText(text); label.show(); return; @@ -363,7 +379,8 @@ void SplitHeader::handleChannelChanged() this->channelConnections_.clear(); auto channel = this->split_->getChannel(); - if (auto twitchChannel = dynamic_cast(channel.get())) { + if (auto twitchChannel = dynamic_cast(channel.get())) + { this->channelConnections_.emplace_back( twitchChannel->liveStatusChanged.connect( [this]() { this->updateChannelText(); })); @@ -397,10 +414,12 @@ void SplitHeader::updateChannelText() if (indirectChannel.getType() == Channel::Type::TwitchWatching) title = "watching: " + (title.isEmpty() ? "none" : title); - if (auto twitchChannel = dynamic_cast(channel.get())) { + if (auto twitchChannel = dynamic_cast(channel.get())) + { const auto streamStatus = twitchChannel->accessStreamStatus(); - if (streamStatus->live) { + if (streamStatus->live) + { this->isLive_ = true; this->tooltipText_ = formatTooltip(*streamStatus); title += formatTitle(*streamStatus, *getSettings()); @@ -437,7 +456,8 @@ void SplitHeader::paintEvent(QPaintEvent *) void SplitHeader::mousePressEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton) { + if (event->button() == Qt::LeftButton) + { this->dragging_ = true; this->dragStart_ = event->pos(); @@ -448,14 +468,17 @@ void SplitHeader::mousePressEvent(QMouseEvent *event) void SplitHeader::mouseReleaseEvent(QMouseEvent *event) { - if (this->dragging_ && event->button() == Qt::LeftButton) { + if (this->dragging_ && event->button() == Qt::LeftButton) + { auto pos = event->globalPos(); - if (!showingHelpTooltip_) { + if (!showingHelpTooltip_) + { this->showingHelpTooltip_ = true; QTimer::singleShot(400, this, [this, pos] { - if (this->doubleClicked_) { + if (this->doubleClicked_) + { this->doubleClicked_ = false; this->showingHelpTooltip_ = false; return; @@ -484,8 +507,10 @@ void SplitHeader::mouseReleaseEvent(QMouseEvent *event) void SplitHeader::mouseMoveEvent(QMouseEvent *event) { - if (this->dragging_) { - if (distance(this->dragStart_, event->pos()) > 15 * this->getScale()) { + if (this->dragging_) + { + if (distance(this->dragStart_, event->pos()) > 15 * this->getScale()) + { this->split_->drag(); this->dragging_ = false; } @@ -494,7 +519,8 @@ void SplitHeader::mouseMoveEvent(QMouseEvent *event) void SplitHeader::mouseDoubleClickEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton) { + if (event->button() == Qt::LeftButton) + { this->split_->changeChannel(); } this->doubleClicked_ = true; @@ -502,7 +528,8 @@ void SplitHeader::mouseDoubleClickEvent(QMouseEvent *event) void SplitHeader::enterEvent(QEvent *event) { - if (!this->tooltipText_.isEmpty()) { + if (!this->tooltipText_.isEmpty()) + { auto tooltip = TooltipWidget::getInstance(); tooltip->moveTo(this, this->mapToGlobal(this->rect().bottomLeft()), false); @@ -527,19 +554,25 @@ void SplitHeader::themeChangedEvent() { auto palette = QPalette(); - if (this->split_->hasFocus()) { + if (this->split_->hasFocus()) + { palette.setColor(QPalette::Foreground, this->theme->splits.header.focusedText); - } else { + } + else + { palette.setColor(QPalette::Foreground, this->theme->splits.header.text); } this->titleLabel_->setPalette(palette); // -- - if (this->theme->isLightTheme()) { + if (this->theme->isLightTheme()) + { this->dropdownButton_->setPixmap(getApp()->resources->buttons.menuDark); this->addButton_->setPixmap(getApp()->resources->buttons.addSplit); - } else { + } + else + { this->dropdownButton_->setPixmap( getApp()->resources->buttons.menuLight); this->addButton_->setPixmap(getApp()->resources->buttons.addSplitDark); diff --git a/src/widgets/splits/SplitInput.cpp b/src/widgets/splits/SplitInput.cpp index aa7a18e55..2f997d8d6 100644 --- a/src/widgets/splits/SplitInput.cpp +++ b/src/widgets/splits/SplitInput.cpp @@ -90,7 +90,8 @@ void SplitInput::initLayout() // clear channelview selection when selecting in the input QObject::connect(this->ui_.textEdit, &QTextEdit::copyAvailable, [this](bool available) { - if (available) { + if (available) + { this->split_->view_->clearSelection(); } }); @@ -139,7 +140,8 @@ void SplitInput::updateEmoteButton() QString text = ""; text.replace("xD", QString::number(int(12 * scale))); - if (this->theme->isLightTheme()) { + if (this->theme->isLightTheme()) + { text.replace("emote", "emoteDark"); } @@ -149,17 +151,20 @@ void SplitInput::updateEmoteButton() void SplitInput::openEmotePopup() { - if (!this->emotePopup_) { + if (!this->emotePopup_) + { this->emotePopup_ = std::make_unique(); this->emotePopup_->linkClicked.connect([this](const Link &link) { - if (link.type == Link::InsertText) { + if (link.type == Link::InsertText) + { QTextCursor cursor = this->ui_.textEdit->textCursor(); QString textToInsert(link.value + " "); // If symbol before cursor isn't space or empty // Then insert space before emote. if (cursor.position() > 0 && - !this->getInputText()[cursor.position() - 1].isSpace()) { + !this->getInputText()[cursor.position() - 1].isSpace()) + { textToInsert = " " + textToInsert; } this->insertText(textToInsert); @@ -179,9 +184,11 @@ void SplitInput::installKeyPressedEvent() auto app = getApp(); this->ui_.textEdit->keyPressed.connect([this, app](QKeyEvent *event) { - if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { + if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) + { auto c = this->split_->getChannel(); - if (c == nullptr) { + if (c == nullptr) + { return; } @@ -198,28 +205,39 @@ void SplitInput::installKeyPressedEvent() this->prevMsg_.append(message); event->accept(); - if (!(event->modifiers() == Qt::ControlModifier)) { + if (!(event->modifiers() == Qt::ControlModifier)) + { this->currMsg_ = QString(); this->ui_.textEdit->setText(QString()); this->prevIndex_ = 0; - } else if (message == - this->prevMsg_.at(this->prevMsg_.size() - 1)) { + } + else if (message == this->prevMsg_.at(this->prevMsg_.size() - 1)) + { this->prevMsg_.removeLast(); } this->prevIndex_ = this->prevMsg_.size(); - } else if (event->key() == Qt::Key_Up) { - if ((event->modifiers() & Qt::ShiftModifier) != 0) { + } + else if (event->key() == Qt::Key_Up) + { + if ((event->modifiers() & Qt::ShiftModifier) != 0) + { return; } - if (event->modifiers() == Qt::AltModifier) { + if (event->modifiers() == Qt::AltModifier) + { SplitContainer *page = this->split_->getContainer(); - if (page != nullptr) { + if (page != nullptr) + { page->selectNextSplit(SplitContainer::Above); } - } else { - if (this->prevMsg_.size() && this->prevIndex_) { - if (this->prevIndex_ == (this->prevMsg_.size())) { + } + else + { + if (this->prevMsg_.size() && this->prevIndex_) + { + if (this->prevIndex_ == (this->prevMsg_.size())) + { this->currMsg_ = ui_.textEdit->toPlainText(); } @@ -232,36 +250,50 @@ void SplitInput::installKeyPressedEvent() this->ui_.textEdit->setTextCursor(cursor); } } - } else if (event->key() == Qt::Key_Down) { - if ((event->modifiers() & Qt::ShiftModifier) != 0) { + } + else if (event->key() == Qt::Key_Down) + { + if ((event->modifiers() & Qt::ShiftModifier) != 0) + { return; } - if (event->modifiers() == Qt::AltModifier) { + if (event->modifiers() == Qt::AltModifier) + { SplitContainer *page = this->split_->getContainer(); - if (page != nullptr) { + if (page != nullptr) + { page->selectNextSplit(SplitContainer::Below); } - } else { + } + else + { // If user did not write anything before then just do nothing. - if (this->prevMsg_.isEmpty()) { + if (this->prevMsg_.isEmpty()) + { return; } bool cursorToEnd = true; QString message = ui_.textEdit->toPlainText(); if (this->prevIndex_ != (this->prevMsg_.size() - 1) && - this->prevIndex_ != this->prevMsg_.size()) { + this->prevIndex_ != this->prevMsg_.size()) + { this->prevIndex_++; this->ui_.textEdit->setText( this->prevMsg_.at(this->prevIndex_)); - } else { + } + else + { this->prevIndex_ = this->prevMsg_.size(); - if (message == this->prevMsg_.at(this->prevIndex_ - 1)) { + if (message == this->prevMsg_.at(this->prevIndex_ - 1)) + { // If user has just come from a message history // Then simply get currMsg_. this->ui_.textEdit->setText(this->currMsg_); - } else if (message != this->currMsg_) { + } + else if (message != this->currMsg_) + { // If user are already in current message // And type something new // Then replace currMsg_ with new one. @@ -273,30 +305,42 @@ void SplitInput::installKeyPressedEvent() (message == this->prevMsg_.at(this->prevIndex_ - 1)); } - if (cursorToEnd) { + if (cursorToEnd) + { QTextCursor cursor = this->ui_.textEdit->textCursor(); cursor.movePosition(QTextCursor::End); this->ui_.textEdit->setTextCursor(cursor); } } - } else if (event->key() == Qt::Key_Left) { - if (event->modifiers() == Qt::AltModifier) { + } + else if (event->key() == Qt::Key_Left) + { + if (event->modifiers() == Qt::AltModifier) + { SplitContainer *page = this->split_->getContainer(); - if (page != nullptr) { + if (page != nullptr) + { page->selectNextSplit(SplitContainer::Left); } } - } else if (event->key() == Qt::Key_Right) { - if (event->modifiers() == Qt::AltModifier) { + } + else if (event->key() == Qt::Key_Right) + { + if (event->modifiers() == Qt::AltModifier) + { SplitContainer *page = this->split_->getContainer(); - if (page != nullptr) { + if (page != nullptr) + { page->selectNextSplit(SplitContainer::Right); } } - } else if (event->key() == Qt::Key_Tab) { - if (event->modifiers() == Qt::ControlModifier) { + } + else if (event->key() == Qt::Key_Tab) + { + if (event->modifiers() == Qt::ControlModifier) + { SplitContainer *page = static_cast(this->split_->parentWidget()); @@ -305,9 +349,11 @@ void SplitInput::installKeyPressedEvent() notebook->selectNextTab(); } - } else if (event->key() == Qt::Key_Backtab) { - if (event->modifiers() == - (Qt::ControlModifier | Qt::ShiftModifier)) { + } + else if (event->key() == Qt::Key_Backtab) + { + if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) + { SplitContainer *page = static_cast(this->split_->parentWidget()); @@ -316,14 +362,19 @@ void SplitInput::installKeyPressedEvent() notebook->selectPreviousTab(); } - } else if (event->key() == Qt::Key_C && - event->modifiers() == Qt::ControlModifier) { - if (this->split_->view_->hasSelection()) { + } + else if (event->key() == Qt::Key_C && + event->modifiers() == Qt::ControlModifier) + { + if (this->split_->view_->hasSelection()) + { this->split_->copyToClipboard(); event->accept(); } - } else if (event->key() == Qt::Key_E && - event->modifiers() == Qt::ControlModifier) { + } + else if (event->key() == Qt::Key_E && + event->modifiers() == Qt::ControlModifier) + { this->openEmotePopup(); } }); @@ -360,11 +411,14 @@ void SplitInput::editTextChanged() this->split_->getChannel()->isTwitchChannel()) // { QString lastUser = app->twitch.server->lastUserThatWhisperedMe.get(); - if (!lastUser.isEmpty()) { + if (!lastUser.isEmpty()) + { this->ui_.textEdit->setPlainText("/w " + lastUser + text.mid(2)); this->ui_.textEdit->moveCursor(QTextCursor::EndOfBlock); } - } else { + } + else + { this->textChanged.invoke(text); text = text.trimmed(); @@ -377,9 +431,12 @@ void SplitInput::editTextChanged() QString labelText; - if (text.length() == 0 || getSettings()->showMessageLength) { + if (text.length() == 0 || getSettings()->showMessageLength) + { labelText = ""; - } else { + } + else + { labelText = QString::number(text.length()); } @@ -390,7 +447,8 @@ void SplitInput::paintEvent(QPaintEvent *) { QPainter painter(this); - if (this->theme->isLightTheme()) { + if (this->theme->isLightTheme()) + { int s = int(3 * this->getScale()); QRect rect = this->rect().marginsRemoved(QMargins(s - 1, s - 1, s, s)); @@ -398,7 +456,9 @@ void SplitInput::paintEvent(QPaintEvent *) painter.setPen(QColor("#ccc")); painter.drawRect(rect); - } else { + } + else + { int s = int(1 * this->getScale()); QRect rect = this->rect().marginsRemoved(QMargins(s - 1, s - 1, s, s)); @@ -416,9 +476,12 @@ void SplitInput::paintEvent(QPaintEvent *) void SplitInput::resizeEvent(QResizeEvent *) { - if (this->height() == this->maximumHeight()) { + if (this->height() == this->maximumHeight()) + { this->ui_.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - } else { + } + else + { this->ui_.textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); } } diff --git a/src/widgets/splits/SplitOverlay.cpp b/src/widgets/splits/SplitOverlay.cpp index 1b38c0ca2..8bb17349c 100644 --- a/src/widgets/splits/SplitOverlay.cpp +++ b/src/widgets/splits/SplitOverlay.cpp @@ -95,31 +95,43 @@ SplitOverlay::SplitOverlay(Split *parent) void SplitOverlay::paintEvent(QPaintEvent *) { QPainter painter(this); - if (this->theme->isLightTheme()) { + if (this->theme->isLightTheme()) + { painter.fillRect(this->rect(), QColor(255, 255, 255, 200)); - } else { + } + else + { painter.fillRect(this->rect(), QColor(0, 0, 0, 150)); } QRect rect; - switch (this->hoveredElement_) { - case SplitLeft: { + switch (this->hoveredElement_) + { + case SplitLeft: + { rect = QRect(0, 0, this->width() / 2, this->height()); - } break; + } + break; - case SplitRight: { + case SplitRight: + { rect = QRect(this->width() / 2, 0, this->width() / 2, this->height()); - } break; + } + break; - case SplitUp: { + case SplitUp: + { rect = QRect(0, 0, this->width(), this->height() / 2); - } break; + } + break; - case SplitDown: { + case SplitDown: + { rect = QRect(0, this->height() / 2, this->width(), this->height() / 2); - } break; + } + break; default:; } @@ -127,7 +139,8 @@ void SplitOverlay::paintEvent(QPaintEvent *) rect.setRight(rect.right() - 1); rect.setBottom(rect.bottom() - 1); - if (!rect.isNull()) { + if (!rect.isNull()) + { painter.setPen(getApp()->themes->splits.dropPreviewBorder); painter.setBrush(getApp()->themes->splits.dropPreview); painter.drawRect(rect); @@ -169,46 +182,60 @@ SplitOverlay::ButtonEventFilter::ButtonEventFilter(SplitOverlay *_parent, bool SplitOverlay::ButtonEventFilter::eventFilter(QObject *watched, QEvent *event) { - switch (event->type()) { - case QEvent::Enter: { + switch (event->type()) + { + case QEvent::Enter: + { QGraphicsOpacityEffect *effect = dynamic_cast( ((QWidget *)watched)->graphicsEffect()); - if (effect != nullptr) { + if (effect != nullptr) + { effect->setOpacity(0.99); } this->parent->hoveredElement_ = this->hoveredElement; this->parent->update(); - } break; - case QEvent::Leave: { + } + break; + case QEvent::Leave: + { QGraphicsOpacityEffect *effect = dynamic_cast( ((QWidget *)watched)->graphicsEffect()); - if (effect != nullptr) { + if (effect != nullptr) + { effect->setOpacity(0.7); } this->parent->hoveredElement_ = HoveredElement::None; this->parent->update(); - } break; - case QEvent::MouseButtonPress: { - if (this->hoveredElement == HoveredElement::SplitMove) { + } + break; + case QEvent::MouseButtonPress: + { + if (this->hoveredElement == HoveredElement::SplitMove) + { QMouseEvent *mouseEvent = static_cast(event); - if (mouseEvent->button() == Qt::LeftButton) { + if (mouseEvent->button() == Qt::LeftButton) + { this->parent->split_->drag(); } return true; } - } break; - case QEvent::MouseButtonRelease: { - if (this->hoveredElement != HoveredElement::SplitMove) { + } + break; + case QEvent::MouseButtonRelease: + { + if (this->hoveredElement != HoveredElement::SplitMove) + { SplitContainer *container = this->parent->split_->getContainer(); - if (container != nullptr) { + if (container != nullptr) + { auto *_split = new Split(container); auto dir = SplitContainer::Direction(this->hoveredElement + SplitContainer::Left - @@ -217,7 +244,8 @@ bool SplitOverlay::ButtonEventFilter::eventFilter(QObject *watched, this->parent->hide(); } } - } break; + } + break; default:; } return QObject::eventFilter(watched, event);