Overhaul quick settings for VDS and PrintingSelector (#5602)

* Move show folders option next to the search bar.

* Add a new settings button and settings popup, move the folder visibility checkbox there and the ability to hide tags.

* Make popup not close when interacting with child widgets.

* Fix mocks.

* Include cog icon.

* Move PrintingSelector Display options to new quick settings widget.

* Adjust size before first show so as to not overflow.

* Add option to hide card size slider in VDS.

* Qt5 support.

* Fix some warnings by containerizing layouts because addChildLayout is silly.

* Fix an incorrect slot/signal assignment.

* Correct sub-categories for settings to persist them.

* Shuffle some slots and signals around to distinguish between the tag filter and the tags on the deck preview widgets.

* Add a quick setting to draw unused color identities and center them.

* Respect the setting on startup.

* Move card size slider to the quick settings menu.

* Move PrintingSelector card size slider to quick menu, adjust other layout from other options.

* Improve layout, add a gray border.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-02-10 17:50:08 +01:00 committed by GitHub
parent d1102939a2
commit 7c9bf75393
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 413 additions and 409 deletions

View file

@ -11,8 +11,8 @@
* This widget allows users to dynamically change the card size in a linked FlowWidget
* and updates the application's settings accordingly.
*/
CardSizeWidget::CardSizeWidget(QWidget *parent, FlowWidget *flowWidget, int defaultValue)
: parent(parent), flowWidget(flowWidget)
CardSizeWidget::CardSizeWidget(QWidget *parent, FlowWidget *_flowWidget, int defaultValue)
: parent(parent), flowWidget(_flowWidget)
{
cardSizeLayout = new QHBoxLayout(this);
cardSizeLayout->setContentsMargins(9, 0, 9, 0);

View file

@ -5,7 +5,6 @@
#include "printing_selector_card_search_widget.h"
#include "printing_selector_card_selection_widget.h"
#include "printing_selector_card_sorting_widget.h"
#include "printing_selector_view_options_toolbar_widget.h"
#include <QScrollBar>
@ -29,29 +28,49 @@ PrintingSelector::PrintingSelector(QWidget *parent,
: QWidget(parent), deckEditor(deckEditor), deckModel(deckModel), deckView(deckView)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
layout = new QVBoxLayout();
layout = new QVBoxLayout(this);
setLayout(layout);
widgetLoadingBufferTimer = new QTimer(this);
// Initialize toolbar and widgets
viewOptionsToolbar = new PrintingSelectorViewOptionsToolbarWidget(this, this);
layout->addWidget(viewOptionsToolbar);
flowWidget = new FlowWidget(this, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
sortToolBar = new PrintingSelectorCardSortingWidget(this);
sortToolBar->setVisible(SettingsCache::instance().getPrintingSelectorSortOptionsVisible());
layout->addWidget(sortToolBar);
sortToolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
displayOptionsWidget = new SettingsButtonWidget(this);
displayOptionsWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
// Create the checkbox for navigation buttons visibility
navigationCheckBox = new QCheckBox(this);
navigationCheckBox->setChecked(SettingsCache::instance().getPrintingSelectorNavigationButtonsVisible());
connect(navigationCheckBox, &QCheckBox::QT_STATE_CHANGED, this,
&PrintingSelector::toggleVisibilityNavigationButtons);
connect(navigationCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setPrintingSelectorNavigationButtonsVisible);
cardSizeWidget =
new CardSizeWidget(displayOptionsWidget, flowWidget, SettingsCache::instance().getPrintingSelectorCardSize());
displayOptionsWidget->addSettingsWidget(sortToolBar);
displayOptionsWidget->addSettingsWidget(navigationCheckBox);
displayOptionsWidget->addSettingsWidget(cardSizeWidget);
sortAndOptionsContainer = new QWidget(this);
sortAndOptionsLayout = new QHBoxLayout(sortAndOptionsContainer);
sortAndOptionsLayout->setSpacing(3);
sortAndOptionsLayout->setContentsMargins(0, 0, 0, 0);
sortAndOptionsContainer->setLayout(sortAndOptionsLayout);
searchBar = new PrintingSelectorCardSearchWidget(this);
searchBar->setVisible(SettingsCache::instance().getPrintingSelectorSearchBarVisible());
layout->addWidget(searchBar);
flowWidget = new FlowWidget(this, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
sortAndOptionsLayout->addWidget(searchBar);
sortAndOptionsLayout->addWidget(displayOptionsWidget);
layout->addWidget(sortAndOptionsContainer);
layout->addWidget(flowWidget);
cardSizeWidget = new CardSizeWidget(this, flowWidget, SettingsCache::instance().getPrintingSelectorCardSize());
cardSizeWidget->setVisible(SettingsCache::instance().getPrintingSelectorCardSizeSliderVisible());
layout->addWidget(cardSizeWidget);
cardSelectionBar = new PrintingSelectorCardSelectionWidget(this);
cardSelectionBar->setVisible(SettingsCache::instance().getPrintingSelectorNavigationButtonsVisible());
layout->addWidget(cardSelectionBar);
@ -59,6 +78,13 @@ PrintingSelector::PrintingSelector(QWidget *parent,
// Connect deck model data change signal to update display
connect(deckModel, &DeckListModel::rowsInserted, this, &PrintingSelector::printingsInDeckChanged);
connect(deckModel, &DeckListModel::rowsRemoved, this, &PrintingSelector::printingsInDeckChanged);
retranslateUi();
}
void PrintingSelector::retranslateUi()
{
navigationCheckBox->setText(tr("Display Navigation Buttons"));
}
void PrintingSelector::printingsInDeckChanged()
@ -206,36 +232,6 @@ void PrintingSelector::getAllSetsForCurrentCard()
widgetLoadingBufferTimer->start(0); // Process as soon as possible
}
/**
* @brief Toggles the visibility of the sorting options toolbar.
*
* @param _state The visibility state to set.
*/
void PrintingSelector::toggleVisibilitySortOptions(bool _state)
{
sortToolBar->setVisible(_state);
}
/**
* @brief Toggles the visibility of the search bar.
*
* @param _state The visibility state to set.
*/
void PrintingSelector::toggleVisibilitySearchBar(bool _state)
{
searchBar->setVisible(_state);
}
/**
* @brief Toggles the visibility of the card size slider.
*
* @param _state The visibility state to set.
*/
void PrintingSelector::toggleVisibilityCardSizeSlider(bool _state)
{
cardSizeWidget->setVisible(_state);
}
/**
* @brief Toggles the visibility of the navigation buttons.
*

View file

@ -5,7 +5,9 @@
#include "../../../../game/cards/card_database.h"
#include "../cards/card_size_widget.h"
#include "../general/layout_containers/flow_widget.h"
#include "../quick_settings/settings_button_widget.h"
#include <QCheckBox>
#include <QLabel>
#include <QTreeView>
#include <QVBoxLayout>
@ -16,7 +18,7 @@
class PrintingSelectorCardSearchWidget;
class PrintingSelectorCardSelectionWidget;
class PrintingSelectorCardSortingWidget;
class PrintingSelectorViewOptionsToolbarWidget;
class PrintingSelectorViewOptionsWidget;
class TabDeckEditor;
class PrintingSelector : public QWidget
{
@ -24,16 +26,15 @@ class PrintingSelector : public QWidget
public:
PrintingSelector(QWidget *parent, TabDeckEditor *deckEditor, DeckListModel *deckModel, QTreeView *deckView);
void setCard(const CardInfoPtr &newCard, const QString &_currentZone);
void getAllSetsForCurrentCard();
public slots:
void retranslateUi();
void updateDisplay();
void selectPreviousCard();
void selectNextCard();
void toggleVisibilitySortOptions(bool _state);
void toggleVisibilitySearchBar(bool _state);
void toggleVisibilityCardSizeSlider(bool _state);
void toggleVisibilityNavigationButtons(bool _state);
private slots:
@ -41,7 +42,10 @@ private slots:
private:
QVBoxLayout *layout;
PrintingSelectorViewOptionsToolbarWidget *viewOptionsToolbar;
SettingsButtonWidget *displayOptionsWidget;
QWidget *sortAndOptionsContainer;
QHBoxLayout *sortAndOptionsLayout;
QCheckBox *navigationCheckBox;
PrintingSelectorCardSortingWidget *sortToolBar;
PrintingSelectorCardSearchWidget *searchBar;
FlowWidget *flowWidget;

View file

@ -18,8 +18,8 @@ const QStringList PrintingSelectorCardSortingWidget::SORT_OPTIONS = {SORT_OPTION
*/
PrintingSelectorCardSortingWidget::PrintingSelectorCardSortingWidget(PrintingSelector *parent) : parent(parent)
{
setMinimumWidth(300);
sortToolBar = new QHBoxLayout(this);
sortToolBar->setContentsMargins(9, 0, 9, 0);
sortOptionsSelector = new QComboBox(this);
sortOptionsSelector->addItems(SORT_OPTIONS);

View file

@ -1,140 +0,0 @@
#include "printing_selector_view_options_toolbar_widget.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
/**
* @class PrintingSelectorViewOptionsToolbarWidget
* @brief A widget that provides a toolbar for view options with collapsible and expandable functionality.
*
* This widget allows the user to collapse or expand the view options for the PrintingSelector,
* providing a more compact interface when collapsed and a full view of options when expanded.
*/
PrintingSelectorViewOptionsToolbarWidget::PrintingSelectorViewOptionsToolbarWidget(QWidget *_parent,
PrintingSelector *_printingSelector)
: QWidget(_parent), printingSelector(_printingSelector)
{
// Set up layout for the widget
layout = new QVBoxLayout();
layout->setContentsMargins(9, 0, 9, 0);
layout->setSpacing(0);
setLayout(layout);
// Set up the expanded widget with its layout
expandedWidget = new QWidget(this);
auto *expandedLayout = new QVBoxLayout(expandedWidget);
expandedLayout->setContentsMargins(0, 0, 0, 0);
expandedLayout->setSpacing(0);
// Collapse button to toggle between expanded and collapsed states
collapseButton = new QPushButton("", this);
collapseButton->setFixedSize(20, 20);
collapseButton->setToolTip("Collapse");
collapseButton->setStyleSheet("border: none;");
connect(collapseButton, &QPushButton::clicked, this, &PrintingSelectorViewOptionsToolbarWidget::collapse);
expandedLayout->addWidget(collapseButton, 0, Qt::AlignLeft);
// View options widget
viewOptions = new PrintingSelectorViewOptionsWidget(expandedWidget, printingSelector);
expandedLayout->addWidget(viewOptions);
expandedWidget->setLayout(expandedLayout);
// Set up the collapsed widget with its layout
collapsedWidget = new QWidget(this);
auto *collapsedLayout = new QHBoxLayout(collapsedWidget);
collapsedLayout->setContentsMargins(5, 0, 5, 0);
collapsedLayout->setSpacing(0);
// Expand button to show full options
expandButton = new QPushButton("", this);
expandButton->setFixedSize(20, 20);
expandButton->setToolTip("Expand");
expandButton->setStyleSheet("border: none;");
connect(expandButton, &QPushButton::clicked, this, &PrintingSelectorViewOptionsToolbarWidget::expand);
collapsedLayout->addWidget(expandButton);
// Label for collapsed state
auto *collapsedLabel = new QLabel(tr("Display Options"), this);
collapsedLayout->addWidget(collapsedLabel);
collapsedWidget->setLayout(collapsedLayout);
// Stack widget to switch between expanded and collapsed states
stackedWidget = new QStackedWidget(this);
stackedWidget->addWidget(expandedWidget);
stackedWidget->addWidget(collapsedWidget);
layout->addWidget(stackedWidget);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
// Default to the expanded widget
stackedWidget->setCurrentWidget(expandedWidget);
// Connect the stacked widget to update the layout when it changes
connect(stackedWidget, &QStackedWidget::currentChanged, this,
&PrintingSelectorViewOptionsToolbarWidget::onWidgetChanged);
}
/**
* @brief Toggles the widget to the collapsed state.
*/
void PrintingSelectorViewOptionsToolbarWidget::collapse()
{
stackedWidget->setCurrentWidget(collapsedWidget);
updateGeometry();
}
/**
* @brief Toggles the widget to the expanded state.
*/
void PrintingSelectorViewOptionsToolbarWidget::expand()
{
stackedWidget->setCurrentWidget(expandedWidget);
updateGeometry();
}
/**
* @brief Handles the geometry update when the stacked widget changes.
*
* This ensures that the parent layout is also updated when the widget's display state changes.
*/
void PrintingSelectorViewOptionsToolbarWidget::onWidgetChanged(int)
{
updateGeometry();
if (parentWidget() && parentWidget()->layout()) {
parentWidget()->layout()->invalidate();
}
}
/**
* @brief Provides the recommended size for the widget based on the current view.
*
* @return QSize The suggested size for the widget.
*/
QSize PrintingSelectorViewOptionsToolbarWidget::sizeHint() const
{
return stackedWidget->currentWidget()->sizeHint();
}
/**
* @brief Provides the minimum size required for the widget based on the current view.
*
* @return QSize The minimum size required for the widget.
*/
QSize PrintingSelectorViewOptionsToolbarWidget::minimumSizeHint() const
{
return stackedWidget->currentWidget()->minimumSizeHint();
}
/**
* @brief Returns the view options widget contained within this toolbar.
*
* @return PrintingSelectorViewOptionsWidget* The view options widget.
*/
PrintingSelectorViewOptionsWidget *PrintingSelectorViewOptionsToolbarWidget::getViewOptionsWidget() const
{
return viewOptions;
}

View file

@ -1,36 +0,0 @@
#ifndef PRINTING_SELECTOR_SORT_AND_SEARCH_TOOLBAR_WIDGET_H
#define PRINTING_SELECTOR_SORT_AND_SEARCH_TOOLBAR_WIDGET_H
#include "printing_selector.h"
#include "printing_selector_view_options_widget.h"
#include <QPushButton>
#include <QStackedWidget>
#include <QVBoxLayout>
#include <QWidget>
class PrintingSelectorViewOptionsToolbarWidget : public QWidget
{
Q_OBJECT
public:
explicit PrintingSelectorViewOptionsToolbarWidget(QWidget *parent, PrintingSelector *printingSelector);
void collapse();
void expand();
void onWidgetChanged(int);
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
PrintingSelectorViewOptionsWidget *getViewOptionsWidget() const;
private:
QVBoxLayout *layout;
PrintingSelector *printingSelector;
PrintingSelectorViewOptionsWidget *viewOptions;
QWidget *expandedWidget;
QPushButton *collapseButton;
QWidget *collapsedWidget;
QPushButton *expandButton;
QStackedWidget *stackedWidget;
};
#endif // PRINTING_SELECTOR_SORT_AND_SEARCH_TOOLBAR_WIDGET_H

View file

@ -1,63 +0,0 @@
#include "printing_selector_view_options_widget.h"
#include "../../../../settings/cache_settings.h"
/**
* @class PrintingSelectorViewOptionsWidget
* @brief A widget that provides the view options for the PrintingSelector, including checkboxes
* for sorting, search bar, card size slider, and navigation buttons.
*
* This widget allows the user to toggle the visibility of various interface components of the
* PrintingSelector through checkboxes. The state of the checkboxes is saved and restored using
* the `SettingsCache`.
*/
PrintingSelectorViewOptionsWidget::PrintingSelectorViewOptionsWidget(QWidget *parent,
PrintingSelector *_printingSelector)
: QWidget(parent), printingSelector(_printingSelector)
{
// Create the grid to hold the checkboxes
gridLayout = new QGridLayout(this);
setLayout(gridLayout);
// Create the checkbox for sorting options visibility
sortCheckBox = new QCheckBox(this);
sortCheckBox->setText(tr("Display Sorting Options"));
sortCheckBox->setChecked(SettingsCache::instance().getPrintingSelectorSortOptionsVisible());
connect(sortCheckBox, &QCheckBox::QT_STATE_CHANGED, printingSelector,
&PrintingSelector::toggleVisibilitySortOptions);
connect(sortCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setPrintingSelectorSortOptionsVisible);
// Create the checkbox for search bar visibility
searchCheckBox = new QCheckBox(this);
searchCheckBox->setText(tr("Display Search Bar"));
searchCheckBox->setChecked(SettingsCache::instance().getPrintingSelectorSearchBarVisible());
connect(searchCheckBox, &QCheckBox::QT_STATE_CHANGED, printingSelector,
&PrintingSelector::toggleVisibilitySearchBar);
connect(searchCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setPrintingSelectorSearchBarVisible);
// Create the checkbox for card size slider visibility
cardSizeCheckBox = new QCheckBox(this);
cardSizeCheckBox->setText(tr("Display Card Size Slider"));
cardSizeCheckBox->setChecked(SettingsCache::instance().getPrintingSelectorCardSizeSliderVisible());
connect(cardSizeCheckBox, &QCheckBox::QT_STATE_CHANGED, printingSelector,
&PrintingSelector::toggleVisibilityCardSizeSlider);
connect(cardSizeCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setPrintingSelectorCardSizeSliderVisible);
// Create the checkbox for navigation buttons visibility
navigationCheckBox = new QCheckBox(this);
navigationCheckBox->setText(tr("Display Navigation Buttons"));
navigationCheckBox->setChecked(SettingsCache::instance().getPrintingSelectorNavigationButtonsVisible());
connect(navigationCheckBox, &QCheckBox::QT_STATE_CHANGED, printingSelector,
&PrintingSelector::toggleVisibilityNavigationButtons);
connect(navigationCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setPrintingSelectorNavigationButtonsVisible);
// Add checkboxes to the grid
gridLayout->addWidget(sortCheckBox, 0, 0);
gridLayout->addWidget(searchCheckBox, 0, 1);
gridLayout->addWidget(cardSizeCheckBox, 1, 0);
gridLayout->addWidget(navigationCheckBox, 1, 1);
}

View file

@ -1,27 +0,0 @@
#ifndef PRINTING_SELECTOR_VIEW_OPTIONS_WIDGET_H
#define PRINTING_SELECTOR_VIEW_OPTIONS_WIDGET_H
#include "../general/layout_containers/flow_widget.h"
#include "printing_selector.h"
#include <QCheckBox>
#include <QHBoxLayout>
#include <QWidget>
class PrintingSelectorViewOptionsWidget : public QWidget
{
Q_OBJECT
public:
explicit PrintingSelectorViewOptionsWidget(QWidget *parent, PrintingSelector *_printingSelector);
private:
QGridLayout *gridLayout;
PrintingSelector *printingSelector;
QCheckBox *sortCheckBox;
QCheckBox *searchCheckBox;
QCheckBox *cardSizeCheckBox;
QCheckBox *navigationCheckBox;
};
#endif // PRINTING_SELECTOR_VIEW_OPTIONS_WIDGET_H

View file

@ -0,0 +1,80 @@
#include "settings_button_widget.h"
#include <QApplication>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QScreen>
SettingsButtonWidget::SettingsButtonWidget(QWidget *parent)
: QWidget(parent), button(new QToolButton(this)), popup(new SettingsPopupWidget(this))
{
button->setIcon(QPixmap("theme:icons/cogwheel"));
button->setCheckable(true);
button->setFixedSize(32, 32);
connect(button, &QToolButton::clicked, this, &SettingsButtonWidget::togglePopup);
connect(popup, &SettingsPopupWidget::aboutToClose, this, &SettingsButtonWidget::onPopupClosed);
layout = new QHBoxLayout(this);
layout->addWidget(button);
layout->setContentsMargins(0, 0, 0, 0);
setLayout(layout);
}
void SettingsButtonWidget::addSettingsWidget(QWidget *toAdd) const
{
popup->addSettingsWidget(toAdd);
}
void SettingsButtonWidget::togglePopup()
{
if (popup->isVisible()) {
popup->close();
} else {
// Ensure popup size is known before positioning
popup->adjustSize();
QSize popupSize = popup->size();
// Get button position
QPoint buttonGlobalPos = button->mapToGlobal(QPoint(0, button->height()));
// Get screen geometry
QScreen *screen = QApplication::screenAt(buttonGlobalPos);
QRect screenGeom = screen ? screen->availableGeometry() : QApplication::primaryScreen()->availableGeometry();
int x = buttonGlobalPos.x();
int y = buttonGlobalPos.y();
// Adjust X position if popup overflows the right side of the screen
if (x + popupSize.width() > screenGeom.right()) {
x = buttonGlobalPos.x() - popupSize.width() + button->width(); // Move left
}
// Adjust Y position if popup overflows the bottom of the screen
if (y + popupSize.height() > screenGeom.bottom()) {
y = buttonGlobalPos.y() - popupSize.height() - button->height(); // Move up
}
popup->move(x, y);
popup->show();
popup->setFocus();
button->setChecked(true); // Ensure button is checked when popup is visible
}
}
void SettingsButtonWidget::onPopupClosed() const
{
button->setChecked(false); // Ensure button unchecks when popup closes
}
void SettingsButtonWidget::mousePressEvent(QMouseEvent *event)
{
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (popup->isVisible() && !popup->geometry().contains(event->globalPosition().toPoint())) {
#else
if (popup->isVisible() && !popup->geometry().contains(event->globalPos())) {
#endif
popup->close();
}
QWidget::mousePressEvent(event);
}

View file

@ -0,0 +1,30 @@
#ifndef SETTINGS_BUTTON_WIDGET_H
#define SETTINGS_BUTTON_WIDGET_H
#include "settings_popup_widget.h"
#include <QToolButton>
#include <QWidget>
class SettingsButtonWidget : public QWidget
{
Q_OBJECT
public:
explicit SettingsButtonWidget(QWidget *parent = nullptr);
void addSettingsWidget(QWidget *toAdd) const;
protected:
void mousePressEvent(QMouseEvent *event) override;
private slots:
void togglePopup();
void onPopupClosed() const;
private:
QHBoxLayout *layout;
QToolButton *button;
SettingsPopupWidget *popup;
};
#endif // SETTINGS_BUTTON_WIDGET_H

View file

@ -0,0 +1,37 @@
#include "settings_popup_widget.h"
#include <QApplication>
#include <QFocusEvent>
#include <QPainter>
SettingsPopupWidget::SettingsPopupWidget(QWidget *parent) : QWidget(parent, Qt::Popup | Qt::FramelessWindowHint)
{
layout = new QVBoxLayout(this);
}
void SettingsPopupWidget::addSettingsWidget(QWidget *toAdd) const
{
layout->addWidget(toAdd);
}
void SettingsPopupWidget::focusOutEvent(QFocusEvent *event)
{
if (!this->isAncestorOf(QApplication::focusWidget())) {
close();
}
QWidget::focusOutEvent(event);
}
void SettingsPopupWidget::closeEvent(QCloseEvent *event)
{
emit aboutToClose();
QWidget::closeEvent(event);
}
void SettingsPopupWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setPen(Qt::gray);
painter.drawRect(rect().adjusted(0, 0, -1, -1));
QWidget::paintEvent(event);
}

View file

@ -0,0 +1,27 @@
#ifndef SETTINGS_POPUP_WIDGET_H
#define SETTINGS_POPUP_WIDGET_H
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
class SettingsPopupWidget : public QWidget
{
Q_OBJECT
public:
explicit SettingsPopupWidget(QWidget *parent = nullptr);
void addSettingsWidget(QWidget *toAdd) const;
signals:
void aboutToClose();
protected:
void focusOutEvent(QFocusEvent *event) override;
void closeEvent(QCloseEvent *event) override;
void paintEvent(QPaintEvent *event) override;
QVBoxLayout *layout;
};
#endif // SETTINGSPOPUP_H

View file

@ -119,9 +119,10 @@ QChar DeckPreviewColorCircleWidget::getColorChar() const
DeckPreviewColorIdentityWidget::DeckPreviewColorIdentityWidget(QWidget *parent, const QString &colorIdentity)
: QWidget(parent)
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout = new QHBoxLayout(this);
layout->setSpacing(5);
layout->setContentsMargins(0, 0, 0, 0);
layout->setAlignment(Qt::AlignHCenter);
setLayout(layout);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
@ -143,6 +144,25 @@ DeckPreviewColorIdentityWidget::DeckPreviewColorIdentityWidget(QWidget *parent,
}
}
}
connect(&SettingsCache::instance(), &SettingsCache::visualDeckStorageDrawUnusedColorIdentitiesChanged, this,
&DeckPreviewColorIdentityWidget::toggleUnusedVisibility);
toggleUnusedVisibility(SettingsCache::instance().getVisualDeckStorageDrawUnusedColorIdentities());
}
void DeckPreviewColorIdentityWidget::toggleUnusedVisibility(bool _visible) const
{
if (_visible) {
for (DeckPreviewColorCircleWidget *circle : findChildren<DeckPreviewColorCircleWidget *>()) {
circle->setVisible(true);
}
} else {
for (DeckPreviewColorCircleWidget *circle : findChildren<DeckPreviewColorCircleWidget *>()) {
if (!circle->getIsActive()) {
circle->setHidden(true);
}
}
}
}
void DeckPreviewColorIdentityWidget::resizeEvent(QResizeEvent *event)

View file

@ -15,6 +15,10 @@ public:
void setColorActive(bool active);
QChar getColorChar() const;
bool getIsActive() const
{
return isActive;
}
protected:
void resizeEvent(QResizeEvent *event) override;
@ -35,8 +39,14 @@ class DeckPreviewColorIdentityWidget : public QWidget
public:
explicit DeckPreviewColorIdentityWidget(QWidget *parent, const QString &colorIdentity);
public slots:
void toggleUnusedVisibility(bool _visible) const;
protected:
void resizeEvent(QResizeEvent *event) override;
private:
QHBoxLayout *layout;
};
#endif // DECK_PREVIEW_COLOR_IDENTITY_WIDGET_H

View file

@ -1,6 +1,7 @@
#include "deck_preview_widget.h"
#include "../../../../../game/cards/card_database_manager.h"
#include "../../../../../settings/cache_settings.h"
#include "../../cards/deck_preview_card_picture_widget.h"
#include "deck_preview_deck_tags_display_widget.h"
@ -30,6 +31,9 @@ DeckPreviewWidget::DeckPreviewWidget(QWidget *_parent,
connect(bannerCardDisplayWidget, &DeckPreviewCardPictureWidget::imageDoubleClicked, this,
&DeckPreviewWidget::imageDoubleClickedEvent);
connect(&SettingsCache::instance(), &SettingsCache::visualDeckStorageShowTagsOnDeckPreviewsChanged, this,
&DeckPreviewWidget::updateTagsVisibility);
layout->addWidget(bannerCardDisplayWidget);
}
@ -51,6 +55,7 @@ void DeckPreviewWidget::initializeUi(const bool deckLoadSuccess)
colorIdentityWidget = new DeckPreviewColorIdentityWidget(this, getColorIdentity());
deckTagsDisplayWidget = new DeckPreviewDeckTagsDisplayWidget(this, deckLoader);
updateTagsVisibility(SettingsCache::instance().getVisualDeckStorageShowTagsOnDeckPreviews());
layout->addWidget(colorIdentityWidget);
layout->addWidget(deckTagsDisplayWidget);
@ -72,6 +77,15 @@ bool DeckPreviewWidget::checkVisibility() const
return true;
}
void DeckPreviewWidget::updateTagsVisibility(bool visible)
{
if (visible) {
deckTagsDisplayWidget->setVisible(true);
} else {
deckTagsDisplayWidget->setHidden(true);
}
}
QString DeckPreviewWidget::getColorIdentity()
{
QStringList cardList = deckLoader->getCardList();

View file

@ -45,6 +45,7 @@ public slots:
void imageDoubleClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
void initializeUi(bool deckLoadSuccess);
void updateVisibility();
void updateTagsVisibility(bool visible);
};
#endif // DECK_PREVIEW_WIDGET_H

View file

@ -172,7 +172,7 @@ void VisualDeckStorageFolderDisplayWidget::updateShowFolders(bool enabled)
if (!showFolders) {
flattenFolderStructure();
} else {
// if setting was switched from disabled to enabled, we assume that there isn't any existing subfolders
// if setting was switched from disabled to enabled, we assume that there aren't any existing subfolders
createWidgetsForFiles();
createWidgetsForFolders();
}

View file

@ -2,6 +2,7 @@
#include "../../../../game/cards/card_database_manager.h"
#include "../../../../settings/cache_settings.h"
#include "../quick_settings/settings_button_widget.h"
#include "deck_preview/deck_preview_widget.h"
#include "visual_deck_storage_folder_display_widget.h"
#include "visual_deck_storage_search_widget.h"
@ -24,37 +25,59 @@ VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(pare
setLayout(layout);
// search bar row
searchAndSortLayout = new QHBoxLayout(this);
searchAndSortContainer = new QWidget(this);
searchAndSortLayout = new QHBoxLayout(searchAndSortContainer);
searchAndSortLayout->setSpacing(3);
searchAndSortLayout->setContentsMargins(9, 0, 9, 0);
searchAndSortContainer->setLayout(searchAndSortLayout);
deckPreviewColorIdentityFilterWidget = new DeckPreviewColorIdentityFilterWidget(this);
sortWidget = new VisualDeckStorageSortWidget(this);
searchWidget = new VisualDeckStorageSearchWidget(this);
searchAndSortLayout->addWidget(deckPreviewColorIdentityFilterWidget);
searchAndSortLayout->addWidget(sortWidget);
searchAndSortLayout->addWidget(searchWidget);
// checkbox row
QHBoxLayout *checkBoxLayout = new QHBoxLayout(this);
checkBoxLayout->setContentsMargins(9, 0, 9, 0);
showFoldersCheckBox = new QCheckBox(this);
showFoldersCheckBox->setChecked(SettingsCache::instance().getVisualDeckStorageShowFolders());
connect(showFoldersCheckBox, &QCheckBox::QT_STATE_CHANGED, this, &VisualDeckStorageWidget::updateShowFolders);
connect(showFoldersCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setVisualDeckStorageShowFolders);
checkBoxLayout->addWidget(showFoldersCheckBox);
checkBoxLayout->addStretch();
tagFilterVisibilityCheckBox = new QCheckBox(this);
tagFilterVisibilityCheckBox->setChecked(SettingsCache::instance().getVisualDeckStorageShowTagFilter());
connect(tagFilterVisibilityCheckBox, &QCheckBox::QT_STATE_CHANGED, this,
&VisualDeckStorageWidget::updateTagsVisibility);
connect(tagFilterVisibilityCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setVisualDeckStorageShowTagFilter);
// tag filter box
tagFilterWidget = new VisualDeckStorageTagFilterWidget(this);
tagsOnWidgetsVisibilityCheckBox = new QCheckBox(this);
tagsOnWidgetsVisibilityCheckBox->setChecked(SettingsCache::instance().getVisualDeckStorageShowTagsOnDeckPreviews());
connect(tagsOnWidgetsVisibilityCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setVisualDeckStorageShowTagsOnDeckPreviews);
drawUnusedColorIdentitiesCheckBox = new QCheckBox(this);
drawUnusedColorIdentitiesCheckBox->setChecked(
SettingsCache::instance().getVisualDeckStorageDrawUnusedColorIdentities());
connect(drawUnusedColorIdentitiesCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setVisualDeckStorageDrawUnusedColorIdentities);
// card size slider
cardSizeWidget = new CardSizeWidget(this, nullptr, SettingsCache::instance().getVisualDeckStorageCardSize());
quickSettingsWidget = new SettingsButtonWidget(this);
quickSettingsWidget->addSettingsWidget(showFoldersCheckBox);
quickSettingsWidget->addSettingsWidget(tagFilterVisibilityCheckBox);
quickSettingsWidget->addSettingsWidget(tagsOnWidgetsVisibilityCheckBox);
quickSettingsWidget->addSettingsWidget(drawUnusedColorIdentitiesCheckBox);
quickSettingsWidget->addSettingsWidget(cardSizeWidget);
searchAndSortLayout->addWidget(deckPreviewColorIdentityFilterWidget);
searchAndSortLayout->addWidget(sortWidget);
searchAndSortLayout->addWidget(searchWidget);
searchAndSortLayout->addWidget(quickSettingsWidget);
// tag filter box
tagFilterWidget = new VisualDeckStorageTagFilterWidget(this);
updateTagsVisibility(SettingsCache::instance().getVisualDeckStorageShowTagFilter());
// deck area
scrollArea = new QScrollArea(this);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
@ -62,11 +85,9 @@ VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(pare
scrollArea->setWidgetResizable(true);
// putting everything together
layout->addLayout(searchAndSortLayout);
layout->addLayout(checkBoxLayout);
layout->addWidget(searchAndSortContainer);
layout->addWidget(tagFilterWidget);
layout->addWidget(scrollArea);
layout->addWidget(cardSizeWidget);
connect(CardDatabaseManager::getInstance(), &CardDatabase::cardDatabaseLoadingFinished, this,
&VisualDeckStorageWidget::createRootFolderWidget);
@ -108,6 +129,9 @@ void VisualDeckStorageWidget::retranslateUi()
databaseLoadIndicator->setText(tr("Loading database ..."));
showFoldersCheckBox->setText(tr("Show Folders"));
tagFilterVisibilityCheckBox->setText(tr("Show Tag Filter"));
tagsOnWidgetsVisibilityCheckBox->setText(tr("Show Tags On Deck Previews"));
drawUnusedColorIdentitiesCheckBox->setText(tr("Draw not contained Color Identities"));
}
void VisualDeckStorageWidget::deckPreviewClickedEvent(QMouseEvent *event, DeckPreviewWidget *instance)
@ -174,3 +198,13 @@ void VisualDeckStorageWidget::updateSearchFilter()
}
emit searchFilterUpdated();
}
void VisualDeckStorageWidget::updateTagsVisibility(const bool visible)
{
if (visible) {
tagFilterWidget->setVisible(true);
} else {
tagFilterWidget->setHidden(true);
}
}

View file

@ -4,6 +4,7 @@
#include "../../../../deck/deck_list_model.h"
#include "../../../ui/widgets/general/layout_containers/flow_widget.h"
#include "../cards/card_size_widget.h"
#include "../quick_settings/settings_button_widget.h"
#include "deck_preview/deck_preview_color_identity_filter_widget.h"
#include "deck_preview/deck_preview_widget.h"
#include "visual_deck_storage_folder_display_widget.h"
@ -24,8 +25,8 @@ class VisualDeckStorageWidget final : public QWidget
Q_OBJECT
public:
explicit VisualDeckStorageWidget(QWidget *parent);
void retranslateUi();
CardSizeWidget *cardSizeWidget;
VisualDeckStorageTagFilterWidget *tagFilterWidget;
@ -37,6 +38,7 @@ public slots:
void updateTagFilter();
void updateColorFilter();
void updateSearchFilter();
void updateTagsVisibility(bool visible);
void updateSortOrder();
void resizeEvent(QResizeEvent *event) override;
void showEvent(QShowEvent *event) override;
@ -52,15 +54,18 @@ signals:
private:
QVBoxLayout *layout;
QWidget *searchAndSortContainer;
QHBoxLayout *searchAndSortLayout;
DeckListModel *deckListModel;
QLabel *databaseLoadIndicator;
VisualDeckStorageSortWidget *sortWidget;
VisualDeckStorageSearchWidget *searchWidget;
DeckPreviewColorIdentityFilterWidget *deckPreviewColorIdentityFilterWidget;
SettingsButtonWidget *quickSettingsWidget;
QCheckBox *showFoldersCheckBox;
QCheckBox *drawUnusedColorIdentitiesCheckBox;
QCheckBox *tagFilterVisibilityCheckBox;
QCheckBox *tagsOnWidgetsVisibilityCheckBox;
QScrollArea *scrollArea;
VisualDeckStorageFolderDisplayWidget *folderWidget;
};