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/createinstancedialog.ui | 204 +++++++++++++++++++++-----------------
src/createinstancedialogpages.cpp | 46 ++++++++-
src/createinstancedialogpages.h | 9 +-
3 files changed, 161 insertions(+), 98 deletions(-)
(limited to 'src')
diff --git a/src/createinstancedialog.ui b/src/createinstancedialog.ui
index cafccb36..a8f21c51 100644
--- a/src/createinstancedialog.ui
+++ b/src/createinstancedialog.ui
@@ -127,7 +127,7 @@
-
-
+
0
@@ -141,11 +141,8 @@
0
-
-
-
-
- 0
-
+
+
0
@@ -184,22 +181,22 @@
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 40
-
-
-
-
@@ -226,32 +223,12 @@
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
- Show all supported games
-
-
-
-
-
+
0
@@ -265,59 +242,104 @@
0
-
-
-
- Qt::ScrollBarAlwaysOff
-
-
- true
-
-
-
-
- 0
- 0
- 455
- 308
-
+
+
+
+ 0
-
-
- 0
- 0
-
+
+ 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
-
-
- 0
- 0
-
-
-
- Qt::Vertical
-
-
- QDialogButtonBox::NoButton
+
+ 0
+
+
+ 0
+
+
-
+
+
+ true
+
+
+
+
+ 0
+ 0
+ 98
+ 28
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ PushButton
+
+
+
+
-
-
-
+
+
+
+
+
+ -
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ Show all supported games
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 175
+ 20
+
+
+
+
+ -
+
+
+ Filter
+
+
+
+
@@ -387,8 +409,8 @@
0
0
- 455
- 278
+ 98
+ 28
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)) {
diff --git a/src/createinstancedialogpages.h b/src/createinstancedialogpages.h
index b8366234..f2f4216d 100644
--- a/src/createinstancedialogpages.h
+++ b/src/createinstancedialogpages.h
@@ -1,10 +1,12 @@
#ifndef MODORGANIZER_CREATEINSTANCEDIALOGPAGES_INCLUDED
#define MODORGANIZER_CREATEINSTANCEDIALOGPAGES_INCLUDED
+#include "createinstancedialog.h"
+#include
+
#include
#include
#include
-#include "createinstancedialog.h"
namespace MOBase { class IPluginGame; }
@@ -107,16 +109,19 @@ private:
std::vector> m_games;
Game* m_selection;
-
+ MOBase::FilterWidget m_filter;
std::vector sortedGamePlugins() const;
Game* findGame(MOBase::IPluginGame* game);
void createGames();
void updateButton(Game* g);
void selectButton(Game* g);
+ void clearButtons();
+ void addButton(QAbstractButton* b);
QCommandLinkButton* createCustomButton();
void createGameButton(Game* g);
void fillList();
+ void onFilter();
Game* checkInstallation(const QString& path, Game* g);
MOBase::IPluginGame* findAnotherGame(const QString& path);
bool confirmUnknown(const QString& path, MOBase::IPluginGame* game);
--
cgit v1.3.1