Commit 4dafee79 authored by Alexander Semke's avatar Alexander Semke

[worksheet] drag the plot axis to change the visible data region.

parent 37eede8e
......@@ -2066,6 +2066,51 @@ void AxisPrivate::hoverLeaveEvent(QGraphicsSceneHoverEvent*) {
}
}
void AxisPrivate::mousePressEvent(QGraphicsSceneMouseEvent* event) {
auto* plot = static_cast<CartesianPlot*>(q->parentAspect());
if (!plot->isLocked()) {
m_panningStarted = true;
m_panningStart = event->pos();
} else
QGraphicsItem::mousePressEvent(event);
}
void AxisPrivate::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
if (m_panningStarted) {
if (orientation == WorksheetElement::Orientation::Horizontal) {
setCursor(Qt::SizeHorCursor);
const int deltaXScene = (m_panningStart.x() - event->pos().x());
if (abs(deltaXScene) < 5)
return;
auto* plot = static_cast<CartesianPlot*>(q->parentAspect());
if (deltaXScene > 0)
plot->shiftRightX();
else
plot->shiftLeftX();
} else {
setCursor(Qt::SizeVerCursor);
const int deltaYScene = (m_panningStart.y() - event->pos().y());
if (abs(deltaYScene) < 5)
return;
auto* plot = static_cast<CartesianPlot*>(q->parentAspect());
if (deltaYScene > 0)
plot->shiftUpY();
else
plot->shiftDownY();
}
m_panningStart = event->pos();
}
}
void AxisPrivate::mouseReleaseEvent(QGraphicsSceneMouseEvent*) {
setCursor(Qt::ArrowCursor);
m_panningStarted = false;
}
void AxisPrivate::setPrinting(bool on) {
m_printing = on;
}
......
......@@ -147,6 +147,9 @@ private:
void contextMenuEvent(QGraphicsSceneContextMenuEvent*) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent*) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override;
void mousePressEvent(QGraphicsSceneMouseEvent*) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent*) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget* widget = nullptr) override;
void addArrow(QPointF point, int direction);
......@@ -169,6 +172,8 @@ private:
bool m_hovered{false};
bool m_suppressRecalc{false};
bool m_printing{false};
bool m_panningStarted{false};
QPointF m_panningStart;
};
#endif
......@@ -1762,7 +1762,7 @@ void CartesianPlot::curveLinePenChanged(QPen pen) {
emit curveLinePenChanged(pen, curve->name());
}
void CartesianPlot::setMouseMode(const MouseMode mouseMode) {
void CartesianPlot::setMouseMode(MouseMode mouseMode) {
Q_D(CartesianPlot);
d->mouseMode = mouseMode;
......@@ -1800,6 +1800,11 @@ void CartesianPlot::setLocked(bool locked) {
d->locked = locked;
}
bool CartesianPlot::isLocked() const {
Q_D(const CartesianPlot);
return d->locked;
}
bool CartesianPlot::scaleAutoX() {
Q_D(CartesianPlot);
if (d->curvesXMinMaxIsDirty) {
......
......@@ -102,8 +102,9 @@ public:
QVector<AbstractAspect*> dependsOn() const override;
void setRect(const QRectF&) override;
QRectF dataRect() const;
void setMouseMode(const MouseMode);
void setLocked(const bool);
void setMouseMode(MouseMode);
void setLocked(bool);
bool isLocked() const;
MouseMode mouseMode() const;
void navigate(NavigationOperation);
void setSuppressDataChangedSignal(bool);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment