rename and refactor some stuff in ZoneViewWidget (#5213)

* fix QComboBox creation order in retranslateUi

* move bottom row creation closer to where it's used

* rename QGraphicsLinearLayout variables

hFilterbox and hPilebox don't make much sense now

* add comment about #5204
This commit is contained in:
RickyRister 2024-11-30 15:54:55 -08:00 committed by GitHub
parent 70559d32df
commit b92047bc3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -43,22 +43,22 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
// If the number is < 0, then it means that we can give the option to make the area sorted // If the number is < 0, then it means that we can give the option to make the area sorted
if (numberCards < 0) { if (numberCards < 0) {
QGraphicsLinearLayout *hPilebox = new QGraphicsLinearLayout(Qt::Horizontal); // top row
QGraphicsLinearLayout *hFilterbox = new QGraphicsLinearLayout(Qt::Horizontal); QGraphicsLinearLayout *hTopRow = new QGraphicsLinearLayout(Qt::Horizontal);
// groupBy options // groupBy options
QGraphicsProxyWidget *groupBySelectorProxy = new QGraphicsProxyWidget; QGraphicsProxyWidget *groupBySelectorProxy = new QGraphicsProxyWidget;
groupBySelectorProxy->setWidget(&groupBySelector); groupBySelectorProxy->setWidget(&groupBySelector);
groupBySelectorProxy->setZValue(2000000008); groupBySelectorProxy->setZValue(2000000008);
hFilterbox->addItem(groupBySelectorProxy); hTopRow->addItem(groupBySelectorProxy);
// sortBy options // sortBy options
QGraphicsProxyWidget *sortBySelectorProxy = new QGraphicsProxyWidget; QGraphicsProxyWidget *sortBySelectorProxy = new QGraphicsProxyWidget;
sortBySelectorProxy->setWidget(&sortBySelector); sortBySelectorProxy->setWidget(&sortBySelector);
sortBySelectorProxy->setZValue(2000000007); sortBySelectorProxy->setZValue(2000000007);
hFilterbox->addItem(sortBySelectorProxy); hTopRow->addItem(sortBySelectorProxy);
vbox->addItem(hFilterbox); vbox->addItem(hTopRow);
// line // line
QGraphicsProxyWidget *lineProxy = new QGraphicsProxyWidget; QGraphicsProxyWidget *lineProxy = new QGraphicsProxyWidget;
@ -68,20 +68,23 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
lineProxy->setWidget(line); lineProxy->setWidget(line);
vbox->addItem(lineProxy); vbox->addItem(lineProxy);
// bottom row
QGraphicsLinearLayout *hBottomRow = new QGraphicsLinearLayout(Qt::Horizontal);
// pile view options // pile view options
QGraphicsProxyWidget *pileViewProxy = new QGraphicsProxyWidget; QGraphicsProxyWidget *pileViewProxy = new QGraphicsProxyWidget;
pileViewProxy->setWidget(&pileViewCheckBox); pileViewProxy->setWidget(&pileViewCheckBox);
hPilebox->addItem(pileViewProxy); hBottomRow->addItem(pileViewProxy);
// shuffle options // shuffle options
if (_origZone->getIsShufflable() && numberCards == -1) { if (_origZone->getIsShufflable() && numberCards == -1) {
shuffleCheckBox.setChecked(true); shuffleCheckBox.setChecked(true);
QGraphicsProxyWidget *shuffleProxy = new QGraphicsProxyWidget; QGraphicsProxyWidget *shuffleProxy = new QGraphicsProxyWidget;
shuffleProxy->setWidget(&shuffleCheckBox); shuffleProxy->setWidget(&shuffleCheckBox);
hPilebox->addItem(shuffleProxy); hBottomRow->addItem(shuffleProxy);
} }
vbox->addItem(hPilebox); vbox->addItem(hBottomRow);
} }
extraHeight = vbox->sizeHint(Qt::PreferredSize).height(); extraHeight = vbox->sizeHint(Qt::PreferredSize).height();
@ -133,6 +136,8 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
connect(zone, SIGNAL(beingDeleted()), this, SLOT(zoneDeleted())); connect(zone, SIGNAL(beingDeleted()), this, SLOT(zoneDeleted()));
zone->initializeCards(cardList); zone->initializeCards(cardList);
// QLabel sizes aren't taken into account until the widget is rendered.
// Force refresh after 1ms to fix glitchy rendering with long QLabels.
auto *lastResizeBeforeVisibleTimer = new QTimer(this); auto *lastResizeBeforeVisibleTimer = new QTimer(this);
connect(lastResizeBeforeVisibleTimer, &QTimer::timeout, this, [=] { connect(lastResizeBeforeVisibleTimer, &QTimer::timeout, this, [=] {
resizeToZoneContents(); resizeToZoneContents();
@ -185,6 +190,15 @@ void ZoneViewWidget::retranslateUi()
setWindowTitle(zone->getTranslatedName(false, CaseNominative)); setWindowTitle(zone->getTranslatedName(false, CaseNominative));
{ // We can't change the strings after they're put into the QComboBox, so this is our workaround { // We can't change the strings after they're put into the QComboBox, so this is our workaround
int oldIndex = groupBySelector.currentIndex();
groupBySelector.clear();
groupBySelector.addItem(tr("Group by ---"), CardList::NoSort);
groupBySelector.addItem(tr("Group by Type"), CardList::SortByType);
groupBySelector.addItem(tr("Group by Mana Value"), CardList::SortByManaValue);
groupBySelector.setCurrentIndex(oldIndex);
}
{
int oldIndex = sortBySelector.currentIndex(); int oldIndex = sortBySelector.currentIndex();
sortBySelector.clear(); sortBySelector.clear();
sortBySelector.addItem(tr("Sort by ---"), CardList::NoSort); sortBySelector.addItem(tr("Sort by ---"), CardList::NoSort);
@ -194,15 +208,6 @@ void ZoneViewWidget::retranslateUi()
sortBySelector.setCurrentIndex(oldIndex); sortBySelector.setCurrentIndex(oldIndex);
} }
{
int oldIndex = groupBySelector.currentIndex();
groupBySelector.clear();
groupBySelector.addItem(tr("Group by ---"), CardList::NoSort);
groupBySelector.addItem(tr("Group by Type"), CardList::SortByType);
groupBySelector.addItem(tr("Group by Mana Value"), CardList::SortByManaValue);
groupBySelector.setCurrentIndex(oldIndex);
}
shuffleCheckBox.setText(tr("shuffle when closing")); shuffleCheckBox.setText(tr("shuffle when closing"));
pileViewCheckBox.setText(tr("pile view")); pileViewCheckBox.setText(tr("pile view"));
} }