mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
add basic hiding of SettingsTabs
This commit is contained in:
parent
54c26d2228
commit
b0459ba646
5 changed files with 51 additions and 21 deletions
|
@ -67,13 +67,31 @@ void SettingsDialog::initUi()
|
|||
auto edit = title.emplace<QLineEdit>().assign(&this->ui_.search);
|
||||
QTimer::singleShot(100, edit.getElement(),
|
||||
[edit = edit.getElement()]() { edit->setFocus(); });
|
||||
QObject::connect(edit.getElement(), &QLineEdit::textChanged, this,
|
||||
[this](const QString &text) {
|
||||
for (auto &&page : this->pages_)
|
||||
{
|
||||
page->filterElements(text);
|
||||
}
|
||||
});
|
||||
QObject::connect(
|
||||
edit.getElement(), &QLineEdit::textChanged, this,
|
||||
[this](const QString &text) {
|
||||
// filter elements and hide pages
|
||||
for (auto &&page : this->pages_)
|
||||
{
|
||||
// filterElements returns true if anything on the page matches the search query
|
||||
page->tab()->setVisible(page->filterElements(text));
|
||||
}
|
||||
|
||||
// TODO: add originally selected page
|
||||
|
||||
// find next visible page
|
||||
if (!this->selectedTab_->isVisible())
|
||||
{
|
||||
for (auto &&tab : this->tabs_)
|
||||
{
|
||||
if (tab->isVisible())
|
||||
{
|
||||
this->selectTab(tab);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
right.emplace<QStackedLayout>()
|
||||
.assign(&this->ui_.pageStack)
|
||||
|
|
|
@ -138,8 +138,10 @@ void SettingsLayout::addSeperator()
|
|||
this->addWidget(new Line(false));
|
||||
}
|
||||
|
||||
void SettingsLayout::filterElements(const QString &query)
|
||||
bool SettingsLayout::filterElements(const QString &query)
|
||||
{
|
||||
bool any{};
|
||||
|
||||
for (auto &&group : this->groups_)
|
||||
{
|
||||
// if group name matches then all should be visible
|
||||
|
@ -152,7 +154,7 @@ void SettingsLayout::filterElements(const QString &query)
|
|||
// check if any match
|
||||
else
|
||||
{
|
||||
auto any = false;
|
||||
auto groupAny = false;
|
||||
|
||||
for (auto &&widget : group.widgets)
|
||||
{
|
||||
|
@ -161,7 +163,7 @@ void SettingsLayout::filterElements(const QString &query)
|
|||
if (keyword.contains(query, Qt::CaseInsensitive))
|
||||
{
|
||||
widget.element->show();
|
||||
any = true;
|
||||
groupAny = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -170,9 +172,11 @@ void SettingsLayout::filterElements(const QString &query)
|
|||
}
|
||||
}
|
||||
|
||||
group.title->setVisible(any);
|
||||
group.title->setVisible(groupAny);
|
||||
}
|
||||
}
|
||||
|
||||
return any;
|
||||
}
|
||||
|
||||
GeneralPage::GeneralPage()
|
||||
|
@ -199,10 +203,13 @@ GeneralPage::GeneralPage()
|
|||
this->initExtra();
|
||||
}
|
||||
|
||||
void GeneralPage::filterElements(const QString &query)
|
||||
bool GeneralPage::filterElements(const QString &query)
|
||||
{
|
||||
if (this->settingsLayout_)
|
||||
this->settingsLayout_->filterElements(query);
|
||||
return this->settingsLayout_->filterElements(query) ||
|
||||
this->name_.contains(query) || query.isEmpty();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void GeneralPage::initLayout(SettingsLayout &layout)
|
||||
|
|
|
@ -131,7 +131,7 @@ public:
|
|||
DescriptionLabel *addDescription(const QString &text);
|
||||
|
||||
void addSeperator();
|
||||
void filterElements(const QString &query);
|
||||
bool filterElements(const QString &query);
|
||||
|
||||
private:
|
||||
struct Widget {
|
||||
|
@ -156,7 +156,7 @@ class GeneralPage : public SettingsPage
|
|||
public:
|
||||
GeneralPage();
|
||||
|
||||
void filterElements(const QString &query);
|
||||
bool filterElements(const QString &query);
|
||||
|
||||
private:
|
||||
void initLayout(SettingsLayout &layout);
|
||||
|
|
|
@ -9,11 +9,14 @@
|
|||
|
||||
namespace chatterino {
|
||||
|
||||
void filterItemsRec(QObject *object, const QString &query)
|
||||
bool filterItemsRec(QObject *object, const QString &query)
|
||||
{
|
||||
bool any{};
|
||||
|
||||
for (auto &&child : object->children())
|
||||
{
|
||||
auto setOpacity = [=](auto *widget, bool condition) {
|
||||
auto setOpacity = [&](auto *widget, bool condition) {
|
||||
any |= condition;
|
||||
widget->greyedOut = !condition;
|
||||
widget->update();
|
||||
};
|
||||
|
@ -39,9 +42,10 @@ void filterItemsRec(QObject *object, const QString &query)
|
|||
}
|
||||
else
|
||||
{
|
||||
filterItemsRec(child, query);
|
||||
any |= filterItemsRec(child, query);
|
||||
}
|
||||
}
|
||||
return any;
|
||||
}
|
||||
|
||||
SettingsPage::SettingsPage(const QString &name, const QString &iconResource)
|
||||
|
@ -50,9 +54,10 @@ SettingsPage::SettingsPage(const QString &name, const QString &iconResource)
|
|||
{
|
||||
}
|
||||
|
||||
void SettingsPage::filterElements(const QString &query)
|
||||
bool SettingsPage::filterElements(const QString &query)
|
||||
{
|
||||
filterItemsRec(this, query);
|
||||
return filterItemsRec(this, query) || query.isEmpty() ||
|
||||
this->name_.contains(query);
|
||||
}
|
||||
|
||||
const QString &SettingsPage::getName()
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
const QString &getName();
|
||||
const QString &getIconResource();
|
||||
|
||||
virtual void filterElements(const QString &query);
|
||||
virtual bool filterElements(const QString &query);
|
||||
|
||||
SettingsDialogTab *tab() const;
|
||||
void setTab(SettingsDialogTab *tab);
|
||||
|
|
Loading…
Reference in a new issue