2018-06-26 14:09:39 +02:00
|
|
|
#include "HighlightingPage.hpp"
|
2018-01-12 23:09:05 +01:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
2018-07-04 13:22:27 +02:00
|
|
|
#include "controllers/highlights/HighlightBlacklistModel.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "controllers/highlights/HighlightController.hpp"
|
|
|
|
#include "controllers/highlights/HighlightModel.hpp"
|
2018-07-05 15:58:20 +02:00
|
|
|
#include "controllers/highlights/UserHighlightModel.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "debug/Log.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/LayoutCreator.hpp"
|
|
|
|
#include "util/StandardItemHelper.hpp"
|
|
|
|
#include "widgets/helper/EditableModelView.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2018-01-13 02:00:02 +01:00
|
|
|
#include <QFileDialog>
|
2018-06-21 13:02:34 +02:00
|
|
|
#include <QHeaderView>
|
2018-01-13 02:00:02 +01:00
|
|
|
#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"
|
2019-08-26 14:07:21 +02:00
|
|
|
#define ALWAYS_PLAY "Play highlight sound even when Chatterino is focused"
|
2018-01-13 02:00:02 +01:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
namespace chatterino {
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
HighlightingPage::HighlightingPage()
|
2018-08-09 06:22:55 +02:00
|
|
|
: SettingsPage("Highlights", ":/settings/notifications.svg")
|
2018-01-12 23:09:05 +01:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2018-06-26 17:06:17 +02:00
|
|
|
LayoutCreator<HighlightingPage> layoutCreator(this);
|
2018-01-13 02:00:02 +01:00
|
|
|
|
|
|
|
auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
|
|
|
|
{
|
|
|
|
// GENERAL
|
2018-08-06 21:17:03 +02:00
|
|
|
// layout.append(this->createCheckBox(ENABLE_HIGHLIGHTS,
|
2018-08-12 12:56:28 +02:00
|
|
|
// getSettings()->enableHighlights));
|
2018-01-13 02:00:02 +01:00
|
|
|
|
|
|
|
// TABS
|
|
|
|
auto tabs = layout.emplace<QTabWidget>();
|
|
|
|
{
|
|
|
|
// HIGHLIGHTS
|
2019-08-26 14:36:06 +02:00
|
|
|
auto highlights = tabs.appendTab(new QVBoxLayout, "Messages");
|
2018-01-13 02:00:02 +01:00
|
|
|
{
|
2019-08-26 14:36:06 +02:00
|
|
|
highlights.emplace<QLabel>("Messages can be highlighted if "
|
|
|
|
"they match a certain pattern.");
|
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
EditableModelView *view =
|
2018-08-06 21:17:03 +02:00
|
|
|
highlights
|
|
|
|
.emplace<EditableModelView>(
|
|
|
|
app->highlights->createModel(nullptr))
|
2018-06-22 12:34:33 +02:00
|
|
|
.getElement();
|
2018-04-25 14:49:30 +02:00
|
|
|
|
2019-08-26 14:07:21 +02:00
|
|
|
view->addRegexHelpLink();
|
2018-08-06 21:17:03 +02:00
|
|
|
view->setTitles({"Pattern", "Flash\ntaskbar", "Play\nsound",
|
2019-09-07 18:56:21 +02:00
|
|
|
"Enable\nregex", "Case-\nsensitive"});
|
2018-08-06 21:17:03 +02:00
|
|
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
|
|
|
QHeaderView::Fixed);
|
2018-05-07 00:47:35 +02:00
|
|
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
|
|
|
0, QHeaderView::Stretch);
|
2018-04-25 14:49:30 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
// fourtf: make class extrend BaseWidget and add this to
|
|
|
|
// dpiChanged
|
2018-04-25 20:35:32 +02:00
|
|
|
QTimer::singleShot(1, [view] {
|
2018-05-06 00:32:45 +02:00
|
|
|
view->getTableView()->resizeColumnsToContents();
|
2018-05-06 12:52:47 +02:00
|
|
|
view->getTableView()->setColumnWidth(0, 200);
|
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([] {
|
2019-09-07 18:56:21 +02:00
|
|
|
getApp()->highlights->phrases.appendItem(HighlightPhrase{
|
|
|
|
"my phrase", true, false, false, false});
|
2018-04-26 20:58:32 +02:00
|
|
|
});
|
2018-01-13 02:00:02 +01:00
|
|
|
}
|
2018-07-04 13:22:27 +02:00
|
|
|
|
2018-07-05 16:22:25 +02:00
|
|
|
auto pingUsers = tabs.appendTab(new QVBoxLayout, "Users");
|
2018-01-13 02:00:02 +01:00
|
|
|
{
|
2019-08-26 14:36:06 +02:00
|
|
|
pingUsers.emplace<QLabel>(
|
|
|
|
"Messages from a certain user can be highlighted.");
|
2018-07-04 13:22:27 +02:00
|
|
|
EditableModelView *view =
|
2018-08-06 21:17:03 +02:00
|
|
|
pingUsers
|
|
|
|
.emplace<EditableModelView>(
|
|
|
|
app->highlights->createUserModel(nullptr))
|
2018-07-04 13:22:27 +02:00
|
|
|
.getElement();
|
2018-01-13 02:00:02 +01:00
|
|
|
|
2019-08-26 14:07:21 +02:00
|
|
|
view->addRegexHelpLink();
|
2019-09-07 18:56:21 +02:00
|
|
|
|
|
|
|
// Case-sensitivity doesn't make sense for user names so it is
|
|
|
|
// set to "false" by default & no checkbox is shown
|
2018-08-06 21:17:03 +02:00
|
|
|
view->setTitles({"Username", "Flash\ntaskbar", "Play\nsound",
|
|
|
|
"Enable\nregex"});
|
|
|
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
|
|
|
QHeaderView::Fixed);
|
2018-07-04 13:22:27 +02:00
|
|
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
|
|
|
0, QHeaderView::Stretch);
|
2018-01-13 02:00:02 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
// fourtf: make class extrend BaseWidget and add this to
|
|
|
|
// dpiChanged
|
2018-07-04 13:22:27 +02:00
|
|
|
QTimer::singleShot(1, [view] {
|
|
|
|
view->getTableView()->resizeColumnsToContents();
|
|
|
|
view->getTableView()->setColumnWidth(0, 200);
|
|
|
|
});
|
2018-01-13 02:00:02 +01:00
|
|
|
|
2018-07-04 13:22:27 +02:00
|
|
|
view->addButtonPressed.connect([] {
|
2018-07-05 16:22:25 +02:00
|
|
|
getApp()->highlights->highlightedUsers.appendItem(
|
2019-09-07 18:56:21 +02:00
|
|
|
HighlightPhrase{"highlighted user", true, false, false,
|
2018-08-06 21:17:03 +02:00
|
|
|
false});
|
2018-01-13 02:00:02 +01:00
|
|
|
});
|
|
|
|
}
|
2018-07-05 15:58:20 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
auto disabledUsers =
|
|
|
|
tabs.appendTab(new QVBoxLayout, "Excluded Users");
|
2018-07-05 15:58:20 +02:00
|
|
|
{
|
2019-08-26 14:36:06 +02:00
|
|
|
disabledUsers.emplace<QLabel>(
|
|
|
|
"This is a list of users (e.g. bots) whose messages should "
|
|
|
|
"<u>not</u> be highlighted.");
|
2018-07-05 15:58:20 +02:00
|
|
|
EditableModelView *view =
|
2018-07-05 16:22:25 +02:00
|
|
|
disabledUsers
|
2018-08-06 21:17:03 +02:00
|
|
|
.emplace<EditableModelView>(
|
|
|
|
app->highlights->createBlacklistModel(nullptr))
|
2018-07-05 15:58:20 +02:00
|
|
|
.getElement();
|
|
|
|
|
2019-08-26 14:07:21 +02:00
|
|
|
view->addRegexHelpLink();
|
2018-07-05 16:22:25 +02:00
|
|
|
view->setTitles({"Pattern", "Enable\nregex"});
|
2018-08-06 21:17:03 +02:00
|
|
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
|
|
|
QHeaderView::Fixed);
|
2018-07-05 15:58:20 +02:00
|
|
|
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
|
|
|
0, QHeaderView::Stretch);
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
// fourtf: make class extrend BaseWidget and add this to
|
|
|
|
// dpiChanged
|
2018-07-05 15:58:20 +02:00
|
|
|
QTimer::singleShot(1, [view] {
|
|
|
|
view->getTableView()->resizeColumnsToContents();
|
|
|
|
view->getTableView()->setColumnWidth(0, 200);
|
|
|
|
});
|
|
|
|
|
|
|
|
view->addButtonPressed.connect([] {
|
2018-07-05 16:22:25 +02:00
|
|
|
getApp()->highlights->blacklistedUsers.appendItem(
|
|
|
|
HighlightBlacklistUser{"blacklisted user", false});
|
2018-07-05 15:58:20 +02:00
|
|
|
});
|
|
|
|
}
|
2018-01-13 02:00:02 +01:00
|
|
|
}
|
2018-04-26 23:07:02 +02:00
|
|
|
|
|
|
|
// MISC
|
|
|
|
auto customSound = layout.emplace<QHBoxLayout>().withoutMargin();
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
customSound.append(this->createCheckBox(
|
2018-08-12 12:56:28 +02:00
|
|
|
"Custom sound", getSettings()->customHighlightSound));
|
2018-08-06 21:17:03 +02:00
|
|
|
auto selectFile =
|
|
|
|
customSound.emplace<QPushButton>("Select custom sound file");
|
|
|
|
QObject::connect(selectFile.getElement(), &QPushButton::clicked,
|
2018-09-30 19:15:17 +02:00
|
|
|
this, [this] {
|
2018-08-06 21:17:03 +02:00
|
|
|
auto fileName = QFileDialog::getOpenFileName(
|
|
|
|
this, tr("Open Sound"), "",
|
|
|
|
tr("Audio Files (*.mp3 *.wav)"));
|
2018-08-12 12:56:28 +02:00
|
|
|
getSettings()->pathHighlightSound = fileName;
|
2018-08-06 21:17:03 +02:00
|
|
|
});
|
2018-04-26 23:07:02 +02:00
|
|
|
}
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
layout.append(createCheckBox(ALWAYS_PLAY,
|
2018-08-12 12:56:28 +02:00
|
|
|
getSettings()->highlightAlwaysPlaySound));
|
2018-10-06 17:51:13 +02:00
|
|
|
layout.append(createCheckBox(
|
|
|
|
"Flash taskbar only stops highlighting when chatterino is focused",
|
|
|
|
getSettings()->longAlerts));
|
2018-01-13 02:00:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---- misc
|
2018-07-06 19:23:47 +02:00
|
|
|
this->disabledUsersChangedTimer_.setSingleShot(true);
|
2018-01-13 02:00:02 +01:00
|
|
|
}
|
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
} // namespace chatterino
|