1 #include "apicalldelegate.h"
3 #include "apitracecall.h"
4 #include "apitracemodel.h"
6 #include <QApplication>
12 ApiCallDelegate::ApiCallDelegate(QWidget *parent)
13 : QStyledItemDelegate(parent),
14 m_stateEmblem(":/resources/dialog-information.png"),
15 m_editEmblem(":/resources/document-edit.png"),
16 m_errorEmblem(":/resources/script-error.png")
20 void ApiCallDelegate::paint(QPainter *painter,
21 const QStyleOptionViewItem &option,
22 const QModelIndex &index) const
24 QVariant var = index.data(ApiTraceModel::EventRole);
25 ApiTraceEvent *event = var.value<ApiTraceEvent*>();
27 Q_ASSERT(index.column() == 0);
31 QStaticText text = event->staticText();
32 //text.setTextWidth(option.rect.width());
33 //QStyledItemDelegate::paint(painter, option, index);
34 QStyle *style = QApplication::style();
35 style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 0);
36 if (event->hasState()) {
37 QPixmap px = m_stateEmblem.pixmap(option.rect.height(),
38 option.rect.height());
39 painter->drawPixmap(option.rect.topLeft(), px);
40 offset = QPoint(option.rect.height() + 5, 0);
42 if (event->type() == ApiTraceEvent::Call) {
43 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
44 if (call->hasError()) {
45 QPixmap px = m_errorEmblem.pixmap(option.rect.height(),
46 option.rect.height());
47 painter->drawPixmap(option.rect.topLeft() + offset, px);
48 offset += QPoint(option.rect.height() + 5, 0);
51 QPixmap px = m_editEmblem.pixmap(option.rect.height(),
52 option.rect.height());
53 painter->drawPixmap(option.rect.topLeft() + offset, px);
54 offset += QPoint(option.rect.height() + 5, 0);
58 painter->drawStaticText(option.rect.topLeft() + offset, text);
60 QStyledItemDelegate::paint(painter, option, index);
64 QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option,
65 const QModelIndex &index) const
67 ApiTraceEvent *event =
68 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
71 /* XXX: This fails on MacOSX, but seems safe to ignore */
72 Q_ASSERT(index.column() == 0);
76 QStaticText text = event->staticText();
77 //text.setTextWidth(option.rect.width());
78 //qDebug()<<"text size = "<<text.size();
79 return text.size().toSize();
81 return QStyledItemDelegate::sizeHint(option, index);
85 #include "apicalldelegate.moc"