Mercurial > hg > svgui
comparison view/View.cpp @ 1401:28075cc658c9
Scale pen for retina display on macOS as well as for hidpi display elsewhere
author | Chris Cannam |
---|---|
date | Thu, 15 Nov 2018 14:04:32 +0000 |
parents | 694004228ab7 |
children | b0eeec95ab5b |
comparison
equal
deleted
inserted
replaced
1400:decb7741d036 | 1401:28075cc658c9 |
---|---|
236 if ((*i)->needsTextLabelHeight()) { | 236 if ((*i)->needsTextLabelHeight()) { |
237 sortedLayers[getObjectExportId(*i)] = *i; | 237 sortedLayers[getObjectExportId(*i)] = *i; |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 int y = ViewManager::scalePixelSize(15) + paint.fontMetrics().ascent(); | 241 int y = scaleSize(15) + paint.fontMetrics().ascent(); |
242 | 242 |
243 for (std::map<int, Layer *>::const_iterator i = sortedLayers.begin(); | 243 for (std::map<int, Layer *>::const_iterator i = sortedLayers.begin(); |
244 i != sortedLayers.end(); ++i) { | 244 i != sortedLayers.end(); ++i) { |
245 if (i->second == layer) break; | 245 if (i->second == layer) break; |
246 y += paint.fontMetrics().height(); | 246 y += paint.fontMetrics().height(); |
672 pb->setTextVisible(false); | 672 pb->setTextVisible(false); |
673 | 673 |
674 QPushButton *cancel = new QPushButton(this); | 674 QPushButton *cancel = new QPushButton(this); |
675 cancel->setIcon(IconLoader().load("cancel")); | 675 cancel->setIcon(IconLoader().load("cancel")); |
676 cancel->setFlat(true); | 676 cancel->setFlat(true); |
677 int scaled20 = ViewManager::scalePixelSize(20); | 677 int scaled20 = scaleSize(20); |
678 cancel->setFixedSize(QSize(scaled20, scaled20)); | 678 cancel->setFixedSize(QSize(scaled20, scaled20)); |
679 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); | 679 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); |
680 | 680 |
681 ProgressBarRec pbr; | 681 ProgressBarRec pbr; |
682 pbr.cancel = cancel; | 682 pbr.cancel = cancel; |
1591 // cerr << "View::getZoomLevelIndex: " << z << " -> " << n << " (max)" | 1591 // cerr << "View::getZoomLevelIndex: " << z << " -> " << n << " (max)" |
1592 // << endl; | 1592 // << endl; |
1593 return n; | 1593 return n; |
1594 } | 1594 } |
1595 | 1595 |
1596 double | |
1597 View::scaleSize(double size) const | |
1598 { | |
1599 static double ratio = 0.0; | |
1600 | |
1601 if (ratio == 0.0) { | |
1602 double baseEm; | |
1603 #ifdef Q_OS_MAC | |
1604 baseEm = 17.0; | |
1605 #else | |
1606 baseEm = 15.0; | |
1607 #endif | |
1608 double em = QFontMetrics(QFont()).height(); | |
1609 ratio = em / baseEm; | |
1610 | |
1611 SVDEBUG << "View::scaleSize: ratio is " << ratio | |
1612 << " (em = " << em << ")" << endl; | |
1613 | |
1614 if (ratio < 1.0) { | |
1615 SVDEBUG << "View::scaleSize: rounding ratio up to 1.0" << endl; | |
1616 ratio = 1.0; | |
1617 } | |
1618 } | |
1619 | |
1620 return size * ratio; | |
1621 } | |
1622 | |
1623 double | |
1624 View::scalePenWidth(double width) const | |
1625 { | |
1626 if (width <= 0) { // zero-width pen, produce a scaled one-pixel pen | |
1627 width = 1; | |
1628 } | |
1629 double ratio = scaleSize(1.0); | |
1630 return width * sqrt(ratio); | |
1631 } | |
1632 | |
1633 QPen | |
1634 View::scalePen(QPen pen) const | |
1635 { | |
1636 return QPen(pen.color(), scalePenWidth(pen.width())); | |
1637 } | |
1638 | |
1596 bool | 1639 bool |
1597 View::areLayerColoursSignificant() const | 1640 View::areLayerColoursSignificant() const |
1598 { | 1641 { |
1599 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { | 1642 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { |
1600 if ((*i)->getLayerColourSignificance() == | 1643 if ((*i)->getLayerColourSignificance() == |
1747 i->second.lastCheck = 0; | 1790 i->second.lastCheck = 0; |
1748 timer->setInterval(2000); | 1791 timer->setInterval(2000); |
1749 timer->start(); | 1792 timer->start(); |
1750 } | 1793 } |
1751 | 1794 |
1752 int scaled20 = ViewManager::scalePixelSize(20); | 1795 int scaled20 = scaleSize(20); |
1753 | 1796 |
1754 cancel->move(0, ph - pb->height()/2 - scaled20/2); | 1797 cancel->move(0, ph - pb->height()/2 - scaled20/2); |
1755 cancel->show(); | 1798 cancel->show(); |
1756 | 1799 |
1757 pb->setValue(completion); | 1800 pb->setValue(completion); |
2168 | 2211 |
2169 bool illuminateThis = | 2212 bool illuminateThis = |
2170 (illuminateFrame >= 0 && i->contains(illuminateFrame)); | 2213 (illuminateFrame >= 0 && i->contains(illuminateFrame)); |
2171 | 2214 |
2172 double h = height(); | 2215 double h = height(); |
2173 double penWidth = PaintAssistant::scalePenWidth(1.0); | 2216 double penWidth = scalePenWidth(1.0); |
2174 double half = penWidth/2.0; | 2217 double half = penWidth/2.0; |
2175 | 2218 |
2176 paint.setPen(QPen(QColor(150, 150, 255), penWidth)); | 2219 paint.setPen(QPen(QColor(150, 150, 255), penWidth)); |
2177 | 2220 |
2178 if (translucent && shouldLabelSelections()) { | 2221 if (translucent && shouldLabelSelections()) { |
2185 paint.drawRect(QRectF(p0, half, p1 - p0, h - penWidth)); | 2228 paint.drawRect(QRectF(p0, half, p1 - p0, h - penWidth)); |
2186 } | 2229 } |
2187 | 2230 |
2188 if (illuminateThis) { | 2231 if (illuminateThis) { |
2189 paint.save(); | 2232 paint.save(); |
2190 penWidth = PaintAssistant::scalePenWidth(2.0); | 2233 penWidth = scalePenWidth(2.0); |
2191 half = penWidth/2.0; | 2234 half = penWidth/2.0; |
2192 paint.setPen(QPen(getForeground(), penWidth)); | 2235 paint.setPen(QPen(getForeground(), penWidth)); |
2193 if (closeToLeft) { | 2236 if (closeToLeft) { |
2194 paint.drawLine(QLineF(p0, half, p1, half)); | 2237 paint.drawLine(QLineF(p0, half, p1, half)); |
2195 paint.drawLine(QLineF(p0, half, p0, h - half)); | 2238 paint.drawLine(QLineF(p0, half, p0, h - half)); |