2018-01-12 23:09:05 +01:00
|
|
|
#include "highlightingpage.hpp"
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
#include "application.hpp"
|
2018-05-06 00:32:45 +02:00
|
|
|
#include "controllers/highlights/highlightcontroller.hpp"
|
|
|
|
#include "controllers/highlights/highlightmodel.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
#include "debug/log.hpp"
|
|
|
|
#include "singletons/settingsmanager.hpp"
|
|
|
|
#include "util/layoutcreator.hpp"
|
|
|
|
#include "util/standarditemhelper.hpp"
|
2018-05-06 00:32:45 +02:00
|
|
|
#include "widgets/helper/editablemodelview.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
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>
|
|
|
|
|
|
|
|
#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-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2018-01-13 02:00:02 +01:00
|
|
|
util::LayoutCreator<HighlightingPage> layoutCreator(this);
|
|
|
|
|
|
|
|
auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
|
|
|
|
{
|
|
|
|
// GENERAL
|
2018-04-28 13:48:49 +02:00
|
|
|
// layout.append(this->createCheckBox(ENABLE_HIGHLIGHTS, app->settings->enableHighlights));
|
2018-01-13 02:00:02 +01:00
|
|
|
|
|
|
|
// TABS
|
|
|
|
auto tabs = layout.emplace<QTabWidget>();
|
|
|
|
{
|
|
|
|
// HIGHLIGHTS
|
|
|
|
auto highlights = tabs.appendTab(new QVBoxLayout, "Highlights");
|
|
|
|
{
|
2018-05-06 00:32:45 +02:00
|
|
|
helper::EditableModelView *view = *highlights.emplace<helper::EditableModelView>(
|
|
|
|
app->highlights->createModel(nullptr));
|
2018-04-25 14:49:30 +02:00
|
|
|
|
2018-05-06 00:32:45 +02:00
|
|
|
view->getTableView()->hideColumn(3);
|
2018-04-26 23:07:02 +02:00
|
|
|
|
2018-05-06 00:32:45 +02:00
|
|
|
view->setTitles({"Pattern", "Flash taskbar", "Play sound", "Regex"});
|
|
|
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
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] {
|
2018-05-06 00:32:45 +02:00
|
|
|
view->getTableView()->resizeColumnsToContents();
|
|
|
|
view->getTableView()->setColumnWidth(0, 250);
|
2018-04-25 20:35:32 +02:00
|
|
|
});
|
2018-01-13 02:00:02 +01:00
|
|
|
|
2018-05-06 00:32:45 +02:00
|
|
|
view->addButtonPressed.connect([] {
|
|
|
|
getApp()->highlights->phrases.appendItem(
|
|
|
|
controllers::highlights::HighlightPhrase{"my phrase", true, false, false});
|
2018-04-26 20:58:32 +02:00
|
|
|
});
|
2018-01-13 02:00:02 +01:00
|
|
|
}
|
|
|
|
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(
|
2018-04-27 22:11:19 +02:00
|
|
|
&this->disabledUsersChangedTimer, &QTimer::timeout, this, [text, app]() {
|
2018-01-13 02:00:02 +01:00
|
|
|
QStringList list = text->toPlainText().split("\n", QString::SkipEmptyParts);
|
|
|
|
list.removeDuplicates();
|
2018-04-27 22:11:19 +02:00
|
|
|
app->settings->highlightUserBlacklist = list.join("\n") + "\n";
|
2018-01-13 02:00:02 +01:00
|
|
|
});
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
app->settings->highlightUserBlacklist.connect([=](const QString &str, auto) {
|
2018-01-13 02:00:02 +01:00
|
|
|
text->setPlainText(str); //
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-04-26 23:07:02 +02:00
|
|
|
|
|
|
|
// MISC
|
|
|
|
auto customSound = layout.emplace<QHBoxLayout>().withoutMargin();
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
customSound.append(
|
|
|
|
this->createCheckBox("Custom sound", app->settings->customHighlightSound));
|
2018-04-26 23:07:02 +02:00
|
|
|
auto selectFile = customSound.emplace<QPushButton>("Select custom sound file");
|
2018-04-27 22:11:19 +02:00
|
|
|
QObject::connect(selectFile.getElement(), &QPushButton::clicked, this, [this, app] {
|
|
|
|
auto fileName = QFileDialog::getOpenFileName(this, tr("Open Sound"), "",
|
|
|
|
tr("Audio Files (*.mp3 *.wav)"));
|
|
|
|
app->settings->pathHighlightSound = fileName;
|
|
|
|
});
|
2018-04-26 23:07:02 +02:00
|
|
|
}
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
layout.append(createCheckBox(ALWAYS_PLAY, app->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
|