Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/GraphicsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ void GraphicsView::keyReleaseEvent(QKeyEvent *event)

void GraphicsView::mousePressEvent(QMouseEvent *event)
{
// The view may miss the Shift release, for example when another widget has the focus.
// The modifiers of the press are always right.
bool const shift = (event->modifiers() & Qt::ShiftModifier) != 0;
setDragMode(shift ? QGraphicsView::RubberBandDrag : QGraphicsView::ScrollHandDrag);

QGraphicsView::mousePressEvent(event);
if (event->button() == Qt::LeftButton) {
_clickPos = mapToScene(event->pos());
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ add_executable(test_nodes
src/TestZoomFeatures.cpp
src/TestLoopDetection.cpp
src/TestEmbeddedWidgetKeys.cpp
src/TestViewDragMode.cpp
include/ApplicationSetup.hpp
include/TestGraphModel.hpp
include/UITestHelper.hpp
Expand Down
38 changes: 38 additions & 0 deletions test/src/TestViewDragMode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "ApplicationSetup.hpp"
#include "UITestHelper.hpp"

#include <QtNodes/DataFlowGraphModel>
#include <QtNodes/DataFlowGraphicsScene>
#include <QtNodes/GraphicsView>
#include <QtNodes/NodeDelegateModelRegistry>

#include <catch2/catch.hpp>

#include <memory>

using QtNodes::DataFlowGraphicsScene;
using QtNodes::DataFlowGraphModel;
using QtNodes::GraphicsView;
using QtNodes::NodeDelegateModelRegistry;

TEST_CASE("A mouse press without Shift drags the view even if the Shift release was not seen",
"[ui][drag-mode]")
{
auto app = applicationSetup();

DataFlowGraphModel model(std::make_shared<NodeDelegateModelRegistry>());
DataFlowGraphicsScene scene(model);
GraphicsView view(&scene);
view.resize(800, 600);
view.show();
REQUIRE(QTest::qWaitForWindowExposed(&view));
view.setFocus();

QTest::keyPress(&view, Qt::Key_Shift);
REQUIRE(view.dragMode() == QGraphicsView::RubberBandDrag);

// The release goes to another widget, so the view never sees it.
UITestHelper::simulateMousePress(&view, QPointF(0, 0));
CHECK(view.dragMode() == QGraphicsView::ScrollHandDrag);
UITestHelper::simulateMouseRelease(&view, QPointF(0, 0));
}
Loading