mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
added highlights page again
This commit is contained in:
parent
d16bbf6899
commit
2073447df7
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QTabWidget>
|
||||
#include <QWidget>
|
||||
|
||||
#include <cassert>
|
||||
|
@ -62,6 +63,20 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
template <typename Q = T, typename T2,
|
||||
typename std::enable_if<std::is_same<QTabWidget, Q>::value, int>::type = 0>
|
||||
LayoutCreator<T2> appendTab(T2 *item, const QString &title)
|
||||
{
|
||||
static_assert(std::is_base_of<QLayout, T2>::value, "needs to be QLayout");
|
||||
|
||||
QWidget *widget = new QWidget;
|
||||
widget->setLayout(item);
|
||||
|
||||
this->item->addTab(widget, title);
|
||||
|
||||
return LayoutCreator<T2>(item);
|
||||
}
|
||||
|
||||
private:
|
||||
T *item;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ void SettingsDialogTab::paintEvent(QPaintEvent *)
|
|||
int a = (this->height() - 20) / 2;
|
||||
QPixmap pixmap = this->ui.icon.pixmap(QSize(20, 20));
|
||||
|
||||
painter.drawPixmap(0, a, pixmap);
|
||||
painter.drawPixmap(0, a + a, pixmap);
|
||||
|
||||
a = a + a + 20;
|
||||
|
||||
|
|
|
@ -42,9 +42,9 @@ void SettingsDialog::initUi()
|
|||
.assign(&this->ui.tabContainer);
|
||||
|
||||
// right side layout
|
||||
auto right = layoutCreator.emplace<QVBoxLayout>();
|
||||
auto right = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
|
||||
{
|
||||
right.emplace<QStackedLayout>().assign(&this->ui.pageStack).emplace<QPushButton>("NaM");
|
||||
right.emplace<QStackedLayout>().assign(&this->ui.pageStack).withoutMargin();
|
||||
|
||||
auto buttons = right.emplace<QDialogButtonBox>(Qt::Horizontal);
|
||||
{
|
||||
|
@ -79,7 +79,7 @@ void SettingsDialog::addTabs()
|
|||
this->addTab(new settingspages::BehaviourPage);
|
||||
this->addTab(new settingspages::CommandPage);
|
||||
this->addTab(new settingspages::EmotesPage);
|
||||
// this->addTab(new settingspages::HighlightingPage);
|
||||
this->addTab(new settingspages::HighlightingPage);
|
||||
// this->addTab(new settingspages::LogsPage);
|
||||
// this->addTab(new settingspages::ModerationPage);
|
||||
this->ui.tabContainer->addStretch(1);
|
||||
|
|
|
@ -16,7 +16,7 @@ AboutPage::AboutPage()
|
|||
{
|
||||
util::LayoutCreator<AboutPage> layoutCreator(this);
|
||||
|
||||
auto layout = layoutCreator.emplace<QVBoxLayout>();
|
||||
auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
|
||||
{
|
||||
QPixmap pixmap;
|
||||
pixmap.load(":/images/aboutlogo.png");
|
||||
|
|
|
@ -1,11 +1,243 @@
|
|||
#include "highlightingpage.hpp"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QListWidget>
|
||||
#include <QPushButton>
|
||||
#include <QTabWidget>
|
||||
#include <QTextEdit>
|
||||
|
||||
#include "debug/log.hpp"
|
||||
#include "singletons/settingsmanager.hpp"
|
||||
#include "util/layoutcreator.hpp"
|
||||
|
||||
#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)"
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
namespace settingspages {
|
||||
HighlightingPage::HighlightingPage()
|
||||
: SettingsPage("Highlights", ":/images/VSO_Link_blue_16x.png")
|
||||
{
|
||||
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));
|
||||
layout.append(this->createCheckBox(HIGHLIGHT_MSG, settings.enableHighlightsSelf));
|
||||
layout.append(this->createCheckBox(PLAY_SOUND, settings.enableHighlightSound));
|
||||
layout.append(this->createCheckBox(FLASH_TASKBAR, settings.enableHighlightTaskbar));
|
||||
|
||||
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));
|
||||
|
||||
// TABS
|
||||
auto tabs = layout.emplace<QTabWidget>();
|
||||
{
|
||||
// HIGHLIGHTS
|
||||
auto highlights = tabs.appendTab(new QVBoxLayout, "Highlights");
|
||||
{
|
||||
highlights.emplace<QListWidget>().assign(&this->highlightList);
|
||||
|
||||
auto buttons = highlights.emplace<QHBoxLayout>();
|
||||
|
||||
buttons.emplace<QPushButton>("Add").assign(&this->highlightAdd);
|
||||
buttons.emplace<QPushButton>("Edit").assign(&this->highlightEdit);
|
||||
buttons.emplace<QPushButton>("Remove").assign(&this->highlightRemove);
|
||||
|
||||
this->addHighlightTabSignals();
|
||||
}
|
||||
// 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); //
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- misc
|
||||
this->disabledUsersChangedTimer.setSingleShot(true);
|
||||
}
|
||||
|
||||
//
|
||||
// DISCLAIMER:
|
||||
//
|
||||
// If you are trying to learn from reading the chatterino code please ignore this segment.
|
||||
//
|
||||
void HighlightingPage::addHighlightTabSignals()
|
||||
{
|
||||
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
||||
|
||||
auto addBtn = this->highlightAdd;
|
||||
auto editBtn = this->highlightEdit;
|
||||
auto delBtn = this->highlightRemove;
|
||||
auto highlights = this->highlightList;
|
||||
|
||||
// Open "Add new highlight" dialog
|
||||
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 sound = new QCheckBox("Play sound");
|
||||
auto task = new QCheckBox("Flash taskbar");
|
||||
|
||||
// Save highlight
|
||||
QObject::connect(add, &QPushButton::clicked, this, [=, &settings] {
|
||||
if (edit->text().length()) {
|
||||
QString highlightKey = edit->text();
|
||||
highlights->addItem(highlightKey);
|
||||
|
||||
auto properties = settings.highlightProperties.getValue();
|
||||
|
||||
messages::HighlightPhrase newHighlightProperty;
|
||||
newHighlightProperty.key = highlightKey;
|
||||
newHighlightProperty.sound = sound->isChecked();
|
||||
newHighlightProperty.alert = task->isChecked();
|
||||
|
||||
properties.push_back(newHighlightProperty);
|
||||
|
||||
settings.highlightProperties = properties;
|
||||
|
||||
show->close();
|
||||
}
|
||||
});
|
||||
box->addWidget(edit);
|
||||
box->addWidget(add);
|
||||
box->addWidget(sound);
|
||||
box->addWidget(task);
|
||||
show->setLayout(box);
|
||||
show->show();
|
||||
});
|
||||
|
||||
// Open "Edit selected highlight" dialog
|
||||
QObject::connect(editBtn, &QPushButton::clicked, this, [highlights, this, &settings] {
|
||||
if (highlights->selectedItems().isEmpty()) {
|
||||
// No item selected
|
||||
return;
|
||||
}
|
||||
|
||||
QListWidgetItem *selectedHighlight = highlights->selectedItems().first();
|
||||
QString highlightKey = selectedHighlight->text();
|
||||
auto properties = settings.highlightProperties.getValue();
|
||||
auto highlightIt = std::find_if(properties.begin(), properties.end(),
|
||||
[highlightKey](const auto &highlight) {
|
||||
return highlight.key == highlightKey; //
|
||||
});
|
||||
|
||||
if (highlightIt == properties.end()) {
|
||||
debug::Log("Unable to find highlight key {} in highlight properties. "
|
||||
"This is weird",
|
||||
highlightKey);
|
||||
return;
|
||||
}
|
||||
|
||||
messages::HighlightPhrase &selectedSetting = *highlightIt;
|
||||
auto show = new QWidget();
|
||||
auto box = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
|
||||
auto edit = new QLineEdit(highlightKey);
|
||||
auto apply = new QPushButton("Apply");
|
||||
|
||||
auto sound = new QCheckBox("Play sound");
|
||||
sound->setChecked(selectedSetting.sound);
|
||||
auto task = new QCheckBox("Flash taskbar");
|
||||
task->setChecked(selectedSetting.alert);
|
||||
|
||||
// Apply edited changes
|
||||
QObject::connect(apply, &QPushButton::clicked, this, [=, &settings] {
|
||||
QString newHighlightKey = edit->text();
|
||||
|
||||
if (newHighlightKey.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto properties = settings.highlightProperties.getValue();
|
||||
auto highlightIt =
|
||||
std::find_if(properties.begin(), properties.end(), [=](const auto &highlight) {
|
||||
return highlight.key == highlightKey; //
|
||||
});
|
||||
|
||||
if (highlightIt == properties.end()) {
|
||||
debug::Log("Unable to find highlight key {} in highlight properties. "
|
||||
"This is weird",
|
||||
highlightKey);
|
||||
return;
|
||||
}
|
||||
auto &highlightProperty = *highlightIt;
|
||||
highlightProperty.key = newHighlightKey;
|
||||
highlightProperty.sound = sound->isCheckable();
|
||||
highlightProperty.alert = task->isCheckable();
|
||||
|
||||
settings.highlightProperties = properties;
|
||||
|
||||
selectedHighlight->setText(newHighlightKey);
|
||||
selectedHighlight->setText(newHighlightKey);
|
||||
|
||||
show->close();
|
||||
});
|
||||
|
||||
box->addWidget(edit);
|
||||
box->addWidget(apply);
|
||||
box->addWidget(sound);
|
||||
box->addWidget(task);
|
||||
show->setLayout(box);
|
||||
show->show();
|
||||
});
|
||||
|
||||
// Delete selected highlight
|
||||
QObject::connect(delBtn, &QPushButton::clicked, this, [highlights, &settings] {
|
||||
if (highlights->selectedItems().isEmpty()) {
|
||||
// No highlight selected
|
||||
return;
|
||||
}
|
||||
|
||||
QListWidgetItem *selectedHighlight = highlights->selectedItems().first();
|
||||
QString highlightKey = selectedHighlight->text();
|
||||
|
||||
auto properties = settings.highlightProperties.getValue();
|
||||
properties.erase(std::remove_if(properties.begin(), properties.end(),
|
||||
[highlightKey](const auto &highlight) {
|
||||
return highlight.key == highlightKey; //
|
||||
}),
|
||||
properties.end());
|
||||
|
||||
settings.highlightProperties = properties;
|
||||
|
||||
delete selectedHighlight;
|
||||
});
|
||||
}
|
||||
} // namespace settingspages
|
||||
} // namespace widgets
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#include "widgets/settingspages/settingspage.hpp"
|
||||
|
||||
class QPushButton;
|
||||
class QListWidget;
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
namespace settingspages {
|
||||
|
@ -10,6 +15,16 @@ class HighlightingPage : public SettingsPage
|
|||
{
|
||||
public:
|
||||
HighlightingPage();
|
||||
|
||||
private:
|
||||
QListWidget *highlightList;
|
||||
QPushButton *highlightAdd;
|
||||
QPushButton *highlightEdit;
|
||||
QPushButton *highlightRemove;
|
||||
|
||||
QTimer disabledUsersChangedTimer;
|
||||
|
||||
void addHighlightTabSignals();
|
||||
};
|
||||
|
||||
} // namespace settingspages
|
||||
|
|
Loading…
Reference in a new issue