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"), |
| 15 | m_editEmblem(":/resources/document-edit.png") |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 16 | { |
| 17 | } |
| 18 | |
Zack Rusin | f6667d1 | 2011-03-30 11:03:37 -0400 | [diff] [blame] | 19 | void ApiCallDelegate::paint(QPainter *painter, |
| 20 | const QStyleOptionViewItem &option, |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 21 | const QModelIndex &index) const |
| 22 | { |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 23 | QVariant var = index.data(ApiTraceModel::EventRole); |
| 24 | ApiTraceEvent *event = var.value<ApiTraceEvent*>(); |
| 25 | |
| 26 | Q_ASSERT(index.column() == 0); |
| 27 | |
| 28 | if (event) { |
| 29 | QPoint offset; |
| 30 | QStaticText text = event->staticText(); |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 31 | //text.setTextWidth(option.rect.width()); |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 32 | //QStyledItemDelegate::paint(painter, option, index); |
| 33 | QStyle *style = QApplication::style(); |
| 34 | style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 0); |
| 35 | if (!event->state().isEmpty()) { |
Zack Rusin | 9af5bff | 2011-04-18 01:05:50 -0400 | [diff] [blame] | 36 | QPixmap px = m_stateEmblem.pixmap(option.rect.height(), |
| 37 | option.rect.height()); |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 38 | painter->drawPixmap(option.rect.topLeft(), px); |
| 39 | offset = QPoint(option.rect.height() + 5, 0); |
Zack Rusin | f6667d1 | 2011-03-30 11:03:37 -0400 | [diff] [blame] | 40 | } |
Zack Rusin | 9af5bff | 2011-04-18 01:05:50 -0400 | [diff] [blame] | 41 | if (event->type() == ApiTraceEvent::Call) { |
| 42 | ApiTraceCall *call = static_cast<ApiTraceCall*>(event); |
| 43 | if (call->edited()) { |
| 44 | QPixmap px = m_editEmblem.pixmap(option.rect.height(), |
| 45 | option.rect.height()); |
| 46 | painter->drawPixmap(option.rect.topLeft() + offset, px); |
| 47 | offset += QPoint(option.rect.height() + 5, 0); |
| 48 | } |
| 49 | } |
| 50 | |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 51 | painter->drawStaticText(option.rect.topLeft() + offset, text); |
| 52 | } else { |
| 53 | QStyledItemDelegate::paint(painter, option, index); |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option, |
| 58 | const QModelIndex &index) const |
| 59 | { |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 60 | ApiTraceEvent *event = |
| 61 | index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>(); |
| 62 | |
| 63 | Q_ASSERT(index.column() == 0); |
| 64 | |
| 65 | if (event) { |
| 66 | QStaticText text = event->staticText(); |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 67 | //text.setTextWidth(option.rect.width()); |
Zack Rusin | c1acc7f | 2011-04-02 01:34:04 -0400 | [diff] [blame] | 68 | //qDebug()<<"text size = "<<text.size(); |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 69 | return text.size().toSize(); |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 70 | } |
| 71 | return QStyledItemDelegate::sizeHint(option, index); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | #include "apicalldelegate.moc" |