Divider that can be dragged, in a dialog QGraphicsView.
More...
#include <ViewProfileDivider.h>
|
void | signalMovedLow (double xSceneOther) |
| Signal used when divider is dragged and m_isLowerBoundary is true. More...
|
|
void | signalMovedHigh (double xSceneOther) |
| Signal used when divider is dragged and m_isLowerBoundary is false. More...
|
|
|
| ViewProfileDivider (QGraphicsScene &scene, QGraphicsView &view, int sceneWidth, int sceneHeight, int yCenter, bool isLowerBoundary) |
| Single constructor. More...
|
|
virtual QVariant | itemChange (GraphicsItemChange change, const QVariant &value) |
| Intercept changes so divider movement can be restricted to horizontal direction only. More...
|
|
virtual void | mousePressEvent (QGraphicsSceneMouseEvent *event) |
| Save paddle position at start of click-and-drag. More...
|
|
void | setX (double x, double xLow, double xHigh) |
| Set the position by specifying the new x coordinate. More...
|
|
Divider that can be dragged, in a dialog QGraphicsView.
Click on the paddle to drag. There are three parts:
- Paddle which is the superclass of this class, since we catch its events so dragging works
- Divider which is a vertical line
- Shaded area that extends from xAnchor to the divider
Definition at line 23 of file ViewProfileDivider.h.
◆ 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.
43 m_shadedArea (
nullptr),
44 m_sceneWidth (sceneWidth),
45 m_sceneHeight (sceneHeight),
46 m_isLowerBoundary (isLowerBoundary)
53 setBrush (QBrush (QColor (140, 255, 140)));
56 setFlags (QGraphicsItem::ItemIsMovable |
57 QGraphicsItem::ItemSendsGeometryChanges);
58 setCursor (Qt::OpenHandCursor);
62 m_arrow =
new QGraphicsPolygonItem (
this);
65 m_shadedArea =
new QGraphicsRectItem (
X_INITIAL,
71 m_shadedArea->setPen (Qt::NoPen);
72 m_shadedArea->setZValue (0.0);
73 scene.addItem (m_shadedArea);
78 m_divider =
new QGraphicsLineItem (
X_INITIAL,
81 2 *
SLOP + sceneHeight);
83 m_divider->setZValue (1.0);
84 scene.addItem (m_divider);
const QColor DIVIDER_COLOR
const double SHADED_AREA_OPACITY
const double DIVIDER_WIDTH
const QColor SHADED_AREA_COLOR
◆ 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.
89 if (change == ItemPositionChange && scene ()) {
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));
97 newPos -= m_startDragPos;
101 updateGeometryDivider();
102 updateGeometryNonPaddle ();
109 return QGraphicsRectItem::itemChange (change, value);
◆ mousePressEvent()
void ViewProfileDivider::mousePressEvent |
( |
QGraphicsSceneMouseEvent * |
event | ) |
|
|
virtual |
Save paddle position at start of click-and-drag.
Definition at line 112 of file ViewProfileDivider.cpp.
115 m_startDragPos = QPointF (rect().x () + rect().width () / 2.0,
116 rect().y () + rect().height () / 2.0);
◆ 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.
133 m_xScene = m_sceneWidth * (x - xLow) / (xHigh - xLow);
136 updateGeometryPaddle ();
137 updateGeometryDivider ();
138 updateGeometryNonPaddle ();
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;
147 QPolygonF polygonArrow;
148 if (m_isLowerBoundary) {
151 polygonArrow.push_front (QPointF (xLeft, yTop));
152 polygonArrow.push_front (QPointF (xRight, yMiddle));
153 polygonArrow.push_front (QPointF (xLeft, yBottom));
158 polygonArrow.push_front (QPointF (xRight, yTop));
159 polygonArrow.push_front (QPointF (xLeft, yMiddle));
160 polygonArrow.push_front (QPointF (xRight, yBottom));
162 m_arrow->setPolygon (polygonArrow);
163 m_arrow->setPen (QPen (Qt::black));
const double ARROW_HEIGHT
const QColor ARROW_COLOR(Qt::NoPen)
◆ 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: