10#include <QGraphicsLineItem>
11#include <QGraphicsPolygonItem>
12#include <QGraphicsScene>
13#include <QGraphicsSceneMouseEvent>
14#include <QGraphicsView>
35 bool isLowerBoundary) :
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);
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);
115 m_startDragPos = QPointF (rect().x () + rect().width () / 2.0,
116 rect().y () + rect().height () / 2.0);
119void ViewProfileDivider::sendSignalMoved ()
121 if (m_isLowerBoundary) {
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));
167void ViewProfileDivider::slotOtherMoved(
double xSceneOther)
169 m_xSceneOther = xSceneOther;
170 updateGeometryNonPaddle ();
173void ViewProfileDivider::updateGeometryDivider ()
175 m_divider->setLine (m_xScene,
178 2 *
SLOP + m_sceneHeight);
181void ViewProfileDivider::updateGeometryNonPaddle()
183 if (m_isLowerBoundary) {
184 if (m_xScene <= m_xSceneOther) {
187 m_shadedArea->setRect (-
SLOP,
190 2 *
SLOP + m_sceneHeight);
195 m_shadedArea->setRect (m_xSceneOther,
197 m_xScene - m_xSceneOther,
198 2 *
SLOP + m_sceneHeight);
203 if (m_xSceneOther <= m_xScene) {
206 m_shadedArea->setRect (m_xScene,
208 SLOP + m_sceneWidth - m_xScene,
209 2 *
SLOP + m_sceneHeight);
215 m_shadedArea->setRect (m_xSceneOther,
218 2 *
SLOP + m_sceneHeight);
223void ViewProfileDivider::updateGeometryPaddle ()
const double DIVIDER_WIDTH
const QColor DIVIDER_COLOR
const QColor ARROW_COLOR(Qt::NoPen)
const double SHADED_AREA_OPACITY
const QColor SHADED_AREA_COLOR
const double ARROW_HEIGHT
void signalMovedHigh(double xSceneOther)
Signal used when divider is dragged and m_isLowerBoundary is false.
void signalMovedLow(double xSceneOther)
Signal used when divider is dragged and m_isLowerBoundary is true.
void setX(double x, double xLow, double xHigh)
Set the position by specifying the new x coordinate.
ViewProfileDivider(QGraphicsScene &scene, QGraphicsView &view, int sceneWidth, int sceneHeight, int yCenter, bool isLowerBoundary)
Single constructor.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
Save paddle position at start of click-and-drag.
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Intercept changes so divider movement can be restricted to horizontal direction only.