-
Notifications
You must be signed in to change notification settings - Fork 0
/
previewcelldelegate.cpp
98 lines (78 loc) · 1.89 KB
/
previewcelldelegate.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "previewcelldelegate.h"
PreviewCellDelegate::PreviewCellDelegate(QWidget *parent) :
QStyledItemDelegate(parent)
{
font.setFamily("Tahoma");
font.setPointSize(8);
font.setBold(true);
}
void PreviewCellDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
Q_ASSERT(index.isValid());
QColor color;
QStyleOptionViewItemV4 myOption = option;
QString text;
// myOption.displayAlignment = Qt::AlignLeft | Qt::AlignBottom;
myOption.displayAlignment = Qt::AlignCenter;
initStyleOption(&myOption, index);
int value = index.data(Qt::UserRole).toInt();
if (value != 0 && value != 1)
text = QVariant(value).toString();
else
text = "";
switch (value)
{
case 0:
color = Qt::darkRed;
break;
case 1:
case 2:
case 4:
case 8:
color = Qt::green;
break;
case 3:
color = Qt::blue;
break;
case 6:
color = Qt::darkBlue;
break;
case 9:
color = Qt::yellow;
break;
case 12:
color = Qt::darkYellow;
break;
case 7:
color = Qt::cyan;
break;
case 13:
color = Qt::darkCyan;
break;
case 11:
color = Qt::magenta;
break;
case 14:
color = Qt::darkMagenta;
break;
case 15:
color = Qt::red;
break;
case 5:
case 10:
color = Qt::cyan;
break;
}
painter->setFont(font);
painter->fillRect(myOption.rect, color);
// painter->drawRect(myOption.rect);
painter->drawText(myOption.rect, Qt::AlignLeft | Qt::AlignTop, text);
}
QSize PreviewCellDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
Q_ASSERT(index.isValid());
return option.rect.size();
}