Add custom image functionality for inline mod buttons. (#5369)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
#include "widgets/helper/IconDelegate.hpp"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QVariant>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
IconDelegate::IconDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
auto data = index.data(Qt::DecorationRole);
|
||||
|
||||
if (data.type() != QVariant::Pixmap)
|
||||
{
|
||||
return QStyledItemDelegate::paint(painter, option, index);
|
||||
}
|
||||
|
||||
auto scaledRect = option.rect;
|
||||
scaledRect.setWidth(scaledRect.height());
|
||||
|
||||
painter->drawPixmap(scaledRect, data.value<QPixmap>());
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
/**
|
||||
* IconDelegate draws the decoration role pixmap scaled down to a square icon
|
||||
*/
|
||||
class IconDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
explicit IconDelegate(QObject *parent = nullptr);
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
Reference in New Issue
Block a user