mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 08:52: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
|
||||
QStringList combinedTags = knownTags + defaultTags + activeTags;
|
||||
QStringList combinedTags = defaultTags + knownTags + activeTags;
|
||||
combinedTags.removeDuplicates();
|
||||
|
||||
// Main layout
|
||||
auto *mainLayout = new QVBoxLayout(this);
|
||||
|
||||
// Filter bar
|
||||
filterInput_ = new QLineEdit(this);
|
||||
mainLayout->addWidget(filterInput_);
|
||||
|
||||
connect(filterInput_, &QLineEdit::textChanged, this, &DeckPreviewTagDialog::filterTags);
|
||||
|
||||
// Instruction label
|
||||
instructionLabel = new QLabel(this);
|
||||
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:"));
|
||||
newTagInput_->setPlaceholderText(tr("Add a new tag (e.g., Aggro️)"));
|
||||
addTagButton_->setText(tr("Add Tag"));
|
||||
filterInput_->setPlaceholderText(tr("Filter tags..."));
|
||||
okButton->setText(tr("OK"));
|
||||
cancelButton->setText(tr("Cancel"));
|
||||
}
|
||||
|
|
@ -191,6 +198,18 @@ void DeckPreviewTagDialog::addTag()
|
|||
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()
|
||||
{
|
||||
activeTags_.clear();
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ public:
|
|||
const QStringList &activeTags,
|
||||
QWidget *parent = nullptr);
|
||||
QStringList getActiveTags() const;
|
||||
void filterTags(const QString &text);
|
||||
|
||||
private slots:
|
||||
void addTag();
|
||||
|
|
@ -27,6 +28,7 @@ private slots:
|
|||
private:
|
||||
QLabel *instructionLabel;
|
||||
QListWidget *tagListView_;
|
||||
QLineEdit *filterInput_;
|
||||
QLineEdit *newTagInput_;
|
||||
QPushButton *addTagButton_;
|
||||
QPushButton *okButton;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue