comparison src/changesetdetailitem.cpp @ 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 533519ebc0cb
children ae67ea0af696
comparison
equal deleted inserted replaced
599:538b6ae5c272 600:641ccce7c771
22 #include "debug.h" 22 #include "debug.h"
23 #include "common.h" 23 #include "common.h"
24 24
25 #include <QTextDocument> 25 #include <QTextDocument>
26 #include <QPainter> 26 #include <QPainter>
27 #include <QAbstractTextDocumentLayout>
27 28
28 ChangesetDetailItem::ChangesetDetailItem(Changeset *cs) : 29 ChangesetDetailItem::ChangesetDetailItem(Changeset *cs) :
29 m_changeset(cs), m_doc(0) 30 m_changeset(cs), m_doc(0)
30 { 31 {
31 m_font = QFont(); 32 m_font = QFont();
71 72
72 ColourSet *colourSet = ColourSet::instance(); 73 ColourSet *colourSet = ColourSet::instance();
73 QColor branchColour = colourSet->getColourFor(m_changeset->branch()); 74 QColor branchColour = colourSet->getColourFor(m_changeset->branch());
74 QColor userColour = colourSet->getColourFor(m_changeset->author()); 75 QColor userColour = colourSet->getColourFor(m_changeset->author());
75 76
76 QFont f(m_font);
77
78 QTransform t = paint->worldTransform(); 77 QTransform t = paint->worldTransform();
79 float scale = std::min(t.m11(), t.m22()); 78 float scale = std::min(t.m11(), t.m22());
80 if (scale > 1.0) {
81 int ps = int((f.pixelSize() / scale) + 0.5);
82 if (ps < 8) ps = 8;
83 f.setPixelSize(ps);
84 }
85 79
86 if (scale < 0.1) { 80 if (scale < 0.1) {
87 paint->setPen(QPen(branchColour, 0)); 81 paint->setPen(QPen(branchColour, 0));
88 } else { 82 } else {
89 paint->setPen(QPen(branchColour, 2)); 83 paint->setPen(QPen(branchColour, 2));
90 } 84 }
91 85
92 paint->setFont(f);
93 QFontMetrics fm(f);
94 int fh = fm.height();
95
96 int width = 350; 86 int width = 350;
97 m_doc->setTextWidth(width); 87 m_doc->setTextWidth(width);
98 int height = m_doc->size().height(); 88 int height = m_doc->size().height();
99 89
100 QRectF r(0.5, 0.5, width - 1, height - 1); 90 QRectF r(0.5, 0.5, width - 1, height - 1);
133 ChangesetDetailItem::makeDocument() 123 ChangesetDetailItem::makeDocument()
134 { 124 {
135 delete m_doc; 125 delete m_doc;
136 m_doc = new QTextDocument; 126 m_doc = new QTextDocument;
137 m_doc->setHtml(m_changeset->formatHtml()); 127 m_doc->setHtml(m_changeset->formatHtml());
128 m_doc->setDefaultFont(m_font);
138 } 129 }
139 130