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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user