c0b46d0514a7 — Chris Cannam 6 years ago
Incomplete scaling updates. Should do this differently
M src/changesetdetailitem.cpp +1 -1
@@ 30,7 30,7 @@ ChangesetDetailItem::ChangesetDetailItem
     m_changeset(cs), m_doc(0)
 {
     m_font = QFont();
-    m_font.setPixelSize(11);
+    m_font.setPixelSize(scalePixelSize(11));
     m_font.setBold(false);
     m_font.setItalic(false);
 

          
M src/changesetitem.cpp +15 -9
@@ 22,6 22,7 @@ 
 #include "textabbrev.h"
 #include "colourset.h"
 #include "debug.h"
+#include "common.h"
 
 #include <QPainter>
 #include <QGraphicsScene>

          
@@ 41,7 42,7 @@ ChangesetItem::ChangesetItem(Changeset *
     m_current(false), m_closing(false), m_new(false), m_searchMatches(false)
 {
     m_font = QFont();
-    m_font.setPixelSize(11);
+    m_font.setPixelSize(scalePixelSize(11));
     m_font.setBold(false);
     m_font.setItalic(false);
     setCursor(Qt::ArrowCursor);

          
@@ 65,7 66,10 @@ ChangesetItem::boundingRect() const
 {
     int w = 100;
     if (m_wide) w = 180;
-    return QRectF(-((w-50)/2 - 1), -30, w - 3, 90);
+    return QRectF(-scalePixelSize((w-50)/2 - 1),
+                  -scalePixelSize(30),
+                  scalePixelSize(w - 3),
+                  scalePixelSize(90));
 }
 
 void

          
@@ 81,8 85,9 @@ ChangesetItem::showDetail()
     if (m_wide) w = 180;
     if (isMerge() || isClosingCommit()) w = 60;
     int h = 80;
-    m_detail->setPos(x() + (w + 50) / 2 + 10 + 0.5,
-                     y() - (m_detail->boundingRect().height() - h) / 3 + 0.5);
+    m_detail->setPos(x() + scalePixelSize((w + 50) / 2 + 10 + 0.5),
+                     y() - (m_detail->boundingRect().height() -
+                            scalePixelSize(h)) / 3 + 0.5);
     m_detailVisible = true;
     emit detailShown();
 }    

          
@@ 335,10 340,10 @@ ChangesetItem::paintNormal(QPainter *pai
 
     int width = 100;
     if (m_wide) width = 180;
-    int x0 = -((width - 50) / 2 - 1);
+    int x0 = -scalePixelSize((width - 50) / 2 - 1);
 
-    int textwid = width - 7;
-
+    int textwid = scalePixelSize(width - 7);
+    
     QString comment;
     QStringList lines;
     int lineCount = 3;

          
@@ 354,7 359,7 @@ ChangesetItem::paintNormal(QPainter *pai
         comment = TextAbbrev::abbreviate(comment, fm, textwid,
                                          TextAbbrev::ElideEnd, "...", 3);
         // abbreviate() changes this (ouch!), restore it
-        textwid = width - 5;
+        textwid = scalePixelSize(width - 7);
 
         lines = comment.split('\n');
         lineCount = lines.size();

          
@@ 362,7 367,8 @@ ChangesetItem::paintNormal(QPainter *pai
         if (lineCount < 2) lineCount = 2;
     }
 
-    int height = (lineCount + 1) * fh + 2;
+    width = scalePixelSize(width);
+    int height = (lineCount + 1) * fh + scalePixelSize(2);
     QRectF r(x0, 0, width - 3, height);
 
     QColor textColour = Qt::black;

          
M src/changesetitem.h +4 -2
@@ 21,6 21,8 @@ 
 #include <QGraphicsObject>
 #include <QFont>
 
+#include "common.h"
+
 class Changeset;
 class ChangesetDetailItem;
 

          
@@ 43,8 45,8 @@ public:
 
     int column() const { return m_column; }
     int row() const { return m_row; }
-    void setColumn(int c) { m_column = c; setX(c * 100); }
-    void setRow(int r) { m_row = r; setY(r * 90); }
+    void setColumn(int c) { m_column = c; setX(c * scalePixelSize(100)); }
+    void setRow(int r) { m_row = r; setY(r * scalePixelSize(90)); }
 
     bool isWide() const { return m_wide; }
     void setWide(bool w) { m_wide = w; }

          
M src/changesetscene.cpp +1 -1
@@ 120,7 120,7 @@ ChangesetScene::recalculateSceneRect()
     QRectF existingSr = sceneRect();
 
     QRectF r = itemsBoundingRect();
-    float minwidth = 300; //!!!
+    float minwidth = scalePixelSize(300); //!!!
     DEBUG << "ChangesetScene::recalculateSceneRect: minwidth = " << minwidth
           << ", r = " << r << endl;
     if (r.width() < minwidth) {

          
M src/changesetview.cpp +6 -3
@@ 19,6 19,7 @@ 
 #include "changesetscene.h"
 #include "colourset.h"
 #include "debug.h"
+#include "common.h"
 
 #include <QScrollBar>
 

          
@@ 76,11 77,13 @@ ChangesetView::drawBackground(QPainter *
 
 	ChangesetScene::DateRange range = i.value();
 
-        QRectF r = QRectF(x, range.minrow * 90 - 25,
-			  w, range.nrows * 90).normalized();
+        int rowSpace = scalePixelSize(90);
+        
+        QRectF r = QRectF(x, range.minrow * rowSpace - scalePixelSize(25),
+			  w, range.nrows * rowSpace).normalized();
 
 	paint->fillRect(r, range.even ? evenBrush : oddBrush);
-        paint->drawText(px, range.minrow * 90 - 10, range.label);
+        paint->drawText(px, range.minrow * rowSpace - scalePixelSize(10), range.label);
     }
 
     paint->restore();

          
M src/common.cpp +22 -0
@@ 23,6 23,8 @@ 
 #include <QStringList>
 #include <QDir>
 #include <QRegExp>
+#include <QFont>
+#include <QFontMetrics>
 
 #include <sys/types.h>
 

          
@@ 352,3 354,23 @@ QByteArray randomKey()
     return ba;
 }
 
+int
+scalePixelSize(int pixels)
+{
+    static double ratio = 0.0;
+    if (ratio == 0.0) {
+        double baseEm;
+#ifdef Q_OS_MAC
+        baseEm = 17.0;
+#else
+        baseEm = 15.0;
+#endif
+        double em = QFontMetrics(QFont()).height();
+        ratio = em / baseEm;
+    }
+
+    int scaled = int(pixels * ratio + 0.5);
+    if (pixels != 0 && scaled == 0) scaled = 1;
+    return scaled;
+}
+

          
M src/common.h +2 -1
@@ 69,7 69,8 @@ QString uniDecode(QString);
  * Generate a 16-byte random key using urandom or equivalent
  */
 QByteArray randomKey();
-    
+
+int scalePixelSize(int pixels);
 
 #endif 	//COMMON_H
 

          
M src/connectionitem.cpp +16 -15
@@ 22,6 22,7 @@ 
 #include "changeset.h"
 #include "colourset.h"
 #include "textabbrev.h"
+#include "common.h"
 
 #include <QPainter>
 #include <QFont>

          
@@ 30,9 31,9 @@ QRectF
 ConnectionItem::boundingRect() const
 {
     if (!(m_child || m_uncommitted)) return QRectF();
-    float xscale = 100;
-    float yscale = 90;
-    float size = 50;
+    float xscale = scalePixelSize(100);
+    float yscale = scalePixelSize(90);
+    float size = scalePixelSize(50);
 
     int c_col, c_row;
     if (m_child) {

          
@@ 48,10 49,10 @@ ConnectionItem::boundingRect() const
         p_col = c_col - 1; p_row = c_row + 1;
     }
 
-    return QRectF(xscale * c_col + size/2 - 2,
-		  yscale * c_row + size - 22,
-		  xscale * p_col - xscale * c_col + 6,
-		  yscale * p_row - yscale * c_row - size + 44)
+    return QRectF(xscale * c_col + size/2 - scalePixelSize(2),
+		  yscale * c_row + size - scalePixelSize(22),
+		  xscale * p_col - xscale * c_col + scalePixelSize(6),
+		  yscale * p_row - yscale * c_row - size + scalePixelSize(44))
 	.normalized();
 }
 

          
@@ 85,10 86,9 @@ ConnectionItem::paint(QPainter *paint, c
 	paint->setPen(QPen(branchColour, 2, ls));
     }
 
-    float xscale = 100;
-
-    float yscale = 90;
-    float size = 50;
+    float xscale = scalePixelSize(100);
+    float yscale = scalePixelSize(90);
+    float size = scalePixelSize(50);
     float ygap = yscale - size - 2;
 
     int c_col, c_row;

          
@@ 111,7 111,7 @@ ConnectionItem::paint(QPainter *paint, c
     // ensure line reaches the box, even if it's in a small height --
     // doesn't matter if we overshoot as the box is opaque and has a
     // greater Z value
-    p.moveTo(c_x, yscale * c_row + size - 20);
+    p.moveTo(c_x, yscale * c_row + size - scalePixelSize(20));
 
     p.lineTo(c_x, yscale * c_row + size);
 

          
@@ 148,12 148,13 @@ ConnectionItem::paint(QPainter *paint, c
 
         // ensure line reaches the node -- again doesn't matter if we
         // overshoot
-        p.lineTo(p_x, yscale * p_row + 20);
+        p.lineTo(p_x, yscale * p_row + scalePixelSize(20));
 
     } else {
 
         // no parent: merge from closed branch: draw only half the line
-        paint->setClipRect(QRectF((c_x + p_x)/2, yscale * c_row + size - 22,
+        paint->setClipRect(QRectF((c_x + p_x)/2,
+                                  yscale * c_row + size - scalePixelSize(22),
                                   xscale, yscale));
     }
     

          
@@ 166,7 167,7 @@ ConnectionItem::paint(QPainter *paint, c
         paint->setClipping(false);
 
         QFont f;
-        f.setPixelSize(11);
+        f.setPixelSize(scalePixelSize(11));
         f.setBold(true);
         f.setItalic(false);
 	paint->setFont(f);

          
M src/uncommitteditem.cpp +25 -18
@@ 19,6 19,7 @@ 
 #include "colourset.h"
 #include "debug.h"
 #include "textabbrev.h"
+#include "common.h"
 
 #include <QPainter>
 #include <QGraphicsScene>

          
@@ 33,7 34,7 @@ UncommittedItem::UncommittedItem() :
     m_column(0), m_row(0), m_wide(false)
 {
     m_font = QFont();
-    m_font.setPixelSize(11);
+    m_font.setPixelSize(scalePixelSize(11));
     m_font.setBold(false);
     m_font.setItalic(false);
     setCursor(Qt::ArrowCursor);

          
@@ 45,7 46,10 @@ UncommittedItem::boundingRect() const
     //!!! this stuff is gross, refactor with changesetitem and connectionitem
     int w = 100;
     if (m_wide) w = 180;
-    return QRectF(-((w-50)/2 - 1), -30, w - 3, 79 + 40);
+    return QRectF(-scalePixelSize((w-50)/2 - 1),
+                  -scalePixelSize(30),
+                  scalePixelSize(w - 3),
+                  scalePixelSize(79 + 40));
 }
 
 void

          
@@ 144,26 148,29 @@ UncommittedItem::paintNormal(QPainter *p
 
     int width = 100;
     if (m_wide) width = 180;
-    int x0 = -((width - 50) / 2 - 1);
+    int x0 = -scalePixelSize((width - 50) / 2 - 1);
 
-    int height = 49;
+    width = scalePixelSize(width);
+    int half = scalePixelSize(50);
+    int height = scalePixelSize(49);
+    
     QRectF r(x0, 0, width - 3, height);
     paint->setBrush(Qt::white);
     paint->drawRoundedRect(r, 7, 7);
 
     if (m_wide) {
         QString label = tr("Uncommitted changes");
-        paint->drawText(-(fm.width(label) - 50)/2,
-                        25 - fm.height()/2 + fm.ascent(),
+        paint->drawText(-(fm.width(label) - half)/2,
+                        height/2 - fm.height()/2 + fm.ascent(),
                         label);
     } else {
         QString label = tr("Uncommitted");
-        paint->drawText(-(fm.width(label) - 50)/2,
-                        25 - fm.height() + fm.ascent(),
+        paint->drawText(-(fm.width(label) - half)/2,
+                        height/2 - fm.height() + fm.ascent(),
                         label);
         label = tr("changes");
-        paint->drawText(-(fm.width(label) - 50)/2,
-                        25 + fm.ascent(),
+        paint->drawText(-(fm.width(label) - half)/2,
+                        height/2 + fm.ascent(),
                         label);
     }        
 

          
@@ 210,24 217,24 @@ UncommittedItem::paintMerge(QPainter *pa
     int fh = fm.height();
 
     int size = fh * 2;
-    int x0 = -size/2 + 25;
+    int x0 = -size/2 + scalePixelSize(25);
 
     paint->setBrush(Qt::white);
     paint->drawEllipse(QRectF(x0, fh, size, size));
     
     if (m_wide) {
         QString label = tr("Uncommitted merge");
-        paint->drawText(size/2 + 28,
-                        25 - fm.height()/2 + fm.ascent(),
+        paint->drawText(size/2 + scalePixelSize(28),
+                        scalePixelSize(25) - fm.height()/2 + fm.ascent(),
                         label);
     } else {
         QString label = tr("Uncommitted");
-        paint->drawText(size/2 + 28,
-                        25 - fm.height() + fm.ascent(),
+        paint->drawText(size/2 + scalePixelSize(28),
+                        scalePixelSize(25) - fm.height() + fm.ascent(),
                         label);
         label = tr("merge");
-        paint->drawText(size/2 + 28,
-                        25 + fm.ascent(),
+        paint->drawText(size/2 + scalePixelSize(28),
+                        scalePixelSize(25) + fm.ascent(),
                         label);
     }        
 

          
@@ 237,7 244,7 @@ UncommittedItem::paintMerge(QPainter *pa
         paint->setFont(f);
 	int wid = size * 3;
 	QString branch = TextAbbrev::abbreviate(m_branch, QFontMetrics(f), wid);
-	paint->drawText(-wid/2 + 25, fm.ascent() - 4, branch);
+	paint->drawText(-wid/2 + scalePixelSize(25), fm.ascent() - 4, branch);
     }
 
     paint->restore();

          
M src/uncommitteditem.h +4 -2
@@ 21,6 21,8 @@ 
 #include <QGraphicsObject>
 #include <QFont>
 
+#include "common.h"
+
 class UncommittedItem : public QGraphicsObject
 {
     Q_OBJECT

          
@@ 45,8 47,8 @@ public:
     
     int column() const { return m_column; }
     int row() const { return m_row; }
-    void setColumn(int c) { m_column = c; setX(c * 100); }
-    void setRow(int r) { m_row = r; setY(r * 90); }
+    void setColumn(int c) { m_column = c; setX(c * scalePixelSize(100)); }
+    void setRow(int r) { m_row = r; setY(r * scalePixelSize(90)); }
 
     bool isWide() const { return m_wide; }
     void setWide(bool w) { m_wide = w; }