mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
reformat code
This commit is contained in:
parent
0088374694
commit
626002c8ff
|
@ -24,7 +24,8 @@ class Message
|
|||
{
|
||||
public:
|
||||
// explicit Message(const QString &text);
|
||||
explicit Message(const QString &text, const std::vector<messages::Word> &words, const bool &highlight);
|
||||
explicit Message(const QString &text, const std::vector<messages::Word> &words,
|
||||
const bool &highlight);
|
||||
|
||||
bool getCanHighlightTab() const;
|
||||
const QString &getTimeoutUser() const;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
#include "messages/message.hpp"
|
||||
|
||||
#include <ctime>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
namespace chatterino {
|
||||
namespace messages {
|
||||
|
||||
|
|
|
@ -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<bool,bool> pair(sound,task);
|
||||
_value.insert(id,pair);
|
||||
void insertMap(QString id, bool sound, bool task)
|
||||
{
|
||||
QPair<bool, bool> pair(sound, task);
|
||||
_value.insert(id, pair);
|
||||
}
|
||||
|
||||
|
||||
boost::signals2::signal<void(const T &newValue)> valueChanged;
|
||||
|
||||
private:
|
||||
|
|
|
@ -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<QString,QPair<bool,bool>>())
|
||||
, highlightProperties(_settingsItems, "highlightProperties", QMap<QString, QPair<bool, bool>>())
|
||||
, 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,7 +159,7 @@ SettingsSnapshot SettingsManager::createSnapshot()
|
|||
SettingsSnapshot snapshot;
|
||||
|
||||
for (auto &item : this->_settingsItems) {
|
||||
if(item.get().getName() != "highlightProperties"){
|
||||
if (item.get().getName() != "highlightProperties") {
|
||||
snapshot.addItem(item, item.get().getVariant());
|
||||
} else {
|
||||
snapshot._mapItems = highlightProperties.get();
|
||||
|
|
|
@ -62,7 +62,7 @@ public:
|
|||
Setting<bool> enableHighlightTaskbar;
|
||||
Setting<bool> customHighlightSound;
|
||||
Setting<QString> pathHighlightSound;
|
||||
Setting<QMap<QString,QPair<bool,bool>>> highlightProperties;
|
||||
Setting<QMap<QString, QPair<bool, bool>>> highlightProperties;
|
||||
Setting<bool> enableTwitchEmotes;
|
||||
Setting<bool> enableBttvEmotes;
|
||||
Setting<bool> enableFfzEmotes;
|
||||
|
|
|
@ -18,12 +18,12 @@ public:
|
|||
std::pair<std::reference_wrapper<BaseSetting>, QVariant>(setting.get(), value));
|
||||
}
|
||||
|
||||
void addMapItem(QString string,QPair<bool,bool> pair){
|
||||
QMap<QString,QPair<bool,bool>> map;
|
||||
_mapItems.insert(string,pair);
|
||||
void addMapItem(QString string, QPair<bool, bool> pair)
|
||||
{
|
||||
QMap<QString, QPair<bool, bool>> map;
|
||||
_mapItems.insert(string, pair);
|
||||
}
|
||||
|
||||
|
||||
void apply()
|
||||
{
|
||||
for (auto &item : _items) {
|
||||
|
@ -31,7 +31,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
QMap<QString,QPair<bool,bool>> _mapItems;
|
||||
QMap<QString, QPair<bool, bool>> _mapItems;
|
||||
|
||||
private:
|
||||
std::vector<std::pair<std::reference_wrapper<BaseSetting>, QVariant>> _items;
|
||||
|
|
|
@ -57,32 +57,34 @@ SharedMessage TwitchMessageBuilder::parse()
|
|||
this->originalMessage = originalMessage;
|
||||
SettingsManager &settings = SettingsManager::getInstance();
|
||||
static auto player = new QMediaPlayer;
|
||||
if(settings.customHighlightSound.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -9,15 +9,15 @@
|
|||
#include <QComboBox>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QFontDialog>
|
||||
#include <QFormLayout>
|
||||
#include <QFileDialog>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
#include <QPalette>
|
||||
#include <QTextEdit>
|
||||
#include <QResource>
|
||||
#include <QTextEdit>
|
||||
|
||||
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,8 +120,8 @@ void SettingsDialog::addTabs()
|
|||
listWidget->setCurrentRow(itemIndex);
|
||||
}
|
||||
|
||||
QObject::connect(listWidget,&QListWidget::clicked,this,[&,listWidget]{
|
||||
if(!listWidget->selectedItems().isEmpty()){
|
||||
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);
|
||||
|
@ -395,7 +399,7 @@ void SettingsDialog::addTabs()
|
|||
auto editBtn = new QPushButton("Edit");
|
||||
auto delBtn = new QPushButton("Remove");
|
||||
|
||||
QObject::connect(addBtn,&QPushButton::clicked,this,[highlights,this,&settings]{
|
||||
QObject::connect(addBtn, &QPushButton::clicked, this, [highlights, this, &settings] {
|
||||
auto show = new QWidget();
|
||||
auto box = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
|
||||
|
@ -405,10 +409,11 @@ void SettingsDialog::addTabs()
|
|||
auto sound = new QCheckBox("Play sound");
|
||||
auto task = new QCheckBox("Flash taskbar");
|
||||
|
||||
QObject::connect(add,&QPushButton::clicked,this,[=,&settings]{
|
||||
if(edit->text().length()){
|
||||
QObject::connect(add, &QPushButton::clicked, this, [=, &settings] {
|
||||
if (edit->text().length()) {
|
||||
highlights->addItem(edit->text());
|
||||
settings.highlightProperties.insertMap(edit->text(),sound->isChecked(),task->isChecked());
|
||||
settings.highlightProperties.insertMap(edit->text(), sound->isChecked(),
|
||||
task->isChecked());
|
||||
show->close();
|
||||
}
|
||||
});
|
||||
|
@ -419,8 +424,8 @@ void SettingsDialog::addTabs()
|
|||
show->setLayout(box);
|
||||
show->show();
|
||||
});
|
||||
QObject::connect(editBtn,&QPushButton::clicked,this,[highlights,this,&settings]{
|
||||
if(!highlights->selectedItems().isEmpty()){
|
||||
QObject::connect(editBtn, &QPushButton::clicked, this, [highlights, this, &settings] {
|
||||
if (!highlights->selectedItems().isEmpty()) {
|
||||
auto show = new QWidget();
|
||||
auto box = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
|
||||
|
@ -431,28 +436,35 @@ void SettingsDialog::addTabs()
|
|||
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(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());
|
||||
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);
|
||||
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);
|
||||
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());
|
||||
QObject::connect(delBtn, &QPushButton::clicked, this, [highlights, &settings] {
|
||||
if (!highlights->selectedItems().isEmpty()) {
|
||||
settings.highlightProperties.getnonConst().remove(
|
||||
highlights->selectedItems().first()->text());
|
||||
delete highlights->selectedItems().first();
|
||||
}
|
||||
});
|
||||
|
@ -586,8 +598,7 @@ void SettingsDialog::cancelButtonClicked()
|
|||
|
||||
QStringList list = instance.highlightProperties.get().keys();
|
||||
list.removeDuplicates();
|
||||
while(globalHighlights->count()>0)
|
||||
{
|
||||
while (globalHighlights->count() > 0) {
|
||||
delete globalHighlights->takeItem(0);
|
||||
}
|
||||
globalHighlights->addItems(list);
|
||||
|
|
|
@ -52,7 +52,7 @@ private:
|
|||
|
||||
SettingsDialogTab *selectedTab = nullptr;
|
||||
|
||||
QListWidget* globalHighlights;
|
||||
QListWidget *globalHighlights;
|
||||
|
||||
/// Widget creation helpers
|
||||
QCheckBox *createCheckbox(const QString &title, Setting<bool> &setting);
|
||||
|
|
Loading…
Reference in a new issue