blob: 11ed3a5ca03d5c59c96b8c7bc05c67e2e5583bf8 [file] [log] [blame]
Zack Rusin18eade52011-03-26 14:23:35 -04001#include "apicalldelegate.h"
2
3#include "apitracecall.h"
Zack Rusinc1acc7f2011-04-02 01:34:04 -04004#include "apitracemodel.h"
Zack Rusin18eade52011-03-26 14:23:35 -04005
Zack Rusinc1acc7f2011-04-02 01:34:04 -04006#include <QApplication>
Zack Rusin18eade52011-03-26 14:23:35 -04007#include <QDebug>
8#include <QPainter>
9#include <QStaticText>
Zack Rusin96130ac2011-03-27 01:48:36 -040010#include <QStyle>
Zack Rusin18eade52011-03-26 14:23:35 -040011
12ApiCallDelegate::ApiCallDelegate(QWidget *parent)
Zack Rusinc1acc7f2011-04-02 01:34:04 -040013 : QStyledItemDelegate(parent),
Zack Rusin9af5bff2011-04-18 01:05:50 -040014 m_stateEmblem(":/resources/dialog-information.png"),
Zack Rusinb53b1612011-04-19 01:33:58 -040015 m_editEmblem(":/resources/document-edit.png"),
16 m_errorEmblem(":/resources/script-error.png")
Zack Rusin18eade52011-03-26 14:23:35 -040017{
18}
19
Zack Rusinf6667d12011-03-30 11:03:37 -040020void ApiCallDelegate::paint(QPainter *painter,
21 const QStyleOptionViewItem &option,
Zack Rusin18eade52011-03-26 14:23:35 -040022 const QModelIndex &index) const
23{
Zack Rusinc1acc7f2011-04-02 01:34:04 -040024 QVariant var = index.data(ApiTraceModel::EventRole);
25 ApiTraceEvent *event = var.value<ApiTraceEvent*>();
26
27 Q_ASSERT(index.column() == 0);
28
29 if (event) {
30 QPoint offset;
31 QStaticText text = event->staticText();
Zack Rusin18eade52011-03-26 14:23:35 -040032 //text.setTextWidth(option.rect.width());
Zack Rusinc1acc7f2011-04-02 01:34:04 -040033 //QStyledItemDelegate::paint(painter, option, index);
34 QStyle *style = QApplication::style();
35 style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 0);
Zack Rusined40bc62011-08-28 17:11:02 -040036 if (event->hasState()) {
Zack Rusin9af5bff2011-04-18 01:05:50 -040037 QPixmap px = m_stateEmblem.pixmap(option.rect.height(),
38 option.rect.height());
Zack Rusinc1acc7f2011-04-02 01:34:04 -040039 painter->drawPixmap(option.rect.topLeft(), px);
40 offset = QPoint(option.rect.height() + 5, 0);
Zack Rusinf6667d12011-03-30 11:03:37 -040041 }
Zack Rusin9af5bff2011-04-18 01:05:50 -040042 if (event->type() == ApiTraceEvent::Call) {
43 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
Zack Rusinb53b1612011-04-19 01:33:58 -040044 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);
49 }
Zack Rusin9af5bff2011-04-18 01:05:50 -040050 if (call->edited()) {
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);
55 }
56 }
57
Zack Rusinc1acc7f2011-04-02 01:34:04 -040058 painter->drawStaticText(option.rect.topLeft() + offset, text);
59 } else {
60 QStyledItemDelegate::paint(painter, option, index);
Zack Rusin18eade52011-03-26 14:23:35 -040061 }
62}
63
64QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option,
65 const QModelIndex &index) const
66{
Zack Rusinc1acc7f2011-04-02 01:34:04 -040067 ApiTraceEvent *event =
68 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
69
José Fonsecaae89afa2011-05-27 20:25:41 +010070#ifndef __APPLE__
71 /* XXX: This fails on MacOSX, but seems safe to ignore */
Zack Rusinc1acc7f2011-04-02 01:34:04 -040072 Q_ASSERT(index.column() == 0);
José Fonsecaae89afa2011-05-27 20:25:41 +010073#endif
Zack Rusinc1acc7f2011-04-02 01:34:04 -040074
75 if (event) {
76 QStaticText text = event->staticText();
Zack Rusin18eade52011-03-26 14:23:35 -040077 //text.setTextWidth(option.rect.width());
Zack Rusinc1acc7f2011-04-02 01:34:04 -040078 //qDebug()<<"text size = "<<text.size();
Zack Rusin18eade52011-03-26 14:23:35 -040079 return text.size().toSize();
Zack Rusin18eade52011-03-26 14:23:35 -040080 }
81 return QStyledItemDelegate::sizeHint(option, index);
82}
83
84
85#include "apicalldelegate.moc"