2020-10-22 23:17:31 +02:00
|
|
|
#include "GeneralPageView.hpp"
|
|
|
|
#include <QScrollBar>
|
2020-10-23 00:38:14 +02:00
|
|
|
#include "Application.hpp"
|
2020-10-22 23:17:31 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
|
|
|
#include "singletons/WindowManager.hpp"
|
|
|
|
#include "util/LayoutHelper.hpp"
|
|
|
|
#include "widgets/dialogs/ColorPickerDialog.hpp"
|
|
|
|
#include "widgets/helper/ColorButton.hpp"
|
|
|
|
#include "widgets/helper/Line.hpp"
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
GeneralPageView::GeneralPageView(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
auto scrollArea = this->contentScrollArea_ =
|
|
|
|
makeScrollArea(this->contentLayout_ = new QVBoxLayout);
|
2020-10-23 09:32:45 +02:00
|
|
|
scrollArea->setObjectName("generalSettingsScrollContent");
|
2020-10-22 23:17:31 +02:00
|
|
|
|
|
|
|
auto navigation =
|
|
|
|
wrapLayout(this->navigationLayout_ = makeLayout<QVBoxLayout>({}));
|
2020-10-23 09:32:45 +02:00
|
|
|
navigation->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
|
|
|
|
this->navigationLayout_->setAlignment(Qt::AlignTop);
|
|
|
|
this->navigationLayout_->addSpacing(6);
|
2020-10-22 23:17:31 +02:00
|
|
|
|
2020-10-23 09:32:45 +02:00
|
|
|
this->setLayout(makeLayout<QHBoxLayout>(
|
|
|
|
{scrollArea, new QSpacerItem(16, 1), navigation}));
|
2020-10-22 23:17:31 +02:00
|
|
|
|
|
|
|
QObject::connect(scrollArea->verticalScrollBar(), &QScrollBar::valueChanged,
|
2020-11-08 12:02:19 +01:00
|
|
|
this, [=] {
|
|
|
|
this->updateNavigationHighlighting();
|
|
|
|
});
|
2020-10-22 23:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralPageView::addWidget(QWidget *widget)
|
|
|
|
{
|
|
|
|
this->contentLayout_->addWidget(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralPageView::addLayout(QLayout *layout)
|
|
|
|
{
|
|
|
|
this->contentLayout_->addLayout(layout);
|
|
|
|
}
|
|
|
|
|
2020-10-23 14:26:04 +02:00
|
|
|
void GeneralPageView::addStretch()
|
|
|
|
{
|
|
|
|
this->contentLayout_->addStretch();
|
|
|
|
}
|
|
|
|
|
2020-10-22 23:17:31 +02:00
|
|
|
TitleLabel *GeneralPageView::addTitle(const QString &title)
|
|
|
|
{
|
|
|
|
// space
|
|
|
|
if (!this->groups_.empty())
|
|
|
|
this->addWidget(this->groups_.back().space = new Space);
|
|
|
|
|
|
|
|
// title
|
|
|
|
auto label = new TitleLabel(title + ":");
|
|
|
|
this->addWidget(label);
|
|
|
|
|
|
|
|
// navigation item
|
|
|
|
auto navLabel = new NavigationLabel(title);
|
|
|
|
navLabel->setCursor(Qt::PointingHandCursor);
|
|
|
|
this->navigationLayout_->addWidget(navLabel);
|
|
|
|
|
|
|
|
QObject::connect(navLabel, &NavigationLabel::leftMouseUp, label, [=] {
|
|
|
|
this->contentScrollArea_->verticalScrollBar()->setValue(label->y());
|
|
|
|
});
|
|
|
|
|
|
|
|
// groups
|
|
|
|
this->groups_.push_back(Group{title, label, navLabel, nullptr, {}});
|
|
|
|
|
|
|
|
if (this->groups_.size() == 1)
|
|
|
|
this->updateNavigationHighlighting();
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2020-10-23 14:26:04 +02:00
|
|
|
SubtitleLabel *GeneralPageView::addSubtitle(const QString &title)
|
|
|
|
{
|
|
|
|
auto label = new SubtitleLabel(title + ":");
|
|
|
|
this->addWidget(label);
|
|
|
|
|
|
|
|
this->groups_.back().widgets.push_back({label, {title}});
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2020-10-22 23:17:31 +02:00
|
|
|
QCheckBox *GeneralPageView::addCheckbox(const QString &text,
|
|
|
|
BoolSetting &setting, bool inverse)
|
|
|
|
{
|
|
|
|
auto check = new QCheckBox(text);
|
|
|
|
|
|
|
|
// update when setting changes
|
|
|
|
setting.connect(
|
|
|
|
[inverse, check](const bool &value, auto) {
|
|
|
|
check->setChecked(inverse ^ value);
|
|
|
|
},
|
|
|
|
this->managedConnections_);
|
|
|
|
|
|
|
|
// update setting on toggle
|
2020-11-08 12:02:19 +01:00
|
|
|
QObject::connect(check, &QCheckBox::toggled, this,
|
|
|
|
[&setting, inverse](bool state) {
|
|
|
|
setting = inverse ^ state;
|
|
|
|
});
|
2020-10-22 23:17:31 +02:00
|
|
|
|
|
|
|
this->addWidget(check);
|
|
|
|
|
|
|
|
// groups
|
|
|
|
this->groups_.back().widgets.push_back({check, {text}});
|
|
|
|
|
|
|
|
return check;
|
|
|
|
}
|
|
|
|
|
|
|
|
ComboBox *GeneralPageView::addDropdown(const QString &text,
|
|
|
|
const QStringList &list)
|
|
|
|
{
|
|
|
|
auto layout = new QHBoxLayout;
|
|
|
|
auto combo = new ComboBox;
|
|
|
|
combo->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
combo->addItems(list);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ComboBox *GeneralPageView::addDropdown(
|
|
|
|
const QString &text, const QStringList &items,
|
|
|
|
pajlada::Settings::Setting<QString> &setting, bool editable)
|
|
|
|
{
|
|
|
|
auto combo = this->addDropdown(text, items);
|
|
|
|
|
|
|
|
if (editable)
|
|
|
|
combo->setEditable(true);
|
|
|
|
|
|
|
|
// update when setting changes
|
|
|
|
setting.connect(
|
2020-11-08 12:02:19 +01:00
|
|
|
[combo](const QString &value, auto) {
|
|
|
|
combo->setCurrentText(value);
|
|
|
|
},
|
2020-10-22 23:17:31 +02:00
|
|
|
this->managedConnections_);
|
|
|
|
|
|
|
|
QObject::connect(combo, &QComboBox::currentTextChanged,
|
|
|
|
[&setting](const QString &newValue) {
|
|
|
|
setting = newValue;
|
|
|
|
getApp()->windows->forceLayoutChannelViews();
|
|
|
|
});
|
|
|
|
|
|
|
|
return combo;
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorButton *GeneralPageView::addColorButton(
|
|
|
|
const QString &text, const QColor &color,
|
|
|
|
pajlada::Settings::Setting<QString> &setting)
|
|
|
|
{
|
|
|
|
auto colorButton = new ColorButton(color);
|
|
|
|
auto layout = new QHBoxLayout();
|
|
|
|
auto label = new QLabel(text + ":");
|
|
|
|
layout->addWidget(label);
|
|
|
|
layout->addStretch(1);
|
|
|
|
layout->addWidget(colorButton);
|
|
|
|
this->addLayout(layout);
|
|
|
|
QObject::connect(
|
2020-10-31 16:42:48 +01:00
|
|
|
colorButton, &ColorButton::clicked, [this, &setting, colorButton]() {
|
|
|
|
auto dialog = new ColorPickerDialog(QColor(setting), this);
|
2020-10-22 23:17:31 +02:00
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dialog->show();
|
2020-10-31 16:42:48 +01:00
|
|
|
dialog->closed.connect([&setting, colorButton](QColor selected) {
|
2020-10-22 23:17:31 +02:00
|
|
|
if (selected.isValid())
|
|
|
|
{
|
|
|
|
setting = selected.name(QColor::HexArgb);
|
|
|
|
colorButton->setColor(selected);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this->groups_.back().widgets.push_back({label, {text}});
|
|
|
|
this->groups_.back().widgets.push_back({colorButton, {text}});
|
|
|
|
|
|
|
|
return colorButton;
|
|
|
|
}
|
|
|
|
|
2020-10-23 09:32:45 +02:00
|
|
|
void GeneralPageView::addNavigationSpacing()
|
|
|
|
{
|
|
|
|
this->navigationLayout_->addSpacing(24);
|
|
|
|
}
|
|
|
|
|
2020-10-22 23:17:31 +02:00
|
|
|
DescriptionLabel *GeneralPageView::addDescription(const QString &text)
|
|
|
|
{
|
|
|
|
auto label = new DescriptionLabel(text);
|
|
|
|
|
|
|
|
label->setTextInteractionFlags(Qt::TextBrowserInteraction |
|
|
|
|
Qt::LinksAccessibleByKeyboard);
|
|
|
|
label->setOpenExternalLinks(true);
|
|
|
|
label->setWordWrap(true);
|
|
|
|
|
|
|
|
this->addWidget(label);
|
|
|
|
|
|
|
|
// groups
|
|
|
|
this->groups_.back().widgets.push_back({label, {text}});
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralPageView::addSeperator()
|
|
|
|
{
|
|
|
|
this->addWidget(new Line(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GeneralPageView::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();
|
2020-10-23 14:26:04 +02:00
|
|
|
|
2020-10-22 23:17:31 +02:00
|
|
|
group.title->show();
|
2020-10-23 14:26:04 +02:00
|
|
|
group.navigationLink->show();
|
2020-10-22 23:17:31 +02:00
|
|
|
any = true;
|
|
|
|
}
|
|
|
|
// check if any match
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto groupAny = false;
|
|
|
|
|
2020-10-23 14:26:04 +02:00
|
|
|
QWidget *currentSubtitle = nullptr;
|
|
|
|
bool currentSubtitleVisible = false;
|
|
|
|
|
2020-10-22 23:17:31 +02:00
|
|
|
for (auto &&widget : group.widgets)
|
|
|
|
{
|
2020-10-23 14:26:04 +02:00
|
|
|
if (dynamic_cast<SubtitleLabel *>(widget.element))
|
|
|
|
{
|
|
|
|
if (currentSubtitle)
|
|
|
|
currentSubtitle->setVisible(currentSubtitleVisible);
|
|
|
|
|
|
|
|
currentSubtitleVisible = false;
|
|
|
|
currentSubtitle = widget.element;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-22 23:17:31 +02:00
|
|
|
for (auto &&keyword : widget.keywords)
|
|
|
|
{
|
|
|
|
if (keyword.contains(query, Qt::CaseInsensitive))
|
|
|
|
{
|
2020-10-23 14:26:04 +02:00
|
|
|
currentSubtitleVisible = true;
|
2020-10-22 23:17:31 +02:00
|
|
|
widget.element->show();
|
|
|
|
groupAny = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
widget.element->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-23 14:26:04 +02:00
|
|
|
if (currentSubtitle)
|
|
|
|
currentSubtitle->setVisible(currentSubtitleVisible);
|
|
|
|
|
2020-10-22 23:17:31 +02:00
|
|
|
if (group.space)
|
|
|
|
group.space->setVisible(groupAny);
|
2020-10-23 14:26:04 +02:00
|
|
|
|
2020-10-22 23:17:31 +02:00
|
|
|
group.title->setVisible(groupAny);
|
2020-10-23 14:26:04 +02:00
|
|
|
group.navigationLink->setVisible(groupAny);
|
2020-10-22 23:17:31 +02:00
|
|
|
any |= groupAny;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return any;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralPageView::updateNavigationHighlighting()
|
|
|
|
{
|
|
|
|
auto scrollY = this->contentScrollArea_->verticalScrollBar()->value();
|
|
|
|
auto first = true;
|
|
|
|
|
|
|
|
for (auto &&group : this->groups_)
|
|
|
|
{
|
|
|
|
if (first && (group.title->geometry().bottom() > scrollY ||
|
|
|
|
&group == &this->groups_.back()))
|
|
|
|
{
|
|
|
|
first = false;
|
2020-10-23 09:32:45 +02:00
|
|
|
group.navigationLink->setStyleSheet("color: #00ABF4");
|
2020-10-22 23:17:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
group.navigationLink->setStyleSheet("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|