Engauge Digitizer  2
ViewPreview.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include <QGraphicsScene>
8 #include <QMouseEvent>
9 #include "ViewPreview.h"
10 
11 ViewPreview::ViewPreview(QGraphicsScene *scene,
12  ViewAspectRatio viewAspectRatio,
13  QWidget *parent) :
14  QGraphicsView (scene, parent),
15  m_viewAspectRatio (viewAspectRatio)
16 {
17  setMouseTracking(true);
18 }
19 
20 void ViewPreview::mouseMoveEvent(QMouseEvent *event)
21 {
22  QPointF pos = mapToScene (event->pos ());
23 
24  emit signalMouseMove (pos);
25 }
26 
27 void ViewPreview::resizeEvent(QResizeEvent *event)
28 {
29  if (m_viewAspectRatio == VIEW_ASPECT_RATIO_ONE_TO_ONE) {
30 
31  fitInView (scene()->sceneRect(),
32  Qt::KeepAspectRatio);
33 
34  } else {
35 
36  // Make image fit the new window size. This is needed since QGraphicsView ignores layout stretching
37  fitInView (scene()->itemsBoundingRect ());
38 
39  QGraphicsView::resizeEvent (event);
40  }
41 }
void signalMouseMove(QPointF pos)
Forward the mouse move events.
ViewAspectRatio
Prevent aspect ratio distortion in certain previews by providing fixed 1:1 aspect ratio option...
Definition: ViewPreview.h:21
virtual void mouseMoveEvent(QMouseEvent *event)
Intercept cursor move events and forward them.
Definition: ViewPreview.cpp:20
virtual void resizeEvent(QResizeEvent *event)
Intercept resize events so we can rescale to the graphics items just fit into the resized window...
Definition: ViewPreview.cpp:27
ViewPreview(QGraphicsScene *scene, ViewAspectRatio viewAspectRatio, QWidget *parent=0)
Single constructor.
Definition: ViewPreview.cpp:11