Move PrintingSelector Display options to new quick settings widget.

This commit is contained in:
Lukas Brübach 2025-02-10 13:41:41 +01:00
parent 7baafa6273
commit 0599da9859
7 changed files with 21 additions and 185 deletions

View file

@ -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_search_widget.cpp
src/client/ui/widgets/printing_selector/printing_selector_card_selection_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_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/printing_selector_view_options_widget.cpp
src/client/ui/widgets/printing_selector/set_name_and_collectors_number_display_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 src/client/ui/widgets/quick_settings/settings_button_widget.cpp

View file

@ -5,7 +5,7 @@
#include "printing_selector_card_search_widget.h" #include "printing_selector_card_search_widget.h"
#include "printing_selector_card_selection_widget.h" #include "printing_selector_card_selection_widget.h"
#include "printing_selector_card_sorting_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 <QScrollBar> #include <QScrollBar>
@ -33,13 +33,22 @@ PrintingSelector::PrintingSelector(QWidget *parent,
setLayout(layout); setLayout(layout);
widgetLoadingBufferTimer = new QTimer(this); widgetLoadingBufferTimer = new QTimer(this);
// Initialize toolbar and widgets displayOptionsWidget = new SettingsButtonWidget(this);
viewOptionsToolbar = new PrintingSelectorViewOptionsToolbarWidget(this, this); displayOptionsWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
layout->addWidget(viewOptionsToolbar); viewOptionsToolbar = new PrintingSelectorViewOptionsWidget(displayOptionsWidget, this);
displayOptionsWidget->addSettingsWidget(viewOptionsToolbar);
sortToolBar = new PrintingSelectorCardSortingWidget(this); sortToolBar = new PrintingSelectorCardSortingWidget(this);
sortToolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
sortToolBar->setVisible(SettingsCache::instance().getPrintingSelectorSortOptionsVisible()); 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 = new PrintingSelectorCardSearchWidget(this);
searchBar->setVisible(SettingsCache::instance().getPrintingSelectorSearchBarVisible()); searchBar->setVisible(SettingsCache::instance().getPrintingSelectorSearchBarVisible());

View file

@ -5,6 +5,8 @@
#include "../../../../game/cards/card_database.h" #include "../../../../game/cards/card_database.h"
#include "../cards/card_size_widget.h" #include "../cards/card_size_widget.h"
#include "../general/layout_containers/flow_widget.h" #include "../general/layout_containers/flow_widget.h"
#include "../quick_settings/settings_button_widget.h"
#include "printing_selector_view_options_widget.h"
#include <QLabel> #include <QLabel>
#include <QTreeView> #include <QTreeView>
@ -16,7 +18,7 @@
class PrintingSelectorCardSearchWidget; class PrintingSelectorCardSearchWidget;
class PrintingSelectorCardSelectionWidget; class PrintingSelectorCardSelectionWidget;
class PrintingSelectorCardSortingWidget; class PrintingSelectorCardSortingWidget;
class PrintingSelectorViewOptionsToolbarWidget; class PrintingSelectorViewOptionsWidget;
class TabDeckEditor; class TabDeckEditor;
class PrintingSelector : public QWidget class PrintingSelector : public QWidget
{ {
@ -41,7 +43,8 @@ private slots:
private: private:
QVBoxLayout *layout; QVBoxLayout *layout;
PrintingSelectorViewOptionsToolbarWidget *viewOptionsToolbar; SettingsButtonWidget *displayOptionsWidget;
PrintingSelectorViewOptionsWidget *viewOptionsToolbar;
PrintingSelectorCardSortingWidget *sortToolBar; PrintingSelectorCardSortingWidget *sortToolBar;
PrintingSelectorCardSearchWidget *searchBar; PrintingSelectorCardSearchWidget *searchBar;
FlowWidget *flowWidget; FlowWidget *flowWidget;

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

@ -8,6 +8,7 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QWidget> #include <QWidget>
class PrintingSelector;
class PrintingSelectorViewOptionsWidget : public QWidget class PrintingSelectorViewOptionsWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT

View file

@ -3,7 +3,7 @@
#include <QApplication> #include <QApplication>
#include <QFocusEvent> #include <QFocusEvent>
SettingsPopupWidget::SettingsPopupWidget(QWidget *parent) : QWidget(parent, Qt::Popup | Qt::FramelessWindowHint) SettingsPopupWidget::SettingsPopupWidget(QWidget *parent) : QWidget(parent, Qt::Popup)
{ {
layout = new QVBoxLayout(this); layout = new QVBoxLayout(this);
} }