changeset 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 005a54380502
files changesetdetailitem.cpp changesetdetailitem.h changesetitem.cpp filestatuswidget.cpp
diffstat 4 files changed, 94 insertions(+), 12 deletions(-) [+]
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);
+}
+
--- a/changesetdetailitem.h	Fri Nov 26 22:46:29 2010 +0000
+++ b/changesetdetailitem.h	Fri Nov 26 23:49:48 2010 +0000
@@ -27,6 +27,7 @@
 {
 public:
     ChangesetDetailItem(Changeset *cs);
+    virtual ~ChangesetDetailItem();
 
     virtual QRectF boundingRect() const;
     virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
@@ -36,6 +37,9 @@
 private:
     QFont m_font;
     Changeset *m_changeset;
+    QTextDocument *m_doc;
+
+    void makeDocument();
 };
 
 #endif // CHANGESETDETAILITEM_H
--- a/changesetitem.cpp	Fri Nov 26 22:46:29 2010 +0000
+++ b/changesetitem.cpp	Fri Nov 26 23:49:48 2010 +0000
@@ -48,7 +48,11 @@
 {
     DEBUG << "ChangesetItem::mousePressEvent" << endl;
     //!!! how best to handle this?
-    if (m_detail) return;
+    if (m_detail) {
+        delete m_detail;
+        m_detail = 0;
+        return;
+    }
     m_detail = new ChangesetDetailItem(m_changeset);
     m_detail->setZValue(zValue() + 1);
     scene()->addItem(m_detail);
--- a/filestatuswidget.cpp	Fri Nov 26 22:46:29 2010 +0000
+++ b/filestatuswidget.cpp	Fri Nov 26 23:49:48 2010 +0000
@@ -83,7 +83,7 @@
     m_descriptions[FileStates::Unknown] = tr("These files are in your working folder but are not under version control.<br>"
                                              "Select a file and use Add to place it under version control or Ignore to remove it from this list.");
 
-    m_highlightExplanation = tr("Files highlighted <font color=red>in red</font> "
+    m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> "
                                 "have appeared since your most recent commit or update.");
 
     for (int i = int(FileStates::FirstState);
@@ -367,7 +367,7 @@
         foreach (QString file, highPriority) {
             QListWidgetItem *item = new QListWidgetItem(file);
             w->addItem(item);
-            item->setForeground(Qt::red); //!!! and a nice gold star
+            item->setForeground(QColor("#d40000")); //!!! and a nice gold star
             item->setSelected(selectedFiles.contains(file));
         }