changeset 600:641ccce7c771

Avoid messing with font size when zooming, let it zoom naturally; don't delete detail item when removing it, just let it wait to be shown again (and do delete it when deleting main item)
author Chris Cannam
date Fri, 11 May 2012 17:44:33 +0100
parents 538b6ae5c272
children 2985c2a90146
files src/changesetdetailitem.cpp src/changesetitem.cpp src/changesetitem.h
diffstat 3 files changed, 21 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/changesetdetailitem.cpp	Tue Apr 24 16:56:29 2012 +0100
+++ b/src/changesetdetailitem.cpp	Fri May 11 17:44:33 2012 +0100
@@ -24,6 +24,7 @@
 
 #include <QTextDocument>
 #include <QPainter>
+#include <QAbstractTextDocumentLayout>
 
 ChangesetDetailItem::ChangesetDetailItem(Changeset *cs) :
     m_changeset(cs), m_doc(0)
@@ -73,26 +74,15 @@
     QColor branchColour = colourSet->getColourFor(m_changeset->branch());
     QColor userColour = colourSet->getColourFor(m_changeset->author());
 
-    QFont f(m_font);
-
     QTransform t = paint->worldTransform();
     float scale = std::min(t.m11(), t.m22());
-    if (scale > 1.0) {
-	int ps = int((f.pixelSize() / scale) + 0.5);
-	if (ps < 8) ps = 8;
-	f.setPixelSize(ps);
-    }
 
     if (scale < 0.1) {
 	paint->setPen(QPen(branchColour, 0));
     } else {
 	paint->setPen(QPen(branchColour, 2));
     }
-
-    paint->setFont(f);
-    QFontMetrics fm(f);
-    int fh = fm.height();
-
+    
     int width = 350;
     m_doc->setTextWidth(width);
     int height = m_doc->size().height();
@@ -135,5 +125,6 @@
     delete m_doc;
     m_doc = new QTextDocument;
     m_doc->setHtml(m_changeset->formatHtml());
+    m_doc->setDefaultFont(m_font);
 }
 
--- a/src/changesetitem.cpp	Tue Apr 24 16:56:29 2012 +0100
+++ b/src/changesetitem.cpp	Fri May 11 17:44:33 2012 +0100
@@ -36,7 +36,7 @@
 QImage *ChangesetItem::m_star = 0;
 
 ChangesetItem::ChangesetItem(Changeset *cs) :
-    m_changeset(cs), m_detail(0),
+    m_changeset(cs), m_detail(0), m_detailVisible(false),
     m_showBranch(false), m_column(0), m_row(0), m_wide(false),
     m_current(false), m_closing(false), m_new(false), m_searchMatches(false)
 {
@@ -49,6 +49,11 @@
     if (!m_star) m_star = new QImage(":images/star.png");
 }
 
+ChangesetItem::~ChangesetItem()
+{
+    if (m_detail && !m_detailVisible) delete m_detail;
+}
+
 QString
 ChangesetItem::getId()
 {
@@ -66,28 +71,28 @@
 void
 ChangesetItem::showDetail()
 {
-    if (m_detail) return;
-    m_detail = new ChangesetDetailItem(m_changeset);
-    m_detail->setZValue(zValue() + 1);
+    if (m_detailVisible) return;
+    if (!m_detail) {
+        m_detail = new ChangesetDetailItem(m_changeset);
+        m_detail->setZValue(zValue() + 1);
+    }
     scene()->addItem(m_detail);
     int w = 100;
     if (m_wide) w = 180;
     if (isMerge() || isClosingCommit()) w = 60;
     int h = 80;
-//    m_detail->moveBy(x() - (m_detail->boundingRect().width() - 50) / 2,
-//                     y() + 60);
-    m_detail->moveBy(x() + (w + 50) / 2 + 10 + 0.5,
+    m_detail->setPos(x() + (w + 50) / 2 + 10 + 0.5,
                      y() - (m_detail->boundingRect().height() - h) / 3 + 0.5);
+    m_detailVisible = true;
     emit detailShown();
 }    
 
 void
 ChangesetItem::hideDetail()
 {
-    if (!m_detail) return;
+    if (!m_detailVisible) return;
     scene()->removeItem(m_detail);
-    delete m_detail;
-    m_detail = 0;
+    m_detailVisible = false;
     emit detailHidden();
 }    
 
@@ -112,7 +117,7 @@
 {
     DEBUG << "ChangesetItem::mousePressEvent" << endl;
     if (e->button() == Qt::LeftButton) {
-        if (m_detail) {
+        if (m_detailVisible) {
             hideDetail();
         } else {
             showDetail();
@@ -303,11 +308,6 @@
 
     QTransform t = paint->worldTransform();
     float scale = std::min(t.m11(), t.m22());
-    if (scale > 1.0) {
-	int ps = int((f.pixelSize() / scale) + 0.5);
-	if (ps < 8) ps = 8;
-	f.setPixelSize(ps);
-    }
 
     bool showText = (scale >= 0.2);
     bool showProperLines = (scale >= 0.1);
--- a/src/changesetitem.h	Tue Apr 24 16:56:29 2012 +0100
+++ b/src/changesetitem.h	Fri May 11 17:44:33 2012 +0100
@@ -33,6 +33,7 @@
 
 public:
     ChangesetItem(Changeset *cs);
+    ~ChangesetItem();
 
     virtual QRectF boundingRect() const;
     virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
@@ -105,6 +106,7 @@
     QFont m_font;
     Changeset *m_changeset;
     ChangesetDetailItem *m_detail;
+    bool m_detailVisible;
     bool m_showBranch;
     int m_column;
     int m_row;