diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2020-07-29 22:14:43 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2020-11-03 11:39:06 -0500 |
| commit | 58479e4b00d399e3025558104e50c75ef609dda0 (patch) | |
| tree | eca6526d52b32da32a1fbebe412702713aca5d79 /src/createinstancedialogpages.cpp | |
| parent | a97638249de0a9a4c17dc28805c35df489a64e26 (diff) | |
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
Diffstat (limited to 'src/createinstancedialogpages.cpp')
| -rw-r--r-- | src/createinstancedialogpages.cpp | 46 |
1 files changed, 41 insertions, 5 deletions
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<QVBoxLayout*>(ui->games->layout()); + + ui->games->setUpdatesEnabled(false); + + // delete all children + qDeleteAll(ui->games->findChildren<QWidget*>("", 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<QVBoxLayout*>(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)) { |
