]> git.cworth.org Git - apitrace/blob - gui/apicalldelegate.cpp
Introduce ApiTrace which encapsulates the data.
[apitrace] / gui / apicalldelegate.cpp
1 #include "apicalldelegate.h"
2
3 #include "apitracecall.h"
4
5 #include <QDebug>
6 #include <QPainter>
7 #include <QStaticText>
8 #include <QStyle>
9
10 ApiCallDelegate::ApiCallDelegate(QWidget *parent)
11     : QStyledItemDelegate(parent)
12 {
13 }
14
15 void ApiCallDelegate::paint(QPainter *painter,
16                             const QStyleOptionViewItem &option,
17                             const QModelIndex &index) const
18 {
19     ApiTraceCall *call = index.data().value<ApiTraceCall*>();
20     if (call) {
21         QStaticText text = call->staticText();
22         //text.setTextWidth(option.rect.width());
23         QStyledItemDelegate::paint(painter, option, index);
24         painter->drawStaticText(option.rect.topLeft(), text);
25     } else {
26         ApiTraceFrame *frame = index.data().value<ApiTraceFrame*>();
27         if (frame) {
28             QStaticText text = frame->staticText();
29             //text.setTextWidth(option.rect.width());
30             QStyledItemDelegate::paint(painter, option, index);
31             painter->drawStaticText(option.rect.topLeft(), text);
32         } else {
33             QStyledItemDelegate::paint(painter, option, index);
34         }
35     }
36 }
37
38 QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option,
39                                 const QModelIndex &index) const
40 {
41     ApiTraceCall *call = index.data().value<ApiTraceCall*>();
42     if (call) {
43         QStaticText text = call->staticText();
44         //text.setTextWidth(option.rect.width());
45         return text.size().toSize();
46     } else {
47         ApiTraceFrame *frame = index.data().value<ApiTraceFrame*>();
48         if (frame) {
49             QStaticText text = frame->staticText();
50             //text.setTextWidth(option.rect.width());
51             return text.size().toSize();
52         }
53     }
54     return QStyledItemDelegate::sizeHint(option, index);
55 }
56
57
58 #include "apicalldelegate.moc"