Mercurial > hg > svgui
diff layer/PaintAssistant.cpp @ 1228:dc6457ac4d07
Add method to scale pen widths for hi-res screens
author | Chris Cannam |
---|---|
date | Thu, 26 Jan 2017 21:17:19 +0000 |
parents | 1badacff7ab2 |
children | a34a2a25907c |
line wrap: on
line diff
--- a/layer/PaintAssistant.cpp Thu Jan 26 21:16:46 2017 +0000 +++ b/layer/PaintAssistant.cpp Thu Jan 26 21:17:19 2017 +0000 @@ -19,6 +19,7 @@ #include "base/AudioLevel.h" #include "base/Strings.h" +#include "base/Debug.h" #include <QPaintDevice> #include <QPainter> @@ -262,3 +263,42 @@ std::cerr << "ERROR: PaintAssistant::drawVisibleText: Boxed style not yet implemented!" << std::endl; } } + +double +PaintAssistant::scalePenWidth(double width) +{ + 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; + + SVDEBUG << "PaintAssistant::scalePenWidth: ratio is " << ratio + << " (em = " << em << ")" << endl; + } + + if (ratio <= 1.0) { + // we only ever scale up in this method + return width; + } + + if (width <= 0) { + // zero-width pen, produce a scaled one-pixel pen + return ratio; + } + + return width * ratio; +} + +QPen +PaintAssistant::scalePen(QPen pen) +{ + return QPen(pen.color(), scalePenWidth(pen.width())); +} + +