]> git.cworth.org Git - apitrace/commitdiff
some color in the list
authorZack Rusin <zack@kde.org>
Sat, 26 Mar 2011 18:23:35 +0000 (14:23 -0400)
committerZack Rusin <zack@kde.org>
Thu, 31 Mar 2011 02:48:41 +0000 (22:48 -0400)
gui/CMakeLists.txt
gui/apicalldelegate.cpp [new file with mode: 0644]
gui/apicalldelegate.h [new file with mode: 0644]
gui/apitracecall.cpp
gui/apitracecall.h
gui/apitracemodel.cpp
gui/mainwindow.cpp

index 3a6ef757f5ff4737ba28507ed47da080dbb1a4df..3ffb14778a069d870247b4e4376fca21931d438e 100644 (file)
@@ -1,4 +1,5 @@
 set(qapitrace_SRCS
+   apicalldelegate.cpp
    apitracecall.cpp
    apitracefilter.cpp
    apitracemodel.cpp
diff --git a/gui/apicalldelegate.cpp b/gui/apicalldelegate.cpp
new file mode 100644 (file)
index 0000000..43c96e9
--- /dev/null
@@ -0,0 +1,40 @@
+#include "apicalldelegate.h"
+
+#include "apitracecall.h"
+
+#include <QDebug>
+#include <QPainter>
+#include <QStaticText>
+
+ApiCallDelegate::ApiCallDelegate(QWidget *parent)
+    : QStyledItemDelegate(parent)
+{
+}
+
+void ApiCallDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+                            const QModelIndex &index) const
+{
+    ApiTraceCall *call = static_cast<ApiTraceCall*>(index.internalPointer());
+    if (call) {
+        QStaticText text = call->staticText();
+        //text.setTextWidth(option.rect.width());
+        painter->drawStaticText(option.rect.topLeft(), text);
+    } else{
+        QStyledItemDelegate::paint(painter, option, index);
+    }
+}
+
+QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option,
+                                const QModelIndex &index) const
+{
+    ApiTraceCall *call = static_cast<ApiTraceCall*>(index.internalPointer());
+    if (call) {
+        QStaticText text = call->staticText();
+        //text.setTextWidth(option.rect.width());
+        return text.size().toSize();
+    }
+    return QStyledItemDelegate::sizeHint(option, index);
+}
+
+
+#include "apicalldelegate.moc"
diff --git a/gui/apicalldelegate.h b/gui/apicalldelegate.h
new file mode 100644 (file)
index 0000000..0329839
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef APICALLDELEGATE_H
+#define APICALLDELEGATE_H
+
+
+
+#include <QStyledItemDelegate>
+
+class ApiCallDelegate : public QStyledItemDelegate
+{
+    Q_OBJECT
+
+public:
+    ApiCallDelegate(QWidget *parent = 0);
+
+    void paint(QPainter *painter, const QStyleOptionViewItem &option,
+               const QModelIndex &index) const;
+    QSize sizeHint(const QStyleOptionViewItem &option,
+                   const QModelIndex &index) const;
+};
+
+#endif
index 679ee5c85954a6f93c7878150b921bb469123a9b..b964739726f26b974ba23278a55b06946444bc4d 100644 (file)
@@ -224,3 +224,42 @@ void ApiArray::init(const Trace::Array *arr)
         m_array.append(vis.variant());
     }
 }
+
+QStaticText ApiTraceCall::staticText() const
+{
+    if (!m_richText.isEmpty())
+        return m_staticText;
+
+    m_richText = QString::fromLatin1("<span style=\"font-weight:bold\">%1</span>(").arg(name);
+    for (int i = 0; i < argNames.count(); ++i) {
+        m_richText += argNames[i];
+        m_richText += QString::fromLatin1(" = ");
+        m_richText += QLatin1String("<span style=\"color:#0000ff\">");
+        m_richText += apiVariantToString(argValues[i]);
+        m_richText += QLatin1String("</span>");
+        if (i < argNames.count() - 1)
+            m_richText += QString::fromLatin1(", ");
+    }
+    m_richText += QLatin1String(")");
+
+    if (returnValue.isValid()) {
+        m_richText += QLatin1String(" = ");
+        m_richText += QLatin1String("<span style=\"color:#0000ff\">");
+        m_richText += apiVariantToString(returnValue);
+        m_richText += QLatin1String("</span>");
+    }
+
+    m_staticText.setText(m_richText);
+    QTextOption opt;
+    opt.setWrapMode(QTextOption::NoWrap);
+    m_staticText.setTextOption(opt);
+    m_staticText.prepare();
+
+    return m_staticText;
+}
+
+QString ApiTraceCall::richText() const
+{
+    staticText();
+    return m_richText;
+}
index 8dffb27c94374c5ff794a20c1862e2b2fa3c5670..1c0340873741092b806400722e6dfd003ab98cfe 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef APITRACECALL_H
 #define APITRACECALL_H
 
+#include <QStaticText>
 #include <QStringList>
 #include <QVariant>
 
@@ -104,6 +105,12 @@ public:
     QStringList argNames;
     QVariantList argValues;
     QVariant returnValue;
+
+    QString richText() const;
+    QStaticText staticText() const;
+private:
+    mutable QString m_richText;
+    mutable QStaticText m_staticText;
 };
 
 #endif
index f63529410737a21d625b51365e254805aa97c140..c2a5e96468780474f27eb6e07a39e36dea85b854 100644 (file)
@@ -38,25 +38,7 @@ QVariant ApiTraceModel::data(const QModelIndex &index, int role) const
 
     switch (index.column()) {
     case 0: {
-        QString str;
-        str += QString::number(index.row());
-        str += QLatin1String(") ");
-        str += item->name;
-        str += QLatin1String("(");
-        for (int i = 0; i < item->argNames.count(); ++i) {
-            str += item->argNames[i];
-            str += QString::fromLatin1(" = ");
-            str += apiVariantToString(item->argValues[i]);
-            if (i < item->argNames.count() - 1)
-                str += QString::fromLatin1(", ");
-        }
-        str += QLatin1String(")");
-
-        if (item->returnValue.isValid()) {
-            str += QLatin1String(" = ");
-            str += apiVariantToString(item->returnValue);
-        }
-        return str;
+        return item->richText();
     }
     default:
         return QVariant();
index 05dbb630dfddcb90c78df05357f4bc768931c04d..a2fc380250fbd1733d73bc31a56d37bd8dbe4468 100644 (file)
@@ -1,5 +1,6 @@
 #include "mainwindow.h"
 
+#include "apicalldelegate.h"
 #include "apitracemodel.h"
 #include "apitracefilter.h"
 
@@ -18,6 +19,7 @@ MainWindow::MainWindow()
     m_proxyModel = new ApiTraceFilter();
     m_proxyModel->setSourceModel(m_model);
     m_ui.callView->setModel(m_model);
+    m_ui.callView->setItemDelegate(new ApiCallDelegate);
     for (int column = 0; column < m_model->columnCount(); ++column)
         m_ui.callView->resizeColumnToContents(column);