blob: c68717580ddc6e5e5d94f3b95eb9fd27b8d6cf45 [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) {
Dan McCabe10bd4242012-03-05 17:20:40 -080030 QPoint offset = QPoint(0, 0);
Zack Rusinc1acc7f2011-04-02 01:34:04 -040031 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);
Dan McCabe10bd4242012-03-05 17:20:40 -080036
37 // draw thumbnail of frame
38 if(event->type() == ApiTraceEvent::Frame) {
39 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
José Fonseca8759ae02012-03-24 07:44:43 +000040 const QImage & thumbnail = frame->thumbnail();
Dan McCabe10bd4242012-03-05 17:20:40 -080041 if (!thumbnail.isNull()) {
42 painter->drawImage(option.rect.topLeft() + offset, thumbnail);
43 offset += QPoint(option.rect.height() + 16, 0);
44 }
45 }
46
Zack Rusined40bc62011-08-28 17:11:02 -040047 if (event->hasState()) {
Zack Rusin9af5bff2011-04-18 01:05:50 -040048 QPixmap px = m_stateEmblem.pixmap(option.rect.height(),
49 option.rect.height());
Zack Rusinc1acc7f2011-04-02 01:34:04 -040050 painter->drawPixmap(option.rect.topLeft(), px);
51 offset = QPoint(option.rect.height() + 5, 0);
Zack Rusinf6667d12011-03-30 11:03:37 -040052 }
Zack Rusin9af5bff2011-04-18 01:05:50 -040053 if (event->type() == ApiTraceEvent::Call) {
54 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
Zack Rusinb53b1612011-04-19 01:33:58 -040055 if (call->hasError()) {
56 QPixmap px = m_errorEmblem.pixmap(option.rect.height(),
57 option.rect.height());
58 painter->drawPixmap(option.rect.topLeft() + offset, px);
59 offset += QPoint(option.rect.height() + 5, 0);
60 }
Zack Rusin9af5bff2011-04-18 01:05:50 -040061 if (call->edited()) {
62 QPixmap px = m_editEmblem.pixmap(option.rect.height(),
63 option.rect.height());
64 painter->drawPixmap(option.rect.topLeft() + offset, px);
65 offset += QPoint(option.rect.height() + 5, 0);
66 }
67 }
68
Zack Rusinc1acc7f2011-04-02 01:34:04 -040069 painter->drawStaticText(option.rect.topLeft() + offset, text);
70 } else {
71 QStyledItemDelegate::paint(painter, option, index);
Zack Rusin18eade52011-03-26 14:23:35 -040072 }
73}
74
75QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option,
76 const QModelIndex &index) const
77{
Zack Rusinc1acc7f2011-04-02 01:34:04 -040078 ApiTraceEvent *event =
79 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
80
José Fonsecaae89afa2011-05-27 20:25:41 +010081#ifndef __APPLE__
82 /* XXX: This fails on MacOSX, but seems safe to ignore */
Zack Rusinc1acc7f2011-04-02 01:34:04 -040083 Q_ASSERT(index.column() == 0);
José Fonsecaae89afa2011-05-27 20:25:41 +010084#endif
Zack Rusinc1acc7f2011-04-02 01:34:04 -040085
86 if (event) {
87 QStaticText text = event->staticText();
Zack Rusin18eade52011-03-26 14:23:35 -040088 //text.setTextWidth(option.rect.width());
Zack Rusinc1acc7f2011-04-02 01:34:04 -040089 //qDebug()<<"text size = "<<text.size();
Zack Rusin18eade52011-03-26 14:23:35 -040090 return text.size().toSize();
Zack Rusin18eade52011-03-26 14:23:35 -040091 }
92 return QStyledItemDelegate::sizeHint(option, index);
93}
94
95
96#include "apicalldelegate.moc"