mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-13 05:20:00 -08:00
Keep Essence selection and mode inside one fixed-width popup to prevent toolbar clipping
This commit is contained in:
parent
08e0eb3dab
commit
2b35b0a6ab
1 changed files with 25 additions and 9 deletions
|
|
@ -21,16 +21,18 @@ EssenceFilterPicker::EssenceFilterPicker(QWidget *parent) : QToolButton(parent)
|
||||||
setPopupMode(QToolButton::InstantPopup);
|
setPopupMode(QToolButton::InstantPopup);
|
||||||
setToolButtonStyle(Qt::ToolButtonTextOnly); // Keep the summary visible even without a button icon.
|
setToolButtonStyle(Qt::ToolButtonTextOnly); // Keep the summary visible even without a button icon.
|
||||||
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
setMinimumWidth(130);
|
// Force a stable toolbar footprint independent of popup and font sizing.
|
||||||
|
// Modes and all 15 Essence icons are contained inside the popup.
|
||||||
|
setFixedWidth(144);
|
||||||
|
|
||||||
popupMenu = new QMenu(this);
|
popupMenu = new QMenu(this);
|
||||||
auto *panel = new QWidget(popupMenu);
|
auto *panel = new QWidget(popupMenu);
|
||||||
auto *vertical = new QVBoxLayout(panel);
|
panelLayout = new QVBoxLayout(panel);
|
||||||
vertical->setContentsMargins(10, 10, 10, 10);
|
panelLayout->setContentsMargins(10, 10, 10, 10);
|
||||||
vertical->setSpacing(7);
|
panelLayout->setSpacing(7);
|
||||||
|
|
||||||
auto *heading = new QLabel(tr("Filter by Essence"), panel);
|
auto *heading = new QLabel(tr("Filter by Essence"), panel);
|
||||||
vertical->addWidget(heading);
|
panelLayout->addWidget(heading);
|
||||||
|
|
||||||
auto *grid = new QGridLayout();
|
auto *grid = new QGridLayout();
|
||||||
grid->setSpacing(5);
|
grid->setSpacing(5);
|
||||||
|
|
@ -58,19 +60,22 @@ EssenceFilterPicker::EssenceFilterPicker(QWidget *parent) : QToolButton(parent)
|
||||||
buttons.insert(essence, button);
|
buttons.insert(essence, button);
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
vertical->addLayout(grid);
|
panelLayout->addLayout(grid);
|
||||||
|
|
||||||
auto *clearButton = new QPushButton(tr("Clear Essence selection"), panel);
|
auto *clearButton = new QPushButton(tr("Clear Essence selection"), panel);
|
||||||
connect(clearButton, &QPushButton::clicked, this, [this]() {
|
connect(clearButton, &QPushButton::clicked, this, [this]() {
|
||||||
// The popup remains open while changing several Essence types.
|
// Clear as ONE model operation, so Exact Match and Include/Exclude
|
||||||
// Emit only for entries that actually changed.
|
// don't retain stale "not this Essence" predicates.
|
||||||
for (const QChar essence : Essence::symbols()) {
|
for (const QChar essence : Essence::symbols()) {
|
||||||
if (auto *button = buttons.value(essence); button && button->isChecked()) {
|
if (auto *button = buttons.value(essence); button && button->isChecked()) {
|
||||||
|
const QSignalBlocker blocker(button);
|
||||||
button->setChecked(false);
|
button->setChecked(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateSummary();
|
||||||
|
emit selectionCleared();
|
||||||
});
|
});
|
||||||
vertical->addWidget(clearButton);
|
panelLayout->addWidget(clearButton);
|
||||||
|
|
||||||
auto *panelAction = new QWidgetAction(popupMenu);
|
auto *panelAction = new QWidgetAction(popupMenu);
|
||||||
panelAction->setDefaultWidget(panel);
|
panelAction->setDefaultWidget(panel);
|
||||||
|
|
@ -80,6 +85,17 @@ EssenceFilterPicker::EssenceFilterPicker(QWidget *parent) : QToolButton(parent)
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EssenceFilterPicker::addPopupControl(QWidget *control)
|
||||||
|
{
|
||||||
|
if (!control || !panelLayout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert above the Clear button, keeping the entire configuration in one
|
||||||
|
// popup rather than competing for horizontal space in the main toolbar.
|
||||||
|
panelLayout->insertWidget(panelLayout->count() - 1, control);
|
||||||
|
}
|
||||||
|
|
||||||
QSet<QChar> EssenceFilterPicker::activeEssences() const
|
QSet<QChar> EssenceFilterPicker::activeEssences() const
|
||||||
{
|
{
|
||||||
QSet<QChar> active;
|
QSet<QChar> active;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue