]> git.cworth.org Git - apitrace/blobdiff - gui/apicalldelegate.cpp
Cleanup the event model code.
[apitrace] / gui / apicalldelegate.cpp
index 5376c0dcdb3d266a5964ffafb230b0c252945ae0..4eb542be2171bce1c410da3397fb8eb7592356c1 100644 (file)
@@ -1,14 +1,17 @@
 #include "apicalldelegate.h"
 
 #include "apitracecall.h"
+#include "apitracemodel.h"
 
+#include <QApplication>
 #include <QDebug>
 #include <QPainter>
 #include <QStaticText>
 #include <QStyle>
 
 ApiCallDelegate::ApiCallDelegate(QWidget *parent)
-    : QStyledItemDelegate(parent)
+    : QStyledItemDelegate(parent),
+      m_stateEmblem(":/resources/dialog-information.png")
 {
 }
 
@@ -16,40 +19,42 @@ void ApiCallDelegate::paint(QPainter *painter,
                             const QStyleOptionViewItem &option,
                             const QModelIndex &index) const
 {
-    ApiTraceCall *call = index.data().value<ApiTraceCall*>();
-    if (call) {
-        QStaticText text = call->staticText();
+    QVariant var = index.data(ApiTraceModel::EventRole);
+    ApiTraceEvent *event = var.value<ApiTraceEvent*>();
+
+    Q_ASSERT(index.column() == 0);
+
+    if (event) {
+        QPoint offset;
+        QStaticText text = event->staticText();
         //text.setTextWidth(option.rect.width());
-        QStyledItemDelegate::paint(painter, option, index);
-        painter->drawStaticText(option.rect.topLeft(), text);
-    } else {
-        ApiTraceFrame *frame = index.data().value<ApiTraceFrame*>();
-        if (frame) {
-            QStaticText text = frame->staticText();
-            //text.setTextWidth(option.rect.width());
-            QStyledItemDelegate::paint(painter, option, index);
-            painter->drawStaticText(option.rect.topLeft(), text);
-        } else {
-            QStyledItemDelegate::paint(painter, option, index);
+        //QStyledItemDelegate::paint(painter, option, index);
+        QStyle *style = QApplication::style();
+        style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 0);
+        if (!event->state().isEmpty()) {
+            QPixmap px = m_stateEmblem.pixmap(option.rect.height(), option.rect.height());
+            painter->drawPixmap(option.rect.topLeft(), px);
+            offset = QPoint(option.rect.height() + 5, 0);
         }
+        painter->drawStaticText(option.rect.topLeft() + offset, text);
+    } else {
+        QStyledItemDelegate::paint(painter, option, index);
     }
 }
 
 QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option,
                                 const QModelIndex &index) const
 {
-    ApiTraceCall *call = index.data().value<ApiTraceCall*>();
-    if (call) {
-        QStaticText text = call->staticText();
+    ApiTraceEvent *event =
+        index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
+
+    Q_ASSERT(index.column() == 0);
+
+    if (event) {
+        QStaticText text = event->staticText();
         //text.setTextWidth(option.rect.width());
+        //qDebug()<<"text size = "<<text.size();
         return text.size().toSize();
-    } else {
-        ApiTraceFrame *frame = index.data().value<ApiTraceFrame*>();
-        if (frame) {
-            QStaticText text = frame->staticText();
-            //text.setTextWidth(option.rect.width());
-            return text.size().toSize();
-        }
     }
     return QStyledItemDelegate::sizeHint(option, index);
 }