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
|
#include "apicalldelegate.h"
#include "apitracecall.h"
#include "apitracemodel.h"
#include <QApplication>
#include <QDebug>
#include <QPainter>
#include <QStaticText>
#include <QStyle>
ApiCallDelegate::ApiCallDelegate(QWidget *parent)
: QStyledItemDelegate(parent),
m_stateEmblem(":/resources/dialog-information.png"),
m_editEmblem(":/resources/document-edit.png"),
m_errorEmblem(":/resources/script-error.png")
{
}
void ApiCallDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QVariant var = index.data(ApiTraceModel::EventRole);
ApiTraceEvent *event = var.value<ApiTraceEvent*>();
Q_ASSERT(index.column() == 0);
if (event) {
QPoint offset = QPoint(0, 0);
QStaticText text = event->staticText();
//text.setTextWidth(option.rect.width());
//QStyledItemDelegate::paint(painter, option, index);
QStyle *style = QApplication::style();
style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 0);
// draw thumbnail of frame
if(event->type() == ApiTraceEvent::Frame) {
ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
const QImage & thumbnail = frame->thumbnail();
if (!thumbnail.isNull()) {
painter->drawImage(option.rect.topLeft() + offset, thumbnail);
offset += QPoint(option.rect.height() + 16, 0);
}
}
if (event->hasState()) {
QPixmap px = m_stateEmblem.pixmap(option.rect.height(),
option.rect.height());
painter->drawPixmap(option.rect.topLeft(), px);
offset = QPoint(option.rect.height() + 5, 0);
}
if (event->type() == ApiTraceEvent::Call) {
ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
if (call->hasError()) {
QPixmap px = m_errorEmblem.pixmap(option.rect.height(),
option.rect.height());
painter->drawPixmap(option.rect.topLeft() + offset, px);
offset += QPoint(option.rect.height() + 5, 0);
}
if (call->edited()) {
QPixmap px = m_editEmblem.pixmap(option.rect.height(),
option.rect.height());
painter->drawPixmap(option.rect.topLeft() + offset, px);
offset += QPoint(option.rect.height() + 5, 0);
}
}
painter->drawStaticText(option.rect.topLeft() + offset, text);
} else {
QStyledItemDelegate::paint(painter, option, index);
}
}
QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
ApiTraceEvent *event =
index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
#ifndef __APPLE__
/* XXX: This fails on MacOSX, but seems safe to ignore */
Q_ASSERT(index.column() == 0);
#endif
if (event) {
QStaticText text = event->staticText();
//text.setTextWidth(option.rect.width());
//qDebug()<<"text size = "<<text.size();
return text.size().toSize();
}
return QStyledItemDelegate::sizeHint(option, index);
}
#include "apicalldelegate.moc"
|