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 #ifndef VIEW_PREVIEW_H
8 #define VIEW_PREVIEW_H
9 
10 #include <QGraphicsView>
11 #include <QPointF>
12 
13 /// Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window, after resize events.
14 class ViewPreview : public QGraphicsView
15 {
16   Q_OBJECT;
17 
18 public:
19 
20   /// Prevent aspect ratio distortion in certain previews by providing fixed 1:1 aspect ratio option
21   enum ViewAspectRatio {
22     VIEW_ASPECT_RATIO_VARIABLE,
23     VIEW_ASPECT_RATIO_ONE_TO_ONE
24   };
25 
26   /// Single constructor.
27   ViewPreview(QGraphicsScene *scene,
28               ViewAspectRatio viewAspectRatio,
29               QWidget *parent = 0);
30 
31   /// Intercept cursor move events and forward them
32   virtual void mouseMoveEvent(QMouseEvent *event);
33 
34   /// Intercept resize events so we can rescale to the graphics items just fit into the resized window.
35   virtual void resizeEvent(QResizeEvent *event);
36 
37   /// Intercept wheel event and discard it so accidentally moving the wheel does not move drawn items out of view
38   virtual void wheelEvent (QWheelEvent *event);
39 
40 signals:
41   /// Forward the mouse move events
42   void signalMouseMove (QPointF pos);
43 
44 private:
45   ViewPreview();
46 
47   ViewAspectRatio m_viewAspectRatio;
48 
49 };
50 
51 #endif // VIEW_PREVIEW_H
52