2018-01-12 23:09:05 +01:00
|
|
|
#include "highlightingpage.hpp"
|
|
|
|
|
2018-01-13 02:00:02 +01:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QPushButton>
|
2018-04-26 20:58:32 +02:00
|
|
|
#include <QStandardItemModel>
|
2018-01-13 02:00:02 +01:00
|
|
|
#include <QTabWidget>
|
2018-04-25 14:49:30 +02:00
|
|
|
#include <QTableView>
|
2018-01-13 02:00:02 +01:00
|
|
|
#include <QTextEdit>
|
|
|
|
|
|
|
|
#include "debug/log.hpp"
|
|
|
|
#include "singletons/settingsmanager.hpp"
|
|
|
|
#include "util/layoutcreator.hpp"
|
2018-04-26 23:07:02 +02:00
|
|
|
#include "util/standarditemhelper.hpp"
|
2018-01-13 02:00:02 +01:00
|
|
|
|
|
|
|
#define ENABLE_HIGHLIGHTS "Enable Highlighting"
|
|
|
|
#define HIGHLIGHT_MSG "Highlight messages containing your name"
|
|
|
|
#define PLAY_SOUND "Play sound when your name is mentioned"
|
|
|
|
#define FLASH_TASKBAR "Flash taskbar when your name is mentioned"
|
|
|
|
#define ALWAYS_PLAY "Always play highlight sound (Even if Chatterino is focused)"
|
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
|
|
|
namespace settingspages {
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
HighlightingPage::HighlightingPage()
|
2018-01-13 02:21:08 +01:00
|
|
|
: SettingsPage("Highlights", ":/images/notifications.svg")
|
2018-01-12 23:09:05 +01:00
|
|
|
{
|
2018-01-13 02:00:02 +01:00
|
|
|
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
|
|
|
util::LayoutCreator<HighlightingPage> layoutCreator(this);
|
|
|
|
|
|
|
|
auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
|
|
|
|
{
|
|
|
|
// GENERAL
|
|
|
|
layout.append(this->createCheckBox(ENABLE_HIGHLIGHTS, settings.enableHighlights));
|
|
|
|
|
|
|
|
// TABS
|
|
|
|
auto tabs = layout.emplace<QTabWidget>();
|
|
|
|
{
|
|
|
|
// HIGHLIGHTS
|
|
|
|
auto highlights = tabs.appendTab(new QVBoxLayout, "Highlights");
|
|
|
|
{
|
2018-04-25 14:49:30 +02:00
|
|
|
QTableView *view = *highlights.emplace<QTableView>();
|
2018-04-26 20:58:32 +02:00
|
|
|
auto *model = new QStandardItemModel(0, 4, view);
|
2018-04-26 23:07:02 +02:00
|
|
|
model->setHeaderData(0, Qt::Horizontal, "Pattern");
|
|
|
|
model->setHeaderData(1, Qt::Horizontal, "Flash taskbar");
|
|
|
|
model->setHeaderData(2, Qt::Horizontal, "Play sound");
|
|
|
|
model->setHeaderData(3, Qt::Horizontal, "Regex");
|
|
|
|
view->setModel(model);
|
|
|
|
view->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
view->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
view->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
2018-04-25 14:49:30 +02:00
|
|
|
|
2018-04-26 23:07:02 +02:00
|
|
|
// own name
|
|
|
|
auto *yourName = util::stringItem("Your name (automatic)", false, false);
|
|
|
|
yourName->setData(QBrush("#666"), Qt::ForegroundRole);
|
|
|
|
yourName->setFlags(yourName->flags() | Qt::ItemIsUserCheckable |
|
|
|
|
Qt::ItemIsUserCheckable);
|
|
|
|
yourName->setData(settings.enableHighlightsSelf ? 2 : 0, Qt::CheckStateRole);
|
|
|
|
model->appendRow(
|
|
|
|
{yourName,
|
|
|
|
util::boolItem(settings.enableHighlightTaskbar.getValue(), true, false),
|
|
|
|
util::boolItem(settings.enableHighlightSound.getValue(), true, false),
|
|
|
|
util::emptyItem()});
|
|
|
|
|
|
|
|
// highlight phrases
|
2018-04-25 14:49:30 +02:00
|
|
|
// fourtf: could crash
|
|
|
|
for (const messages::HighlightPhrase &phrase :
|
|
|
|
settings.highlightProperties.getValue()) {
|
2018-04-26 23:07:02 +02:00
|
|
|
model->appendRow({util::stringItem(phrase.key), util::boolItem(phrase.alert),
|
|
|
|
util::boolItem(phrase.sound), util::boolItem(phrase.regex)});
|
2018-04-25 14:49:30 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 20:35:32 +02:00
|
|
|
// fourtf: make class extrend BaseWidget and add this to dpiChanged
|
|
|
|
QTimer::singleShot(1, [view] {
|
|
|
|
view->resizeColumnsToContents();
|
|
|
|
view->setColumnWidth(0, 250);
|
|
|
|
});
|
2018-01-13 02:00:02 +01:00
|
|
|
|
|
|
|
auto buttons = highlights.emplace<QHBoxLayout>();
|
|
|
|
|
2018-04-26 23:07:02 +02:00
|
|
|
QObject::connect(model, &QStandardItemModel::dataChanged,
|
|
|
|
[model](const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
|
|
|
const QVector<int> &roles) {
|
|
|
|
std::vector<messages::HighlightPhrase> phrases;
|
|
|
|
for (int i = 1; i < model->rowCount(); i++) {
|
|
|
|
phrases.push_back(messages::HighlightPhrase{
|
|
|
|
model->item(i, 0)->data(Qt::DisplayRole).toString(),
|
|
|
|
model->item(i, 1)->data(Qt::CheckStateRole).toBool(),
|
|
|
|
model->item(i, 2)->data(Qt::CheckStateRole).toBool(),
|
|
|
|
model->item(i, 3)->data(Qt::CheckStateRole).toBool()});
|
|
|
|
}
|
|
|
|
auto &settings = singletons::SettingManager::getInstance();
|
|
|
|
settings.highlightProperties.setValue(phrases);
|
|
|
|
settings.enableHighlightsSelf.setValue(
|
|
|
|
model->item(0, 0)->data(Qt::CheckStateRole).toBool());
|
|
|
|
settings.enableHighlightTaskbar.setValue(
|
|
|
|
model->item(0, 1)->data(Qt::CheckStateRole).toBool());
|
|
|
|
settings.enableHighlightSound.setValue(
|
|
|
|
model->item(0, 2)->data(Qt::CheckStateRole).toBool());
|
|
|
|
});
|
2018-04-25 14:49:30 +02:00
|
|
|
|
|
|
|
auto add = buttons.emplace<QPushButton>("Add");
|
2018-04-26 23:07:02 +02:00
|
|
|
QObject::connect(*add, &QPushButton::clicked, [model, view] {
|
|
|
|
model->appendRow({util::stringItem(""),
|
|
|
|
util::boolItem(model->item(model->rowCount() - 1, 1)
|
|
|
|
->data(Qt::CheckStateRole)
|
|
|
|
.toBool()),
|
|
|
|
util::boolItem(model->item(model->rowCount() - 1, 2)
|
|
|
|
->data(Qt::CheckStateRole)
|
|
|
|
.toBool()),
|
|
|
|
util::boolItem(false)});
|
|
|
|
view->scrollToBottom();
|
2018-04-26 20:58:32 +02:00
|
|
|
});
|
2018-04-25 14:49:30 +02:00
|
|
|
auto remove = buttons.emplace<QPushButton>("Remove");
|
|
|
|
QObject::connect(*remove, &QPushButton::clicked, [view, model] {
|
2018-04-26 23:07:02 +02:00
|
|
|
std::vector<int> indices;
|
|
|
|
|
|
|
|
for (const QModelIndex &index : view->selectionModel()->selectedRows(0)) {
|
|
|
|
indices.push_back(index.row());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(indices.begin(), indices.end());
|
|
|
|
|
|
|
|
for (int i = indices.size() - 1; i >= 0; i--) {
|
|
|
|
model->removeRow(indices[i]);
|
2018-04-25 14:49:30 +02:00
|
|
|
}
|
|
|
|
});
|
2018-01-13 02:00:02 +01:00
|
|
|
|
2018-04-25 14:49:30 +02:00
|
|
|
view->hideColumn(3);
|
2018-01-13 02:00:02 +01:00
|
|
|
}
|
|
|
|
// DISABLED USERS
|
|
|
|
auto disabledUsers = tabs.appendTab(new QVBoxLayout, "Disabled Users");
|
|
|
|
{
|
|
|
|
auto text = disabledUsers.emplace<QTextEdit>().getElement();
|
|
|
|
|
|
|
|
QObject::connect(text, &QTextEdit::textChanged, this,
|
|
|
|
[this] { this->disabledUsersChangedTimer.start(200); });
|
|
|
|
|
|
|
|
QObject::connect(
|
|
|
|
&this->disabledUsersChangedTimer, &QTimer::timeout, this, [text, &settings]() {
|
|
|
|
QStringList list = text->toPlainText().split("\n", QString::SkipEmptyParts);
|
|
|
|
list.removeDuplicates();
|
|
|
|
settings.highlightUserBlacklist = list.join("\n") + "\n";
|
|
|
|
});
|
|
|
|
|
|
|
|
settings.highlightUserBlacklist.connect([=](const QString &str, auto) {
|
|
|
|
text->setPlainText(str); //
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-04-26 23:07:02 +02:00
|
|
|
|
|
|
|
// MISC
|
|
|
|
auto customSound = layout.emplace<QHBoxLayout>().withoutMargin();
|
|
|
|
{
|
|
|
|
customSound.append(this->createCheckBox("Custom sound", settings.customHighlightSound));
|
|
|
|
auto selectFile = customSound.emplace<QPushButton>("Select custom sound file");
|
|
|
|
QObject::connect(selectFile.getElement(), &QPushButton::clicked, this,
|
|
|
|
[&settings, this] {
|
|
|
|
auto fileName = QFileDialog::getOpenFileName(
|
|
|
|
this, tr("Open Sound"), "", tr("Audio Files (*.mp3 *.wav)"));
|
|
|
|
settings.pathHighlightSound = fileName;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
layout.append(createCheckBox(ALWAYS_PLAY, settings.highlightAlwaysPlaySound));
|
2018-01-13 02:00:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---- misc
|
|
|
|
this->disabledUsersChangedTimer.setSingleShot(true);
|
|
|
|
}
|
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
} // namespace settingspages
|
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|