mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-20 17:32: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.cpp
|
||||||
src/client/ui/widgets/printing_selector/printing_selector_card_display_widget.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_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_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/set_name_and_collectors_number_display_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 "../../../../settings/cache_settings.h"
|
||||||
#include "printing_selector_card_display_widget.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_selection_widget.h"
|
||||||
#include "printing_selector_card_sorting_widget.h"
|
#include "printing_selector_card_sorting_widget.h"
|
||||||
|
|
||||||
|
|
@ -10,7 +11,6 @@
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
|
||||||
|
|
||||||
PrintingSelector::PrintingSelector(QWidget *parent,
|
PrintingSelector::PrintingSelector(QWidget *parent,
|
||||||
TabDeckEditor *deckEditor,
|
TabDeckEditor *deckEditor,
|
||||||
DeckListModel *deckModel,
|
DeckListModel *deckModel,
|
||||||
|
|
@ -20,24 +20,15 @@ PrintingSelector::PrintingSelector(QWidget *parent,
|
||||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
layout = new QVBoxLayout();
|
layout = new QVBoxLayout();
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
timer = new QTimer(this);
|
widgetLoadingBufferTimer = new QTimer(this);
|
||||||
|
|
||||||
sortToolBar = new PrintingSelectorCardSortingWidget(this);
|
sortToolBar = new PrintingSelectorCardSortingWidget(this);
|
||||||
layout->addWidget(sortToolBar);
|
layout->addWidget(sortToolBar);
|
||||||
|
|
||||||
// Add the search bar
|
// Add the search bar
|
||||||
searchBar = new QLineEdit(this);
|
searchBar = new PrintingSelectorCardSearchWidget(this);
|
||||||
searchBar->setPlaceholderText(tr("Search by set name or set code"));
|
|
||||||
layout->addWidget(searchBar);
|
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);
|
flowWidget = new FlowWidget(this, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
|
||||||
layout->addWidget(flowWidget);
|
layout->addWidget(flowWidget);
|
||||||
|
|
||||||
|
|
@ -55,9 +46,9 @@ PrintingSelector::PrintingSelector(QWidget *parent,
|
||||||
|
|
||||||
void PrintingSelector::updateDisplay()
|
void PrintingSelector::updateDisplay()
|
||||||
{
|
{
|
||||||
timer->stop();
|
widgetLoadingBufferTimer->stop();
|
||||||
timer->deleteLater();
|
widgetLoadingBufferTimer->deleteLater();
|
||||||
timer = new QTimer(this);
|
widgetLoadingBufferTimer = new QTimer(this);
|
||||||
flowWidget->clearLayout();
|
flowWidget->clearLayout();
|
||||||
if (selectedCard != nullptr) {
|
if (selectedCard != nullptr) {
|
||||||
setWindowTitle(selectedCard->getName());
|
setWindowTitle(selectedCard->getName());
|
||||||
|
|
@ -144,7 +135,8 @@ void PrintingSelector::getAllSetsForCurrentCard()
|
||||||
|
|
||||||
CardInfoPerSetMap cardInfoPerSets = selectedCard->getSets();
|
CardInfoPerSetMap cardInfoPerSets = selectedCard->getSets();
|
||||||
const QList<CardInfoPerSet> sortedSets = sortToolBar->sortSets(cardInfoPerSets);
|
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;
|
QList<CardInfoPerSet> setsToUse;
|
||||||
|
|
||||||
if (SettingsCache::instance().getBumpSetsWithCardsInDeckToTop()) {
|
if (SettingsCache::instance().getBumpSetsWithCardsInDeckToTop()) {
|
||||||
|
|
@ -156,7 +148,7 @@ void PrintingSelector::getAllSetsForCurrentCard()
|
||||||
// Defer widget creation
|
// Defer widget creation
|
||||||
currentIndex = 0;
|
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) {
|
for (int i = 0; i < BATCH_SIZE && currentIndex < setsToUse.size(); ++i, ++currentIndex) {
|
||||||
auto *cardDisplayWidget = new PrintingSelectorCardDisplayWidget(this, deckEditor, deckModel, deckView,
|
auto *cardDisplayWidget = new PrintingSelectorCardDisplayWidget(this, deckEditor, deckModel, deckView,
|
||||||
cardSizeWidget->getSlider(), selectedCard,
|
cardSizeWidget->getSlider(), selectedCard,
|
||||||
|
|
@ -167,9 +159,9 @@ void PrintingSelector::getAllSetsForCurrentCard()
|
||||||
|
|
||||||
// Stop timer when done
|
// Stop timer when done
|
||||||
if (currentIndex >= setsToUse.size()) {
|
if (currentIndex >= setsToUse.size()) {
|
||||||
timer->stop();
|
widgetLoadingBufferTimer->stop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
currentIndex = 0;
|
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
|
#define BATCH_SIZE 10
|
||||||
|
|
||||||
|
class PrintingSelectorCardSearchWidget;
|
||||||
class PrintingSelectorCardSelectionWidget;
|
class PrintingSelectorCardSelectionWidget;
|
||||||
class PrintingSelectorCardSortingWidget;
|
class PrintingSelectorCardSortingWidget;
|
||||||
class TabDeckEditor;
|
class TabDeckEditor;
|
||||||
|
|
@ -37,8 +38,7 @@ public slots:
|
||||||
private:
|
private:
|
||||||
QVBoxLayout *layout;
|
QVBoxLayout *layout;
|
||||||
PrintingSelectorCardSortingWidget *sortToolBar;
|
PrintingSelectorCardSortingWidget *sortToolBar;
|
||||||
QLineEdit *searchBar;
|
PrintingSelectorCardSearchWidget *searchBar;
|
||||||
QTimer *searchDebounceTimer;
|
|
||||||
FlowWidget *flowWidget;
|
FlowWidget *flowWidget;
|
||||||
CardSizeWidget *cardSizeWidget;
|
CardSizeWidget *cardSizeWidget;
|
||||||
PrintingSelectorCardSelectionWidget *cardSelectionBar;
|
PrintingSelectorCardSelectionWidget *cardSelectionBar;
|
||||||
|
|
@ -47,7 +47,7 @@ private:
|
||||||
QTreeView *deckView;
|
QTreeView *deckView;
|
||||||
CardInfoPtr selectedCard;
|
CardInfoPtr selectedCard;
|
||||||
QString currentZone;
|
QString currentZone;
|
||||||
QTimer *timer;
|
QTimer *widgetLoadingBufferTimer;
|
||||||
int currentIndex = 0;
|
int currentIndex = 0;
|
||||||
void selectCard(int changeBy);
|
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