|
|
@@ -98,10 +98,81 @@ void HeroSpellWidget::on_customizeSpells_toggled(bool checked)
|
|
|
{
|
|
|
hero.removeAllSpells();
|
|
|
}
|
|
|
+ ui->filter->clear();
|
|
|
+ ui->filter->setEnabled(checked);
|
|
|
ui->tabWidget->setEnabled(checked);
|
|
|
initSpellLists();
|
|
|
}
|
|
|
|
|
|
+void HeroSpellWidget::on_filter_textChanged(const QString & keyword)
|
|
|
+{
|
|
|
+ if (keyword.toStdString().find_first_not_of(' ') == std::string::npos)
|
|
|
+ {
|
|
|
+ const auto exists = QString::fromStdString(".*");
|
|
|
+ showItemIfMatches(exists);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ const auto doesNotContainKeyword = QString::fromStdString("^((?!") + keyword + QString::fromStdString(").)*$");
|
|
|
+ hideItemIfMatches(doesNotContainKeyword);
|
|
|
+
|
|
|
+ const auto containsKeyword = QString::fromStdString(".*") + keyword + QString::fromStdString(".*");
|
|
|
+ showItemIfMatches(containsKeyword);
|
|
|
+ }
|
|
|
+
|
|
|
+ hideEmptySpellLists();
|
|
|
+}
|
|
|
+
|
|
|
+void HeroSpellWidget::showItemIfMatches(const QString & match)
|
|
|
+{
|
|
|
+ toggleHiddenForItemIfMatches(match, false);
|
|
|
+}
|
|
|
+
|
|
|
+void HeroSpellWidget::hideItemIfMatches(const QString & match)
|
|
|
+{
|
|
|
+ toggleHiddenForItemIfMatches(match, true);
|
|
|
+}
|
|
|
+
|
|
|
+void HeroSpellWidget::toggleHiddenForItemIfMatches(const QString & match, bool hidden)
|
|
|
+{
|
|
|
+ QListWidget * spellLists[] = { ui->spellList1, ui->spellList2, ui->spellList3, ui->spellList4, ui->spellList5 };
|
|
|
+ for (const QListWidget * list : spellLists)
|
|
|
+ {
|
|
|
+ const auto items = list->findItems(match, Qt::MatchRegularExpression);
|
|
|
+ for (QListWidgetItem * item : items)
|
|
|
+ {
|
|
|
+ item->setHidden(hidden);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void HeroSpellWidget::hideEmptySpellLists()
|
|
|
+{
|
|
|
+
|
|
|
+ QListWidget * spellLists[] = { ui->spellList1, ui->spellList2, ui->spellList3, ui->spellList4, ui->spellList5 };
|
|
|
+ auto toggleSpellListVisibility = [&](const QListWidget * list, bool visible)
|
|
|
+ {
|
|
|
+ auto * parent = list->parentWidget();
|
|
|
+ int index = ui->tabWidget->indexOf(parent);
|
|
|
+ ui->tabWidget->setTabVisible(index, visible);
|
|
|
+ };
|
|
|
+
|
|
|
+ for (const QListWidget * list : spellLists)
|
|
|
+ {
|
|
|
+ const auto allItems = list->findItems("*", Qt::MatchWildcard);
|
|
|
+ bool isListEmpty = true;
|
|
|
+ for (QListWidgetItem * item : allItems)
|
|
|
+ {
|
|
|
+ if (!item->isHidden())
|
|
|
+ {
|
|
|
+ isListEmpty = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ toggleSpellListVisibility(list, !isListEmpty);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
HeroSpellDelegate::HeroSpellDelegate(CGHeroInstance & h)
|
|
|
: BaseInspectorItemDelegate()
|
|
|
, hero(h)
|