[LayoutSettings] Refactor how widgetSize settings are managed (#6594)

This commit is contained in:
RickyRister
2026-02-08 05:07:53 -08:00
committed by GitHub
parent 1eb6027443
commit ac7ff3a0e9
8 changed files with 92 additions and 211 deletions

View File

@@ -75,7 +75,7 @@ AbstractTabDeckEditor::AbstractTabDeckEditor(TabSupervisor *_tabSupervisor) : Ta
&AbstractTabDeckEditor::refreshShortcuts);
}
void AbstractTabDeckEditor::registerDockWidget(QMenu *_viewMenu, QDockWidget *widget)
void AbstractTabDeckEditor::registerDockWidget(QMenu *_viewMenu, QDockWidget *widget, const QSize &defaultSize)
{
QMenu *menu = _viewMenu->addMenu(QString());
@@ -102,7 +102,7 @@ void AbstractTabDeckEditor::registerDockWidget(QMenu *_viewMenu, QDockWidget *wi
connect(filter, &VisibilityChangeListener::visibilityChanged, aVisible,
[aVisible](bool visible) { aVisible->setChecked(visible); });
dockToActions.insert(widget, {menu, aVisible, aFloating});
dockToActions.insert(widget, {menu, aVisible, aFloating, defaultSize});
}
/**

View File

@@ -274,13 +274,14 @@ protected:
QMenu *menu; ///< The menu containing the actions
QAction *aVisible; ///< The menu action that toggles visibility
QAction *aFloating; ///< The menu action that toggles floating
QSize defaultSize; ///< The default size of the dock
};
/**
* @brief registers a QDockWidget as a managed dock widget. Creates the associated actions and menu, adds them to
* the viewMenu, and connects those actions to the tab's slots.
*/
void registerDockWidget(QMenu *_viewMenu, QDockWidget *widget);
void registerDockWidget(QMenu *_viewMenu, QDockWidget *widget, const QSize &defaultSize);
/** @brief Confirms deck open action based on settings and modified state.
* @param openInSameTabIfBlank Whether to reuse same tab if blank.

View File

@@ -54,11 +54,11 @@ void TabDeckEditor::createMenus()
viewMenu = new QMenu(this);
registerDockWidget(viewMenu, cardDatabaseDockWidget);
registerDockWidget(viewMenu, cardInfoDockWidget);
registerDockWidget(viewMenu, deckDockWidget);
registerDockWidget(viewMenu, filterDockWidget);
registerDockWidget(viewMenu, printingSelectorDockWidget);
registerDockWidget(viewMenu, cardDatabaseDockWidget, {500, 500});
registerDockWidget(viewMenu, cardInfoDockWidget, {250, 500});
registerDockWidget(viewMenu, deckDockWidget, {250, 360});
registerDockWidget(viewMenu, filterDockWidget, {250, 250});
registerDockWidget(viewMenu, printingSelectorDockWidget, {525, 250});
connect(&SettingsCache::instance(), &SettingsCache::overrideAllCardArtWithPersonalPreferenceChanged, this,
[this](bool enabled) { dockToActions[printingSelectorDockWidget].menu->setEnabled(!enabled); });
@@ -144,20 +144,14 @@ void TabDeckEditor::loadLayout()
restoreGeometry(layouts.getDeckEditorGeometry());
}
cardDatabaseDockWidget->setMinimumSize(layouts.getDeckEditorCardDatabaseSize());
cardDatabaseDockWidget->setMaximumSize(layouts.getDeckEditorCardDatabaseSize());
for (auto it = dockToActions.constKeyValueBegin(); it != dockToActions.constKeyValueEnd(); ++it) {
auto dockWidget = it->first;
auto actions = it->second;
cardInfoDockWidget->setMinimumSize(layouts.getDeckEditorCardSize());
cardInfoDockWidget->setMaximumSize(layouts.getDeckEditorCardSize());
filterDockWidget->setMinimumSize(layouts.getDeckEditorFilterSize());
filterDockWidget->setMaximumSize(layouts.getDeckEditorFilterSize());
deckDockWidget->setMinimumSize(layouts.getDeckEditorDeckSize());
deckDockWidget->setMaximumSize(layouts.getDeckEditorDeckSize());
printingSelectorDockWidget->setMinimumSize(layouts.getDeckEditorPrintingSelectorSize());
printingSelectorDockWidget->setMaximumSize(layouts.getDeckEditorPrintingSelectorSize());
QSize size = layouts.getDeckEditorWidgetSize(dockWidget->objectName(), actions.defaultSize);
dockWidget->setMinimumSize(size);
dockWidget->setMaximumSize(size);
}
QTimer::singleShot(100, this, &TabDeckEditor::freeDocksSize);
}
@@ -208,11 +202,10 @@ bool TabDeckEditor::eventFilter(QObject *o, QEvent *e)
LayoutsSettings &layouts = SettingsCache::instance().layouts();
layouts.setDeckEditorLayoutState(saveState());
layouts.setDeckEditorGeometry(saveGeometry());
layouts.setDeckEditorCardDatabaseSize(cardDatabaseDockWidget->size());
layouts.setDeckEditorCardSize(cardInfoDockWidget->size());
layouts.setDeckEditorFilterSize(filterDockWidget->size());
layouts.setDeckEditorDeckSize(deckDockWidget->size());
layouts.setDeckEditorPrintingSelectorSize(printingSelectorDockWidget->size());
for (auto dockWidget : dockToActions.keys()) {
layouts.setDeckEditorWidgetSize(dockWidget->objectName(), dockWidget->size());
}
}
return false;
}

View File

@@ -1034,12 +1034,12 @@ void TabGame::createViewMenuItems()
{
viewMenu = new QMenu(this);
registerDockWidget(viewMenu, cardInfoDock);
registerDockWidget(viewMenu, messageLayoutDock);
registerDockWidget(viewMenu, playerListDock);
registerDockWidget(viewMenu, cardInfoDock, {250, 360});
registerDockWidget(viewMenu, messageLayoutDock, {250, 200});
registerDockWidget(viewMenu, playerListDock, {250, 50});
if (replayDock) {
registerDockWidget(viewMenu, replayDock);
registerDockWidget(viewMenu, replayDock, {900, 100});
}
viewMenu->addSeparator();
@@ -1051,7 +1051,7 @@ void TabGame::createViewMenuItems()
addTabMenu(viewMenu);
}
void TabGame::registerDockWidget(QMenu *_viewMenu, QDockWidget *widget)
void TabGame::registerDockWidget(QMenu *_viewMenu, QDockWidget *widget, const QSize &defaultSize)
{
QMenu *menu = _viewMenu->addMenu(QString());
@@ -1078,7 +1078,7 @@ void TabGame::registerDockWidget(QMenu *_viewMenu, QDockWidget *widget)
connect(filter, &VisibilityChangeListener::visibilityChanged, aVisible,
[aVisible](bool visible) { aVisible->setChecked(visible); });
dockToActions.insert(widget, {menu, aVisible, aFloating});
dockToActions.insert(widget, {menu, aVisible, aFloating, defaultSize});
}
void TabGame::loadLayout()
@@ -1088,24 +1088,27 @@ void TabGame::loadLayout()
restoreGeometry(layouts.getReplayPlayAreaGeometry());
restoreState(layouts.getReplayPlayAreaLayoutState());
cardInfoDock->setMinimumSize(layouts.getReplayCardInfoSize());
cardInfoDock->setMaximumSize(layouts.getReplayCardInfoSize());
messageLayoutDock->setMinimumSize(layouts.getReplayMessageLayoutSize());
messageLayoutDock->setMaximumSize(layouts.getReplayMessageLayoutSize());
playerListDock->setMinimumSize(layouts.getReplayPlayerListSize());
playerListDock->setMaximumSize(layouts.getReplayPlayerListSize());
replayDock->setMinimumSize(layouts.getReplayReplaySize());
replayDock->setMaximumSize(layouts.getReplayReplaySize());
for (auto it = dockToActions.constKeyValueBegin(); it != dockToActions.constKeyValueEnd(); ++it) {
auto dockWidget = it->first;
auto actions = it->second;
QSize size = layouts.getReplayPlayAreaWidgetSize(dockWidget->objectName(), actions.defaultSize);
dockWidget->setMinimumSize(size);
dockWidget->setMaximumSize(size);
}
} else {
restoreGeometry(layouts.getGamePlayAreaGeometry());
restoreState(layouts.getGamePlayAreaLayoutState());
cardInfoDock->setMinimumSize(layouts.getGameCardInfoSize());
cardInfoDock->setMaximumSize(layouts.getGameCardInfoSize());
messageLayoutDock->setMinimumSize(layouts.getGameMessageLayoutSize());
messageLayoutDock->setMaximumSize(layouts.getGameMessageLayoutSize());
playerListDock->setMinimumSize(layouts.getGamePlayerListSize());
playerListDock->setMaximumSize(layouts.getGamePlayerListSize());
for (auto it = dockToActions.constKeyValueBegin(); it != dockToActions.constKeyValueEnd(); ++it) {
auto dockWidget = it->first;
auto actions = it->second;
QSize size = layouts.getGamePlayAreaWidgetSize(dockWidget->objectName(), actions.defaultSize);
dockWidget->setMinimumSize(size);
dockWidget->setMaximumSize(size);
}
}
QTimer::singleShot(100, this, &TabGame::freeDocksSize);
@@ -1333,16 +1336,17 @@ void TabGame::hideEvent(QHideEvent *event)
if (replayDock) {
layouts.setReplayPlayAreaState(saveState());
layouts.setReplayPlayAreaGeometry(saveGeometry());
layouts.setReplayCardInfoSize(cardInfoDock->size());
layouts.setReplayMessageLayoutSize(messageLayoutDock->size());
layouts.setReplayPlayerListSize(playerListDock->size());
layouts.setReplayReplaySize(replayDock->size());
for (auto dockWidget : dockToActions.keys()) {
layouts.setReplayPlayAreaWidgetSize(dockWidget->objectName(), dockWidget->size());
}
} else {
layouts.setGamePlayAreaState(saveState());
layouts.setGamePlayAreaGeometry(saveGeometry());
layouts.setGameCardInfoSize(cardInfoDock->size());
layouts.setGameMessageLayoutSize(messageLayoutDock->size());
layouts.setGamePlayerListSize(playerListDock->size());
for (auto dockWidget : dockToActions.keys()) {
layouts.setGamePlayAreaWidgetSize(dockWidget->objectName(), dockWidget->size());
}
}
Tab::hideEvent(event);

View File

@@ -94,6 +94,7 @@ private:
QMenu *menu;
QAction *aVisible;
QAction *aFloating;
QSize defaultSize;
};
QMap<QDockWidget *, DockActions> dockToActions;
@@ -117,7 +118,7 @@ private:
void createMenuItems();
void createReplayMenuItems();
void createViewMenuItems();
void registerDockWidget(QMenu *_viewMenu, QDockWidget *widget);
void registerDockWidget(QMenu *_viewMenu, QDockWidget *widget, const QSize &defaultSize);
void createCardInfoDock(bool bReplay = false);
void createPlayerListDock(bool bReplay = false);
void createMessageDock(bool bReplay = false);

View File

@@ -97,10 +97,10 @@ void TabDeckEditorVisual::createMenus()
viewMenu = new QMenu(this);
registerDockWidget(viewMenu, cardInfoDockWidget);
registerDockWidget(viewMenu, deckDockWidget);
registerDockWidget(viewMenu, filterDockWidget);
registerDockWidget(viewMenu, printingSelectorDockWidget);
registerDockWidget(viewMenu, cardInfoDockWidget, {250, 500});
registerDockWidget(viewMenu, deckDockWidget, {250, 360});
registerDockWidget(viewMenu, filterDockWidget, {250, 250});
registerDockWidget(viewMenu, printingSelectorDockWidget, {525, 250});
viewMenu->addSeparator();
@@ -274,17 +274,14 @@ void TabDeckEditorVisual::loadLayout()
restoreGeometry(layouts.getDeckEditorGeometry());
}
cardInfoDockWidget->setMinimumSize(layouts.getDeckEditorCardSize());
cardInfoDockWidget->setMaximumSize(layouts.getDeckEditorCardSize());
for (auto it = dockToActions.constKeyValueBegin(); it != dockToActions.constKeyValueEnd(); ++it) {
auto dockWidget = it->first;
auto actions = it->second;
filterDockWidget->setMinimumSize(layouts.getDeckEditorFilterSize());
filterDockWidget->setMaximumSize(layouts.getDeckEditorFilterSize());
deckDockWidget->setMinimumSize(layouts.getDeckEditorDeckSize());
deckDockWidget->setMaximumSize(layouts.getDeckEditorDeckSize());
printingSelectorDockWidget->setMinimumSize(layouts.getDeckEditorPrintingSelectorSize());
printingSelectorDockWidget->setMaximumSize(layouts.getDeckEditorPrintingSelectorSize());
QSize size = layouts.getDeckEditorWidgetSize(dockWidget->objectName(), actions.defaultSize);
dockWidget->setMinimumSize(size);
dockWidget->setMaximumSize(size);
}
QTimer::singleShot(100, this, &TabDeckEditorVisual::freeDocksSize);
}
@@ -349,10 +346,10 @@ bool TabDeckEditorVisual::eventFilter(QObject *o, QEvent *e)
LayoutsSettings &layouts = SettingsCache::instance().layouts();
layouts.setDeckEditorLayoutState(saveState());
layouts.setDeckEditorGeometry(saveGeometry());
layouts.setDeckEditorCardSize(cardInfoDockWidget->size());
layouts.setDeckEditorFilterSize(filterDockWidget->size());
layouts.setDeckEditorDeckSize(deckDockWidget->size());
layouts.setDeckEditorPrintingSelectorSize(printingSelectorDockWidget->size());
for (auto dockWidget : dockToActions.keys()) {
layouts.setDeckEditorWidgetSize(dockWidget->objectName(), dockWidget->size());
}
}
return false;
}

View File

@@ -47,59 +47,15 @@ void LayoutsSettings::setDeckEditorGeometry(const QByteArray &value)
setValue(value, GEOMETRY_PROP, GROUP_DECK_EDITOR);
}
QSize LayoutsSettings::getDeckEditorCardDatabaseSize()
void LayoutsSettings::setDeckEditorWidgetSize(const QString &widgetName, const QSize &value)
{
QVariant previous = getValue("cardDatabase", GROUP_DECK_EDITOR, SIZE_PROP);
return previous == QVariant() ? QSize(500, 500) : previous.toSize();
setValue(value, widgetName, GROUP_DECK_EDITOR, SIZE_PROP);
}
void LayoutsSettings::setDeckEditorCardDatabaseSize(const QSize &value)
QSize LayoutsSettings::getDeckEditorWidgetSize(const QString &widgetName, const QSize &defaultValue)
{
setValue(value, "cardDatabase", GROUP_DECK_EDITOR, SIZE_PROP);
}
QSize LayoutsSettings::getDeckEditorCardSize()
{
QVariant previous = getValue("card", GROUP_DECK_EDITOR, SIZE_PROP);
return previous == QVariant() ? QSize(250, 500) : previous.toSize();
}
void LayoutsSettings::setDeckEditorCardSize(const QSize &value)
{
setValue(value, "card", GROUP_DECK_EDITOR, SIZE_PROP);
}
QSize LayoutsSettings::getDeckEditorDeckSize()
{
QVariant previous = getValue("deck", GROUP_DECK_EDITOR, SIZE_PROP);
return previous == QVariant() ? QSize(250, 360) : previous.toSize();
}
void LayoutsSettings::setDeckEditorDeckSize(const QSize &value)
{
setValue(value, "deck", GROUP_DECK_EDITOR, SIZE_PROP);
}
QSize LayoutsSettings::getDeckEditorPrintingSelectorSize()
{
QVariant previous = getValue("printingSelector", GROUP_DECK_EDITOR, SIZE_PROP);
return previous == QVariant() ? QSize(525, 250) : previous.toSize();
}
void LayoutsSettings::setDeckEditorPrintingSelectorSize(const QSize &value)
{
setValue(value, "printingSelector", GROUP_DECK_EDITOR, SIZE_PROP);
}
QSize LayoutsSettings::getDeckEditorFilterSize()
{
QVariant previous = getValue("filter", GROUP_DECK_EDITOR, SIZE_PROP);
return previous == QVariant() ? QSize(250, 250) : previous.toSize();
}
void LayoutsSettings::setDeckEditorFilterSize(const QSize &value)
{
setValue(value, "filter", GROUP_DECK_EDITOR, SIZE_PROP);
QVariant previous = getValue(widgetName, GROUP_DECK_EDITOR, SIZE_PROP);
return previous == QVariant() ? defaultValue : previous.toSize();
}
QByteArray LayoutsSettings::getDeckEditorDbHeaderState()
@@ -162,37 +118,15 @@ QByteArray LayoutsSettings::getGamePlayAreaGeometry()
return getValue(GEOMETRY_PROP, GROUP_GAME_PLAY_AREA).toByteArray();
}
QSize LayoutsSettings::getGameCardInfoSize()
void LayoutsSettings::setGamePlayAreaWidgetSize(const QString &widgetName, const QSize &value)
{
QVariant previous = getValue("cardInfo", GROUP_GAME_PLAY_AREA, SIZE_PROP);
return previous == QVariant() ? QSize(250, 360) : previous.toSize();
setValue(value, widgetName, GROUP_GAME_PLAY_AREA, SIZE_PROP);
}
void LayoutsSettings::setGameCardInfoSize(const QSize &value)
QSize LayoutsSettings::getGamePlayAreaWidgetSize(const QString &widgetName, const QSize &defaultValue)
{
setValue(value, "cardInfo", GROUP_GAME_PLAY_AREA, SIZE_PROP);
}
QSize LayoutsSettings::getGameMessageLayoutSize()
{
QVariant previous = getValue("messageLayout", GROUP_GAME_PLAY_AREA, SIZE_PROP);
return previous == QVariant() ? QSize(250, 250) : previous.toSize();
}
void LayoutsSettings::setGameMessageLayoutSize(const QSize &value)
{
setValue(value, "messageLayout", GROUP_GAME_PLAY_AREA, SIZE_PROP);
}
QSize LayoutsSettings::getGamePlayerListSize()
{
QVariant previous = getValue("playerList", GROUP_GAME_PLAY_AREA, SIZE_PROP);
return previous == QVariant() ? QSize(250, 50) : previous.toSize();
}
void LayoutsSettings::setGamePlayerListSize(const QSize &value)
{
setValue(value, "playerList", GROUP_GAME_PLAY_AREA, SIZE_PROP);
QVariant previous = getValue(widgetName, GROUP_GAME_PLAY_AREA, SIZE_PROP);
return previous == QVariant() ? defaultValue : previous.toSize();
}
void LayoutsSettings::setReplayPlayAreaGeometry(const QByteArray &value)
@@ -215,46 +149,13 @@ QByteArray LayoutsSettings::getReplayPlayAreaGeometry()
return getValue(GEOMETRY_PROP, GROUP_REPLAY_PLAY_AREA).toByteArray();
}
QSize LayoutsSettings::getReplayCardInfoSize()
void LayoutsSettings::setReplayPlayAreaWidgetSize(const QString &widgetName, const QSize &value)
{
QVariant previous = getValue("cardInfo", GROUP_REPLAY_PLAY_AREA, SIZE_PROP);
return previous == QVariant() ? QSize(250, 360) : previous.toSize();
setValue(value, widgetName, GROUP_REPLAY_PLAY_AREA, SIZE_PROP);
}
void LayoutsSettings::setReplayCardInfoSize(const QSize &value)
QSize LayoutsSettings::getReplayPlayAreaWidgetSize(const QString &widgetName, const QSize &defaultValue)
{
setValue(value, "cardInfo", GROUP_REPLAY_PLAY_AREA, SIZE_PROP);
}
QSize LayoutsSettings::getReplayMessageLayoutSize()
{
QVariant previous = getValue("messageLayout", GROUP_REPLAY_PLAY_AREA, SIZE_PROP);
return previous == QVariant() ? QSize(250, 200) : previous.toSize();
}
void LayoutsSettings::setReplayMessageLayoutSize(const QSize &value)
{
setValue(value, "messageLayout", GROUP_REPLAY_PLAY_AREA, SIZE_PROP);
}
QSize LayoutsSettings::getReplayPlayerListSize()
{
QVariant previous = getValue("playerList", GROUP_REPLAY_PLAY_AREA, SIZE_PROP);
return previous == QVariant() ? QSize(250, 50) : previous.toSize();
}
void LayoutsSettings::setReplayPlayerListSize(const QSize &value)
{
setValue(value, "playerList", GROUP_REPLAY_PLAY_AREA, SIZE_PROP);
}
QSize LayoutsSettings::getReplayReplaySize()
{
QVariant previous = getValue("replay", GROUP_REPLAY_PLAY_AREA, SIZE_PROP);
return previous == QVariant() ? QSize(900, 100) : previous.toSize();
}
void LayoutsSettings::setReplayReplaySize(const QSize &value)
{
setValue(value, "replay", GROUP_REPLAY_PLAY_AREA, SIZE_PROP);
}
QVariant previous = getValue(widgetName, GROUP_REPLAY_PLAY_AREA, SIZE_PROP);
return previous == QVariant() ? defaultValue : previous.toSize();
}

View File

@@ -21,11 +21,8 @@ public:
void setDeckEditorLayoutState(const QByteArray &value);
void setDeckEditorGeometry(const QByteArray &value);
void setDeckEditorCardDatabaseSize(const QSize &value);
void setDeckEditorCardSize(const QSize &value);
void setDeckEditorDeckSize(const QSize &value);
void setDeckEditorPrintingSelectorSize(const QSize &value);
void setDeckEditorFilterSize(const QSize &value);
void setDeckEditorWidgetSize(const QString &widgetName, const QSize &value);
void setDeckEditorDbHeaderState(const QByteArray &value);
void setSetsDialogHeaderState(const QByteArray &value);
void setSetsDialogGeometry(const QByteArray &value);
@@ -33,26 +30,18 @@ public:
void setGamePlayAreaGeometry(const QByteArray &value);
void setGamePlayAreaState(const QByteArray &value);
void setGameCardInfoSize(const QSize &value);
void setGameMessageLayoutSize(const QSize &value);
void setGamePlayerListSize(const QSize &value);
void setGamePlayAreaWidgetSize(const QString &widgetName, const QSize &value);
void setReplayPlayAreaGeometry(const QByteArray &value);
void setReplayPlayAreaState(const QByteArray &value);
void setReplayCardInfoSize(const QSize &value);
void setReplayMessageLayoutSize(const QSize &value);
void setReplayPlayerListSize(const QSize &value);
void setReplayReplaySize(const QSize &value);
void setReplayPlayAreaWidgetSize(const QString &widgetName, const QSize &value);
QByteArray getMainWindowGeometry();
QByteArray getDeckEditorLayoutState();
QByteArray getDeckEditorGeometry();
QSize getDeckEditorCardDatabaseSize();
QSize getDeckEditorCardSize();
QSize getDeckEditorDeckSize();
QSize getDeckEditorPrintingSelectorSize();
QSize getDeckEditorFilterSize();
QSize getDeckEditorWidgetSize(const QString &widgetName, const QSize &defaultValue = {});
QByteArray getDeckEditorDbHeaderState();
QByteArray getSetsDialogHeaderState();
QByteArray getSetsDialogGeometry();
@@ -60,16 +49,11 @@ public:
QByteArray getGamePlayAreaLayoutState();
QByteArray getGamePlayAreaGeometry();
QSize getGameCardInfoSize();
QSize getGameMessageLayoutSize();
QSize getGamePlayerListSize();
QSize getGamePlayAreaWidgetSize(const QString &widgetName, const QSize &defaultValue = {});
QByteArray getReplayPlayAreaLayoutState();
QByteArray getReplayPlayAreaGeometry();
QSize getReplayCardInfoSize();
QSize getReplayMessageLayoutSize();
QSize getReplayPlayerListSize();
QSize getReplayReplaySize();
QSize getReplayPlayAreaWidgetSize(const QString &widgetName, const QSize &defaultValue = {});
signals:
public slots: