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