2018-07-05 15:58:20 +02:00
|
|
|
#include "UserHighlightModel.hpp"
|
|
|
|
|
|
|
|
#include "Application.hpp"
|
2020-01-25 11:03:10 +01:00
|
|
|
#include "controllers/highlights/HighlightModel.hpp"
|
2018-07-05 15:58:20 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
|
|
|
#include "util/StandardItemHelper.hpp"
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2020-10-24 14:33:15 +02:00
|
|
|
using Column = HighlightModel::Column;
|
|
|
|
|
2018-07-05 15:58:20 +02:00
|
|
|
// commandmodel
|
|
|
|
UserHighlightModel::UserHighlightModel(QObject *parent)
|
2020-10-24 14:33:15 +02:00
|
|
|
: SignalVectorModel<HighlightPhrase>(Column::COUNT, parent)
|
2018-07-05 15:58:20 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// turn vector item into model row
|
2018-08-06 21:17:03 +02:00
|
|
|
HighlightPhrase UserHighlightModel::getItemFromRow(
|
|
|
|
std::vector<QStandardItem *> &row, const HighlightPhrase &original)
|
2018-07-05 15:58:20 +02:00
|
|
|
{
|
2020-01-25 11:03:10 +01:00
|
|
|
// In order for old messages to update their highlight color, we need to
|
|
|
|
// update the highlight color here.
|
|
|
|
auto highlightColor = original.getColor();
|
|
|
|
*highlightColor =
|
|
|
|
row[Column::Color]->data(Qt::DecorationRole).value<QColor>();
|
|
|
|
|
|
|
|
return HighlightPhrase{
|
|
|
|
row[Column::Pattern]->data(Qt::DisplayRole).toString(),
|
2020-10-24 14:33:15 +02:00
|
|
|
row[Column::ShowInMentions]->data(Qt::CheckStateRole).toBool(),
|
2020-01-25 11:03:10 +01:00
|
|
|
row[Column::FlashTaskbar]->data(Qt::CheckStateRole).toBool(),
|
|
|
|
row[Column::PlaySound]->data(Qt::CheckStateRole).toBool(),
|
|
|
|
row[Column::UseRegex]->data(Qt::CheckStateRole).toBool(),
|
|
|
|
row[Column::CaseSensitive]->data(Qt::CheckStateRole).toBool(),
|
|
|
|
row[Column::SoundPath]->data(Qt::UserRole).toString(),
|
|
|
|
highlightColor};
|
2018-07-05 15:58:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// row into vector item
|
|
|
|
void UserHighlightModel::getRowFromItem(const HighlightPhrase &item,
|
|
|
|
std::vector<QStandardItem *> &row)
|
|
|
|
{
|
2020-01-25 11:03:10 +01:00
|
|
|
setStringItem(row[Column::Pattern], item.getPattern());
|
2020-10-24 14:33:15 +02:00
|
|
|
setBoolItem(row[Column::ShowInMentions], item.showInMentions());
|
2020-01-25 11:03:10 +01:00
|
|
|
setBoolItem(row[Column::FlashTaskbar], item.hasAlert());
|
|
|
|
setBoolItem(row[Column::PlaySound], item.hasSound());
|
|
|
|
setBoolItem(row[Column::UseRegex], item.isRegex());
|
|
|
|
setBoolItem(row[Column::CaseSensitive], item.isCaseSensitive());
|
|
|
|
setFilePathItem(row[Column::SoundPath], item.getSoundUrl());
|
|
|
|
setColorItem(row[Column::Color], *item.getColor());
|
2018-07-05 15:58:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|