From 58479e4b00d399e3025558104e50c75ef609dda0 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 29 Jul 2020 22:14:43 -0400 Subject: filter for games replaced the button box with a regular widget with vertical layout it was doing weird things to buttons with focus when removing and adding buttons on the fly because of filtering --- src/createinstancedialogpages.cpp | 46 ++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'src/createinstancedialogpages.cpp') diff --git a/src/createinstancedialogpages.cpp b/src/createinstancedialogpages.cpp index 3f35b4fe..2aac93a0 100644 --- a/src/createinstancedialogpages.cpp +++ b/src/createinstancedialogpages.cpp @@ -12,6 +12,7 @@ namespace cid using MOBase::IPluginGame; using MOBase::TaskDialog; +using MOBase::FilterWidget; QString makeDefaultPath(const std::wstring& dir) { @@ -228,6 +229,9 @@ GamePage::GamePage(CreateInstanceDialog& dlg) createGames(); fillList(); + m_filter.setEdit(ui->gamesFilter); + + QObject::connect(&m_filter, &FilterWidget::changed, [&]{ fillList(); }); QObject::connect(ui->showAllGames, &QCheckBox::clicked, [&]{ fillList(); }); } @@ -362,6 +366,7 @@ void GamePage::updateButton(Game* g) } g->button->setText(g->game->gameName()); + g->button->setIcon(g->game->gameIcon()); if (g->installed) { g->button->setDescription(g->dir); @@ -394,7 +399,7 @@ void GamePage::selectButton(Game* g) // was not installed; create it and show it // and it has a button, just check it createGameButton(gg.get()); - ui->games->addButton(gg->button, QDialogButtonBox::AcceptRole); + addButton(gg->button); } gg->button->setChecked(true); @@ -439,9 +444,8 @@ void GamePage::fillList() { const bool showAll = ui->showAllGames->isChecked(); - ui->games->clear(); - - ui->games->addButton(createCustomButton(), QDialogButtonBox::AcceptRole); + clearButtons(); + addButton(createCustomButton()); for (auto& g : m_games) { g->button = nullptr; @@ -451,11 +455,43 @@ void GamePage::fillList() continue; } + if (!m_filter.matches(g->game->gameName())) { + continue; + } + createGameButton(g.get()); - ui->games->addButton(g->button, QDialogButtonBox::AcceptRole); + addButton(g->button); } } +void GamePage::clearButtons() +{ + auto* ly = static_cast(ui->games->layout()); + + ui->games->setUpdatesEnabled(false); + + // delete all children + qDeleteAll(ui->games->findChildren("", Qt::FindDirectChildrenOnly)); + + // stretch widgets added with addStretch() are not in the parent widget, + // they have to be deleted from the layout itself + while (auto* child=ly->takeAt(0)) + delete child; + + // add a stretch, buttons will be added before + ly->addStretch(); + + ui->games->setUpdatesEnabled(true); +} + +void GamePage::addButton(QAbstractButton* b) +{ + auto* ly = static_cast(ui->games->layout()); + + // insert before the stretch + ly->insertWidget(ly->count() - 1, b); +} + GamePage::Game* GamePage::checkInstallation(const QString& path, Game* g) { if (g->game->looksValid(path)) { -- cgit v1.3.1