From b92047bc3f611dbb659d6e9c2e0e683995fc6778 Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Sat, 30 Nov 2024 15:54:55 -0800 Subject: [PATCH] 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 --- .../src/game/zones/view_zone_widget.cpp | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/cockatrice/src/game/zones/view_zone_widget.cpp b/cockatrice/src/game/zones/view_zone_widget.cpp index d4b5b3b54..e23a714b8 100644 --- a/cockatrice/src/game/zones/view_zone_widget.cpp +++ b/cockatrice/src/game/zones/view_zone_widget.cpp @@ -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 (numberCards < 0) { - QGraphicsLinearLayout *hPilebox = new QGraphicsLinearLayout(Qt::Horizontal); - QGraphicsLinearLayout *hFilterbox = new QGraphicsLinearLayout(Qt::Horizontal); + // top row + QGraphicsLinearLayout *hTopRow = new QGraphicsLinearLayout(Qt::Horizontal); // groupBy options QGraphicsProxyWidget *groupBySelectorProxy = new QGraphicsProxyWidget; groupBySelectorProxy->setWidget(&groupBySelector); groupBySelectorProxy->setZValue(2000000008); - hFilterbox->addItem(groupBySelectorProxy); + hTopRow->addItem(groupBySelectorProxy); // sortBy options QGraphicsProxyWidget *sortBySelectorProxy = new QGraphicsProxyWidget; sortBySelectorProxy->setWidget(&sortBySelector); sortBySelectorProxy->setZValue(2000000007); - hFilterbox->addItem(sortBySelectorProxy); + hTopRow->addItem(sortBySelectorProxy); - vbox->addItem(hFilterbox); + vbox->addItem(hTopRow); // line QGraphicsProxyWidget *lineProxy = new QGraphicsProxyWidget; @@ -68,20 +68,23 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, lineProxy->setWidget(line); vbox->addItem(lineProxy); + // bottom row + QGraphicsLinearLayout *hBottomRow = new QGraphicsLinearLayout(Qt::Horizontal); + // pile view options QGraphicsProxyWidget *pileViewProxy = new QGraphicsProxyWidget; pileViewProxy->setWidget(&pileViewCheckBox); - hPilebox->addItem(pileViewProxy); + hBottomRow->addItem(pileViewProxy); // shuffle options if (_origZone->getIsShufflable() && numberCards == -1) { shuffleCheckBox.setChecked(true); QGraphicsProxyWidget *shuffleProxy = new QGraphicsProxyWidget; shuffleProxy->setWidget(&shuffleCheckBox); - hPilebox->addItem(shuffleProxy); + hBottomRow->addItem(shuffleProxy); } - vbox->addItem(hPilebox); + vbox->addItem(hBottomRow); } extraHeight = vbox->sizeHint(Qt::PreferredSize).height(); @@ -133,6 +136,8 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, connect(zone, SIGNAL(beingDeleted()), this, SLOT(zoneDeleted())); 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); connect(lastResizeBeforeVisibleTimer, &QTimer::timeout, this, [=] { resizeToZoneContents(); @@ -185,6 +190,15 @@ void ZoneViewWidget::retranslateUi() setWindowTitle(zone->getTranslatedName(false, CaseNominative)); { // 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(); sortBySelector.clear(); sortBySelector.addItem(tr("Sort by ---"), CardList::NoSort); @@ -194,15 +208,6 @@ void ZoneViewWidget::retranslateUi() 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")); pileViewCheckBox.setText(tr("pile view")); }