mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-20 01:12:15 -07:00
Add a search bar for tags.
This commit is contained in:
parent
8455e77ddd
commit
3976ab8d5d
2 changed files with 22 additions and 1 deletions
|
|
@ -97,12 +97,18 @@ DeckPreviewTagDialog::DeckPreviewTagDialog(const QStringList &knownTags, const Q
|
||||||
};
|
};
|
||||||
|
|
||||||
// Merge knownTags with defaultTags, ensuring no duplicates
|
// Merge knownTags with defaultTags, ensuring no duplicates
|
||||||
QStringList combinedTags = knownTags + defaultTags + activeTags;
|
QStringList combinedTags = defaultTags + knownTags + activeTags;
|
||||||
combinedTags.removeDuplicates();
|
combinedTags.removeDuplicates();
|
||||||
|
|
||||||
// Main layout
|
// Main layout
|
||||||
auto *mainLayout = new QVBoxLayout(this);
|
auto *mainLayout = new QVBoxLayout(this);
|
||||||
|
|
||||||
|
// Filter bar
|
||||||
|
filterInput_ = new QLineEdit(this);
|
||||||
|
mainLayout->addWidget(filterInput_);
|
||||||
|
|
||||||
|
connect(filterInput_, &QLineEdit::textChanged, this, &DeckPreviewTagDialog::filterTags);
|
||||||
|
|
||||||
// Instruction label
|
// Instruction label
|
||||||
instructionLabel = new QLabel(this);
|
instructionLabel = new QLabel(this);
|
||||||
instructionLabel->setWordWrap(true);
|
instructionLabel->setWordWrap(true);
|
||||||
|
|
@ -151,6 +157,7 @@ void DeckPreviewTagDialog::retranslateUi()
|
||||||
instructionLabel->setText(tr("Manage your deck tags. Check or uncheck tags as needed, or add new ones:"));
|
instructionLabel->setText(tr("Manage your deck tags. Check or uncheck tags as needed, or add new ones:"));
|
||||||
newTagInput_->setPlaceholderText(tr("Add a new tag (e.g., Aggro️)"));
|
newTagInput_->setPlaceholderText(tr("Add a new tag (e.g., Aggro️)"));
|
||||||
addTagButton_->setText(tr("Add Tag"));
|
addTagButton_->setText(tr("Add Tag"));
|
||||||
|
filterInput_->setPlaceholderText(tr("Filter tags..."));
|
||||||
okButton->setText(tr("OK"));
|
okButton->setText(tr("OK"));
|
||||||
cancelButton->setText(tr("Cancel"));
|
cancelButton->setText(tr("Cancel"));
|
||||||
}
|
}
|
||||||
|
|
@ -191,6 +198,18 @@ void DeckPreviewTagDialog::addTag()
|
||||||
newTagInput_->clear();
|
newTagInput_->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckPreviewTagDialog::filterTags(const QString &text)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < tagListView_->count(); ++i) {
|
||||||
|
auto *item = tagListView_->item(i);
|
||||||
|
auto *tagWidget = qobject_cast<DeckPreviewTagItemWidget *>(tagListView_->itemWidget(item));
|
||||||
|
if (tagWidget) {
|
||||||
|
bool matches = tagWidget->checkBox()->text().contains(text, Qt::CaseInsensitive);
|
||||||
|
item->setHidden(!matches);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DeckPreviewTagDialog::onCheckboxStateChanged()
|
void DeckPreviewTagDialog::onCheckboxStateChanged()
|
||||||
{
|
{
|
||||||
activeTags_.clear();
|
activeTags_.clear();
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ public:
|
||||||
const QStringList &activeTags,
|
const QStringList &activeTags,
|
||||||
QWidget *parent = nullptr);
|
QWidget *parent = nullptr);
|
||||||
QStringList getActiveTags() const;
|
QStringList getActiveTags() const;
|
||||||
|
void filterTags(const QString &text);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void addTag();
|
void addTag();
|
||||||
|
|
@ -27,6 +28,7 @@ private slots:
|
||||||
private:
|
private:
|
||||||
QLabel *instructionLabel;
|
QLabel *instructionLabel;
|
||||||
QListWidget *tagListView_;
|
QListWidget *tagListView_;
|
||||||
|
QLineEdit *filterInput_;
|
||||||
QLineEdit *newTagInput_;
|
QLineEdit *newTagInput_;
|
||||||
QPushButton *addTagButton_;
|
QPushButton *addTagButton_;
|
||||||
QPushButton *okButton;
|
QPushButton *okButton;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue