-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsoundlistdelegate.cpp
36 lines (26 loc) · 1.14 KB
/
soundlistdelegate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# include "soundlistdelegate.h"
# include "listmodelbase.h"
# include "sound.h"
# include <QPainter>
SoundListDelegate::SoundListDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
QSize SoundListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const {
return QSize(option.rect.width(), 40);
}
void SoundListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
Sound sound = ((ListModelBase*)index.model())->getItem(index);
QPoint titleBaseline = option.rect.topLeft() + QPoint(5, 33);
QPoint userBaseline = option.rect.topLeft() + QPoint(5, 17);
QColor titleColor(51,51,51);
QColor userColor(153,153,153);
QFont font = painter->font();
font.setPointSize(10);
painter->setPen(titleColor);
painter->setFont(font);
painter->drawText(titleBaseline, sound.getTitle());
font.setPointSize(9);
painter->setPen(userColor);
painter->setFont(font);
painter->drawText(userBaseline, sound.getUser());
}