allow to move the selection panel via mouse drag
This commit is contained in:
@@ -154,3 +154,78 @@ TEST_CASE("A panel that fits on neither side is pushed inside the view", "[layou
|
||||
kMarginPx);
|
||||
REQUIRE(placed == QRect(700, 100, 300, 200));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Where it stands once the player has dragged it (REQ-UI-SELECTION-PANEL-DRAG)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("A dragged panel stands where it was dropped", "[layout]")
|
||||
{
|
||||
// With room for it there, the desired top-left corner is the answer: nothing about
|
||||
// the selection it describes is consulted any more.
|
||||
const QRect placed = placeAtDesiredTopLeft(makeBand(), QPoint(420, 180),
|
||||
QSize(300, 200), {}, kMarginPx);
|
||||
REQUIRE(placed == QRect(420, 180, 300, 200));
|
||||
}
|
||||
|
||||
TEST_CASE("A panel dragged past the view's edges is pushed back inside", "[layout]")
|
||||
{
|
||||
// Dropped off the right edge and below the bottom, it is brought back within the
|
||||
// band, as an anchored panel is.
|
||||
REQUIRE(placeAtDesiredTopLeft(makeBand(), QPoint(900, 500), QSize(300, 200), {},
|
||||
kMarginPx)
|
||||
== QRect(700, 400, 300, 200));
|
||||
|
||||
// And off the left edge and above the top, the other way.
|
||||
REQUIRE(placeAtDesiredTopLeft(makeBand(), QPoint(-120, -60), QSize(300, 200), {},
|
||||
kMarginPx)
|
||||
== QRect(0, 0, 300, 200));
|
||||
}
|
||||
|
||||
TEST_CASE("A dragged panel rises above the widget it was dropped over", "[layout]")
|
||||
{
|
||||
// The player drops it over the build button bar; it lands above the bar's top by the
|
||||
// margin instead, the bar staying where it is (REQ-UI-BUILD-BAR).
|
||||
const std::vector<QRect> occupied = { QRect(400, 520, 200, 72) };
|
||||
const QRect placed = placeAtDesiredTopLeft(makeBand(), QPoint(450, 480),
|
||||
QSize(300, 200), occupied, kMarginPx);
|
||||
REQUIRE(placed == QRect(450, 312, 300, 200));
|
||||
}
|
||||
|
||||
TEST_CASE("A widget beside a dragged panel's column does not move it", "[layout]")
|
||||
{
|
||||
// Only what the panel's own column meets is in its way: the controls panel in the
|
||||
// bottom-left corner leaves a panel dropped at the right edge alone
|
||||
// (REQ-UI-CONTROLS-PANEL).
|
||||
const std::vector<QRect> occupied = { QRect(0, 300, 260, 300) };
|
||||
const QRect placed = placeAtDesiredTopLeft(makeBand(), QPoint(600, 380),
|
||||
QSize(300, 200), occupied, kMarginPx);
|
||||
REQUIRE(placed == QRect(600, 380, 300, 200));
|
||||
}
|
||||
|
||||
TEST_CASE("A dragged panel too tall for the room left is capped", "[layout]")
|
||||
{
|
||||
// Capping is the caller's cue to scroll here too: a card asking for 700 px over a bar
|
||||
// that leaves 512 px of band gets what there is, from the top of the band.
|
||||
const std::vector<QRect> occupied = { QRect(400, 520, 200, 72) };
|
||||
const QRect placed = placeAtDesiredTopLeft(makeBand(), QPoint(450, 100),
|
||||
QSize(300, 700), occupied, kMarginPx);
|
||||
REQUIRE(placed == QRect(450, 0, 300, 512));
|
||||
}
|
||||
|
||||
TEST_CASE("A dragged panel returns to where it was dropped", "[layout]")
|
||||
{
|
||||
// The resolution never writes back to the desired position: a panel lifted above the
|
||||
// build button bar goes back to the point the player dropped it at as soon as the bar
|
||||
// stops meeting its column -- here because the bar's button set shrank.
|
||||
const QPoint desired(450, 380);
|
||||
const std::vector<QRect> wideBar = { QRect(400, 520, 200, 72) };
|
||||
REQUIRE(placeAtDesiredTopLeft(makeBand(), desired, QSize(300, 200), wideBar,
|
||||
kMarginPx)
|
||||
== QRect(450, 312, 300, 200));
|
||||
|
||||
const std::vector<QRect> narrowBar = { QRect(400, 520, 40, 72) };
|
||||
REQUIRE(placeAtDesiredTopLeft(makeBand(), desired, QSize(300, 200), narrowBar,
|
||||
kMarginPx)
|
||||
== QRect(450, 380, 300, 200));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user