diff --git a/sources/editor/elementprimitivedecorator.cpp b/sources/editor/elementprimitivedecorator.cpp index 3b678a7d4..8c01c3693 100644 --- a/sources/editor/elementprimitivedecorator.cpp +++ b/sources/editor/elementprimitivedecorator.cpp @@ -206,7 +206,13 @@ void ElementPrimitiveDecorator::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { // When moving the selection, consider the position of the first selected item QPointF current_position = scene_pos - mouse_offset_; - QPointF rounded_current_position = snapConstPointToGrid(current_position); + // Snap to the editor's grid, as a single part does (bugtracker + // #112); Ctrl keeps the fine 1-unit step. + ElementScene *element_scene = qobject_cast(scene()); + QPointF rounded_current_position = + (element_scene && !(event->modifiers() & Qt::ControlModifier)) + ? element_scene->snapToGrid(current_position) + : snapConstPointToGrid(current_position); movement = rounded_current_position - decorated_items_.at(0) -> toItem() -> scenePos(); QRectF bounding_rect = modified_bounding_rect_; diff --git a/sources/editor/elementview.cpp b/sources/editor/elementview.cpp index 641581820..588ac2399 100644 --- a/sources/editor/elementview.cpp +++ b/sources/editor/elementview.cpp @@ -538,12 +538,11 @@ void ElementView::drawBackground(QPainter *p, const QRectF &r) { // choisit la granularite de la grille en fonction du zoom en cours // selects the grid granularity according to the current zoom level const ElementViewGrid grid = ElementViewGrid::forZoom(zoom_factor); - const int drawn_x_grid = grid.step; - const int drawn_y_grid = grid.step; + const int grid_step = grid.step; const bool draw_grid = grid.draw_grid; const bool draw_cross = grid.draw_cross; - m_scene->setGrid(drawn_x_grid, drawn_y_grid); + m_scene->setGrid(grid_step, grid_step); if (draw_grid) { // draw the dots of the grid @@ -573,12 +572,12 @@ void ElementView::drawBackground(QPainter *p, const QRectF &r) { qreal limit_y = r.y() + r.height(); int g_x = (int)ceil(r.x()); - while (g_x % drawn_x_grid) ++ g_x; + while (g_x % grid_step) ++ g_x; int g_y = (int)ceil(r.y()); - while (g_y % drawn_y_grid) ++ g_y; + while (g_y % grid_step) ++ g_y; - for (int gx = g_x ; gx < limit_x ; gx += drawn_x_grid) { - for (int gy = g_y ; gy < limit_y ; gy += drawn_y_grid) { + for (int gx = g_x ; gx < limit_x ; gx += grid_step) { + for (int gy = g_y ; gy < limit_y ; gy += grid_step) { if (draw_cross) { if (!(gx % 10) && !(gy % 10)) { p -> drawLine(QLineF(gx - (pen.width()/4.0), gy, gx + (pen.width()/4.0), gy)); diff --git a/tests/qttest/tst_elementviewgrid.cpp b/tests/qttest/tst_elementviewgrid.cpp index 5082666f6..bf3c48e3b 100644 --- a/tests/qttest/tst_elementviewgrid.cpp +++ b/tests/qttest/tst_elementviewgrid.cpp @@ -24,6 +24,14 @@ private slots: QTest::newRow("400 %") << 4.0 << 5 << true << true; QTest::newRow("800 %") << 8.0 << 2 << true << true; QTest::newRow("1000 %") << 10.0 << 1 << true << true; + + // Just below each threshold: the comparisons are strict (<), so a + // change to <= would move these rows into the next band. + QTest::newRow("99.9 %") << 0.999 << 10 << false << false; + QTest::newRow("399.9 %") << 3.999 << 10 << true << false; + QTest::newRow("401 %") << 4.01 << 5 << true << true; + QTest::newRow("799.9 %") << 7.999 << 5 << true << true; + QTest::newRow("999.9 %") << 9.999 << 2 << true << true; } void stepAtZoom()