X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=gui%2Fapicalldelegate.cpp;h=11ed3a5ca03d5c59c96b8c7bc05c67e2e5583bf8;hb=daf82af9d5f270c87434cc1142f32a6407703781;hp=43c96e9906f6af0db3fee4556d82733bad934d0c;hpb=18eade5a1b8820633210e4127129a8b14450e13f;p=apitrace diff --git a/gui/apicalldelegate.cpp b/gui/apicalldelegate.cpp index 43c96e9..11ed3a5 100644 --- a/gui/apicalldelegate.cpp +++ b/gui/apicalldelegate.cpp @@ -1,25 +1,62 @@ #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") { } -void ApiCallDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, +void ApiCallDelegate::paint(QPainter *painter, + const QStyleOptionViewItem &option, const QModelIndex &index) const { - ApiTraceCall *call = static_cast(index.internalPointer()); - 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()); - painter->drawStaticText(option.rect.topLeft(), text); - } else{ + //QStyledItemDelegate::paint(painter, option, index); + QStyle *style = QApplication::style(); + style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 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(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); } } @@ -27,10 +64,18 @@ void ApiCallDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - ApiTraceCall *call = static_cast(index.internalPointer()); - 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 = "<