From 0599da98592dec02c68d226067be8eb027e19a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Mon, 10 Feb 2025 13:41:41 +0100 Subject: [PATCH] Move PrintingSelector Display options to new quick settings widget. --- cockatrice/CMakeLists.txt | 1 - .../printing_selector/printing_selector.cpp | 19 ++- .../printing_selector/printing_selector.h | 7 +- ...g_selector_view_options_toolbar_widget.cpp | 140 ------------------ ...ing_selector_view_options_toolbar_widget.h | 36 ----- .../printing_selector_view_options_widget.h | 1 + .../quick_settings/settings_popup_widget.cpp | 2 +- 7 files changed, 21 insertions(+), 185 deletions(-) delete mode 100644 cockatrice/src/client/ui/widgets/printing_selector/printing_selector_view_options_toolbar_widget.cpp delete mode 100644 cockatrice/src/client/ui/widgets/printing_selector/printing_selector_view_options_toolbar_widget.h diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 770bf4f22..072ed598e 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -110,7 +110,6 @@ set(cockatrice_SOURCES src/client/ui/widgets/printing_selector/printing_selector_card_search_widget.cpp src/client/ui/widgets/printing_selector/printing_selector_card_selection_widget.cpp src/client/ui/widgets/printing_selector/printing_selector_card_sorting_widget.cpp - src/client/ui/widgets/printing_selector/printing_selector_view_options_toolbar_widget.cpp src/client/ui/widgets/printing_selector/printing_selector_view_options_widget.cpp src/client/ui/widgets/printing_selector/set_name_and_collectors_number_display_widget.cpp src/client/ui/widgets/quick_settings/settings_button_widget.cpp diff --git a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.cpp b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.cpp index 4a3d9fe80..fe6e98ec5 100644 --- a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.cpp +++ b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.cpp @@ -5,7 +5,7 @@ #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 "printing_selector_view_options_widget.h" #include @@ -33,13 +33,22 @@ PrintingSelector::PrintingSelector(QWidget *parent, setLayout(layout); widgetLoadingBufferTimer = new QTimer(this); - // Initialize toolbar and widgets - viewOptionsToolbar = new PrintingSelectorViewOptionsToolbarWidget(this, this); - layout->addWidget(viewOptionsToolbar); + displayOptionsWidget = new SettingsButtonWidget(this); + displayOptionsWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); + viewOptionsToolbar = new PrintingSelectorViewOptionsWidget(displayOptionsWidget, this); + + displayOptionsWidget->addSettingsWidget(viewOptionsToolbar); sortToolBar = new PrintingSelectorCardSortingWidget(this); + sortToolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); sortToolBar->setVisible(SettingsCache::instance().getPrintingSelectorSortOptionsVisible()); - layout->addWidget(sortToolBar); + + auto sortAndOptionsLayout = new QHBoxLayout(this); + + sortAndOptionsLayout->addWidget(sortToolBar); + sortAndOptionsLayout->addWidget(displayOptionsWidget); + + layout->addLayout(sortAndOptionsLayout); searchBar = new PrintingSelectorCardSearchWidget(this); searchBar->setVisible(SettingsCache::instance().getPrintingSelectorSearchBarVisible()); diff --git a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.h b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.h index 24020a7cc..b0a259626 100644 --- a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.h +++ b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.h @@ -5,6 +5,8 @@ #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 "printing_selector_view_options_widget.h" #include #include @@ -16,7 +18,7 @@ class PrintingSelectorCardSearchWidget; class PrintingSelectorCardSelectionWidget; class PrintingSelectorCardSortingWidget; -class PrintingSelectorViewOptionsToolbarWidget; +class PrintingSelectorViewOptionsWidget; class TabDeckEditor; class PrintingSelector : public QWidget { @@ -41,7 +43,8 @@ private slots: private: QVBoxLayout *layout; - PrintingSelectorViewOptionsToolbarWidget *viewOptionsToolbar; + SettingsButtonWidget *displayOptionsWidget; + PrintingSelectorViewOptionsWidget *viewOptionsToolbar; PrintingSelectorCardSortingWidget *sortToolBar; PrintingSelectorCardSearchWidget *searchBar; FlowWidget *flowWidget; diff --git a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_view_options_toolbar_widget.cpp b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_view_options_toolbar_widget.cpp deleted file mode 100644 index cd03db466..000000000 --- a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_view_options_toolbar_widget.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include "printing_selector_view_options_toolbar_widget.h" - -#include -#include -#include - -/** - * @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; -} diff --git a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_view_options_toolbar_widget.h b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_view_options_toolbar_widget.h deleted file mode 100644 index 875f669f6..000000000 --- a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_view_options_toolbar_widget.h +++ /dev/null @@ -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 -#include -#include -#include - -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 diff --git a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_view_options_widget.h b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_view_options_widget.h index 3d0dec77e..1aedab875 100644 --- a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_view_options_widget.h +++ b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_view_options_widget.h @@ -8,6 +8,7 @@ #include #include +class PrintingSelector; class PrintingSelectorViewOptionsWidget : public QWidget { Q_OBJECT diff --git a/cockatrice/src/client/ui/widgets/quick_settings/settings_popup_widget.cpp b/cockatrice/src/client/ui/widgets/quick_settings/settings_popup_widget.cpp index d521c1a3a..a0a5f0806 100644 --- a/cockatrice/src/client/ui/widgets/quick_settings/settings_popup_widget.cpp +++ b/cockatrice/src/client/ui/widgets/quick_settings/settings_popup_widget.cpp @@ -3,7 +3,7 @@ #include #include -SettingsPopupWidget::SettingsPopupWidget(QWidget *parent) : QWidget(parent, Qt::Popup | Qt::FramelessWindowHint) +SettingsPopupWidget::SettingsPopupWidget(QWidget *parent) : QWidget(parent, Qt::Popup) { layout = new QVBoxLayout(this); }