mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-23 10:05:10 -07:00
[TabDeckEditor] Automatically sync view menu actions (#6522)
This commit is contained in:
parent
6213ccff48
commit
57e6c91689
11 changed files with 65 additions and 199 deletions
|
|
@ -97,10 +97,10 @@ void TabDeckEditorVisual::createMenus()
|
|||
|
||||
viewMenu = new QMenu(this);
|
||||
|
||||
registerDockWidget(cardInfoDockWidget);
|
||||
registerDockWidget(deckDockWidget);
|
||||
registerDockWidget(filterDockWidget);
|
||||
registerDockWidget(printingSelectorDockWidget);
|
||||
registerDockWidget(viewMenu, cardInfoDockWidget);
|
||||
registerDockWidget(viewMenu, deckDockWidget);
|
||||
registerDockWidget(viewMenu, filterDockWidget);
|
||||
registerDockWidget(viewMenu, printingSelectorDockWidget);
|
||||
|
||||
if (SettingsCache::instance().getOverrideAllCardArtWithPersonalPreference()) {
|
||||
dockToActions[printingSelectorDockWidget].menu->setEnabled(false);
|
||||
|
|
@ -241,7 +241,6 @@ void TabDeckEditorVisual::showPrintingSelector()
|
|||
{
|
||||
printingSelectorDockWidget->printingSelector->setCard(cardInfoDockWidget->cardInfo->getCard().getCardPtr());
|
||||
printingSelectorDockWidget->printingSelector->updateDisplay();
|
||||
dockToActions[printingSelectorDockWidget].aVisible->setChecked(true);
|
||||
printingSelectorDockWidget->setVisible(true);
|
||||
}
|
||||
|
||||
|
|
@ -283,19 +282,9 @@ void TabDeckEditorVisual::loadLayout()
|
|||
if (SettingsCache::instance().getOverrideAllCardArtWithPersonalPreference()) {
|
||||
if (!printingSelectorDockWidget->isHidden()) {
|
||||
printingSelectorDockWidget->setHidden(true);
|
||||
dockToActions[printingSelectorDockWidget].aVisible->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = dockToActions.begin(); it != dockToActions.end(); ++it) {
|
||||
QDockWidget *dockWidget = it.key();
|
||||
const DockActions &actions = it.value();
|
||||
|
||||
actions.aVisible->setChecked(dockWidget->isHidden());
|
||||
actions.aFloating->setEnabled(actions.aVisible->isChecked());
|
||||
actions.aFloating->setChecked(dockWidget->isFloating());
|
||||
}
|
||||
|
||||
cardInfoDockWidget->setMinimumSize(layouts.getDeckEditorCardSize());
|
||||
cardInfoDockWidget->setMaximumSize(layouts.getDeckEditorCardSize());
|
||||
|
||||
|
|
@ -314,20 +303,10 @@ void TabDeckEditorVisual::loadLayout()
|
|||
/** @brief Resets the layout to default positions and dock states. */
|
||||
void TabDeckEditorVisual::restartLayout()
|
||||
{
|
||||
for (auto it = dockToActions.begin(); it != dockToActions.end(); ++it) {
|
||||
QDockWidget *dockWidget = it.key();
|
||||
const DockActions &actions = it.value();
|
||||
|
||||
actions.aFloating->setEnabled(false);
|
||||
for (auto dockWidget : dockToActions.keys()) {
|
||||
dockWidget->setFloating(false);
|
||||
}
|
||||
|
||||
dockToActions[cardInfoDockWidget].aVisible->setChecked(true);
|
||||
dockToActions[deckDockWidget].aVisible->setChecked(true);
|
||||
dockToActions[filterDockWidget].aVisible->setChecked(false);
|
||||
dockToActions[printingSelectorDockWidget].aVisible->setChecked(
|
||||
!SettingsCache::instance().getOverrideAllCardArtWithPersonalPreference());
|
||||
|
||||
deckDockWidget->setVisible(true);
|
||||
cardInfoDockWidget->setVisible(true);
|
||||
filterDockWidget->setVisible(false);
|
||||
|
|
@ -377,15 +356,6 @@ void TabDeckEditorVisual::retranslateUi()
|
|||
*/
|
||||
bool TabDeckEditorVisual::eventFilter(QObject *o, QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::Close) {
|
||||
auto dockWidget = qobject_cast<QDockWidget *>(o);
|
||||
if (dockToActions.contains(dockWidget)) {
|
||||
DockActions actions = dockToActions.value(dockWidget);
|
||||
actions.aVisible->setChecked(false);
|
||||
actions.aFloating->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (o == this && e->type() == QEvent::Hide) {
|
||||
LayoutsSettings &layouts = SettingsCache::instance().layouts();
|
||||
layouts.setDeckEditorLayoutState(saveState());
|
||||
|
|
@ -397,47 +367,3 @@ bool TabDeckEditorVisual::eventFilter(QObject *o, QEvent *e)
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @brief Toggles dock visibility based on the corresponding menu action. */
|
||||
void TabDeckEditorVisual::dockVisibleTriggered()
|
||||
{
|
||||
QObject *o = sender();
|
||||
for (auto it = dockToActions.begin(); it != dockToActions.end(); ++it) {
|
||||
QDockWidget *dockWidget = it.key();
|
||||
const DockActions &actions = it.value();
|
||||
|
||||
if (o == actions.aVisible) {
|
||||
dockWidget->setHidden(!actions.aVisible->isChecked());
|
||||
actions.aFloating->setEnabled(actions.aVisible->isChecked());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Toggles dock floating state based on the corresponding menu action. */
|
||||
void TabDeckEditorVisual::dockFloatingTriggered()
|
||||
{
|
||||
QObject *o = sender();
|
||||
|
||||
for (auto it = dockToActions.begin(); it != dockToActions.end(); ++it) {
|
||||
QDockWidget *dockWidget = it.key();
|
||||
const DockActions &actions = it.value();
|
||||
|
||||
if (o == actions.aFloating) {
|
||||
dockWidget->setFloating(actions.aFloating->isChecked());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Updates menu checkboxes when a dock's top-level/floating state changes. */
|
||||
void TabDeckEditorVisual::dockTopLevelChanged(bool topLevel)
|
||||
{
|
||||
QObject *o = sender();
|
||||
|
||||
auto dockWidget = qobject_cast<QDockWidget *>(o);
|
||||
if (dockToActions.contains(dockWidget)) {
|
||||
DockActions actions = dockToActions.value(dockWidget);
|
||||
actions.aFloating->setChecked(topLevel);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,22 +84,6 @@ protected slots:
|
|||
*/
|
||||
bool eventFilter(QObject *o, QEvent *e) override;
|
||||
|
||||
/**
|
||||
* @brief Triggered when a dock visibility menu item is clicked.
|
||||
*/
|
||||
void dockVisibleTriggered() override;
|
||||
|
||||
/**
|
||||
* @brief Triggered when a dock floating menu item is clicked.
|
||||
*/
|
||||
void dockFloatingTriggered() override;
|
||||
|
||||
/**
|
||||
* @brief Triggered when a dock top-level state changes.
|
||||
* @param topLevel True if the dock became floating.
|
||||
*/
|
||||
void dockTopLevelChanged(bool topLevel) override;
|
||||
|
||||
protected:
|
||||
TabDeckEditorVisualTabWidget *tabContainer; ///< Tab container holding different visual widgets.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue