Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/application/LayoutCanvasRendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ bool LayoutCanvasCamera::handleKeyRelease(QKeyEvent* event) {
}

bool LayoutCanvasCamera::beginPan(QMouseEvent* event) {
if (event->button() != Qt::MiddleButton && !(event->button() == Qt::LeftButton && spacePressed_)) {
if (event->button() != Qt::MiddleButton
&& !(event->button() == Qt::LeftButton && (spacePressed_ || allowLeftDragPan_))) {
return false;
}

Expand Down Expand Up @@ -495,6 +496,9 @@ bool LayoutCanvasCamera::zoomAt(QWheelEvent* event, const LayoutCanvasBounds& bo
void LayoutCanvasCamera::reset() {
zoom_ = 1.0;
panOffset_ = {};
panning_ = false;
panButton_ = Qt::NoButton;
lastMousePosition_ = {};
}

void includeLayoutCanvasPoint(LayoutCanvasBounds& bounds, const safecrowd::domain::Point2D& point) {
Expand Down
5 changes: 5 additions & 0 deletions src/application/LayoutCanvasRendering.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class LayoutCanvasCamera {
bool zoomAt(QWheelEvent* event, const LayoutCanvasBounds& bounds, const QRectF& viewport);
void reset();

void setAllowLeftDragPan(bool allow) noexcept {
allowLeftDragPan_ = allow;
}

double zoom() const noexcept {
return zoom_;
}
Expand Down Expand Up @@ -88,6 +92,7 @@ class LayoutCanvasCamera {
Qt::MouseButton panButton_{Qt::NoButton};
bool panning_{false};
bool spacePressed_{false};
bool allowLeftDragPan_{false};
};

void includeLayoutCanvasPoint(LayoutCanvasBounds& bounds, const safecrowd::domain::Point2D& point);
Expand Down
4 changes: 4 additions & 0 deletions src/application/SimulationCanvasWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ SimulationCanvasWidget::SimulationCanvasWidget(safecrowd::domain::FacilityLayout
setFocusPolicy(Qt::StrongFocus);
setMinimumSize(520, 360);
setStyleSheet("QWidget { background: #f4f7fb; }");
camera_.setAllowLeftDragPan(true);
currentFloorId_ = defaultFloorId(layout_);
layoutBounds_ = collectLayoutCanvasBounds(layout_, currentFloorId_);
QCoreApplication::instance()->installEventFilter(this);
Expand Down Expand Up @@ -214,6 +215,7 @@ void SimulationCanvasWidget::keyReleaseEvent(QKeyEvent* event) {
void SimulationCanvasWidget::mouseDoubleClickEvent(QMouseEvent* event) {
if (event->button() == Qt::LeftButton) {
camera_.reset();
unsetCursor();
layoutCacheValid_ = false;
update();
event->accept();
Expand All @@ -234,13 +236,15 @@ void SimulationCanvasWidget::mouseMoveEvent(QMouseEvent* event) {
void SimulationCanvasWidget::mousePressEvent(QMouseEvent* event) {
setFocus(Qt::MouseFocusReason);
if (camera_.beginPan(event)) {
setCursor(Qt::SizeAllCursor);
return;
}
QWidget::mousePressEvent(event);
}

void SimulationCanvasWidget::mouseReleaseEvent(QMouseEvent* event) {
if (camera_.finishPan(event)) {
unsetCursor();
return;
}
QWidget::mouseReleaseEvent(event);
Expand Down
Loading