@@ -251,39 +251,35 @@ qreal LayoutViewer::computePixelsPerDBU(const QSize& size, const Rect& dbu_rect)
251251 size.height () / (double ) dbu_rect.dy ());
252252}
253253
254- void LayoutViewer::setPixelsPerDBU (qreal pixels_per_dbu )
254+ void LayoutViewer::setPixelsPerDBU (qreal target_pixels_per_dbu )
255255{
256256 if (!hasDesign ()) {
257257 return ;
258258 }
259259
260260 bool scroll_bars_visible = scroller_->horizontalScrollBar ()->isVisible ()
261261 || scroller_->verticalScrollBar ()->isVisible ();
262- bool zoomed_out = pixels_per_dbu_ /* old*/ > pixels_per_dbu /* new*/ ;
262+ bool zoomed_out = pixels_per_dbu_ /* old*/ > target_pixels_per_dbu /* new*/ ;
263263
264264 if (!scroll_bars_visible && zoomed_out) {
265265 return ;
266266 }
267267
268- const Rect current_viewer (0 ,
269- 0 ,
270- this ->size ().width () / pixels_per_dbu_,
271- this ->size ().height () / pixels_per_dbu_);
268+ qreal current_viewer_x = this ->size ().width () / pixels_per_dbu_;
269+ qreal current_viewer_y = this ->size ().height () / pixels_per_dbu_;
272270
273271 // ensure max size is not exceeded
274272 qreal maximum_pixels_per_dbu
275273 = 0.98
276274 * computePixelsPerDBU (QSize (QWIDGETSIZE_MAX, QWIDGETSIZE_MAX),
277- current_viewer);
278- qreal target_pixels_per_dbu
279- = std::min (pixels_per_dbu, maximum_pixels_per_dbu);
275+ Rect (0 , 0 , current_viewer_x, current_viewer_y));
280276
281- if (target_pixels_per_dbu = = maximum_pixels_per_dbu) {
277+ if (target_pixels_per_dbu > = maximum_pixels_per_dbu) {
282278 return ;
283279 }
284280
285- const QSize new_size (ceil (current_viewer. dx () * target_pixels_per_dbu),
286- ceil (current_viewer. dy () * target_pixels_per_dbu));
281+ const QSize new_size (ceil (current_viewer_x * target_pixels_per_dbu),
282+ ceil (current_viewer_y * target_pixels_per_dbu));
287283
288284 resize (new_size);
289285}
@@ -421,17 +417,46 @@ void LayoutViewer::zoom(const odb::Point& focus,
421417
422418void LayoutViewer::zoomTo (const Rect& rect_dbu)
423419{
424- const Rect padded_rect = getPaddedRect (rect_dbu);
425-
426- // set resolution required to view the whole padded rect
427- setPixelsPerDBU (
428- computePixelsPerDBU (scroller_-> maximumViewportSize (), padded_rect) );
420+ qreal pixels_per_DBU
421+ = computePixelsPerDBU (scroller_-> maximumViewportSize (), rect_dbu);
422+ qreal pixels_per_DBU_with_margins
423+ = pixels_per_DBU / ( 1 + 2 * defaultZoomMargin);
424+ setPixelsPerDBU (pixels_per_DBU_with_margins );
429425
430426 // center the layout at the middle of the rect
431427 centerAt (Point (rect_dbu.xMin () + rect_dbu.dx () / 2 ,
432428 rect_dbu.yMin () + rect_dbu.dy () / 2 ));
433429}
434430
431+ void LayoutViewer::zoomTo (const odb::Point& focus, int diameter)
432+ {
433+ odb::Point ref
434+ = odb::Point (focus.x () - (diameter / 2 ), focus.y () - (diameter / 2 ));
435+ zoomTo (odb::Rect (ref.x (), ref.y (), ref.x () + diameter, ref.y () + diameter));
436+ }
437+
438+ int LayoutViewer::getVisibleDiameter ()
439+ {
440+ odb::Rect bounds = getVisibleBounds ();
441+ // scrollbar
442+ int scrollBarWidth
443+ = std::ceil ((qApp->style ()->pixelMetric (QStyle::PM_ScrollBarExtent))
444+ / pixels_per_dbu_);
445+ if (scroller_->verticalScrollBar ()->isVisible ()) {
446+ bounds.set_xhi (bounds.xMax () + scrollBarWidth);
447+ }
448+ if (scroller_->horizontalScrollBar ()->isVisible ()) {
449+ bounds.set_yhi (bounds.yMax () + scrollBarWidth);
450+ }
451+
452+ // undo the margin
453+ const int smaller_side = std::min (bounds.dx (), bounds.dy ());
454+ const int margin = std::ceil (smaller_side * 2 * defaultZoomMargin
455+ / (1 + 2 * defaultZoomMargin));
456+
457+ return std::min (bounds.dx (), bounds.dy ()) - margin;
458+ }
459+
435460int LayoutViewer::edgeToPointDistance (const odb::Point& pt,
436461 const Edge& edge) const
437462{
@@ -1986,6 +2011,8 @@ void LayoutViewer::fullRepaint()
19862011 setLoadingState ();
19872012 viewer_thread_.render (rect, selected_, highlighted_, rulers_, labels_);
19882013 }
2014+
2015+ emit (viewUpdated ());
19892016}
19902017
19912018void LayoutViewer::fit ()
0 commit comments