From f5bfeb3eae299339483f2f534de146e9708cf81b Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Sat, 6 Nov 2021 13:41:15 +0100 Subject: [PATCH] Fix auto-scaling of the grid over the displayed area. * Bug: In CellWidget::drawGrid(), the scaling of grid was never recomputed according to the zoom level. So in low zoom, it was too fine and hidding everything underneath... Now always display between 1 and 10 lines. Lines are put on the grid step. Makes the grid draw in dotted lines, seems to looks nicer. --- hurricane/src/viewer/CellWidget.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/hurricane/src/viewer/CellWidget.cpp b/hurricane/src/viewer/CellWidget.cpp index 24d0d75a..6f24daeb 100644 --- a/hurricane/src/viewer/CellWidget.cpp +++ b/hurricane/src/viewer/CellWidget.cpp @@ -370,7 +370,7 @@ namespace Hurricane { { _normalPen = pen; _linePen = pen; - _linePen.setStyle( Qt::SolidLine ); + //_linePen.setStyle( Qt::SolidLine ); #if 0 //#if (QT_VERSION == QT_VERSION_CHECK(4,8,5)) @@ -1841,17 +1841,26 @@ namespace Hurricane { // _drawingPlanes.select ( PlaneId::Normal ); // _drawingPlanes.begin (); // _drawingPlanes.painter().setClipRect( redrawArea ); - _drawingPlanes.setPen ( Graphics::getPen (("grid"), getDarkening() )); + QPen pen = Graphics::getPen( ("grid"), getDarkening() ); + pen.setStyle( Qt::DashLine ); + _drawingPlanes.setPen ( pen ); + //_drawingPlanes.setPen ( Graphics::getPen (("grid"), getDarkening() )); _drawingPlanes.setBrush( Graphics::getBrush(("grid"), getDarkening() )); Box redrawBox = screenToDbuBox( redrawArea ).inflate( DbU::lambda(1.0) ); //bool detailedGrid = _underDetailedGridThreshold(); + DbU::Unit longerSide = std::max( _screenArea.getWidth(), _screenArea.getHeight() ); + double scale = std::pow( 10.0 + , std::max( 1.0 + , std::floor( std::log10( longerSide / _snapGridStep() )))); + DbU::Unit gridStep = ((symbolicMode()) ? 1 : 10) * _snapGridStep(); - DbU::Unit superGridStep = gridStep*10; + DbU::Unit superGridStep = _snapGridStep() * scale; DbU::Unit xGrid; DbU::Unit yGrid; QPoint center; + //cerr << "scale=" << scale << " superGridstep=" << DbU::getValueString(superGridStep) << endl; #if 0 cerr << "CellWidget::drawGrid() step:" << DbU::getValueString(gridStep)