fix crash

This commit is contained in:
fourtf 2020-02-28 19:05:50 +01:00
parent ba5d842767
commit b887f1c90e
4 changed files with 15 additions and 9 deletions

View file

@ -155,26 +155,26 @@ void SettingsDialog::addTabs()
// clang-format off // clang-format off
this->addTab([]{return new GeneralPage;}, "General", ":/settings/about.svg"); this->addTab([]{return new GeneralPage;}, "General", ":/settings/about.svg");
this->ui_.tabContainer->addSpacing(16); this->ui_.tabContainer->addSpacing(16);
this->addTab([]{return new AccountsPage;}, "Accounts", ":/settings/accounts.svg"); this->addTab([]{return new AccountsPage;}, "Accounts", ":/settings/accounts.svg", SettingsTabId::Accounts);
this->ui_.tabContainer->addSpacing(16); this->ui_.tabContainer->addSpacing(16);
this->addTab([]{return new CommandPage;}, "Commands", ":/settings/commands.svg"); this->addTab([]{return new CommandPage;}, "Commands", ":/settings/commands.svg");
this->addTab([]{return new HighlightingPage;}, "Highlights", ":/settings/notifications.svg"); this->addTab([]{return new HighlightingPage;}, "Highlights", ":/settings/notifications.svg");
this->addTab([]{return new IgnoresPage;}, "Ignores", ":/settings/ignore.svg"); this->addTab([]{return new IgnoresPage;}, "Ignores", ":/settings/ignore.svg");
this->ui_.tabContainer->addSpacing(16); this->ui_.tabContainer->addSpacing(16);
this->addTab([]{return new KeyboardSettingsPage;}, "Keybindings", ":/settings/keybinds.svg"); this->addTab([]{return new KeyboardSettingsPage;}, "Keybindings", ":/settings/keybinds.svg");
this->addTab([]{return new ModerationPage;}, "Moderation", ":/settings/moderation.svg"); this->addTab([]{return new ModerationPage;}, "Moderation", ":/settings/moderation.svg", SettingsTabId::Moderation);
this->addTab([]{return new NotificationPage;}, "Notifications", ":/settings/notification2.svg"); this->addTab([]{return new NotificationPage;}, "Notifications", ":/settings/notification2.svg");
this->addTab([]{return new ExternalToolsPage;}, "External tools", ":/settings/externaltools.svg"); this->addTab([]{return new ExternalToolsPage;}, "External tools", ":/settings/externaltools.svg");
this->ui_.tabContainer->addStretch(1); this->ui_.tabContainer->addStretch(1);
this->addTab([]{return new AboutPage;}, "About", ":/settings/about.svg", Qt::AlignBottom); this->addTab([]{return new AboutPage;}, "About", ":/settings/about.svg", SettingsTabId(), Qt::AlignBottom);
// clang-format on // clang-format on
} }
void SettingsDialog::addTab(std::function<SettingsPage *()> page, void SettingsDialog::addTab(std::function<SettingsPage *()> page,
const QString &name, const QString &iconPath, const QString &name, const QString &iconPath,
Qt::Alignment alignment) SettingsTabId id, Qt::Alignment alignment)
{ {
auto tab = new SettingsDialogTab(this, std::move(page), name, iconPath); auto tab = new SettingsDialogTab(this, std::move(page), name, iconPath, id);
this->ui_.tabContainer->addWidget(tab, 0, alignment); this->ui_.tabContainer->addWidget(tab, 0, alignment);
this->tabs_.push_back(tab); this->tabs_.push_back(tab);
@ -216,7 +216,12 @@ void SettingsDialog::selectTab(SettingsDialogTab *tab, bool byUser)
void SettingsDialog::selectTab(SettingsTabId id) void SettingsDialog::selectTab(SettingsTabId id)
{ {
this->selectTab(this->tab(id)); auto t = this->tab(id);
assert(t);
if (!t)
return;
this->selectTab(t);
} }
SettingsDialogTab *SettingsDialog::tab(SettingsTabId id) SettingsDialogTab *SettingsDialog::tab(SettingsTabId id)

View file

@ -51,7 +51,7 @@ private:
void initUi(); void initUi();
void addTabs(); void addTabs();
void addTab(std::function<SettingsPage *()> page, const QString &name, void addTab(std::function<SettingsPage *()> page, const QString &name,
const QString &iconPath, const QString &iconPath, SettingsTabId id = {},
Qt::Alignment alignment = Qt::AlignTop); Qt::Alignment alignment = Qt::AlignTop);
void selectTab(SettingsDialogTab *tab, const bool byUser = true); void selectTab(SettingsDialogTab *tab, const bool byUser = true);
void selectTab(SettingsTabId id); void selectTab(SettingsTabId id);

View file

@ -26,7 +26,7 @@ public:
SettingsDialogTab(SettingsDialog *dialog_, SettingsDialogTab(SettingsDialog *dialog_,
std::function<SettingsPage *()> page_, std::function<SettingsPage *()> page_,
const QString &name, QString imageFileName, const QString &name, QString imageFileName,
SettingsTabId id = {}); SettingsTabId id);
void setSelected(bool selected_); void setSelected(bool selected_);
SettingsPage *page(); SettingsPage *page();

View file

@ -328,7 +328,8 @@ void GeneralPage::initLayout(SettingsLayout &layout)
layout.addCheckbox("Smooth scrolling on new messages", layout.addCheckbox("Smooth scrolling on new messages",
s.enableSmoothScrollingNewMessages); s.enableSmoothScrollingNewMessages);
layout.addDropdown<float>( layout.addDropdown<float>(
"Pause on hover", {"Disabled", "0.5s", "1s", "2s", "5s", "Indefinite"}, "Pause after hover",
{"Disabled", "0.5s", "1s", "2s", "5s", "Indefinite"},
s.pauseOnHoverDuration, s.pauseOnHoverDuration,
[](auto val) { [](auto val) {
if (val < -0.5f) if (val < -0.5f)