allow to move the selection panel via mouse drag

This commit is contained in:
2026-08-09 22:09:41 +02:00
parent 37a7a7499a
commit 37378e3c1b
8 changed files with 274 additions and 38 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include <QPoint>
#include <QRect>
#include <QWidget>
@@ -25,6 +26,7 @@ class BuildingIconCache;
class ItemIconCache;
class SelectionContent;
class Simulation;
class QMouseEvent;
class QScrollArea;
class QVBoxLayout;
@@ -64,6 +66,14 @@ public:
void placeIn(const QRect& viewRect,
const std::vector<QRect>& occupiedRects) override;
protected:
// The panel is moved by dragging its card header (REQ-UI-SELECTION-PANEL-DRAG). Every
// other mouse event over the panel is swallowed here so that none of them reaches the
// game world beneath (REQ-UI-SELECTION-PANEL).
void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
private:
void handleEvent(std::shared_ptr<const SelectionChangedEvent> event) override;
void handleEvent(std::shared_ptr<const SelectionAnchorChangedEvent> event) override;
@@ -98,10 +108,23 @@ private:
// scrolling view or a moving ship, the side because a card that grows must not flip
// the panel across the object (REQ-UI-SELECTION-PANEL). The side is resolved on the
// first placement after a new anchor, being the first point at which the panel's
// width is known.
// width is known. Dragging the panel supersedes the pair for the rest of the
// selection (REQ-UI-SELECTION-PANEL-DRAG).
QRect m_anchorRect;
std::optional<PanelSide> m_side;
// Where the player dragged the panel, in the game world view's coordinates, and the
// cursor's offset within the panel while a drag is running
// (REQ-UI-SELECTION-PANEL-DRAG). The desired position is kept exactly as dropped:
// resolving it against the view's edges and the widgets the panel steps around never
// writes back to it, so the panel returns to it once the room is there again. It
// lasts as long as the selection it was set in.
std::optional<QPoint> m_desiredTopLeftPx;
std::optional<QPoint> m_dragGrabOffsetPx;
// Origin of the view the panel was last placed in, which is what the two coordinate
// systems differ by -- the panel is a sibling of the view, not a child of it.
QPoint m_viewOriginPx;
// Scrolls the card once it outgrows the space the panel has (REQ-UI-SELECTION-PANEL).
// The card is a child of m_body, not of the panel itself.
QScrollArea* m_scrollArea;