Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 1 | #include "apicalldelegate.h" |
| 2 | |
| 3 | #include "apitracecall.h" |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 4 | #include "apitracemodel.h" |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 5 | |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 6 | #include <QApplication> |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 7 | #include <QDebug> |
| 8 | #include <QPainter> |
| 9 | #include <QStaticText> |
Zack Rusin | 96130ac | 2011-03-27 01:48:36 -0400 | [diff] [blame] | 10 | #include <QStyle> |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 11 | |
| 12 | ApiCallDelegate::ApiCallDelegate(QWidget *parent) |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 13 | : QStyledItemDelegate(parent), |
Zack Rusin | 9af5bff | 2011-04-18 01:05:50 -0400 | [diff] [blame] | 14 | m_stateEmblem(":/resources/dialog-information.png"), |
Zack Rusin | b53b161 | 2011-04-19 01:33:58 -0400 | [diff] [blame] | 15 | m_editEmblem(":/resources/document-edit.png"), |
| 16 | m_errorEmblem(":/resources/script-error.png") |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 17 | { |
| 18 | } |
| 19 | |
Zack Rusin | f6667d1 | 2011-03-30 11:03:37 -0400 | [diff] [blame] | 20 | void ApiCallDelegate::paint(QPainter *painter, |
| 21 | const QStyleOptionViewItem &option, |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 22 | const QModelIndex &index) const |
| 23 | { |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 24 | 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 Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 32 | //text.setTextWidth(option.rect.width()); |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 33 | //QStyledItemDelegate::paint(painter, option, index); |
| 34 | QStyle *style = QApplication::style(); |
| 35 | style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 0); |
Zack Rusin | ed40bc6 | 2011-08-28 17:11:02 -0400 | [diff] [blame^] | 36 | if (event->hasState()) { |
Zack Rusin | 9af5bff | 2011-04-18 01:05:50 -0400 | [diff] [blame] | 37 | QPixmap px = m_stateEmblem.pixmap(option.rect.height(), |
| 38 | option.rect.height()); |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 39 | painter->drawPixmap(option.rect.topLeft(), px); |
| 40 | offset = QPoint(option.rect.height() + 5, 0); |
Zack Rusin | f6667d1 | 2011-03-30 11:03:37 -0400 | [diff] [blame] | 41 | } |
Zack Rusin | 9af5bff | 2011-04-18 01:05:50 -0400 | [diff] [blame] | 42 | if (event->type() == ApiTraceEvent::Call) { |
| 43 | ApiTraceCall *call = static_cast<ApiTraceCall*>(event); |
Zack Rusin | b53b161 | 2011-04-19 01:33:58 -0400 | [diff] [blame] | 44 | 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 Rusin | 9af5bff | 2011-04-18 01:05:50 -0400 | [diff] [blame] | 50 | 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 Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 58 | painter->drawStaticText(option.rect.topLeft() + offset, text); |
| 59 | } else { |
| 60 | QStyledItemDelegate::paint(painter, option, index); |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option, |
| 65 | const QModelIndex &index) const |
| 66 | { |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 67 | ApiTraceEvent *event = |
| 68 | index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>(); |
| 69 | |
José Fonseca | ae89afa | 2011-05-27 20:25:41 +0100 | [diff] [blame] | 70 | #ifndef __APPLE__ |
| 71 | /* XXX: This fails on MacOSX, but seems safe to ignore */ |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 72 | Q_ASSERT(index.column() == 0); |
José Fonseca | ae89afa | 2011-05-27 20:25:41 +0100 | [diff] [blame] | 73 | #endif |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 74 | |
| 75 | if (event) { |
| 76 | QStaticText text = event->staticText(); |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 77 | //text.setTextWidth(option.rect.width()); |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 78 | //qDebug()<<"text size = "<<text.size(); |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 79 | return text.size().toSize(); |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 80 | } |
| 81 | return QStyledItemDelegate::sizeHint(option, index); |
| 82 | } |
| 83 | |
| 84 | |
| 85 | #include "apicalldelegate.moc" |