X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=gui%2Fapicalldelegate.cpp;h=dc9dc94a45248a50caf0a9941085a20d6367418a;hb=3c70dbfb4ca01d92172f87109ba995f6db5f7835;hp=5376c0dcdb3d266a5964ffafb230b0c252945ae0;hpb=f6667d1331849a8534ead1c653ab4a1aeaeddcc8;p=apitrace diff --git a/gui/apicalldelegate.cpp b/gui/apicalldelegate.cpp index 5376c0d..dc9dc94 100644 --- a/gui/apicalldelegate.cpp +++ b/gui/apicalldelegate.cpp @@ -1,14 +1,19 @@ #include "apicalldelegate.h" #include "apitracecall.h" +#include "apitracemodel.h" +#include #include #include #include #include ApiCallDelegate::ApiCallDelegate(QWidget *parent) - : QStyledItemDelegate(parent) + : QStyledItemDelegate(parent), + m_stateEmblem(":/resources/dialog-information.png"), + m_editEmblem(":/resources/document-edit.png"), + m_errorEmblem(":/resources/script-error.png") { } @@ -16,40 +21,62 @@ void ApiCallDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - ApiTraceCall *call = index.data().value(); - if (call) { - QStaticText text = call->staticText(); + QVariant var = index.data(ApiTraceModel::EventRole); + ApiTraceEvent *event = var.value(); + + Q_ASSERT(index.column() == 0); + + if (event) { + QPoint offset; + QStaticText text = event->staticText(); //text.setTextWidth(option.rect.width()); - QStyledItemDelegate::paint(painter, option, index); - painter->drawStaticText(option.rect.topLeft(), text); - } else { - ApiTraceFrame *frame = index.data().value(); - if (frame) { - QStaticText text = frame->staticText(); - //text.setTextWidth(option.rect.width()); - QStyledItemDelegate::paint(painter, option, index); - painter->drawStaticText(option.rect.topLeft(), text); - } else { - QStyledItemDelegate::paint(painter, option, index); + //QStyledItemDelegate::paint(painter, option, index); + QStyle *style = QApplication::style(); + style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 0); + if (!event->state().isEmpty()) { + 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(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 { - ApiTraceCall *call = index.data().value(); - if (call) { - QStaticText text = call->staticText(); + ApiTraceEvent *event = + index.data(ApiTraceModel::EventRole).value(); + +#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 = "<(); - if (frame) { - QStaticText text = frame->staticText(); - //text.setTextWidth(option.rect.width()); - return text.size().toSize(); - } } return QStyledItemDelegate::sizeHint(option, index); }