diff changesetdetailitem.cpp @ 118:9734fb0d6fff

* Rudimentary version of the popup showing more information when you click on a changeset in history graph
author Chris Cannam
date Fri, 26 Nov 2010 23:49:48 +0000
parents d5db15bf250c
children 1f27f71a7034
line wrap: on
line diff
--- a/changesetdetailitem.cpp	Fri Nov 26 22:46:29 2010 +0000
+++ b/changesetdetailitem.cpp	Fri Nov 26 23:49:48 2010 +0000
@@ -20,22 +20,33 @@
 #include "textabbrev.h"
 #include "colourset.h"
 #include "debug.h"
+#include "common.h"
 
+#include <QTextDocument>
 #include <QPainter>
 
 ChangesetDetailItem::ChangesetDetailItem(Changeset *cs) :
-    m_changeset(cs)
+    m_changeset(cs), m_doc(0)
 {
     m_font = QFont();
     m_font.setPixelSize(11);
     m_font.setBold(false);
     m_font.setItalic(false);
+
+    makeDocument();
+}
+
+ChangesetDetailItem::~ChangesetDetailItem()
+{
+    delete m_doc;
 }
 
 QRectF
 ChangesetDetailItem::boundingRect() const
 {
-    return QRectF(0, 0, 350, 200);
+    int w = 350;
+    m_doc->setTextWidth(w);
+    return QRectF(0, -10, w, m_doc->size().height() + 10);
 }
 
 void
@@ -70,7 +81,8 @@
     int fh = fm.height();
 
     int width = 350;
-    int height = 200;
+    m_doc->setTextWidth(width);
+    int height = m_doc->size().height();
 
     QRectF r(0.5, 0.5, width - 1, height - 1);
     paint->setBrush(Qt::white);
@@ -80,6 +92,17 @@
 	paint->restore();
 	return;
     }
+
+    paint->setBrush(branchColour);
+    QVector<QPointF> pts;
+    pts.push_back(QPointF(width/2 - 5, 0));
+    pts.push_back(QPointF(width/2 + 5, 0));
+    pts.push_back(QPointF(width/2, -10));
+    pts.push_back(QPointF(width/2 - 5, 0));
+    paint->drawPolygon(QPolygonF(pts));
+
+    m_doc->drawContents(paint, r);
+
 /*
     paint->fillRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5),
 		    QBrush(userColour));
@@ -109,12 +132,6 @@
     fh = fm.height();
     paint->setFont(f);
 
-    QString comment = m_changeset->comment().trimmed();
-    comment = comment.replace("\\n", " ");
-    comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), "");
-    comment = comment.replace(QRegExp("\"$"), "");
-    comment = comment.replace("\\\"", "\"");
-
     wid = width - 5;
     int nlines = (height / fh) - 1;
     if (nlines < 1) nlines = 1;
@@ -128,3 +145,60 @@
     */
     paint->restore();
 }
+
+void
+ChangesetDetailItem::makeDocument()
+{
+    delete m_doc;
+
+    QString description;
+    QString rowTemplate = "<tr><td><b>%1</b></td><td>%2</td></tr>";
+
+    description = "<qt><table border=0>";
+
+    QString comment = m_changeset->comment().trimmed();
+    comment = comment.replace(QRegExp("^\""), "");
+    comment = comment.replace(QRegExp("\"$"), "");
+    comment = comment.replace("\\\"", "\"");
+    comment = xmlEncode(comment);
+    comment = comment.replace("\\n", "<br>");
+
+    QStringList propNames, propTexts;
+    
+    propNames << "id"
+	      << "author"
+	      << "datetime"
+	      << "branch"
+	      << "tag"
+	      << "comment";
+
+    propTexts << QObject::tr("Identifier")
+	      << QObject::tr("Author")
+	      << QObject::tr("Date")
+	      << QObject::tr("Branch")
+	      << QObject::tr("Tag")
+	      << QObject::tr("Comment");
+
+    for (int i = 0; i < propNames.size(); ++i) {
+	QString prop = propNames[i];
+	QString value;
+	if (prop == "comment") value = comment;
+	else {
+	    value = xmlEncode(m_changeset->property
+			      (prop.toLocal8Bit().data()).toString());
+	}
+	if (value != "") {
+	    description += rowTemplate
+		.arg(xmlEncode(propTexts[i]))
+		.arg(value);
+	}
+    }
+
+    description += "</table></qt>";
+
+    DEBUG << "ChangesetDetailItem: description = " << description << endl;
+
+    m_doc = new QTextDocument;
+    m_doc->setHtml(description);
+}
+