Mercurial > hg > easyhg
changeset 678:c0b46d0514a7 scale
Incomplete scaling updates. Should do this differently
author | Chris Cannam |
---|---|
date | Thu, 06 Dec 2018 14:55:45 +0000 |
parents | 0329bbd4b57c |
children | |
files | src/changesetdetailitem.cpp src/changesetitem.cpp src/changesetitem.h src/changesetscene.cpp src/changesetview.cpp src/common.cpp src/common.h src/connectionitem.cpp src/uncommitteditem.cpp src/uncommitteditem.h |
diffstat | 10 files changed, 96 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/src/changesetdetailitem.cpp Thu Dec 06 13:54:34 2018 +0000 +++ b/src/changesetdetailitem.cpp Thu Dec 06 14:55:45 2018 +0000 @@ -30,7 +30,7 @@ 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);
--- a/src/changesetitem.cpp Thu Dec 06 13:54:34 2018 +0000 +++ b/src/changesetitem.cpp Thu Dec 06 14:55:45 2018 +0000 @@ -22,6 +22,7 @@ #include "textabbrev.h" #include "colourset.h" #include "debug.h" +#include "common.h" #include <QPainter> #include <QGraphicsScene> @@ -41,7 +42,7 @@ 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 @@ { 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 @@ 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 @@ 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 @@ 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 @@ 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;
--- a/src/changesetitem.h Thu Dec 06 13:54:34 2018 +0000 +++ b/src/changesetitem.h Thu Dec 06 14:55:45 2018 +0000 @@ -21,6 +21,8 @@ #include <QGraphicsObject> #include <QFont> +#include "common.h" + class Changeset; class ChangesetDetailItem; @@ -43,8 +45,8 @@ 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; }
--- a/src/changesetscene.cpp Thu Dec 06 13:54:34 2018 +0000 +++ b/src/changesetscene.cpp Thu Dec 06 14:55:45 2018 +0000 @@ -120,7 +120,7 @@ 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) {
--- a/src/changesetview.cpp Thu Dec 06 13:54:34 2018 +0000 +++ b/src/changesetview.cpp Thu Dec 06 14:55:45 2018 +0000 @@ -19,6 +19,7 @@ #include "changesetscene.h" #include "colourset.h" #include "debug.h" +#include "common.h" #include <QScrollBar> @@ -76,11 +77,13 @@ 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();
--- a/src/common.cpp Thu Dec 06 13:54:34 2018 +0000 +++ b/src/common.cpp Thu Dec 06 14:55:45 2018 +0000 @@ -23,6 +23,8 @@ #include <QStringList> #include <QDir> #include <QRegExp> +#include <QFont> +#include <QFontMetrics> #include <sys/types.h> @@ -352,3 +354,23 @@ 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; +} +
--- a/src/common.h Thu Dec 06 13:54:34 2018 +0000 +++ b/src/common.h Thu Dec 06 14:55:45 2018 +0000 @@ -69,7 +69,8 @@ * Generate a 16-byte random key using urandom or equivalent */ QByteArray randomKey(); - + +int scalePixelSize(int pixels); #endif //COMMON_H
--- a/src/connectionitem.cpp Thu Dec 06 13:54:34 2018 +0000 +++ b/src/connectionitem.cpp Thu Dec 06 14:55:45 2018 +0000 @@ -22,6 +22,7 @@ #include "changeset.h" #include "colourset.h" #include "textabbrev.h" +#include "common.h" #include <QPainter> #include <QFont> @@ -30,9 +31,9 @@ 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 @@ 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 @@ 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 @@ // 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 @@ // 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 @@ paint->setClipping(false); QFont f; - f.setPixelSize(11); + f.setPixelSize(scalePixelSize(11)); f.setBold(true); f.setItalic(false); paint->setFont(f);
--- a/src/uncommitteditem.cpp Thu Dec 06 13:54:34 2018 +0000 +++ b/src/uncommitteditem.cpp Thu Dec 06 14:55:45 2018 +0000 @@ -19,6 +19,7 @@ #include "colourset.h" #include "debug.h" #include "textabbrev.h" +#include "common.h" #include <QPainter> #include <QGraphicsScene> @@ -33,7 +34,7 @@ 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 @@ //!!! 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 @@ 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 @@ 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 @@ 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();
--- a/src/uncommitteditem.h Thu Dec 06 13:54:34 2018 +0000 +++ b/src/uncommitteditem.h Thu Dec 06 14:55:45 2018 +0000 @@ -21,6 +21,8 @@ #include <QGraphicsObject> #include <QFont> +#include "common.h" + class UncommittedItem : public QGraphicsObject { Q_OBJECT @@ -45,8 +47,8 @@ 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; }