1 #include "apicalldelegate.h"
3 #include "apitracecall.h"
4 #include "apitracemodel.h"
7 #include <QApplication>
10 #include <QStaticText>
13 ApiCallDelegate::ApiCallDelegate(QWidget *parent)
14 : QStyledItemDelegate(parent),
15 m_stateEmblem(":/resources/dialog-information.png"),
16 m_editEmblem(":/resources/document-edit.png"),
17 m_errorEmblem(":/resources/script-error.png")
21 void ApiCallDelegate::paint(QPainter *painter,
22 const QStyleOptionViewItem &option,
23 const QModelIndex &index) const
25 QVariant var = index.data(ApiTraceModel::EventRole);
26 ApiTraceEvent *event = var.value<ApiTraceEvent*>();
28 Q_ASSERT(index.column() == 0);
31 QPoint offset = option.rect.topLeft();
32 QStaticText text = event->staticText();
33 QSize textSize = text.size().toSize();
34 //text.setTextWidth(option.rect.width());
35 //QStyledItemDelegate::paint(painter, option, index);
36 QStyle *style = QApplication::style();
37 style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 0);
39 // draw thumbnail of frame
40 if (event->type() == ApiTraceEvent::Frame) {
41 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
42 const QImage & thumbnail = frame->thumbnail();
43 if (!thumbnail.isNull()) {
44 painter->drawImage(offset, thumbnail);
45 offset += QPoint(textSize.height() + thumbnail.width(), option.rect.height()/2 - textSize.height()/2);
49 if (event->hasState()) {
50 QPixmap px = m_stateEmblem.pixmap(textSize.height(),
52 painter->drawPixmap(option.rect.topLeft(), px);
53 offset += QPoint(textSize.height() + 5, 0);
55 if (event->type() == ApiTraceEvent::Call) {
56 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
57 if (call->hasError()) {
58 QPixmap px = m_errorEmblem.pixmap(textSize.height(),
60 painter->drawPixmap(offset, px);
61 offset += QPoint(textSize.height() + 5, 0);
64 QPixmap px = m_editEmblem.pixmap(textSize.height(),
66 painter->drawPixmap(offset, px);
67 offset += QPoint(textSize.height() + 5, 0);
71 painter->drawStaticText(offset, text);
73 QStyledItemDelegate::paint(painter, option, index);
77 QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option,
78 const QModelIndex &index) const
80 QVariant var = index.data(ApiTraceModel::EventRole);
81 ApiTraceEvent *event = var.value<ApiTraceEvent*>();
84 /* XXX: This fails on MacOSX, but seems safe to ignore */
85 Q_ASSERT(index.column() == 0);
89 QStaticText text = event->staticText();
90 //text.setTextWidth(option.rect.width());
91 //qDebug()<<"text size = "<<text.size();
92 QSize size = text.size().toSize();
94 // Adjust for thumbnail
95 if (event->type() == ApiTraceEvent::Frame) {
96 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
97 const QImage & thumbnail = frame->thumbnail();
98 if (!thumbnail.isNull()) {
99 size.rwidth() += thumbnail.width();
100 if (size.height() < thumbnail.height()) {
101 size.setHeight(thumbnail.height());
108 return QStyledItemDelegate::sizeHint(option, index);
112 #include "apicalldelegate.moc"