mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 17:02:15 -07:00
Move the search bar to its own widget.
This commit is contained in:
parent
060e8f0cfd
commit
322d61e7ef
5 changed files with 65 additions and 22 deletions
|
|
@ -100,6 +100,7 @@ set(cockatrice_SOURCES
|
|||
src/client/ui/widgets/printing_selector/printing_selector.cpp
|
||||
src/client/ui/widgets/printing_selector/printing_selector_card_display_widget.cpp
|
||||
src/client/ui/widgets/printing_selector/printing_selector_card_overlay_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_sorting_widget.cpp
|
||||
src/client/ui/widgets/printing_selector/set_name_and_collectors_number_display_widget.cpp
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "../../../../settings/cache_settings.h"
|
||||
#include "printing_selector_card_display_widget.h"
|
||||
#include "printing_selector_card_search_widget.h"
|
||||
#include "printing_selector_card_selection_widget.h"
|
||||
#include "printing_selector_card_sorting_widget.h"
|
||||
|
||||
|
|
@ -10,7 +11,6 @@
|
|||
#include <QHBoxLayout>
|
||||
#include <QScrollBar>
|
||||
|
||||
|
||||
PrintingSelector::PrintingSelector(QWidget *parent,
|
||||
TabDeckEditor *deckEditor,
|
||||
DeckListModel *deckModel,
|
||||
|
|
@ -20,24 +20,15 @@ PrintingSelector::PrintingSelector(QWidget *parent,
|
|||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
layout = new QVBoxLayout();
|
||||
setLayout(layout);
|
||||
timer = new QTimer(this);
|
||||
widgetLoadingBufferTimer = new QTimer(this);
|
||||
|
||||
sortToolBar = new PrintingSelectorCardSortingWidget(this);
|
||||
layout->addWidget(sortToolBar);
|
||||
|
||||
// Add the search bar
|
||||
searchBar = new QLineEdit(this);
|
||||
searchBar->setPlaceholderText(tr("Search by set name or set code"));
|
||||
searchBar = new PrintingSelectorCardSearchWidget(this);
|
||||
layout->addWidget(searchBar);
|
||||
|
||||
// Add a debounce timer for the search bar
|
||||
searchDebounceTimer = new QTimer(this);
|
||||
searchDebounceTimer->setSingleShot(true);
|
||||
connect(searchBar, &QLineEdit::textChanged, this, [this]() {
|
||||
searchDebounceTimer->start(300); // 300ms debounce
|
||||
});
|
||||
connect(searchDebounceTimer, &QTimer::timeout, this, &PrintingSelector::updateDisplay);
|
||||
|
||||
flowWidget = new FlowWidget(this, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
|
||||
layout->addWidget(flowWidget);
|
||||
|
||||
|
|
@ -55,9 +46,9 @@ PrintingSelector::PrintingSelector(QWidget *parent,
|
|||
|
||||
void PrintingSelector::updateDisplay()
|
||||
{
|
||||
timer->stop();
|
||||
timer->deleteLater();
|
||||
timer = new QTimer(this);
|
||||
widgetLoadingBufferTimer->stop();
|
||||
widgetLoadingBufferTimer->deleteLater();
|
||||
widgetLoadingBufferTimer = new QTimer(this);
|
||||
flowWidget->clearLayout();
|
||||
if (selectedCard != nullptr) {
|
||||
setWindowTitle(selectedCard->getName());
|
||||
|
|
@ -144,7 +135,8 @@ void PrintingSelector::getAllSetsForCurrentCard()
|
|||
|
||||
CardInfoPerSetMap cardInfoPerSets = selectedCard->getSets();
|
||||
const QList<CardInfoPerSet> sortedSets = sortToolBar->sortSets(cardInfoPerSets);
|
||||
const QList<CardInfoPerSet> filteredSets = sortToolBar->filterSets(sortedSets, searchBar->text().trimmed().toLower());
|
||||
const QList<CardInfoPerSet> filteredSets =
|
||||
sortToolBar->filterSets(sortedSets, searchBar->getSearchText().trimmed().toLower());
|
||||
QList<CardInfoPerSet> setsToUse;
|
||||
|
||||
if (SettingsCache::instance().getBumpSetsWithCardsInDeckToTop()) {
|
||||
|
|
@ -156,7 +148,7 @@ void PrintingSelector::getAllSetsForCurrentCard()
|
|||
// Defer widget creation
|
||||
currentIndex = 0;
|
||||
|
||||
connect(timer, &QTimer::timeout, this, [=]() mutable {
|
||||
connect(widgetLoadingBufferTimer, &QTimer::timeout, this, [=]() mutable {
|
||||
for (int i = 0; i < BATCH_SIZE && currentIndex < setsToUse.size(); ++i, ++currentIndex) {
|
||||
auto *cardDisplayWidget = new PrintingSelectorCardDisplayWidget(this, deckEditor, deckModel, deckView,
|
||||
cardSizeWidget->getSlider(), selectedCard,
|
||||
|
|
@ -167,9 +159,9 @@ void PrintingSelector::getAllSetsForCurrentCard()
|
|||
|
||||
// Stop timer when done
|
||||
if (currentIndex >= setsToUse.size()) {
|
||||
timer->stop();
|
||||
widgetLoadingBufferTimer->stop();
|
||||
}
|
||||
});
|
||||
currentIndex = 0;
|
||||
timer->start(0); // Process as soon as possible
|
||||
widgetLoadingBufferTimer->start(0); // Process as soon as possible
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#define BATCH_SIZE 10
|
||||
|
||||
class PrintingSelectorCardSearchWidget;
|
||||
class PrintingSelectorCardSelectionWidget;
|
||||
class PrintingSelectorCardSortingWidget;
|
||||
class TabDeckEditor;
|
||||
|
|
@ -37,8 +38,7 @@ public slots:
|
|||
private:
|
||||
QVBoxLayout *layout;
|
||||
PrintingSelectorCardSortingWidget *sortToolBar;
|
||||
QLineEdit *searchBar;
|
||||
QTimer *searchDebounceTimer;
|
||||
PrintingSelectorCardSearchWidget *searchBar;
|
||||
FlowWidget *flowWidget;
|
||||
CardSizeWidget *cardSizeWidget;
|
||||
PrintingSelectorCardSelectionWidget *cardSelectionBar;
|
||||
|
|
@ -47,7 +47,7 @@ private:
|
|||
QTreeView *deckView;
|
||||
CardInfoPtr selectedCard;
|
||||
QString currentZone;
|
||||
QTimer *timer;
|
||||
QTimer *widgetLoadingBufferTimer;
|
||||
int currentIndex = 0;
|
||||
void selectCard(int changeBy);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
#include "printing_selector_card_search_widget.h"
|
||||
|
||||
PrintingSelectorCardSearchWidget::PrintingSelectorCardSearchWidget(PrintingSelector *parent) : parent(parent)
|
||||
{
|
||||
layout = new QHBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
||||
searchBar = new QLineEdit(this);
|
||||
searchBar->setPlaceholderText(tr("Search by set name or set code"));
|
||||
layout->addWidget(searchBar);
|
||||
|
||||
// Add a debounce timer for the search bar
|
||||
searchDebounceTimer = new QTimer(this);
|
||||
searchDebounceTimer->setSingleShot(true);
|
||||
connect(searchBar, &QLineEdit::textChanged, this, [this]() {
|
||||
searchDebounceTimer->start(300); // 300ms debounce
|
||||
});
|
||||
|
||||
connect(searchDebounceTimer, &QTimer::timeout, parent, &PrintingSelector::updateDisplay);
|
||||
}
|
||||
|
||||
QString PrintingSelectorCardSearchWidget::getSearchText()
|
||||
{
|
||||
return searchBar->text();
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef PRINTING_SELECTOR_CARD_SEARCH_WIDGET_H
|
||||
#define PRINTING_SELECTOR_CARD_SEARCH_WIDGET_H
|
||||
|
||||
#include "printing_selector.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
class PrintingSelectorCardSearchWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PrintingSelectorCardSearchWidget(PrintingSelector *parent);
|
||||
QString getSearchText();
|
||||
|
||||
private:
|
||||
QHBoxLayout *layout;
|
||||
PrintingSelector *parent;
|
||||
QLineEdit *searchBar;
|
||||
QTimer *searchDebounceTimer;
|
||||
};
|
||||
|
||||
#endif // PRINTING_SELECTOR_CARD_SEARCH_WIDGET_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue