Expand/shrink card view window on double click (#5652)

This commit is contained in:
RickyRister
2025-02-25 15:32:45 -08:00
committed by GitHub
parent 21e22ed5fb
commit 47311b1dfd
8 changed files with 116 additions and 8 deletions

View File

@@ -401,8 +401,13 @@ AppearanceSettingsPage::AppearanceSettingsPage()
cardViewInitialRowsMaxBox.setRange(1, 999);
cardViewInitialRowsMaxBox.setValue(SettingsCache::instance().getCardViewInitialRowsMax());
connect(&cardViewInitialRowsMaxBox, qOverload<int>(&QSpinBox::valueChanged), &SettingsCache::instance(),
&SettingsCache::setCardViewInitialRowsMax);
connect(&cardViewInitialRowsMaxBox, qOverload<int>(&QSpinBox::valueChanged), this,
&AppearanceSettingsPage::cardViewInitialRowsMaxChanged);
cardViewExpandedRowsMaxBox.setRange(1, 999);
cardViewExpandedRowsMaxBox.setValue(SettingsCache::instance().getCardViewExpandedRowsMax());
connect(&cardViewExpandedRowsMaxBox, qOverload<int>(&QSpinBox::valueChanged), this,
&AppearanceSettingsPage::cardViewExpandedRowsMaxChanged);
auto *cardsGrid = new QGridLayout;
cardsGrid->addWidget(&displayCardNamesCheckBox, 0, 0, 1, 2);
@@ -414,6 +419,8 @@ AppearanceSettingsPage::AppearanceSettingsPage()
cardsGrid->addWidget(&verticalCardOverlapPercentBox, 5, 1, 1, 1);
cardsGrid->addWidget(&cardViewInitialRowsMaxLabel, 6, 0);
cardsGrid->addWidget(&cardViewInitialRowsMaxBox, 6, 1);
cardsGrid->addWidget(&cardViewExpandedRowsMaxLabel, 7, 0);
cardsGrid->addWidget(&cardViewExpandedRowsMaxBox, 7, 1);
cardsGroupBox = new QGroupBox;
cardsGroupBox->setLayout(cardsGrid);
@@ -500,6 +507,32 @@ void AppearanceSettingsPage::showShortcutsChanged(QT_STATE_CHANGED_T value)
qApp->setAttribute(Qt::AA_DontShowShortcutsInContextMenus, value == 0); // 0 = unchecked
}
/**
* Updates the settings for cardViewInitialRowsMax.
* Forces expanded rows max to always be >= initial rows max
* @param value The new value
*/
void AppearanceSettingsPage::cardViewInitialRowsMaxChanged(int value)
{
SettingsCache::instance().setCardViewInitialRowsMax(value);
if (cardViewExpandedRowsMaxBox.value() < value) {
cardViewExpandedRowsMaxBox.setValue(value);
}
}
/**
* Updates the settings for cardViewExpandedRowsMax.
* Forces initial rows max to always be <= expanded rows max
* @param value The new value
*/
void AppearanceSettingsPage::cardViewExpandedRowsMaxChanged(int value)
{
SettingsCache::instance().setCardViewExpandedRowsMax(value);
if (cardViewInitialRowsMaxBox.value() > value) {
cardViewInitialRowsMaxBox.setValue(value);
}
}
void AppearanceSettingsPage::retranslateUi()
{
themeGroupBox->setTitle(tr("Theme settings"));
@@ -526,6 +559,8 @@ void AppearanceSettingsPage::retranslateUi()
tr("Minimum overlap percentage of cards on the stack and in vertical hand"));
cardViewInitialRowsMaxLabel.setText(tr("Maximum initial height for card view window:"));
cardViewInitialRowsMaxBox.setSuffix(tr(" rows"));
cardViewExpandedRowsMaxLabel.setText(tr("Maximum expanded height for card view window:"));
cardViewExpandedRowsMaxBox.setSuffix(tr(" rows"));
handGroupBox->setTitle(tr("Hand layout"));
horizontalHandCheckBox.setText(tr("Display hand horizontally (wastes space)"));

View File

@@ -91,6 +91,9 @@ private slots:
void openThemeLocation();
void showShortcutsChanged(QT_STATE_CHANGED_T enabled);
void cardViewInitialRowsMaxChanged(int value);
void cardViewExpandedRowsMaxChanged(int value);
private:
QLabel themeLabel;
QComboBox themeBox;
@@ -110,6 +113,8 @@ private:
QSpinBox verticalCardOverlapPercentBox;
QLabel cardViewInitialRowsMaxLabel;
QSpinBox cardViewInitialRowsMaxBox;
QLabel cardViewExpandedRowsMaxLabel;
QSpinBox cardViewExpandedRowsMaxBox;
QCheckBox horizontalHandCheckBox;
QCheckBox leftJustifiedHandCheckBox;
QCheckBox invertVerticalCoordinateCheckBox;

View File

@@ -132,7 +132,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
setLayout(vbox);
connect(zone, &ZoneViewZone::optimumRectChanged, this, &ZoneViewWidget::resizeToZoneContents);
connect(zone, &ZoneViewZone::optimumRectChanged, this, [this] { resizeToZoneContents(); });
connect(zone, &ZoneViewZone::closed, this, &ZoneViewWidget::zoneDeleted);
zone->initializeCards(cardList);
@@ -258,14 +258,25 @@ void ZoneViewWidget::resizeScrollbar(const qreal newZoneHeight)
scrollBar->setMaximum(newMax);
}
/**
* Maps a height that is given as number of rows of cards to the actual height, given in pixels.
*
* @param rows Rows of cards
* @return The height in pixels
*/
static qreal rowsToHeight(int rows)
{
const qreal cardsHeight = (rows + 1) * (CARD_HEIGHT / 3);
return cardsHeight + 5; // +5 padding to make the cutoff look nicer
}
/**
* Calculates the max initial height from the settings.
* The max initial height setting is given as number of rows, so we need to map it to a height.
**/
static qreal calcMaxInitialHeight()
{
const qreal cardsHeight = (SettingsCache::instance().getCardViewInitialRowsMax() + 1) * (CARD_HEIGHT / 3);
return cardsHeight + 5; // +5 padding to make the cutoff look nicer
return rowsToHeight(SettingsCache::instance().getCardViewInitialRowsMax());
}
/**
@@ -282,7 +293,7 @@ static qreal determineNewZoneHeight(qreal oldZoneHeight)
return calcMaxInitialHeight();
}
void ZoneViewWidget::resizeToZoneContents()
void ZoneViewWidget::resizeToZoneContents(bool forceInitialHeight)
{
QRectF zoneRect = zone->getOptimumRect();
qreal totalZoneHeight = zoneRect.height();
@@ -293,7 +304,7 @@ void ZoneViewWidget::resizeToZoneContents()
QSizeF maxSize(width, zoneRect.height() + extraHeight + 10);
qreal currentZoneHeight = rect().height() - extraHeight - 10;
qreal newZoneHeight = determineNewZoneHeight(currentZoneHeight);
qreal newZoneHeight = forceInitialHeight ? calcMaxInitialHeight() : determineNewZoneHeight(currentZoneHeight);
QSizeF initialSize(width, newZoneHeight + extraHeight + 10);
@@ -335,3 +346,39 @@ void ZoneViewWidget::initStyleOption(QStyleOption *option) const
if (titleBar)
titleBar->icon = QPixmap("theme:cockatrice");
}
/**
* Expands/shrinks the window, depending on the current height as well as the configured initial and expanded max
* heights.
*/
void ZoneViewWidget::expandWindow()
{
qreal maxInitialHeight = calcMaxInitialHeight();
qreal maxExpandedHeight = rowsToHeight(SettingsCache::instance().getCardViewExpandedRowsMax());
qreal height = rect().height() - extraHeight - 10;
qreal maxHeight = maximumHeight() - extraHeight - 10;
// reset window to initial max height if...
bool doResetSize =
// current height is less than that
(height < maxInitialHeight) ||
// current height is at expanded max height
(height == maxExpandedHeight) ||
// current height is at actual max height, and actual max height is less than expanded max height
(height == maxHeight && height > maxInitialHeight && height < maxExpandedHeight);
if (doResetSize) {
resizeToZoneContents(true);
} else {
// expand/shrink window to expanded max height if current height is anywhere at or between initial max height
// and actual max height
resize(maximumSize().boundedTo({maximumWidth(), maxExpandedHeight + extraHeight + 10}));
}
}
void ZoneViewWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
if (event->pos().y() <= 0) {
expandWindow();
}
}

View File

@@ -63,11 +63,12 @@ private slots:
void processGroupBy(int value);
void processSortBy(int value);
void processSetPileView(QT_STATE_CHANGED_T value);
void resizeToZoneContents();
void resizeToZoneContents(bool forceInitialHeight = false);
void handleScrollBarChange(int value);
void zoneDeleted();
void moveEvent(QGraphicsSceneMoveEvent * /* event */) override;
void resizeEvent(QGraphicsSceneResizeEvent * /* event */) override;
void expandWindow();
public:
ZoneViewWidget(Player *_player,
@@ -90,6 +91,7 @@ public:
protected:
void closeEvent(QCloseEvent *event) override;
void initStyleOption(QStyleOption *option) const override;
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
};
#endif

View File

@@ -249,6 +249,7 @@ SettingsCache::SettingsCache()
knownMissingFeatures = settings->value("interface/knownmissingfeatures", "").toString();
useTearOffMenus = settings->value("interface/usetearoffmenus", true).toBool();
cardViewInitialRowsMax = settings->value("interface/cardViewInitialRowsMax", 14).toInt();
cardViewExpandedRowsMax = settings->value("interface/cardViewExpandedRowsMax", 20).toInt();
closeEmptyCardView = settings->value("interface/closeEmptyCardView", true).toBool();
showShortcuts = settings->value("menu/showshortcuts", true).toBool();
@@ -344,6 +345,12 @@ void SettingsCache::setCardViewInitialRowsMax(int _cardViewInitialRowsMax)
settings->setValue("interface/cardViewInitialRowsMax", cardViewInitialRowsMax);
}
void SettingsCache::setCardViewExpandedRowsMax(int value)
{
cardViewExpandedRowsMax = value;
settings->setValue("interface/cardViewExpandedRowsMax", cardViewExpandedRowsMax);
}
void SettingsCache::setCloseEmptyCardView(QT_STATE_CHANGED_T value)
{
closeEmptyCardView = value;

View File

@@ -165,6 +165,7 @@ private:
QString knownMissingFeatures;
bool useTearOffMenus;
int cardViewInitialRowsMax;
int cardViewExpandedRowsMax;
bool closeEmptyCardView;
int pixmapCacheSize;
int networkCacheSize;
@@ -642,6 +643,7 @@ public:
void setKnownMissingFeatures(const QString &_knownMissingFeatures);
void setUseTearOffMenus(bool _useTearOffMenus);
void setCardViewInitialRowsMax(int _cardViewInitialRowsMax);
void setCardViewExpandedRowsMax(int value);
void setCloseEmptyCardView(QT_STATE_CHANGED_T value);
QString getClientID()
{
@@ -663,6 +665,10 @@ public:
{
return cardViewInitialRowsMax;
}
int getCardViewExpandedRowsMax() const
{
return cardViewExpandedRowsMax;
}
bool getCloseEmptyCardView() const
{
return closeEmptyCardView;

View File

@@ -58,6 +58,9 @@ void SettingsCache::setUseTearOffMenus(bool /* _useTearOffMenus */)
void SettingsCache::setCardViewInitialRowsMax(int /* _cardViewInitialRowsMax */)
{
}
void SettingsCache::setCardViewExpandedRowsMax(int /* value */)
{
}
void SettingsCache::setCloseEmptyCardView(const QT_STATE_CHANGED_T /* value */)
{
}

View File

@@ -62,6 +62,9 @@ void SettingsCache::setUseTearOffMenus(bool /* _useTearOffMenus */)
void SettingsCache::setCardViewInitialRowsMax(int /* _cardViewInitialRowsMax */)
{
}
void SettingsCache::setCardViewExpandedRowsMax(int /* value */)
{
}
void SettingsCache::setCloseEmptyCardView(QT_STATE_CHANGED_T /* value */)
{
}