diff --git a/src/messages/message.hpp b/src/messages/message.hpp index 1aa708c4..19592ffa 100644 --- a/src/messages/message.hpp +++ b/src/messages/message.hpp @@ -24,7 +24,8 @@ class Message { public: // explicit Message(const QString &text); - explicit Message(const QString &text, const std::vector &words, const bool &highlight); + explicit Message(const QString &text, const std::vector &words, + const bool &highlight); bool getCanHighlightTab() const; const QString &getTimeoutUser() const; diff --git a/src/messages/messagebuilder.cpp b/src/messages/messagebuilder.cpp index aa1fa95c..845ace18 100644 --- a/src/messages/messagebuilder.cpp +++ b/src/messages/messagebuilder.cpp @@ -16,7 +16,7 @@ MessageBuilder::MessageBuilder() SharedMessage MessageBuilder::build() { - return SharedMessage(new Message(this->originalMessage, _words,highlight)); + return SharedMessage(new Message(this->originalMessage, _words, highlight)); } void MessageBuilder::appendWord(const Word &word) @@ -31,7 +31,8 @@ void MessageBuilder::appendTimestamp() appendTimestamp(t); } -void MessageBuilder::setHighlight(const bool &value){ +void MessageBuilder::setHighlight(const bool &value) +{ highlight = value; } @@ -58,9 +59,12 @@ void MessageBuilder::appendTimestamp(time_t time) QString MessageBuilder::matchLink(const QString &string) { - QString match = regex.match(string,0,QRegularExpression::PartialPreferCompleteMatch,QRegularExpression::NoMatchOption).captured(); - if(!match.contains(QRegularExpression("\\bhttps?:\/\/"))){ - match.insert(0,"https://"); + QString match = regex + .match(string, 0, QRegularExpression::PartialPreferCompleteMatch, + QRegularExpression::NoMatchOption) + .captured(); + if (!match.contains(QRegularExpression("\\bhttps?:\/\/"))) { + match.insert(0, "https://"); } return match; } diff --git a/src/messages/messagebuilder.hpp b/src/messages/messagebuilder.hpp index 27c01737..86f2494a 100644 --- a/src/messages/messagebuilder.hpp +++ b/src/messages/messagebuilder.hpp @@ -2,9 +2,10 @@ #include "messages/message.hpp" -#include #include +#include + namespace chatterino { namespace messages { diff --git a/src/setting.hpp b/src/setting.hpp index 73fc850d..8e7930e8 100644 --- a/src/setting.hpp +++ b/src/setting.hpp @@ -43,7 +43,8 @@ public: return _value; } - T &getnonConst() { + T &getnonConst() + { return _value; } @@ -69,12 +70,12 @@ public: } } - void insertMap(QString id, bool sound, bool task){ - QPair pair(sound,task); - _value.insert(id,pair); + void insertMap(QString id, bool sound, bool task) + { + QPair pair(sound, task); + _value.insert(id, pair); } - boost::signals2::signal valueChanged; private: diff --git a/src/settingsmanager.cpp b/src/settingsmanager.cpp index 81cf0b25..a5d65a8e 100644 --- a/src/settingsmanager.cpp +++ b/src/settingsmanager.cpp @@ -27,12 +27,12 @@ SettingsManager::SettingsManager() , mentionUsersWithAt(_settingsItems, "mentionUsersWithAt", false) , allowCommandsAtEnd(_settingsItems, "allowCommandsAtEnd", false) , enableHighlights(_settingsItems, "enableHighlights", true) - , enableHighlightsSelf(_settingsItems,"enableHighlightsSelf", true) + , enableHighlightsSelf(_settingsItems, "enableHighlightsSelf", true) , enableHighlightSound(_settingsItems, "enableHighlightSound", true) , enableHighlightTaskbar(_settingsItems, "enableHighlightTaskbar", true) , customHighlightSound(_settingsItems, "customHighlightSound", false) , pathHighlightSound(_settingsItems, "pathHighlightSound", "qrc:/sounds/ping2.wav") - , highlightProperties(_settingsItems,"highlightProperties",QMap>()) + , highlightProperties(_settingsItems, "highlightProperties", QMap>()) , enableTwitchEmotes(_settingsItems, "enableTwitchEmotes", true) , enableBttvEmotes(_settingsItems, "enableBttvEmotes", true) , enableFfzEmotes(_settingsItems, "enableFfzEmotes", true) @@ -64,17 +64,17 @@ SettingsManager::SettingsManager() void SettingsManager::save() { for (auto &item : _settingsItems) { - if(item.get().getName() != "highlightProperties"){ + if (item.get().getName() != "highlightProperties") { _settings.setValue(item.get().getName(), item.get().getVariant()); } else { _settings.beginGroup("Highlights"); QStringList list = highlightProperties.get().keys(); list.removeAll(""); _settings.remove(""); - for (auto string : list){ + for (auto string : list) { _settings.beginGroup(string); - _settings.setValue("highlightSound",highlightProperties.get().value(string).first); - _settings.setValue("highlightTask",highlightProperties.get().value(string).second); + _settings.setValue("highlightSound", highlightProperties.get().value(string).first); + _settings.setValue("highlightTask", highlightProperties.get().value(string).second); _settings.endGroup(); } _settings.endGroup(); @@ -85,15 +85,16 @@ void SettingsManager::save() void SettingsManager::load() { for (auto &item : _settingsItems) { - if(item.get().getName() != "highlightProperties"){ + if (item.get().getName() != "highlightProperties") { item.get().setVariant(_settings.value(item.get().getName())); } else { _settings.beginGroup("Highlights"); QStringList list = _settings.childGroups(); qDebug() << list.join(","); - for (auto string : list){ + for (auto string : list) { _settings.beginGroup(string); - highlightProperties.insertMap(string,_settings.value("highlightSound").toBool(),_settings.value("highlightTask").toBool()); + highlightProperties.insertMap(string, _settings.value("highlightSound").toBool(), + _settings.value("highlightTask").toBool()); _settings.endGroup(); } _settings.endGroup(); @@ -101,7 +102,6 @@ void SettingsManager::load() } } - Word::Type SettingsManager::getWordTypeMask() { return _wordTypeMask; @@ -159,8 +159,8 @@ SettingsSnapshot SettingsManager::createSnapshot() SettingsSnapshot snapshot; for (auto &item : this->_settingsItems) { - if(item.get().getName() != "highlightProperties"){ - snapshot.addItem(item, item.get().getVariant()); + if (item.get().getName() != "highlightProperties") { + snapshot.addItem(item, item.get().getVariant()); } else { snapshot._mapItems = highlightProperties.get(); } diff --git a/src/settingsmanager.hpp b/src/settingsmanager.hpp index c59564e0..10735e24 100644 --- a/src/settingsmanager.hpp +++ b/src/settingsmanager.hpp @@ -34,7 +34,7 @@ private: messages::Word::Type _wordTypeMask = messages::Word::Default; // methods -public: // temporary +public: // temporary void updateWordTypeMask(); public: @@ -62,7 +62,7 @@ public: Setting enableHighlightTaskbar; Setting customHighlightSound; Setting pathHighlightSound; - Setting>> highlightProperties; + Setting>> highlightProperties; Setting enableTwitchEmotes; Setting enableBttvEmotes; Setting enableFfzEmotes; diff --git a/src/settingssnapshot.hpp b/src/settingssnapshot.hpp index 990352ac..56a4a8a0 100644 --- a/src/settingssnapshot.hpp +++ b/src/settingssnapshot.hpp @@ -18,12 +18,12 @@ public: std::pair, QVariant>(setting.get(), value)); } - void addMapItem(QString string,QPair pair){ - QMap> map; - _mapItems.insert(string,pair); + void addMapItem(QString string, QPair pair) + { + QMap> map; + _mapItems.insert(string, pair); } - void apply() { for (auto &item : _items) { @@ -31,7 +31,7 @@ public: } } - QMap> _mapItems; + QMap> _mapItems; private: std::vector, QVariant>> _items; diff --git a/src/twitch/twitchmessagebuilder.cpp b/src/twitch/twitchmessagebuilder.cpp index 4d1ed7fe..df12bc64 100644 --- a/src/twitch/twitchmessagebuilder.cpp +++ b/src/twitch/twitchmessagebuilder.cpp @@ -57,32 +57,34 @@ SharedMessage TwitchMessageBuilder::parse() this->originalMessage = originalMessage; SettingsManager &settings = SettingsManager::getInstance(); static auto player = new QMediaPlayer; - if(settings.customHighlightSound.get()){ - player->setMedia(QUrl(settings.pathHighlightSound.get())); + if (settings.customHighlightSound.get()) { + player->setMedia(QUrl(settings.pathHighlightSound.get())); } else { player->setMedia(QUrl("qrc:/sounds/ping2.wav")); } - if(settings.enableHighlights.get() && ircMessage->nick().compare(settings.selectedUser.get(), Qt::CaseInsensitive)){ - if(settings.enableHighlightsSelf.get() && originalMessage.contains(settings.selectedUser.get(), Qt::CaseInsensitive)){ + if (settings.enableHighlights.get() && + ircMessage->nick().compare(settings.selectedUser.get(), Qt::CaseInsensitive)) { + if (settings.enableHighlightsSelf.get() && + originalMessage.contains(settings.selectedUser.get(), Qt::CaseInsensitive)) { this->setHighlight(true); - if(settings.enableHighlightSound.get()){ + if (settings.enableHighlightSound.get()) { player->play(); } - if(settings.enableHighlightTaskbar.get()){ - QApplication::alert(windowManager.getMainWindow().window(),2500); + if (settings.enableHighlightTaskbar.get()) { + QApplication::alert(windowManager.getMainWindow().window(), 2500); } } else { QStringList lines = settings.highlightProperties.get().keys(); - for(QString string : lines){ - if(originalMessage.contains(string,Qt::CaseInsensitive)){ + for (QString string : lines) { + if (originalMessage.contains(string, Qt::CaseInsensitive)) { this->setHighlight(true); // Sound - if(settings.highlightProperties.get().value(string).first){ + if (settings.highlightProperties.get().value(string).first) { player->play(); } // Taskbar - if(settings.highlightProperties.get().value(string).second){ - QApplication::alert(windowManager.getMainWindow().window(),2500); + if (settings.highlightProperties.get().value(string).second) { + QApplication::alert(windowManager.getMainWindow().window(), 2500); } } } diff --git a/src/widgets/chatwidgetview.cpp b/src/widgets/chatwidgetview.cpp index 0ef5e205..ce6cf8cb 100644 --- a/src/widgets/chatwidgetview.cpp +++ b/src/widgets/chatwidgetview.cpp @@ -227,7 +227,9 @@ void ChatWidgetView::paintEvent(QPaintEvent * /*event*/) // update messages that have been changed if (updateBuffer) { QPainter painter(buffer); - painter.fillRect(buffer->rect(), (messageRef->getMessage()->getCanHighlightTab()) ? this->colorScheme.ChatBackgroundHighlighted : this->colorScheme.ChatBackground); + painter.fillRect(buffer->rect(), (messageRef->getMessage()->getCanHighlightTab()) + ? this->colorScheme.ChatBackgroundHighlighted + : this->colorScheme.ChatBackground); for (messages::WordPart const &wordPart : messageRef->getWordParts()) { // image if (wordPart.getWord().isImage()) { @@ -380,7 +382,7 @@ void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event) auto &link = hoverWord.getLink(); switch (link.getType()) { - case messages::Link::UserInfo:{ + case messages::Link::UserInfo: { auto user = message->getMessage()->getUserName(); this->userPopupWidget.setName(user); this->userPopupWidget.move(event->screenPos().toPoint()); @@ -390,7 +392,7 @@ void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event) qDebug() << "Clicked " << user << "s message"; break; } - case messages::Link::Url:{ + case messages::Link::Url: { QDesktopServices::openUrl(QUrl(link.getValue())); break; } diff --git a/src/widgets/settingsdialog.cpp b/src/widgets/settingsdialog.cpp index 2459746e..5a39aa21 100644 --- a/src/widgets/settingsdialog.cpp +++ b/src/widgets/settingsdialog.cpp @@ -9,15 +9,15 @@ #include #include #include +#include #include #include -#include #include #include #include #include -#include #include +#include namespace chatterino { namespace widgets { @@ -108,10 +108,11 @@ void SettingsDialog::addTabs() listWidget->addItem(user.getUserName()); } - if(listWidget->count()){ + if (listWidget->count()) { int itemIndex = 0; - for(; itemIndex < listWidget->count(); ++itemIndex){ - if(listWidget->item(itemIndex)->text().compare(settings.selectedUser.get(),Qt::CaseInsensitive)){ + for (; itemIndex < listWidget->count(); ++itemIndex) { + if (listWidget->item(itemIndex)->text().compare(settings.selectedUser.get(), + Qt::CaseInsensitive)) { ++itemIndex; break; } @@ -119,9 +120,9 @@ void SettingsDialog::addTabs() listWidget->setCurrentRow(itemIndex); } - QObject::connect(listWidget,&QListWidget::clicked,this,[&,listWidget]{ - if(!listWidget->selectedItems().isEmpty()){ - settings.selectedUser.set(listWidget->currentItem()->text()); + QObject::connect(listWidget, &QListWidget::clicked, this, [&, listWidget] { + if (!listWidget->selectedItems().isEmpty()) { + settings.selectedUser.set(listWidget->currentItem()->text()); } }); @@ -374,14 +375,17 @@ void SettingsDialog::addTabs() auto soundForm = new QFormLayout(); { vbox->addWidget(createCheckbox("Enable Highlighting", settings.enableHighlights)); - vbox->addWidget(createCheckbox("Highlight messages containing your name", settings.enableHighlightsSelf)); - vbox->addWidget(createCheckbox("Play sound when your name is mentioned", settings.enableHighlightSound)); - vbox->addWidget(createCheckbox("Flash taskbar when your name is mentioned", settings.enableHighlightTaskbar)); + vbox->addWidget(createCheckbox("Highlight messages containing your name", + settings.enableHighlightsSelf)); + vbox->addWidget(createCheckbox("Play sound when your name is mentioned", + settings.enableHighlightSound)); + vbox->addWidget(createCheckbox("Flash taskbar when your name is mentioned", + settings.enableHighlightTaskbar)); customSound->addWidget(createCheckbox("Custom sound", settings.customHighlightSound)); auto selectBtn = new QPushButton("Select"); - QObject::connect(selectBtn,&QPushButton::clicked,this,[&settings,this]{ - auto fileName = QFileDialog::getOpenFileName(this, - tr("Open Sound"), "", tr("Image Files (*.mp3 *.wav)")); + QObject::connect(selectBtn, &QPushButton::clicked, this, [&settings, this] { + auto fileName = QFileDialog::getOpenFileName(this, tr("Open Sound"), "", + tr("Image Files (*.mp3 *.wav)")); settings.pathHighlightSound.set(fileName); }); customSound->addWidget(selectBtn); @@ -390,80 +394,88 @@ void SettingsDialog::addTabs() soundForm->addRow(customSound); { - auto hbox = new QHBoxLayout(); - auto addBtn = new QPushButton("Add"); - auto editBtn = new QPushButton("Edit"); - auto delBtn = new QPushButton("Remove"); + auto hbox = new QHBoxLayout(); + auto addBtn = new QPushButton("Add"); + auto editBtn = new QPushButton("Edit"); + auto delBtn = new QPushButton("Remove"); - QObject::connect(addBtn,&QPushButton::clicked,this,[highlights,this,&settings]{ - auto show = new QWidget(); - auto box = new QBoxLayout(QBoxLayout::TopToBottom); + QObject::connect(addBtn, &QPushButton::clicked, this, [highlights, this, &settings] { + auto show = new QWidget(); + auto box = new QBoxLayout(QBoxLayout::TopToBottom); - auto edit = new QLineEdit(); - auto add = new QPushButton("Add"); + auto edit = new QLineEdit(); + auto add = new QPushButton("Add"); - auto sound = new QCheckBox("Play sound"); - auto task = new QCheckBox("Flash taskbar"); + auto sound = new QCheckBox("Play sound"); + auto task = new QCheckBox("Flash taskbar"); - QObject::connect(add,&QPushButton::clicked,this,[=,&settings]{ - if(edit->text().length()){ - highlights->addItem(edit->text()); - settings.highlightProperties.insertMap(edit->text(),sound->isChecked(),task->isChecked()); - show->close(); + QObject::connect(add, &QPushButton::clicked, this, [=, &settings] { + if (edit->text().length()) { + highlights->addItem(edit->text()); + settings.highlightProperties.insertMap(edit->text(), sound->isChecked(), + task->isChecked()); + show->close(); + } + }); + box->addWidget(edit); + box->addWidget(add); + box->addWidget(sound); + box->addWidget(task); + show->setLayout(box); + show->show(); + }); + QObject::connect(editBtn, &QPushButton::clicked, this, [highlights, this, &settings] { + if (!highlights->selectedItems().isEmpty()) { + auto show = new QWidget(); + auto box = new QBoxLayout(QBoxLayout::TopToBottom); + + auto edit = new QLineEdit(); + edit->setText(highlights->selectedItems().first()->text()); + auto add = new QPushButton("Apply"); + + auto sound = new QCheckBox("Play sound"); + auto task = new QCheckBox("Flash taskbar"); + + QObject::connect(add, &QPushButton::clicked, this, [=, &settings] { + if (edit->text().length()) { + settings.highlightProperties.getnonConst().remove( + highlights->selectedItems().first()->text()); + delete highlights->selectedItems().first(); + highlights->addItem(edit->text()); + settings.highlightProperties.insertMap(edit->text(), sound->isChecked(), + task->isChecked()); + show->close(); + } + }); + box->addWidget(edit); + box->addWidget(add); + box->addWidget(sound); + sound->setChecked(settings.highlightProperties.get() + .value(highlights->selectedItems().first()->text()) + .first); + box->addWidget(task); + task->setChecked(settings.highlightProperties.get() + .value(highlights->selectedItems().first()->text()) + .second); + show->setLayout(box); + show->show(); } }); - box->addWidget(edit); - box->addWidget(add); - box->addWidget(sound); - box->addWidget(task); - show->setLayout(box); - show->show(); - }); - QObject::connect(editBtn,&QPushButton::clicked,this,[highlights,this,&settings]{ - if(!highlights->selectedItems().isEmpty()){ - auto show = new QWidget(); - auto box = new QBoxLayout(QBoxLayout::TopToBottom); - - auto edit = new QLineEdit(); - edit->setText(highlights->selectedItems().first()->text()); - auto add = new QPushButton("Apply"); - - auto sound = new QCheckBox("Play sound"); - auto task = new QCheckBox("Flash taskbar"); - - QObject::connect(add,&QPushButton::clicked,this,[=,&settings]{ - if(edit->text().length()){ - settings.highlightProperties.getnonConst().remove(highlights->selectedItems().first()->text()); + QObject::connect(delBtn, &QPushButton::clicked, this, [highlights, &settings] { + if (!highlights->selectedItems().isEmpty()) { + settings.highlightProperties.getnonConst().remove( + highlights->selectedItems().first()->text()); delete highlights->selectedItems().first(); - highlights->addItem(edit->text()); - settings.highlightProperties.insertMap(edit->text(),sound->isChecked(),task->isChecked()); - show->close(); } }); - box->addWidget(edit); - box->addWidget(add); - box->addWidget(sound); - sound->setChecked(settings.highlightProperties.get().value(highlights->selectedItems().first()->text()).first); - box->addWidget(task); - task->setChecked(settings.highlightProperties.get().value(highlights->selectedItems().first()->text()).second); - show->setLayout(box); - show->show(); - } - }); - QObject::connect(delBtn,&QPushButton::clicked,this,[highlights,&settings]{ - if(!highlights->selectedItems().isEmpty()){ - settings.highlightProperties.getnonConst().remove(highlights->selectedItems().first()->text()); - delete highlights->selectedItems().first(); - } - }); - vbox->addLayout(soundForm); - vbox->addWidget(highlights); + vbox->addLayout(soundForm); + vbox->addWidget(highlights); - hbox->addWidget(addBtn); - hbox->addWidget(editBtn); - hbox->addWidget(delBtn); + hbox->addWidget(addBtn); + hbox->addWidget(editBtn); + hbox->addWidget(delBtn); - vbox->addLayout(hbox); + vbox->addLayout(hbox); } vbox->addStretch(1); addTab(vbox, "Highlighting", ":/images/format_Bold_16xLG.png"); @@ -586,9 +598,8 @@ void SettingsDialog::cancelButtonClicked() QStringList list = instance.highlightProperties.get().keys(); list.removeDuplicates(); - while(globalHighlights->count()>0) - { - delete globalHighlights->takeItem(0); + while (globalHighlights->count() > 0) { + delete globalHighlights->takeItem(0); } globalHighlights->addItems(list); diff --git a/src/widgets/settingsdialog.hpp b/src/widgets/settingsdialog.hpp index cb898861..e1e800af 100644 --- a/src/widgets/settingsdialog.hpp +++ b/src/widgets/settingsdialog.hpp @@ -52,7 +52,7 @@ private: SettingsDialogTab *selectedTab = nullptr; - QListWidget* globalHighlights; + QListWidget *globalHighlights; /// Widget creation helpers QCheckBox *createCheckbox(const QString &title, Setting &setting);