]> git.cworth.org Git - apitrace/blob - gui/apicalldelegate.cpp
Merge branch 'master' into noglut
[apitrace] / gui / apicalldelegate.cpp
1 #include "apicalldelegate.h"
2
3 #include "apitracecall.h"
4 #include "apitracemodel.h"
5
6 #include <QApplication>
7 #include <QDebug>
8 #include <QPainter>
9 #include <QStaticText>
10 #include <QStyle>
11
12 ApiCallDelegate::ApiCallDelegate(QWidget *parent)
13     : QStyledItemDelegate(parent),
14       m_stateEmblem(":/resources/dialog-information.png")
15 {
16 }
17
18 void ApiCallDelegate::paint(QPainter *painter,
19                             const QStyleOptionViewItem &option,
20                             const QModelIndex &index) const
21 {
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();
30         //text.setTextWidth(option.rect.width());
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);
38         }
39         painter->drawStaticText(option.rect.topLeft() + offset, text);
40     } else {
41         QStyledItemDelegate::paint(painter, option, index);
42     }
43 }
44
45 QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option,
46                                 const QModelIndex &index) const
47 {
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();
55         //text.setTextWidth(option.rect.width());
56         //qDebug()<<"text size = "<<text.size();
57         return text.size().toSize();
58     }
59     return QStyledItemDelegate::sizeHint(option, index);
60 }
61
62
63 #include "apicalldelegate.moc"