Moved highlight row index numbers to enum (#3829)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Auro 2022-06-25 05:14:19 -04:00 committed by GitHub
parent 95e6d8ac2f
commit cdd949efd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 33 deletions

View file

@ -74,7 +74,7 @@ void HighlightModel::afterInit()
auto selfColor = ColorProvider::instance().color(ColorType::SelfHighlight); auto selfColor = ColorProvider::instance().color(ColorType::SelfHighlight);
setColorItem(usernameRow[Column::Color], *selfColor, false); setColorItem(usernameRow[Column::Color], *selfColor, false);
this->insertCustomRow(usernameRow, {}); this->insertCustomRow(usernameRow, HighlightRowIndexes::SelfHighlightRow);
// Highlight settings for whispers // Highlight settings for whispers
std::vector<QStandardItem *> whisperRow = this->createRow(); std::vector<QStandardItem *> whisperRow = this->createRow();
@ -99,7 +99,7 @@ void HighlightModel::afterInit()
// setColorItem(whisperRow[Column::Color], *whisperColor, false); // setColorItem(whisperRow[Column::Color], *whisperColor, false);
whisperRow[Column::Color]->setFlags(Qt::ItemFlag::NoItemFlags); whisperRow[Column::Color]->setFlags(Qt::ItemFlag::NoItemFlags);
this->insertCustomRow(whisperRow, WHISPER_ROW); this->insertCustomRow(whisperRow, HighlightRowIndexes::WhisperRow);
// Highlight settings for subscription messages // Highlight settings for subscription messages
std::vector<QStandardItem *> subRow = this->createRow(); std::vector<QStandardItem *> subRow = this->createRow();
@ -121,7 +121,7 @@ void HighlightModel::afterInit()
auto subColor = ColorProvider::instance().color(ColorType::Subscription); auto subColor = ColorProvider::instance().color(ColorType::Subscription);
setColorItem(subRow[Column::Color], *subColor, false); setColorItem(subRow[Column::Color], *subColor, false);
this->insertCustomRow(subRow, 2); this->insertCustomRow(subRow, HighlightRowIndexes::SubRow);
// Highlight settings for redeemed highlight messages // Highlight settings for redeemed highlight messages
std::vector<QStandardItem *> redeemedRow = this->createRow(); std::vector<QStandardItem *> redeemedRow = this->createRow();
@ -149,7 +149,7 @@ void HighlightModel::afterInit()
ColorProvider::instance().color(ColorType::RedeemedHighlight); ColorProvider::instance().color(ColorType::RedeemedHighlight);
setColorItem(redeemedRow[Column::Color], *RedeemedColor, false); setColorItem(redeemedRow[Column::Color], *RedeemedColor, false);
this->insertCustomRow(redeemedRow, 3); this->insertCustomRow(redeemedRow, HighlightRowIndexes::RedeemedRow);
// Highlight settings for first messages // Highlight settings for first messages
std::vector<QStandardItem *> firstMessageRow = this->createRow(); std::vector<QStandardItem *> firstMessageRow = this->createRow();
@ -179,7 +179,8 @@ void HighlightModel::afterInit()
ColorProvider::instance().color(ColorType::FirstMessageHighlight); ColorProvider::instance().color(ColorType::FirstMessageHighlight);
setColorItem(firstMessageRow[Column::Color], *FirstMessageColor, false); setColorItem(firstMessageRow[Column::Color], *FirstMessageColor, false);
this->insertCustomRow(firstMessageRow, 4); this->insertCustomRow(firstMessageRow,
HighlightRowIndexes::FirstMessageRow);
} }
void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row, void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
@ -191,25 +192,25 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
case Column::Pattern: { case Column::Pattern: {
if (role == Qt::CheckStateRole) if (role == Qt::CheckStateRole)
{ {
if (rowIndex == 0) if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
{ {
getSettings()->enableSelfHighlight.setValue(value.toBool()); getSettings()->enableSelfHighlight.setValue(value.toBool());
} }
else if (rowIndex == WHISPER_ROW) else if (rowIndex == HighlightRowIndexes::WhisperRow)
{ {
getSettings()->enableWhisperHighlight.setValue( getSettings()->enableWhisperHighlight.setValue(
value.toBool()); value.toBool());
} }
else if (rowIndex == 2) else if (rowIndex == HighlightRowIndexes::SubRow)
{ {
getSettings()->enableSubHighlight.setValue(value.toBool()); getSettings()->enableSubHighlight.setValue(value.toBool());
} }
else if (rowIndex == 3) else if (rowIndex == HighlightRowIndexes::RedeemedRow)
{ {
getSettings()->enableRedeemedHighlight.setValue( getSettings()->enableRedeemedHighlight.setValue(
value.toBool()); value.toBool());
} }
else if (rowIndex == 4) else if (rowIndex == HighlightRowIndexes::FirstMessageRow)
{ {
getSettings()->enableFirstMessageHighlight.setValue( getSettings()->enableFirstMessageHighlight.setValue(
value.toBool()); value.toBool());
@ -220,7 +221,7 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
case Column::ShowInMentions: { case Column::ShowInMentions: {
if (role == Qt::CheckStateRole) if (role == Qt::CheckStateRole)
{ {
if (rowIndex == 0) if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
{ {
getSettings()->showSelfHighlightInMentions.setValue( getSettings()->showSelfHighlightInMentions.setValue(
value.toBool()); value.toBool());
@ -231,27 +232,27 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
case Column::FlashTaskbar: { case Column::FlashTaskbar: {
if (role == Qt::CheckStateRole) if (role == Qt::CheckStateRole)
{ {
if (rowIndex == 0) if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
{ {
getSettings()->enableSelfHighlightTaskbar.setValue( getSettings()->enableSelfHighlightTaskbar.setValue(
value.toBool()); value.toBool());
} }
else if (rowIndex == WHISPER_ROW) else if (rowIndex == HighlightRowIndexes::WhisperRow)
{ {
getSettings()->enableWhisperHighlightTaskbar.setValue( getSettings()->enableWhisperHighlightTaskbar.setValue(
value.toBool()); value.toBool());
} }
else if (rowIndex == 2) else if (rowIndex == HighlightRowIndexes::SubRow)
{ {
getSettings()->enableSubHighlightTaskbar.setValue( getSettings()->enableSubHighlightTaskbar.setValue(
value.toBool()); value.toBool());
} }
else if (rowIndex == 3) else if (rowIndex == HighlightRowIndexes::RedeemedRow)
{ {
// getSettings()->enableRedeemedHighlightTaskbar.setValue( // getSettings()->enableRedeemedHighlightTaskbar.setValue(
// value.toBool()); // value.toBool());
} }
else if (rowIndex == 4) else if (rowIndex == HighlightRowIndexes::FirstMessageRow)
{ {
// getSettings()->enableFirstMessageHighlightTaskbar.setValue( // getSettings()->enableFirstMessageHighlightTaskbar.setValue(
// value.toBool()); // value.toBool());
@ -262,27 +263,27 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
case Column::PlaySound: { case Column::PlaySound: {
if (role == Qt::CheckStateRole) if (role == Qt::CheckStateRole)
{ {
if (rowIndex == 0) if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
{ {
getSettings()->enableSelfHighlightSound.setValue( getSettings()->enableSelfHighlightSound.setValue(
value.toBool()); value.toBool());
} }
else if (rowIndex == WHISPER_ROW) else if (rowIndex == HighlightRowIndexes::WhisperRow)
{ {
getSettings()->enableWhisperHighlightSound.setValue( getSettings()->enableWhisperHighlightSound.setValue(
value.toBool()); value.toBool());
} }
else if (rowIndex == 2) else if (rowIndex == HighlightRowIndexes::SubRow)
{ {
getSettings()->enableSubHighlightSound.setValue( getSettings()->enableSubHighlightSound.setValue(
value.toBool()); value.toBool());
} }
else if (rowIndex == 3) else if (rowIndex == HighlightRowIndexes::RedeemedRow)
{ {
// getSettings()->enableRedeemedHighlightSound.setValue( // getSettings()->enableRedeemedHighlightSound.setValue(
// value.toBool()); // value.toBool());
} }
else if (rowIndex == 4) else if (rowIndex == HighlightRowIndexes::FirstMessageRow)
{ {
// getSettings()->enableFirstMessageHighlightSound.setValue( // getSettings()->enableFirstMessageHighlightSound.setValue(
// value.toBool()); // value.toBool());
@ -302,27 +303,27 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
// Custom sound file // Custom sound file
if (role == Qt::UserRole) if (role == Qt::UserRole)
{ {
if (rowIndex == 0) if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
{ {
getSettings()->selfHighlightSoundUrl.setValue( getSettings()->selfHighlightSoundUrl.setValue(
value.toString()); value.toString());
} }
else if (rowIndex == WHISPER_ROW) else if (rowIndex == HighlightRowIndexes::WhisperRow)
{ {
getSettings()->whisperHighlightSoundUrl.setValue( getSettings()->whisperHighlightSoundUrl.setValue(
value.toString()); value.toString());
} }
else if (rowIndex == 2) else if (rowIndex == HighlightRowIndexes::SubRow)
{ {
getSettings()->subHighlightSoundUrl.setValue( getSettings()->subHighlightSoundUrl.setValue(
value.toString()); value.toString());
} }
else if (rowIndex == 3) else if (rowIndex == HighlightRowIndexes::RedeemedRow)
{ {
getSettings()->redeemedHighlightSoundUrl.setValue( getSettings()->redeemedHighlightSoundUrl.setValue(
value.toString()); value.toString());
} }
else if (rowIndex == 4) else if (rowIndex == HighlightRowIndexes::FirstMessageRow)
{ {
getSettings()->firstMessageHighlightSoundUrl.setValue( getSettings()->firstMessageHighlightSoundUrl.setValue(
value.toString()); value.toString());
@ -335,26 +336,26 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
if (role == Qt::DecorationRole) if (role == Qt::DecorationRole)
{ {
auto colorName = value.value<QColor>().name(QColor::HexArgb); auto colorName = value.value<QColor>().name(QColor::HexArgb);
if (rowIndex == 0) if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
{ {
getSettings()->selfHighlightColor.setValue(colorName); getSettings()->selfHighlightColor.setValue(colorName);
} }
// else if (rowIndex == WHISPER_ROW) // else if (rowIndex == HighlightRowIndexes::WhisperRow)
// { // {
// getSettings()->whisperHighlightColor.setValue(colorName); // getSettings()->whisperHighlightColor.setValue(colorName);
// } // }
else if (rowIndex == 2) else if (rowIndex == HighlightRowIndexes::SubRow)
{ {
getSettings()->subHighlightColor.setValue(colorName); getSettings()->subHighlightColor.setValue(colorName);
} }
else if (rowIndex == 3) else if (rowIndex == HighlightRowIndexes::RedeemedRow)
{ {
getSettings()->redeemedHighlightColor.setValue(colorName); getSettings()->redeemedHighlightColor.setValue(colorName);
const_cast<ColorProvider &>(ColorProvider::instance()) const_cast<ColorProvider &>(ColorProvider::instance())
.updateColor(ColorType::RedeemedHighlight, .updateColor(ColorType::RedeemedHighlight,
QColor(colorName)); QColor(colorName));
} }
else if (rowIndex == 4) else if (rowIndex == HighlightRowIndexes::FirstMessageRow)
{ {
getSettings()->firstMessageHighlightColor.setValue( getSettings()->firstMessageHighlightColor.setValue(
colorName); colorName);

View file

@ -25,7 +25,13 @@ public:
COUNT // keep this as last member of enum COUNT // keep this as last member of enum
}; };
constexpr static int WHISPER_ROW = 1; enum HighlightRowIndexes {
SelfHighlightRow = 0,
WhisperRow = 1,
SubRow = 2,
RedeemedRow = 3,
FirstMessageRow = 4,
};
protected: protected:
// turn a vector item into a model row // turn a vector item into a model row

View file

@ -353,7 +353,8 @@ void HighlightingPage::tableCellClicked(const QModelIndex &clicked,
using Column = HighlightModel::Column; using Column = HighlightModel::Column;
bool restrictColorRow = bool restrictColorRow =
(tab == HighlightTab::Messages && (tab == HighlightTab::Messages &&
clicked.row() == HighlightModel::WHISPER_ROW); clicked.row() ==
HighlightModel::HighlightRowIndexes::WhisperRow);
if (clicked.column() == Column::SoundPath) if (clicked.column() == Column::SoundPath)
{ {
this->openSoundDialog(clicked, view, Column::SoundPath); this->openSoundDialog(clicked, view, Column::SoundPath);