put the controls panel in the corner and let it step around the build bar
This commit is contained in:
@@ -139,9 +139,10 @@ ControlsPanel::ControlsPanel(const GameWorldView* view, QWidget* parent)
|
||||
refresh();
|
||||
}
|
||||
|
||||
void ControlsPanel::anchorTo(const QRect& bandRect)
|
||||
void ControlsPanel::anchorTo(const QRect& worldRect, const QRect& buildBarRect)
|
||||
{
|
||||
m_bandRect = bandRect;
|
||||
m_worldRect = worldRect;
|
||||
m_buildBarRect = buildBarRect;
|
||||
refit();
|
||||
}
|
||||
|
||||
@@ -258,7 +259,7 @@ QString ControlsPanel::getHeadingText(const ControlContext& context) const
|
||||
|
||||
void ControlsPanel::refit()
|
||||
{
|
||||
if (m_bandRect.isNull()) { return; }
|
||||
if (m_worldRect.isNull()) { return; }
|
||||
|
||||
// Rows are torn down and rebuilt wholesale, and a widget added to a layout is only
|
||||
// shown once that layout runs -- without this the new rows count for nothing and
|
||||
@@ -277,13 +278,26 @@ void ControlsPanel::refit()
|
||||
layout()->invalidate();
|
||||
const QSize needed = layout()->totalSizeHint();
|
||||
|
||||
const QRect band = m_bandRect.adjusted(kMarginPx, kMarginPx, -kMarginPx, -kMarginPx);
|
||||
const QRect band = m_worldRect.adjusted(kMarginPx, kMarginPx, -kMarginPx, -kMarginPx);
|
||||
if (band.width() <= 0 || band.height() <= 0) { return; }
|
||||
|
||||
// The bottom-left corner of the view, growing upward as rows are added
|
||||
// (REQ-UI-CONTROLS-PANEL).
|
||||
const int widthPx = qMin(needed.width(), band.width());
|
||||
const int heightPx = qMin(needed.height(), band.height());
|
||||
int heightPx = qMin(needed.height(), band.height());
|
||||
int topPx = band.bottom() - heightPx + 1;
|
||||
|
||||
// Left edge of the band, sitting on its bottom edge, so the panel grows upward as
|
||||
// rows are added (REQ-UI-CONTROLS-PANEL).
|
||||
setGeometry(band.left(), band.bottom() - heightPx + 1, widthPx, heightPx);
|
||||
// The build button bar is centered and sized to its buttons, so it usually leaves
|
||||
// this corner free and the panel can share the bottom edge with it. Only when the
|
||||
// two would actually overlap does the panel rise, clearing the bar's top by the
|
||||
// same margin it keeps from the view's edges (REQ-UI-BUILD-BAR).
|
||||
const QRect wanted(band.left(), topPx, widthPx, heightPx);
|
||||
if (!m_buildBarRect.isNull() && wanted.intersects(m_buildBarRect))
|
||||
{
|
||||
const int availablePx = m_buildBarRect.top() - kMarginPx - band.top();
|
||||
heightPx = qMin(heightPx, qMax(0, availablePx));
|
||||
topPx = m_buildBarRect.top() - kMarginPx - heightPx;
|
||||
}
|
||||
|
||||
setGeometry(band.left(), topPx, widthPx, heightPx);
|
||||
}
|
||||
|
||||
@@ -38,11 +38,13 @@ public:
|
||||
// selection.
|
||||
ControlsPanel(const GameWorldView* view, QWidget* parent = nullptr);
|
||||
|
||||
// Confines the panel to the given band of the game world view: it left-aligns
|
||||
// within it and sits on its bottom edge. The band is the world view less the strip
|
||||
// the build button bar occupies, so the two never overlap and the bar never has to
|
||||
// move (REQ-UI-CONTROLS-PANEL, REQ-UI-BUILD-BAR).
|
||||
void anchorTo(const QRect& bandRect);
|
||||
// Places the panel in the bottom-left corner of the game world view. It shares the
|
||||
// bottom edge with the build button bar rather than clearing its strip, the bar
|
||||
// being centered and sized to its buttons and so usually leaving the left free; it
|
||||
// rises above the bar only when the two would otherwise overlap. `buildBarRect` is
|
||||
// the bar's current geometry in the same coordinates, or a null rect when there is
|
||||
// none to avoid (REQ-UI-CONTROLS-PANEL, REQ-UI-BUILD-BAR).
|
||||
void anchorTo(const QRect& worldRect, const QRect& buildBarRect);
|
||||
|
||||
protected:
|
||||
// Clicking the heading collapses and expands the panel (REQ-UI-CONTROLS-PANEL).
|
||||
@@ -77,7 +79,8 @@ private:
|
||||
// command (REQ-UI-CONTROLS-PANEL).
|
||||
bool m_collapsed = false;
|
||||
|
||||
// The band the panel confines itself to, in the coordinates of its parent; null
|
||||
// until the owner has anchored it for the first time.
|
||||
QRect m_bandRect;
|
||||
// The world view the panel sits in, and the build button bar it steps around, both
|
||||
// in the coordinates of its parent. Null until the owner has anchored it.
|
||||
QRect m_worldRect;
|
||||
QRect m_buildBarRect;
|
||||
};
|
||||
|
||||
@@ -179,10 +179,11 @@ void MainWindow::layoutPanels()
|
||||
// move for it (REQ-UI-SELECTION-PANEL, REQ-UI-BUILD-BAR).
|
||||
m_selectionPanel->anchorTo(
|
||||
worldRect.adjusted(0, 0, 0, -m_buildButtonBar->getStripHeightPx()));
|
||||
// Same band, opposite edge: left and bottom-aligned, so it clears the bar's strip
|
||||
// too and never meets the selection panel (REQ-UI-CONTROLS-PANEL).
|
||||
m_controlsPanel->anchorTo(
|
||||
worldRect.adjusted(0, 0, 0, -m_buildButtonBar->getStripHeightPx()));
|
||||
// The opposite corner: bottom-left of the view, sharing the bottom edge with the
|
||||
// bar rather than clearing its whole strip, and rising only if the two would meet.
|
||||
// Anchored after the bar so the geometry it steps around is the current one
|
||||
// (REQ-UI-CONTROLS-PANEL).
|
||||
m_controlsPanel->anchorTo(worldRect, m_buildButtonBar->geometry());
|
||||
m_dimOverlay->setGeometry(0, 0, totalW, totalH);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user