experiment with making a highlight configure dialog

This commit is contained in:
Rasmus Karlsson 2024-03-17 14:27:23 +01:00
parent 46c5609736
commit 94f218cc26
8 changed files with 301 additions and 58 deletions

View file

@ -568,6 +568,9 @@ set(SOURCE_FILES
widgets/dialogs/EditHotkeyDialog.hpp
widgets/dialogs/EmotePopup.cpp
widgets/dialogs/EmotePopup.hpp
widgets/dialogs/HighlightConfigureDialog.cpp
widgets/dialogs/HighlightConfigureDialog.hpp
widgets/dialogs/HighlightConfigureDialog.ui
widgets/dialogs/IrcConnectionEditor.cpp
widgets/dialogs/IrcConnectionEditor.hpp
widgets/dialogs/IrcConnectionEditor.ui

View file

@ -77,7 +77,8 @@ void HighlightModel::afterInit()
auto selfColor = ColorProvider::instance().color(ColorType::SelfHighlight);
setColorItem(usernameRow[Column::Color], *selfColor, false);
this->insertCustomRow(usernameRow, HighlightRowIndexes::SelfHighlightRow);
this->insertCustomRow(
usernameRow, static_cast<int>(HighlightRowIndexes::SelfHighlightRow));
// Highlight settings for whispers
std::vector<QStandardItem *> whisperRow = this->createRow();
@ -101,7 +102,8 @@ void HighlightModel::afterInit()
auto whisperColor = ColorProvider::instance().color(ColorType::Whisper);
setColorItem(whisperRow[Column::Color], *whisperColor, false);
this->insertCustomRow(whisperRow, HighlightRowIndexes::WhisperRow);
this->insertCustomRow(whisperRow,
static_cast<int>(HighlightRowIndexes::WhisperRow));
// Highlight settings for subscription messages
std::vector<QStandardItem *> subRow = this->createRow();
@ -123,7 +125,8 @@ void HighlightModel::afterInit()
auto subColor = ColorProvider::instance().color(ColorType::Subscription);
setColorItem(subRow[Column::Color], *subColor, false);
this->insertCustomRow(subRow, HighlightRowIndexes::SubRow);
this->insertCustomRow(subRow,
static_cast<int>(HighlightRowIndexes::SubRow));
// Highlight settings for redeemed highlight messages
std::vector<QStandardItem *> redeemedRow = this->createRow();
@ -148,7 +151,8 @@ void HighlightModel::afterInit()
ColorProvider::instance().color(ColorType::RedeemedHighlight);
setColorItem(redeemedRow[Column::Color], *RedeemedColor, false);
this->insertCustomRow(redeemedRow, HighlightRowIndexes::RedeemedRow);
this->insertCustomRow(redeemedRow,
static_cast<int>(HighlightRowIndexes::RedeemedRow));
// Highlight settings for first messages
std::vector<QStandardItem *> firstMessageRow = this->createRow();
@ -174,8 +178,9 @@ void HighlightModel::afterInit()
ColorProvider::instance().color(ColorType::FirstMessageHighlight);
setColorItem(firstMessageRow[Column::Color], *FirstMessageColor, false);
this->insertCustomRow(firstMessageRow,
HighlightRowIndexes::FirstMessageRow);
this->insertCustomRow(
firstMessageRow,
static_cast<int>(HighlightRowIndexes::FirstMessageRow));
// Highlight settings for hype chats
std::vector<QStandardItem *> elevatedMessageRow = this->createRow();
@ -201,8 +206,9 @@ void HighlightModel::afterInit()
setColorItem(elevatedMessageRow[Column::Color], *elevatedMessageColor,
false);
this->insertCustomRow(elevatedMessageRow,
HighlightRowIndexes::ElevatedMessageRow);
this->insertCustomRow(
elevatedMessageRow,
static_cast<int>(HighlightRowIndexes::ElevatedMessageRow));
// Highlight settings for reply threads
std::vector<QStandardItem *> threadMessageRow = this->createRow();
@ -231,8 +237,9 @@ void HighlightModel::afterInit()
ColorProvider::instance().color(ColorType::ThreadMessageHighlight);
setColorItem(threadMessageRow[Column::Color], *threadMessageColor, false);
this->insertCustomRow(threadMessageRow,
HighlightRowIndexes::ThreadMessageRow);
this->insertCustomRow(
threadMessageRow,
static_cast<int>(HighlightRowIndexes::ThreadMessageRow));
// Highlight settings for automod caught messages
const std::vector<QStandardItem *> automodRow = this->createRow();
@ -258,52 +265,55 @@ void HighlightModel::afterInit()
ColorProvider::instance().color(ColorType::AutomodHighlight);
setColorItem(automodRow[Column::Color], *automodColor, false);
this->insertCustomRow(automodRow, HighlightRowIndexes::AutomodRow);
this->insertCustomRow(automodRow,
static_cast<int>(HighlightRowIndexes::AutomodRow));
}
void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
int column, const QVariant &value,
int role, int rowIndex)
{
switch (column)
auto rowIndex2 = static_cast<HighlightRowIndexes>(rowIndex);
auto column2 = static_cast<Column>(column);
switch (column2)
{
case Column::Pattern: {
if (role == Qt::CheckStateRole)
{
if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
if (rowIndex2 == HighlightRowIndexes::SelfHighlightRow)
{
getSettings()->enableSelfHighlight.setValue(value.toBool());
}
else if (rowIndex == HighlightRowIndexes::WhisperRow)
else if (rowIndex2 == HighlightRowIndexes::WhisperRow)
{
getSettings()->enableWhisperHighlight.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::SubRow)
else if (rowIndex2 == HighlightRowIndexes::SubRow)
{
getSettings()->enableSubHighlight.setValue(value.toBool());
}
else if (rowIndex == HighlightRowIndexes::RedeemedRow)
else if (rowIndex2 == HighlightRowIndexes::RedeemedRow)
{
getSettings()->enableRedeemedHighlight.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::FirstMessageRow)
else if (rowIndex2 == HighlightRowIndexes::FirstMessageRow)
{
getSettings()->enableFirstMessageHighlight.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::ElevatedMessageRow)
else if (rowIndex2 == HighlightRowIndexes::ElevatedMessageRow)
{
getSettings()->enableElevatedMessageHighlight.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::ThreadMessageRow)
else if (rowIndex2 == HighlightRowIndexes::ThreadMessageRow)
{
getSettings()->enableThreadHighlight.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::AutomodRow)
else if (rowIndex2 == HighlightRowIndexes::AutomodRow)
{
getSettings()->enableAutomodHighlight.setValue(
value.toBool());
@ -314,17 +324,17 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
case Column::ShowInMentions: {
if (role == Qt::CheckStateRole)
{
if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
if (rowIndex2 == HighlightRowIndexes::SelfHighlightRow)
{
getSettings()->showSelfHighlightInMentions.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::ThreadMessageRow)
else if (rowIndex2 == HighlightRowIndexes::ThreadMessageRow)
{
getSettings()->showThreadHighlightInMentions.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::AutomodRow)
else if (rowIndex2 == HighlightRowIndexes::AutomodRow)
{
getSettings()->showAutomodInMentions.setValue(
value.toBool());
@ -335,43 +345,43 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
case Column::FlashTaskbar: {
if (role == Qt::CheckStateRole)
{
if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
if (rowIndex2 == HighlightRowIndexes::SelfHighlightRow)
{
getSettings()->enableSelfHighlightTaskbar.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::WhisperRow)
else if (rowIndex2 == HighlightRowIndexes::WhisperRow)
{
getSettings()->enableWhisperHighlightTaskbar.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::SubRow)
else if (rowIndex2 == HighlightRowIndexes::SubRow)
{
getSettings()->enableSubHighlightTaskbar.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::RedeemedRow)
else if (rowIndex2 == HighlightRowIndexes::RedeemedRow)
{
// getSettings()->enableRedeemedHighlightTaskbar.setValue(
// value.toBool());
}
else if (rowIndex == HighlightRowIndexes::FirstMessageRow)
else if (rowIndex2 == HighlightRowIndexes::FirstMessageRow)
{
// getSettings()->enableFirstMessageHighlightTaskbar.setValue(
// value.toBool());
}
else if (rowIndex == HighlightRowIndexes::ElevatedMessageRow)
else if (rowIndex2 == HighlightRowIndexes::ElevatedMessageRow)
{
// getSettings()
// ->enableElevatedMessageHighlightTaskbar.setvalue(
// value.toBool());
}
else if (rowIndex == HighlightRowIndexes::ThreadMessageRow)
else if (rowIndex2 == HighlightRowIndexes::ThreadMessageRow)
{
getSettings()->enableThreadHighlightTaskbar.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::AutomodRow)
else if (rowIndex2 == HighlightRowIndexes::AutomodRow)
{
getSettings()->enableAutomodHighlightTaskbar.setValue(
value.toBool());
@ -382,42 +392,42 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
case Column::PlaySound: {
if (role == Qt::CheckStateRole)
{
if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
if (rowIndex2 == HighlightRowIndexes::SelfHighlightRow)
{
getSettings()->enableSelfHighlightSound.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::WhisperRow)
else if (rowIndex2 == HighlightRowIndexes::WhisperRow)
{
getSettings()->enableWhisperHighlightSound.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::SubRow)
else if (rowIndex2 == HighlightRowIndexes::SubRow)
{
getSettings()->enableSubHighlightSound.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::RedeemedRow)
else if (rowIndex2 == HighlightRowIndexes::RedeemedRow)
{
// getSettings()->enableRedeemedHighlightSound.setValue(
// value.toBool());
}
else if (rowIndex == HighlightRowIndexes::FirstMessageRow)
else if (rowIndex2 == HighlightRowIndexes::FirstMessageRow)
{
// getSettings()->enableFirstMessageHighlightSound.setValue(
// value.toBool());
}
else if (rowIndex == HighlightRowIndexes::ElevatedMessageRow)
else if (rowIndex2 == HighlightRowIndexes::ElevatedMessageRow)
{
// getSettings()->enableElevatedMessageHighlightSound.setValue(
// value.toBool());
}
else if (rowIndex == HighlightRowIndexes::ThreadMessageRow)
else if (rowIndex2 == HighlightRowIndexes::ThreadMessageRow)
{
getSettings()->enableThreadHighlightSound.setValue(
value.toBool());
}
else if (rowIndex == HighlightRowIndexes::AutomodRow)
else if (rowIndex2 == HighlightRowIndexes::AutomodRow)
{
getSettings()->enableAutomodHighlightSound.setValue(
value.toBool());
@ -437,27 +447,27 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
// Custom sound file
if (role == Qt::UserRole)
{
if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
if (rowIndex2 == HighlightRowIndexes::SelfHighlightRow)
{
getSettings()->selfHighlightSoundUrl.setValue(
value.toString());
}
else if (rowIndex == HighlightRowIndexes::WhisperRow)
else if (rowIndex2 == HighlightRowIndexes::WhisperRow)
{
getSettings()->whisperHighlightSoundUrl.setValue(
value.toString());
}
else if (rowIndex == HighlightRowIndexes::SubRow)
else if (rowIndex2 == HighlightRowIndexes::SubRow)
{
getSettings()->subHighlightSoundUrl.setValue(
value.toString());
}
else if (rowIndex == HighlightRowIndexes::ThreadMessageRow)
else if (rowIndex2 == HighlightRowIndexes::ThreadMessageRow)
{
getSettings()->threadHighlightSoundUrl.setValue(
value.toString());
}
else if (rowIndex == HighlightRowIndexes::AutomodRow)
else if (rowIndex2 == HighlightRowIndexes::AutomodRow)
{
getSettings()->automodHighlightSoundUrl.setValue(
value.toString());
@ -474,42 +484,42 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
setting.setValue(color.name(QColor::HexArgb));
};
if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
if (rowIndex2 == HighlightRowIndexes::SelfHighlightRow)
{
setColor(getSettings()->selfHighlightColor,
ColorType::SelfHighlight);
}
else if (rowIndex == HighlightRowIndexes::WhisperRow)
else if (rowIndex2 == HighlightRowIndexes::WhisperRow)
{
setColor(getSettings()->whisperHighlightColor,
ColorType::Whisper);
}
else if (rowIndex == HighlightRowIndexes::SubRow)
else if (rowIndex2 == HighlightRowIndexes::SubRow)
{
setColor(getSettings()->subHighlightColor,
ColorType::Subscription);
}
else if (rowIndex == HighlightRowIndexes::RedeemedRow)
else if (rowIndex2 == HighlightRowIndexes::RedeemedRow)
{
setColor(getSettings()->redeemedHighlightColor,
ColorType::RedeemedHighlight);
}
else if (rowIndex == HighlightRowIndexes::FirstMessageRow)
else if (rowIndex2 == HighlightRowIndexes::FirstMessageRow)
{
setColor(getSettings()->firstMessageHighlightColor,
ColorType::FirstMessageHighlight);
}
else if (rowIndex == HighlightRowIndexes::ElevatedMessageRow)
else if (rowIndex2 == HighlightRowIndexes::ElevatedMessageRow)
{
setColor(getSettings()->elevatedMessageHighlightColor,
ColorType::ElevatedMessageHighlight);
}
else if (rowIndex == HighlightRowIndexes::ThreadMessageRow)
else if (rowIndex2 == HighlightRowIndexes::ThreadMessageRow)
{
setColor(getSettings()->threadHighlightColor,
ColorType::ThreadMessageHighlight);
}
else if (rowIndex == HighlightRowIndexes::AutomodRow)
else if (rowIndex2 == HighlightRowIndexes::AutomodRow)
{
setColor(getSettings()->automodHighlightColor,
ColorType::AutomodHighlight);

View file

@ -23,10 +23,11 @@ public:
PlaySound = 5,
SoundPath = 6,
Color = 7,
Configure = 8,
COUNT // keep this as last member of enum
};
enum HighlightRowIndexes {
enum class HighlightRowIndexes {
SelfHighlightRow = 0,
WhisperRow = 1,
SubRow = 2,
@ -35,6 +36,7 @@ public:
ElevatedMessageRow = 5,
ThreadMessageRow = 6,
AutomodRow = 7,
COUNT,
};
enum UserHighlightRowIndexes {

View file

@ -0,0 +1,23 @@
#include "widgets/dialogs/HighlightConfigureDialog.hpp"
#include "widgets/dialogs/ui_HighlightConfigureDialog.h"
namespace chatterino {
HighlightConfigureDialog::HighlightConfigureDialog(HighlightPhrase phrase,
QWidget *parent)
: QDialog(parent, Qt::WindowStaysOnTopHint)
, ui_(new Ui::HighlightConfigureDialog)
{
this->ui_->setupUi(this);
this->ui_->patternLineEdit->setText(phrase.getPattern());
}
HighlightConfigureDialog::~HighlightConfigureDialog()
{
delete ui_;
}
} // namespace chatterino

View file

@ -0,0 +1,35 @@
#pragma once
#include "controllers/highlights/HighlightPhrase.hpp"
#include <QDialog>
namespace Ui {
class HighlightConfigureDialog;
} // namespace Ui
namespace chatterino {
struct IrcServerData;
class HighlightConfigureDialog : public QDialog
{
Q_OBJECT
public:
explicit HighlightConfigureDialog(HighlightPhrase phrase, QWidget *parent);
HighlightConfigureDialog(const HighlightConfigureDialog &) = delete;
HighlightConfigureDialog(HighlightConfigureDialog &&) = delete;
HighlightConfigureDialog &operator=(const HighlightConfigureDialog &) =
delete;
HighlightConfigureDialog &operator=(HighlightConfigureDialog &&) = delete;
~HighlightConfigureDialog() override;
private:
Ui::HighlightConfigureDialog *ui_;
};
} // namespace chatterino

View file

@ -0,0 +1,141 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HighlightConfigureDialog</class>
<widget class="QDialog" name="HighlightConfigureDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Configure highlight</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="patternLabel">
<property name="text">
<string>Pattern</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="patternLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="showInMentionsLabel">
<property name="text">
<string>Show in Mentions</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="showInMentionsCheckBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="flaskTaskbarLabel">
<property name="text">
<string>Flask taskbar</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="flaskTaskbarCheckBox"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="enableRegexLabel">
<property name="text">
<string>Enable regex</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="enableRegexCheckBox"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="playSoundLabel">
<property name="text">
<string>Play sound</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="playSoundCheckBox"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="customSoundLabel">
<property name="text">
<string>Custom sound</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="customSoundLineEdit"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="colorLabel">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QWidget" name="colorWidget" native="true"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>HighlightConfigureDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>HighlightConfigureDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -1,4 +1,4 @@
#include "HighlightingPage.hpp"
#include "widgets/settingspages/HighlightingPage.hpp"
#include "Application.hpp"
#include "controllers/highlights/BadgeHighlightModel.hpp"
@ -15,6 +15,7 @@
#include "util/LayoutCreator.hpp"
#include "widgets/dialogs/BadgePickerDialog.hpp"
#include "widgets/dialogs/ColorPickerDialog.hpp"
#include "widgets/dialogs/HighlightConfigureDialog.hpp"
#include "widgets/helper/color/ColorItemDelegate.hpp"
#include "widgets/helper/EditableModelView.hpp"
@ -75,10 +76,17 @@ HighlightingPage::HighlightingPage()
&getSettings()->highlightedMessages))
.getElement();
view->addRegexHelpLink();
view->setTitles({"Pattern", "Show in\nMentions",
"Flash\ntaskbar", "Enable\nregex",
"Case-\nsensitive", "Play\nsound",
"Custom\nsound", "Color"});
view->setTitles({
"Pattern",
"Show in\nMentions",
"Flash\ntaskbar",
"Enable\nregex",
"Case-\nsensitive",
"Play\nsound",
"Custom\nsound",
"Color",
"Configure",
});
view->getTableView()->horizontalHeader()->setSectionResizeMode(
QHeaderView::Fixed);
view->getTableView()->horizontalHeader()->setSectionResizeMode(
@ -353,6 +361,21 @@ void HighlightingPage::openColorDialog(const QModelIndex &clicked,
dialog->show();
}
void HighlightingPage::openConfigureDialog(const QModelIndex &clicked,
EditableModelView *view,
HighlightTab tab)
{
if (tab != HighlightTab::Messages)
{
return;
}
auto phrase =
getSettings()->highlightedMessages.readOnly()->at(clicked.row());
auto *xd = new HighlightConfigureDialog(phrase, this);
xd->show();
}
void HighlightingPage::tableCellClicked(const QModelIndex &clicked,
EditableModelView *view,
HighlightTab tab)
@ -376,6 +399,10 @@ void HighlightingPage::tableCellClicked(const QModelIndex &clicked,
{
this->openColorDialog(clicked, view, tab);
}
else if (clicked.column() == Column::Configure)
{
this->openConfigureDialog(clicked, view, tab);
}
}
break;

View file

@ -28,6 +28,8 @@ private:
int soundColumn);
void openColorDialog(const QModelIndex &clicked, EditableModelView *view,
HighlightTab tab);
void openConfigureDialog(const QModelIndex &clicked,
EditableModelView *view, HighlightTab tab);
};
} // namespace chatterino