Engauge Digitizer 2
Loading...
Searching...
No Matches
Public Types | Signals | Public Member Functions | List of all members
ViewPreview Class Reference

Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window, after resize events. More...

#include <ViewPreview.h>

Inheritance diagram for ViewPreview:
Inheritance graph
Collaboration diagram for ViewPreview:
Collaboration graph

Public Types

enum  ViewAspectRatio { VIEW_ASPECT_RATIO_VARIABLE , VIEW_ASPECT_RATIO_ONE_TO_ONE }
 Prevent aspect ratio distortion in certain previews by providing fixed 1:1 aspect ratio option. More...
 

Signals

void signalMouseMove (QPointF pos)
 Forward the mouse move events.
 

Public Member Functions

 ViewPreview (QGraphicsScene *scene, ViewAspectRatio viewAspectRatio, QWidget *parent=0)
 Single constructor.
 
virtual void mouseMoveEvent (QMouseEvent *event)
 Intercept cursor move events and forward them.
 
virtual void resizeEvent (QResizeEvent *event)
 Intercept resize events so we can rescale to the graphics items just fit into the resized window.
 
virtual void wheelEvent (QWheelEvent *event)
 Intercept wheel event and discard it so accidentally moving the wheel does not move drawn items out of view.
 

Detailed Description

Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window, after resize events.

Definition at line 14 of file ViewPreview.h.

Member Enumeration Documentation

◆ ViewAspectRatio

Prevent aspect ratio distortion in certain previews by providing fixed 1:1 aspect ratio option.

Enumerator
VIEW_ASPECT_RATIO_VARIABLE 
VIEW_ASPECT_RATIO_ONE_TO_ONE 

Definition at line 21 of file ViewPreview.h.

Constructor & Destructor Documentation

◆ ViewPreview()

ViewPreview::ViewPreview ( QGraphicsScene * scene,
ViewAspectRatio viewAspectRatio,
QWidget * parent = 0 )

Single constructor.

Definition at line 12 of file ViewPreview.cpp.

14 :
15 QGraphicsView (scene, parent),
16 m_viewAspectRatio (viewAspectRatio)
17{
18 setMouseTracking(true);
19}
const int INNER_RADIUS_MIN

Member Function Documentation

◆ mouseMoveEvent()

void ViewPreview::mouseMoveEvent ( QMouseEvent * event)
virtual

Intercept cursor move events and forward them.

Definition at line 21 of file ViewPreview.cpp.

22{
23 QPointF pos = mapToScene (event->pos ());
24
26
27 // Normally we would need to call QGraphicsView::mouseMoveEvent at this point so that the mouse move event could be handled,
28 // but this is unwanted since:
29 // 1) Everywhere, except the pdf import preview, there is nothing to drag
30 // 2) Dragging of PdfFrameHandle objects in the pdf import preview is handled indirectly by PdfCropping
31 QGraphicsView::mouseMoveEvent (event);
32}
void signalMouseMove(QPointF pos)
Forward the mouse move events.

◆ resizeEvent()

void ViewPreview::resizeEvent ( QResizeEvent * event)
virtual

Intercept resize events so we can rescale to the graphics items just fit into the resized window.

Definition at line 34 of file ViewPreview.cpp.

35{
36 if (m_viewAspectRatio == VIEW_ASPECT_RATIO_ONE_TO_ONE) {
37
38 fitInView (scene()->sceneRect(),
39 Qt::KeepAspectRatio);
40
41 } else {
42
43 // Make image fit the new window size by using fitInView. This is needed since QGraphicsView ignores layout stretching.
44 // If there is an image then we use its extent, so DlgSettingsGridDisplay with polar coordinates (which can extend well
45 // outside of image) does not end up with tiny image with wasted space around it
46 bool foundImage = false;
47 for (int i = 0; i < scene()->items().count (); i++) {
48 const QGraphicsItem *item = scene()->items().at (i);
49 const QGraphicsPixmapItem *itemPixmap = dynamic_cast<const QGraphicsPixmapItem*> (item);
50 if (itemPixmap != nullptr) {
51 foundImage = true;
52 fitInView (itemPixmap->boundingRect());
53 }
54 }
55
56 if (!foundImage) {
57 // Use the extent of everything
58 fitInView (scene()->itemsBoundingRect ());
59 }
60
61 QGraphicsView::resizeEvent (event);
62 }
63}

◆ signalMouseMove

void ViewPreview::signalMouseMove ( QPointF pos)
signal

Forward the mouse move events.

◆ wheelEvent()

void ViewPreview::wheelEvent ( QWheelEvent * event)
virtual

Intercept wheel event and discard it so accidentally moving the wheel does not move drawn items out of view.

Definition at line 65 of file ViewPreview.cpp.

66{
67 event->accept ();
68}

The documentation for this class was generated from the following files: