1 #include "UserHighlightModel.hpp"
2
3 #include "Application.hpp"
4 #include "controllers/highlights/HighlightModel.hpp"
5 #include "singletons/Settings.hpp"
6 #include "util/StandardItemHelper.hpp"
7
8 namespace chatterino {
9
10 using Column = HighlightModel::Column;
11
12 // commandmodel
UserHighlightModel(QObject * parent)13 UserHighlightModel::UserHighlightModel(QObject *parent)
14 : SignalVectorModel<HighlightPhrase>(Column::COUNT, parent)
15 {
16 }
17
18 // turn vector item into model row
getItemFromRow(std::vector<QStandardItem * > & row,const HighlightPhrase & original)19 HighlightPhrase UserHighlightModel::getItemFromRow(
20 std::vector<QStandardItem *> &row, const HighlightPhrase &original)
21 {
22 // In order for old messages to update their highlight color, we need to
23 // update the highlight color here.
24 auto highlightColor = original.getColor();
25 *highlightColor =
26 row[Column::Color]->data(Qt::DecorationRole).value<QColor>();
27
28 return HighlightPhrase{
29 row[Column::Pattern]->data(Qt::DisplayRole).toString(),
30 row[Column::ShowInMentions]->data(Qt::CheckStateRole).toBool(),
31 row[Column::FlashTaskbar]->data(Qt::CheckStateRole).toBool(),
32 row[Column::PlaySound]->data(Qt::CheckStateRole).toBool(),
33 row[Column::UseRegex]->data(Qt::CheckStateRole).toBool(),
34 row[Column::CaseSensitive]->data(Qt::CheckStateRole).toBool(),
35 row[Column::SoundPath]->data(Qt::UserRole).toString(),
36 highlightColor};
37 }
38
39 // row into vector item
getRowFromItem(const HighlightPhrase & item,std::vector<QStandardItem * > & row)40 void UserHighlightModel::getRowFromItem(const HighlightPhrase &item,
41 std::vector<QStandardItem *> &row)
42 {
43 setStringItem(row[Column::Pattern], item.getPattern());
44 setBoolItem(row[Column::ShowInMentions], item.showInMentions());
45 setBoolItem(row[Column::FlashTaskbar], item.hasAlert());
46 setBoolItem(row[Column::PlaySound], item.hasSound());
47 setBoolItem(row[Column::UseRegex], item.isRegex());
48 setBoolItem(row[Column::CaseSensitive], item.isCaseSensitive());
49 setFilePathItem(row[Column::SoundPath], item.getSoundUrl());
50 setColorItem(row[Column::Color], *item.getColor());
51 }
52
53 } // namespace chatterino
54