Engauge Digitizer 2
Loading...
Searching...
No Matches
ViewProfileDivider Class Reference

Divider that can be dragged, in a dialog QGraphicsView. More...

#include <ViewProfileDivider.h>

Inheritance diagram for ViewProfileDivider:
Inheritance graph
Collaboration diagram for ViewProfileDivider:
Collaboration graph

Signals

void signalMovedLow (double xSceneOther)
 Signal used when divider is dragged and m_isLowerBoundary is true.
void signalMovedHigh (double xSceneOther)
 Signal used when divider is dragged and m_isLowerBoundary is false.

Public Member Functions

 ViewProfileDivider (QGraphicsScene &scene, QGraphicsView &view, int sceneWidth, int sceneHeight, int yCenter, bool isLowerBoundary)
 Single constructor.
virtual QVariant itemChange (GraphicsItemChange change, const QVariant &value)
 Intercept changes so divider movement can be restricted to horizontal direction only.
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event)
 Save paddle position at start of click-and-drag.
void setX (double x, double xLow, double xHigh)
 Set the position by specifying the new x coordinate.

Detailed Description

Divider that can be dragged, in a dialog QGraphicsView.

Click on the paddle to drag. There are three parts:

  1. Paddle which is the superclass of this class, since we catch its events so dragging works
  2. Divider which is a vertical line
  3. Shaded area that extends from xAnchor to the divider

Definition at line 23 of file ViewProfileDivider.h.

Constructor & Destructor Documentation

◆ ViewProfileDivider()

ViewProfileDivider::ViewProfileDivider ( QGraphicsScene & scene,
QGraphicsView & view,
int sceneWidth,
int sceneHeight,
int yCenter,
bool isLowerBoundary )

Single constructor.

Definition at line 30 of file ViewProfileDivider.cpp.

35 :
36 QGraphicsRectItem (X_INITIAL,
37 0,
40 m_view (view),
41 m_yCenter (yCenter),
42 m_divider (nullptr),
43 m_shadedArea (nullptr),
44 m_sceneWidth (sceneWidth),
45 m_sceneHeight (sceneHeight),
46 m_isLowerBoundary (isLowerBoundary)
47{
48 // Initial positions will not appear since they are overridden by setX
49
50 // Paddle
51 setVisible (true);
52 setPen (QPen (DIVIDER_COLOR));
53 setBrush (QBrush (QColor (140, 255, 140)));
54 setOpacity (1.0);
55 scene.addItem (this);
56 setFlags (QGraphicsItem::ItemIsMovable |
57 QGraphicsItem::ItemSendsGeometryChanges);
58 setCursor (Qt::OpenHandCursor);
59 setZValue (2.0);
60
61 // Arrow on paddle
62 m_arrow = new QGraphicsPolygonItem (this);
63
64 // Shaded area
65 m_shadedArea = new QGraphicsRectItem (X_INITIAL,
66 0,
67 0,
68 sceneHeight - 1);
69 m_shadedArea->setOpacity (SHADED_AREA_OPACITY);
70 m_shadedArea->setBrush (QBrush (SHADED_AREA_COLOR));
71 m_shadedArea->setPen (Qt::NoPen);
72 m_shadedArea->setZValue (0.0);
73 scene.addItem (m_shadedArea);
74
75 // Vertical divider. This is not made a child of the paddle since that will force the divider
76 // to always be drawn above the paddle, rather than underneath the paddle as we want. Even setting
77 // the z values will not succeed in drawing the divider under the paddle if they are child-parent.
78 m_divider = new QGraphicsLineItem (X_INITIAL,
79 -SLOP,
81 2 * SLOP + sceneHeight);
82 m_divider->setPen (QPen (QBrush (DIVIDER_COLOR), DIVIDER_WIDTH));
83 m_divider->setZValue (1.0);
84 scene.addItem (m_divider);
85}
const double DIVIDER_WIDTH
const QColor DIVIDER_COLOR
const int PADDLE_HEIGHT
const int X_INITIAL
const double SHADED_AREA_OPACITY
const QColor SHADED_AREA_COLOR
const int PADDLE_WIDTH
const int SLOP

Member Function Documentation

◆ itemChange()

QVariant ViewProfileDivider::itemChange ( GraphicsItemChange change,
const QVariant & value )
virtual

Intercept changes so divider movement can be restricted to horizontal direction only.

Definition at line 87 of file ViewProfileDivider.cpp.

88{
89 if (change == ItemPositionChange && scene ()) {
90
91 // Clip x coordinate, in pixel coordinates. Y coordinate stays the same (by setting delta to zero)
92 QPointF newPos = QPointF (value.toPointF().x(), 0.0) + m_startDragPos;
93 double newX = newPos.x();
94 newX = qMax (newX, 0.0);
95 newX = qMin (newX, double (m_sceneWidth));
96 newPos.setX (newX);
97 newPos -= m_startDragPos; // Change from absolute coordinates back to relative coordinates
98
99 // Before returning newPos for the paddle, we apply its movement to the divider and shaded area
100 m_xScene = newX;
101 updateGeometryDivider();
102 updateGeometryNonPaddle ();
103
104 sendSignalMoved ();
105
106 return newPos;
107 }
108
109 return QGraphicsRectItem::itemChange (change, value);
110}

◆ mousePressEvent()

void ViewProfileDivider::mousePressEvent ( QGraphicsSceneMouseEvent * event)
virtual

Save paddle position at start of click-and-drag.

Definition at line 112 of file ViewProfileDivider.cpp.

113{
114 // Since the cursor position is probably not in the center of the paddle, we save the paddle center
115 m_startDragPos = QPointF (rect().x () + rect().width () / 2.0,
116 rect().y () + rect().height () / 2.0);
117}

◆ setX()

void ViewProfileDivider::setX ( double x,
double xLow,
double xHigh )

Set the position by specifying the new x coordinate.

Definition at line 128 of file ViewProfileDivider.cpp.

131{
132 // Convert to screen coordinates
133 m_xScene = m_sceneWidth * (x - xLow) / (xHigh - xLow);
134 sendSignalMoved ();
135
136 updateGeometryPaddle ();
137 updateGeometryDivider ();
138 updateGeometryNonPaddle ();
139
140 // Triangle vertices
141 double xLeft = rect().left() + rect().width() / 2.0 - ARROW_WIDTH / 2.0;
142 double xRight = rect().left() + rect().width() / 2.0 + ARROW_WIDTH / 2.0;
143 double yTop = rect().top() + rect().height() / 2.0 - ARROW_HEIGHT / 2.0;
144 double yMiddle = rect().top() + rect().height() / 2.0;
145 double yBottom = rect().top() + rect().height() / 2.0 + ARROW_HEIGHT / 2.0;
146
147 QPolygonF polygonArrow;
148 if (m_isLowerBoundary) {
149
150 // Draw arrow pointing to the right
151 polygonArrow.push_front (QPointF (xLeft, yTop));
152 polygonArrow.push_front (QPointF (xRight, yMiddle));
153 polygonArrow.push_front (QPointF (xLeft, yBottom));
154
155 } else {
156
157 // Draw arrow pointing to the left
158 polygonArrow.push_front (QPointF (xRight, yTop));
159 polygonArrow.push_front (QPointF (xLeft, yMiddle));
160 polygonArrow.push_front (QPointF (xRight, yBottom));
161 }
162 m_arrow->setPolygon (polygonArrow);
163 m_arrow->setPen (QPen (Qt::black));
164 m_arrow->setBrush (QBrush (ARROW_COLOR));
165}
const double ARROW_WIDTH
const QColor ARROW_COLOR(Qt::NoPen)
const double ARROW_HEIGHT

◆ signalMovedHigh

void ViewProfileDivider::signalMovedHigh ( double xSceneOther)
signal

Signal used when divider is dragged and m_isLowerBoundary is false.

◆ signalMovedLow

void ViewProfileDivider::signalMovedLow ( double xSceneOther)
signal

Signal used when divider is dragged and m_isLowerBoundary is true.


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