You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.2 KiB
62 lines
2.2 KiB
#include "accountdelegate.h" |
|
#include "memberlistmodel.h" |
|
#include <QPainter> |
|
#include <QFont> |
|
|
|
AccountDelegate::AccountDelegate(QObject *parent) |
|
: QStyledItemDelegate(parent) {} |
|
|
|
void AccountDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, |
|
const QModelIndex &index) const { |
|
painter->save(); |
|
|
|
if (option.state & QStyle::State_Selected) |
|
painter->fillRect(option.rect, option.palette.highlight()); |
|
else if (option.state & QStyle::State_MouseOver) |
|
painter->fillRect(option.rect, option.palette.light()); |
|
else |
|
painter->fillRect(option.rect, option.palette.alternateBase()); |
|
|
|
const int margin = 4; |
|
const int iconSz = 24; |
|
|
|
QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole)); |
|
if (!icon.isNull()) |
|
icon.paint(painter, option.rect.left() + margin, option.rect.top() + (option.rect.height() - iconSz) / 2, iconSz, iconSz); |
|
|
|
const int x = option.rect.left() + iconSz + margin * 3; |
|
const int w = option.rect.right() - x - margin; |
|
const int yMid = option.rect.top() + option.rect.height() / 2; |
|
|
|
QFont nameFont = painter->font(); |
|
nameFont.setBold(true); |
|
nameFont.setPixelSize(13); |
|
painter->setFont(nameFont); |
|
|
|
QColor textColor = option.palette.color(QPalette::Text); |
|
if (option.state & QStyle::State_Selected) textColor = option.palette.color(QPalette::HighlightedText); |
|
painter->setPen(textColor); |
|
|
|
QString name = index.data(Qt::DisplayRole).toString(); |
|
painter->drawText(QRect(x, option.rect.top() + 2, w, yMid - option.rect.top() - 2), |
|
Qt::AlignLeft | Qt::AlignBottom, name); |
|
|
|
QFont subFont = painter->font(); |
|
subFont.setBold(false); |
|
subFont.setPixelSize(10); |
|
painter->setFont(subFont); |
|
painter->setPen(QColor(130, 130, 130)); |
|
|
|
QString sub = index.data(Qt::UserRole + 1).toString(); |
|
if (!sub.isEmpty()) |
|
painter->drawText(QRect(x, yMid + 2, w, option.rect.bottom() - yMid - 2), |
|
Qt::AlignLeft | Qt::AlignTop, sub); |
|
|
|
painter->restore(); |
|
} |
|
|
|
QSize AccountDelegate::sizeHint(const QStyleOptionViewItem &option, |
|
const QModelIndex &index) const { |
|
(void)option; (void)index; |
|
return QSize(160, 36); |
|
}
|
|
|