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")
19 void ApiCallDelegate::paint(QPainter *painter,
20 const QStyleOptionViewItem &option,
21 const QModelIndex &index) const
23 QVariant var = index.data(ApiTraceModel::EventRole);
24 ApiTraceEvent *event = var.value<ApiTraceEvent*>();
26 Q_ASSERT(index.column() == 0);
30 QStaticText text = event->staticText();
31 //text.setTextWidth(option.rect.width());
32 //QStyledItemDelegate::paint(painter, option, index);
33 QStyle *style = QApplication::style();
34 style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 0);
35 if (!event->state().isEmpty()) {
36 QPixmap px = m_stateEmblem.pixmap(option.rect.height(),
37 option.rect.height());
38 painter->drawPixmap(option.rect.topLeft(), px);
39 offset = QPoint(option.rect.height() + 5, 0);
41 if (event->type() == ApiTraceEvent::Call) {
42 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
44 QPixmap px = m_editEmblem.pixmap(option.rect.height(),
45 option.rect.height());
46 painter->drawPixmap(option.rect.topLeft() + offset, px);
47 offset += QPoint(option.rect.height() + 5, 0);
51 painter->drawStaticText(option.rect.topLeft() + offset, text);
53 QStyledItemDelegate::paint(painter, option, index);
57 QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option,
58 const QModelIndex &index) const
60 ApiTraceEvent *event =
61 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
63 Q_ASSERT(index.column() == 0);
66 QStaticText text = event->staticText();
67 //text.setTextWidth(option.rect.width());
68 //qDebug()<<"text size = "<<text.size();
69 return text.size().toSize();
71 return QStyledItemDelegate::sizeHint(option, index);
75 #include "apicalldelegate.moc"