X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingsdlg.cpp;h=13e6a33b431230cfb3be358a9297c4a6f558c401;hp=748c1ffa134f7b379a3542352f6bfce8e2548e4d;hb=1f21c1f9613031ae263eeed0c4883bfcd5488343;hpb=68878dc8366f2f4a0afe132847aad9a51a80cdbf diff --git a/src/qtui/settingsdlg.cpp b/src/qtui/settingsdlg.cpp index 748c1ffa..13e6a33b 100644 --- a/src/qtui/settingsdlg.cpp +++ b/src/qtui/settingsdlg.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2019 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,84 +18,64 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include +#include "settingsdlg.h" + #include #include -#include "settingsdlg.h" - #include "client.h" +#include "icon.h" -SettingsDlg::SettingsDlg(QWidget *parent) - : QDialog(parent), - _currentPage(0) +SettingsDlg::SettingsDlg(QWidget* parent) + : QDialog(parent) { ui.setupUi(this); setModal(true); setAttribute(Qt::WA_DeleteOnClose, true); - setWindowIcon(QIcon::fromTheme("configure")); + setWindowIcon(icon::get("configure")); updateGeometry(); ui.settingsTree->setRootIsDecorated(false); - connect(ui.settingsTree, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelected())); - connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); + connect(ui.settingsTree, &QTreeWidget::itemSelectionChanged, this, &SettingsDlg::itemSelected); + connect(ui.buttonBox, &QDialogButtonBox::clicked, this, &SettingsDlg::buttonClicked); - connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), SLOT(coreConnectionStateChanged())); + connect(Client::instance(), &Client::coreConnectionStateChanged, this, &SettingsDlg::coreConnectionStateChanged); setButtonStates(); - - // Some settings panes can take a good bit of space. To avoid squashing the settings tree, try - // to resize the dialog. If needed, it can always be resized by the user to take less space. - // - // Only try to resize if the sizes are valid. This shouldn't happen.. but better to be safe. - // See http://www.qtcentre.org/threads/3427-invalid-sizeHint() - if (ui.settingsTree->sizeHint().isValid() && ui.settingsTree->size().isValid()) { - // Find out how much width would make the settings tree happy - int wantedExtraWidth = ui.settingsTree->sizeHint().width() - - ui.settingsTree->size().width(); - // If more space is needed, try to resize to allow for it. Qt should keep the dialog within - // the bounds of the screen. - if (wantedExtraWidth > 0) { - this->resize(this->width() + wantedExtraWidth, this->height()); - } - } } - void SettingsDlg::coreConnectionStateChanged() { for (int i = 0; i < ui.settingsTree->topLevelItemCount(); i++) { - QTreeWidgetItem *catItem = ui.settingsTree->topLevelItem(i); + QTreeWidgetItem* catItem = ui.settingsTree->topLevelItem(i); for (int j = 0; j < catItem->childCount(); j++) { - QTreeWidgetItem *item = catItem->child(j); + QTreeWidgetItem* item = catItem->child(j); setItemState(item); } setItemState(catItem); } } - -void SettingsDlg::setItemState(QTreeWidgetItem *item) +void SettingsDlg::setItemState(QTreeWidgetItem* item) { - SettingsPage *sp = qobject_cast(item->data(0, SettingsPageRole).value()); + auto* sp = qobject_cast(item->data(0, SettingsPageRole).value()); Q_ASSERT(sp); bool disabledDueToConnection = !Client::isConnected() && sp->needsCoreConnection(); bool disabledDueToOwnChoice = !sp->isSelectable(); item->setDisabled(disabledDueToConnection || disabledDueToOwnChoice); } - -void SettingsDlg::registerSettingsPage(SettingsPage *sp) +void SettingsDlg::registerSettingsPage(SettingsPage* sp) { sp->setParent(ui.settingsStack); ui.settingsStack->addWidget(sp); - connect(sp, SIGNAL(changed(bool)), this, SLOT(setButtonStates())); + connect(sp, &SettingsPage::changed, this, &SettingsDlg::setButtonStates); - QTreeWidgetItem *cat; - QList cats = ui.settingsTree->findItems(sp->category(), Qt::MatchExactly); + QTreeWidgetItem* cat; + QList cats = ui.settingsTree->findItems(sp->category(), Qt::MatchExactly); if (!cats.count()) { cat = new QTreeWidgetItem(ui.settingsTree, QStringList(sp->category())); cat->setExpanded(true); @@ -105,14 +85,13 @@ void SettingsDlg::registerSettingsPage(SettingsPage *sp) cat = cats[0]; } - QTreeWidgetItem *item; + QTreeWidgetItem* item; if (sp->title().isEmpty()) item = cat; else item = new QTreeWidgetItem(cat, QStringList(sp->title())); - item->setData(0, SettingsPageRole, QVariant::fromValue(sp)); - ui.settingsTree->setMinimumWidth(ui.settingsTree->header()->sectionSizeHint(0) + 5); + item->setData(0, SettingsPageRole, QVariant::fromValue(sp)); pageIsLoaded[sp] = false; if (!ui.settingsTree->selectedItems().count()) ui.settingsTree->setCurrentItem(item); @@ -120,11 +99,10 @@ void SettingsDlg::registerSettingsPage(SettingsPage *sp) setItemState(item); } - -void SettingsDlg::selectPage(SettingsPage *sp) +void SettingsDlg::selectPage(SettingsPage* sp) { if (!sp) { - _currentPage = 0; + _currentPage = nullptr; ui.settingsStack->setCurrentIndex(0); ui.pageTitle->setText(tr("Settings")); return; @@ -135,17 +113,22 @@ void SettingsDlg::selectPage(SettingsPage *sp) pageIsLoaded[sp] = true; } - if (sp != currentPage() && currentPage() != 0 && currentPage()->hasChanged()) { - int ret = QMessageBox::warning(this, tr("Save changes"), - tr("There are unsaved changes on the current configuration page. Would you like to apply your changes now?"), - QMessageBox::Discard|QMessageBox::Save|QMessageBox::Cancel, QMessageBox::Cancel); + if (sp != currentPage() && currentPage() != nullptr && currentPage()->hasChanged()) { + int ret = QMessageBox:: + warning(this, + tr("Save changes"), + tr("There are unsaved changes on the current configuration page. Would you like to apply your changes now?"), + QMessageBox::Discard | QMessageBox::Save | QMessageBox::Cancel, + QMessageBox::Cancel); if (ret == QMessageBox::Save) { - if (!applyChanges()) sp = currentPage(); + if (!applyChanges()) + sp = currentPage(); } else if (ret == QMessageBox::Discard) { undoChanges(); } - else sp = currentPage(); + else + sp = currentPage(); } if (sp != currentPage()) { @@ -164,35 +147,34 @@ void SettingsDlg::selectPage(SettingsPage *sp) setButtonStates(); } - void SettingsDlg::itemSelected() { - QList items = ui.settingsTree->selectedItems(); - SettingsPage *sp = 0; + QList items = ui.settingsTree->selectedItems(); + SettingsPage* sp = nullptr; if (!items.isEmpty()) { - sp = qobject_cast(items[0]->data(0, SettingsPageRole).value()); + sp = qobject_cast(items[0]->data(0, SettingsPageRole).value()); } selectPage(sp); } - void SettingsDlg::setButtonStates() { - SettingsPage *sp = currentPage(); + SettingsPage* sp = currentPage(); ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(sp && sp->hasChanged()); ui.buttonBox->button(QDialogButtonBox::Reset)->setEnabled(sp && sp->hasChanged()); ui.buttonBox->button(QDialogButtonBox::RestoreDefaults)->setEnabled(sp && sp->hasDefaults()); } - -void SettingsDlg::buttonClicked(QAbstractButton *button) +void SettingsDlg::buttonClicked(QAbstractButton* button) { switch (ui.buttonBox->standardButton(button)) { case QDialogButtonBox::Ok: if (currentPage() && currentPage()->hasChanged()) { - if (applyChanges()) accept(); + if (applyChanges()) + accept(); } - else accept(); + else + accept(); break; case QDialogButtonBox::Apply: applyChanges(); @@ -212,10 +194,10 @@ void SettingsDlg::buttonClicked(QAbstractButton *button) } } - bool SettingsDlg::applyChanges() { - if (!currentPage()) return false; + if (!currentPage()) + return false; if (currentPage()->aboutToSave()) { currentPage()->save(); return true; @@ -223,7 +205,6 @@ bool SettingsDlg::applyChanges() return false; } - void SettingsDlg::undoChanges() { if (currentPage()) { @@ -231,23 +212,29 @@ void SettingsDlg::undoChanges() } } - void SettingsDlg::reload() { - if (!currentPage()) return; - int ret = QMessageBox::question(this, tr("Reload Settings"), tr("Do you like to reload the settings, undoing your changes on this page?"), - QMessageBox::Yes|QMessageBox::No, QMessageBox::No); + if (!currentPage()) + return; + int ret = QMessageBox::question(this, + tr("Reload Settings"), + tr("Do you like to reload the settings, undoing your changes on this page?"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No); if (ret == QMessageBox::Yes) { currentPage()->load(); } } - void SettingsDlg::loadDefaults() { - if (!currentPage()) return; - int ret = QMessageBox::question(this, tr("Restore Defaults"), tr("Do you like to restore the default values for this page?"), - QMessageBox::RestoreDefaults|QMessageBox::Cancel, QMessageBox::Cancel); + if (!currentPage()) + return; + int ret = QMessageBox::question(this, + tr("Restore Defaults"), + tr("Do you like to restore the default values for this page?"), + QMessageBox::RestoreDefaults | QMessageBox::Cancel, + QMessageBox::Cancel); if (ret == QMessageBox::RestoreDefaults) { currentPage()->defaults(); }