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