Merge branch 'search-settings'

This commit is contained in:
fourtf
2019-09-03 11:28:10 +02:00
15 changed files with 398 additions and 146 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ CommandPage::CommandPage()
auto app = getApp();
LayoutCreator<CommandPage> layoutCreator(this);
auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
EditableModelView *view =
layout.emplace<EditableModelView>(app->commands->createModel(nullptr))
+94 -15
View File
@@ -38,20 +38,13 @@ TitleLabel *SettingsLayout::addTitle(const QString &title)
{
auto label = new TitleLabel(title + ":");
if (this->count() != 0)
this->addSpacing(16);
if (this->count() == 0)
label->setStyleSheet("margin-top: 0");
this->addWidget(label);
return label;
}
TitleLabel2 *SettingsLayout::addTitle2(const QString &title)
{
auto label = new TitleLabel2(title + ":");
// groups
this->groups_.push_back(Group{title, label, {}});
this->addSpacing(16);
this->addWidget(label);
return label;
}
@@ -73,6 +66,10 @@ QCheckBox *SettingsLayout::addCheckbox(const QString &text,
[&setting, inverse](bool state) { setting = inverse ^ state; });
this->addWidget(check);
// groups
this->groups_.back().widgets.push_back({check, {text}});
return check;
}
@@ -84,11 +81,17 @@ ComboBox *SettingsLayout::addDropdown(const QString &text,
combo->setFocusPolicy(Qt::StrongFocus);
combo->addItems(list);
layout->addWidget(new QLabel(text + ":"));
auto label = new QLabel(text + ":");
layout->addWidget(label);
layout->addStretch(1);
layout->addWidget(combo);
this->addLayout(layout);
// groups
this->groups_.back().widgets.push_back({combo, {text}});
this->groups_.back().widgets.push_back({label, {text}});
return combo;
}
@@ -126,6 +129,9 @@ DescriptionLabel *SettingsLayout::addDescription(const QString &text)
this->addWidget(label);
// groups
this->groups_.back().widgets.push_back({label, {text}});
return label;
}
@@ -134,6 +140,64 @@ void SettingsLayout::addSeperator()
this->addWidget(new Line(false));
}
bool SettingsLayout::filterElements(const QString &query)
{
bool any{};
for (auto &&group : this->groups_)
{
// if a description in a group matches `query` then show the entire group
bool descriptionMatches{};
for (auto &&widget : group.widgets)
{
if (auto x = dynamic_cast<DescriptionLabel *>(widget.element); x)
{
if (x->text().contains(query, Qt::CaseInsensitive))
{
descriptionMatches = true;
break;
}
}
}
// if group name matches then all should be visible
if (group.name.contains(query, Qt::CaseInsensitive) ||
descriptionMatches)
{
for (auto &&widget : group.widgets)
widget.element->show();
group.title->show();
any = true;
}
// check if any match
else
{
auto groupAny = false;
for (auto &&widget : group.widgets)
{
for (auto &&keyword : widget.keywords)
{
if (keyword.contains(query, Qt::CaseInsensitive))
{
widget.element->show();
groupAny = true;
}
else
{
widget.element->hide();
}
}
}
group.title->setVisible(groupAny);
any |= groupAny;
}
}
return any;
}
GeneralPage::GeneralPage()
: SettingsPage("General", ":/settings/about.svg")
{
@@ -143,6 +207,7 @@ GeneralPage::GeneralPage()
y->addWidget(scroll);
auto x = new QHBoxLayout;
auto layout = new SettingsLayout;
this->settingsLayout_ = layout;
x->addLayout(layout, 0);
x->addStretch(1);
auto z = new QFrame;
@@ -157,6 +222,16 @@ GeneralPage::GeneralPage()
this->initExtra();
}
bool GeneralPage::filterElements(const QString &query)
{
if (this->settingsLayout_)
return this->settingsLayout_->filterElements(query) ||
this->name_.contains(query, Qt::CaseInsensitive) ||
query.isEmpty();
else
return false;
}
void GeneralPage::initLayout(SettingsLayout &layout)
{
auto &s = *getSettings();
@@ -353,15 +428,19 @@ void GeneralPage::initLayout(SettingsLayout &layout)
"store in this directory.");
layout.addWidget(makeOpenSettingDirButton());
} // namespace chatterino
// invisible element for width
auto inv = new BaseWidget(this);
inv->setScaleIndependantWidth(500);
layout.addWidget(inv);
}
void GeneralPage::initExtra()
{
/// update cache path
if (this->cachePath)
if (this->cachePath_)
{
getSettings()->cachePath.connect(
[cachePath = this->cachePath](const auto &, auto) mutable {
[cachePath = this->cachePath_](const auto &, auto) mutable {
QString newPath = getPaths()->cacheDirectory();
QString pathShortened = "Current location: <a href=\"file:///" +
+18 -13
View File
@@ -28,17 +28,6 @@ public:
}
};
class TitleLabel2 : public QLabel
{
Q_OBJECT
public:
TitleLabel2(const QString &text)
: QLabel(text)
{
}
};
class DescriptionLabel : public QLabel
{
Q_OBJECT
@@ -71,7 +60,6 @@ class SettingsLayout : public QVBoxLayout
public:
TitleLabel *addTitle(const QString &text);
TitleLabel2 *addTitle2(const QString &text);
/// @param inverse Inverses true to false and vice versa
QCheckBox *addCheckbox(const QString &text, BoolSetting &setting,
bool inverse = false);
@@ -141,9 +129,23 @@ public:
return combo;
}
DescriptionLabel *addDescription(const QString &text);
void addSeperator();
bool filterElements(const QString &query);
private:
struct Widget {
QWidget *element;
QStringList keywords;
};
struct Group {
QString name;
QWidget *title{};
std::vector<Widget> widgets;
};
std::vector<Group> groups_;
std::vector<pajlada::Signals::ScopedConnection> managedConnections_;
};
@@ -154,13 +156,16 @@ class GeneralPage : public SettingsPage
public:
GeneralPage();
bool filterElements(const QString &query);
private:
void initLayout(SettingsLayout &layout);
void initExtra();
QString getFont(const DropdownArgs &args) const;
DescriptionLabel *cachePath{};
DescriptionLabel *cachePath_{};
SettingsLayout *settingsLayout_{};
};
} // namespace chatterino
@@ -13,7 +13,7 @@ KeyboardSettingsPage::KeyboardSettingsPage()
auto layout =
LayoutCreator<KeyboardSettingsPage>(this).setLayoutType<QVBoxLayout>();
auto form = layout.emplace<QFormLayout>();
auto form = layout.emplace<QFormLayout>().withoutMargin();
form->addRow(new QLabel("Hold Ctrl"), new QLabel("Show resize handles"));
form->addRow(new QLabel("Hold Ctrl + Alt"),
+64 -2
View File
@@ -5,15 +5,77 @@
#include <QDebug>
#include <QPainter>
#include <util/FunctionEventFilter.hpp>
namespace chatterino {
bool filterItemsRec(QObject *object, const QString &query)
{
bool any{};
for (auto &&child : object->children())
{
auto setOpacity = [&](auto *widget, bool condition) {
any |= condition;
widget->greyedOut = !condition;
widget->update();
};
if (auto x = dynamic_cast<SCheckBox *>(child); x)
{
setOpacity(x, x->text().contains(query, Qt::CaseInsensitive));
}
else if (auto x = dynamic_cast<SLabel *>(child); x)
{
setOpacity(x, x->text().contains(query, Qt::CaseInsensitive));
}
else if (auto x = dynamic_cast<SComboBox *>(child); x)
{
setOpacity(x, [=]() {
for (int i = 0; i < x->count(); i++)
{
if (x->itemText(i).contains(query, Qt::CaseInsensitive))
return true;
}
return false;
}());
}
else if (auto x = dynamic_cast<QTabWidget *>(child); x)
{
for (int i = 0; i < x->count(); i++)
{
bool tabAny{};
if (x->tabText(i).contains(query, Qt::CaseInsensitive))
{
tabAny = true;
}
auto widget = x->widget(i);
tabAny |= filterItemsRec(widget, query);
any |= tabAny;
}
}
else
{
any |= filterItemsRec(child, query);
}
}
return any;
}
SettingsPage::SettingsPage(const QString &name, const QString &iconResource)
: name_(name)
, iconResource_(iconResource)
{
}
bool SettingsPage::filterElements(const QString &query)
{
return filterItemsRec(this, query) || query.isEmpty() ||
this->name_.contains(query, Qt::CaseInsensitive);
}
const QString &SettingsPage::getName()
{
return this->name_;
@@ -42,7 +104,7 @@ void SettingsPage::cancel()
QCheckBox *SettingsPage::createCheckBox(
const QString &text, pajlada::Settings::Setting<bool> &setting)
{
QCheckBox *checkbox = new QCheckBox(text);
QCheckBox *checkbox = new SCheckBox(text);
// update when setting changes
setting.connect(
@@ -64,7 +126,7 @@ QCheckBox *SettingsPage::createCheckBox(
QComboBox *SettingsPage::createComboBox(
const QStringList &items, pajlada::Settings::Setting<QString> &setting)
{
QComboBox *combo = new QComboBox();
QComboBox *combo = new SComboBox();
// update setting on toogle
combo->addItems(items);
@@ -8,8 +8,38 @@
#include "singletons/Settings.hpp"
#define SETTINGS_PAGE_WIDGET_BOILERPLATE(type, parent) \
class type : public parent \
{ \
using parent::parent; \
\
public: \
bool greyedOut{}; \
\
protected: \
void paintEvent(QPaintEvent *e) override \
{ \
parent::paintEvent(e); \
\
if (this->greyedOut) \
{ \
QPainter painter(this); \
QColor color = QColor("#222222"); \
color.setAlphaF(0.7); \
painter.fillRect(this->rect(), color); \
} \
} \
};
namespace chatterino {
// S* widgets are the same as their Q* counterparts,
// but they can be greyed out and will be if you search.
SETTINGS_PAGE_WIDGET_BOILERPLATE(SCheckBox, QCheckBox)
SETTINGS_PAGE_WIDGET_BOILERPLATE(SLabel, QLabel)
SETTINGS_PAGE_WIDGET_BOILERPLATE(SComboBox, QComboBox)
SETTINGS_PAGE_WIDGET_BOILERPLATE(SPushButton, QPushButton)
class SettingsDialogTab;
class SettingsPage : public QFrame
@@ -22,6 +52,8 @@ public:
const QString &getName();
const QString &getIconResource();
virtual bool filterElements(const QString &query);
SettingsDialogTab *tab() const;
void setTab(SettingsDialogTab *tab);