Clear up Highlight sound settings (#4194)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com> Closes https://github.com/Chatterino/chatterino2/issues/1540
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "controllers/highlights/UserHighlightModel.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "util/Helpers.hpp"
|
||||
#include "util/LayoutCreator.hpp"
|
||||
#include "util/StandardItemHelper.hpp"
|
||||
#include "widgets/dialogs/BadgePickerDialog.hpp"
|
||||
@@ -14,17 +15,11 @@
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QHeaderView>
|
||||
#include <QListWidget>
|
||||
#include <QPushButton>
|
||||
#include <QStandardItemModel>
|
||||
#include <QTableView>
|
||||
#include <QTabWidget>
|
||||
#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 "Play highlight sound even when Chatterino is focused"
|
||||
|
||||
namespace chatterino {
|
||||
@@ -76,8 +71,8 @@ HighlightingPage::HighlightingPage()
|
||||
.getElement();
|
||||
view->addRegexHelpLink();
|
||||
view->setTitles({"Pattern", "Show in\nMentions",
|
||||
"Flash\ntaskbar", "Play\nsound",
|
||||
"Enable\nregex", "Case-\nsensitive",
|
||||
"Flash\ntaskbar", "Enable\nregex",
|
||||
"Case-\nsensitive", "Play\nsound",
|
||||
"Custom\nsound", "Color"});
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||
QHeaderView::Fixed);
|
||||
@@ -88,7 +83,7 @@ HighlightingPage::HighlightingPage()
|
||||
// dpiChanged
|
||||
QTimer::singleShot(1, [view] {
|
||||
view->getTableView()->resizeColumnsToContents();
|
||||
view->getTableView()->setColumnWidth(0, 200);
|
||||
view->getTableView()->setColumnWidth(0, 400);
|
||||
});
|
||||
|
||||
view->addButtonPressed.connect([] {
|
||||
@@ -127,8 +122,8 @@ HighlightingPage::HighlightingPage()
|
||||
// Case-sensitivity doesn't make sense for user names so it is
|
||||
// set to "false" by default & the column is hidden
|
||||
view->setTitles({"Username", "Show in\nMentions",
|
||||
"Flash\ntaskbar", "Play\nsound",
|
||||
"Enable\nregex", "Case-\nsensitive",
|
||||
"Flash\ntaskbar", "Enable\nregex",
|
||||
"Case-\nsensitive", "Play\nsound",
|
||||
"Custom\nsound", "Color"});
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||
QHeaderView::Fixed);
|
||||
@@ -247,33 +242,57 @@ HighlightingPage::HighlightingPage()
|
||||
// MISC
|
||||
auto customSound = layout.emplace<QHBoxLayout>().withoutMargin();
|
||||
{
|
||||
auto fallbackSound = customSound.append(this->createCheckBox(
|
||||
"Fallback sound (played when no other sound is set)",
|
||||
getSettings()->customHighlightSound));
|
||||
auto label = customSound.append(this->createLabel<QString>(
|
||||
[](const auto &value) {
|
||||
if (value.isEmpty())
|
||||
{
|
||||
return QString("Default sound: Chatterino Ping");
|
||||
}
|
||||
|
||||
auto getSelectFileText = [] {
|
||||
const QString value = getSettings()->pathHighlightSound;
|
||||
return value.isEmpty() ? "Select custom fallback sound"
|
||||
: QUrl::fromLocalFile(value).fileName();
|
||||
};
|
||||
auto url = QUrl::fromLocalFile(value);
|
||||
return QString("Default sound: <a href=\"%1\"><span "
|
||||
"style=\"color: white\">%2</span></a>")
|
||||
.arg(url.toString(QUrl::FullyEncoded),
|
||||
shortenString(url.fileName(), 50));
|
||||
},
|
||||
getSettings()->pathHighlightSound));
|
||||
label->setToolTip(
|
||||
"This sound will play for all highlight phrases that have "
|
||||
"sound enabled and don't have a custom sound set.");
|
||||
label->setTextFormat(Qt::RichText);
|
||||
label->setTextInteractionFlags(Qt::TextBrowserInteraction |
|
||||
Qt::LinksAccessibleByKeyboard);
|
||||
label->setOpenExternalLinks(true);
|
||||
customSound->setStretchFactor(label.getElement(), 1);
|
||||
|
||||
auto selectFile =
|
||||
customSound.emplace<QPushButton>(getSelectFileText());
|
||||
auto clearSound = customSound.emplace<QPushButton>("Clear");
|
||||
auto selectFile = customSound.emplace<QPushButton>("Change...");
|
||||
|
||||
QObject::connect(
|
||||
selectFile.getElement(), &QPushButton::clicked, this,
|
||||
[=]() mutable {
|
||||
auto fileName = QFileDialog::getOpenFileName(
|
||||
this, tr("Open Sound"), "",
|
||||
tr("Audio Files (*.mp3 *.wav)"));
|
||||
QObject::connect(selectFile.getElement(), &QPushButton::clicked,
|
||||
this, [=]() mutable {
|
||||
auto fileName = QFileDialog::getOpenFileName(
|
||||
this, tr("Open Sound"), "",
|
||||
tr("Audio Files (*.mp3 *.wav)"));
|
||||
|
||||
getSettings()->pathHighlightSound = fileName;
|
||||
selectFile.getElement()->setText(getSelectFileText());
|
||||
getSettings()->pathHighlightSound = fileName;
|
||||
});
|
||||
QObject::connect(clearSound.getElement(), &QPushButton::clicked,
|
||||
this, [=]() mutable {
|
||||
getSettings()->pathHighlightSound = QString();
|
||||
});
|
||||
|
||||
// Set check box according to updated value
|
||||
fallbackSound->setCheckState(
|
||||
fileName.isEmpty() ? Qt::Unchecked : Qt::Checked);
|
||||
});
|
||||
getSettings()->pathHighlightSound.connect(
|
||||
[clearSound = clearSound.getElement()](const auto &value) {
|
||||
if (value.isEmpty())
|
||||
{
|
||||
clearSound->hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
clearSound->show();
|
||||
}
|
||||
},
|
||||
this->managedConnections_);
|
||||
}
|
||||
|
||||
layout.append(createCheckBox(ALWAYS_PLAY,
|
||||
@@ -294,13 +313,6 @@ void HighlightingPage::openSoundDialog(const QModelIndex &clicked,
|
||||
tr("Audio Files (*.mp3 *.wav)"));
|
||||
view->getModel()->setData(clicked, fileUrl, Qt::UserRole);
|
||||
view->getModel()->setData(clicked, fileUrl.fileName(), Qt::DisplayRole);
|
||||
|
||||
// Enable custom sound check box if user set a sound
|
||||
if (!fileUrl.isEmpty())
|
||||
{
|
||||
QModelIndex checkBox = clicked.siblingAtColumn(soundColumn);
|
||||
view->getModel()->setData(checkBox, Qt::Checked, Qt::CheckStateRole);
|
||||
}
|
||||
}
|
||||
|
||||
void HighlightingPage::openColorDialog(const QModelIndex &clicked,
|
||||
@@ -356,7 +368,8 @@ void HighlightingPage::tableCellClicked(const QModelIndex &clicked,
|
||||
(tab == HighlightTab::Messages &&
|
||||
clicked.row() ==
|
||||
HighlightModel::HighlightRowIndexes::WhisperRow);
|
||||
if (clicked.column() == Column::SoundPath)
|
||||
if (clicked.column() == Column::SoundPath &&
|
||||
clicked.flags().testFlag(Qt::ItemIsEnabled))
|
||||
{
|
||||
this->openSoundDialog(clicked, view, Column::SoundPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user