Engauge Digitizer  2
ViewProfile.cpp
1 #include <QGraphicsRectItem>
2 #include "ViewProfile.h"
3 #include "ViewProfileParameters.h"
4 
5 const int FRAME_WIDTH = 2;
6 
7 // Insert a little space on the left and right so first and last points are visible. Although the
8 // ViewProfile will no longer be exactly aligned with the ViewScale underneath, the difference is insignificant
9 const double SLOP_ON_SIDES = 0.5;
10 
11 ViewProfile::ViewProfile(QGraphicsScene *scene,
12  int minimumWidth,
13  QWidget *parent) :
14  QGraphicsView (scene, parent)
15 {
16  setRenderHint (QPainter::Antialiasing);
17  setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
18  setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
19 
20  setMinimumHeight (160);
21  setMaximumHeight (160);
22  setMinimumWidth (minimumWidth);
23 
24  createFrame ();
25  refit ();
26 }
27 
28 void ViewProfile::createFrame ()
29 {
30  m_frame = new QGraphicsRectItem (0, 0, 100, 100);
31  m_frame->setPen (QPen (QBrush (qRgb (0.0, 0.0, 0.0)), FRAME_WIDTH));
32 
33  scene()->addItem (m_frame);
34 }
35 
36 void ViewProfile::refit ()
37 {
38  // Force the scene boundaries to be the same, even after resizing
39  QRectF bounds = QRectF (VIEW_PROFILE_X_MIN - SLOP_ON_SIDES,
40  VIEW_PROFILE_Y_MIN,
41  VIEW_PROFILE_X_MAX + 2 * SLOP_ON_SIDES,
42  VIEW_PROFILE_Y_MAX);
43  fitInView (bounds);
44  setSceneRect (bounds);
45 }
46 
47 void ViewProfile::resizeEvent(QResizeEvent *event)
48 {
49  refit ();
50 
51  QGraphicsView::resizeEvent (event);
52 }
virtual void resizeEvent(QResizeEvent *event)
Intercept resize events so the geometry can be scaled to perfectly fit into the window.
Definition: ViewProfile.cpp:47
ViewProfile(QGraphicsScene *scene, int minimumWidth, QWidget *parent=0)
Single constructor.
Definition: ViewProfile.cpp:11