Add ability to highlight messages based on user badges (#1704)

Co-authored-by: Paweł <zneix@zneix.eu>
Co-authored-by: 23rd <23rd@vivaldi.net>
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Daniel
2021-05-02 18:08:08 -04:00
committed by GitHub
parent 6ab5b13017
commit f6d9fb2aac
34 changed files with 956 additions and 115 deletions
@@ -0,0 +1,56 @@
#include "BadgeHighlightModel.hpp"
#include "Application.hpp"
#include "messages/Emote.hpp"
#include "singletons/Settings.hpp"
#include "util/StandardItemHelper.hpp"
namespace chatterino {
// commandmodel
BadgeHighlightModel::BadgeHighlightModel(QObject *parent)
: SignalVectorModel<HighlightBadge>(5, parent)
{
}
// turn vector item into model row
HighlightBadge BadgeHighlightModel::getItemFromRow(
std::vector<QStandardItem *> &row, const HighlightBadge &original)
{
using Column = BadgeHighlightModel::Column;
// 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 HighlightBadge{
original.badgeName(),
row[Column::Badge]->data(Qt::DisplayRole).toString(),
row[Column::FlashTaskbar]->data(Qt::CheckStateRole).toBool(),
row[Column::PlaySound]->data(Qt::CheckStateRole).toBool(),
row[Column::SoundPath]->data(Qt::UserRole).toString(),
highlightColor};
}
// row into vector item
void BadgeHighlightModel::getRowFromItem(const HighlightBadge &item,
std::vector<QStandardItem *> &row)
{
using QIconPtr = std::shared_ptr<QIcon>;
using Column = BadgeHighlightModel::Column;
setStringItem(row[Column::Badge], item.displayName(), false, true);
setBoolItem(row[Column::FlashTaskbar], item.hasAlert());
setBoolItem(row[Column::PlaySound], item.hasSound());
setFilePathItem(row[Column::SoundPath], item.getSoundUrl());
setColorItem(row[Column::Color], *item.getColor());
TwitchBadges::instance()->getBadgeIcon(
item.badgeName(), [item, row](QString /*name*/, const QIconPtr pixmap) {
row[Column::Badge]->setData(QVariant(*pixmap), Qt::DecorationRole);
});
}
} // namespace chatterino