diff --git a/src/Gui/DlgPreferences.ui b/src/Gui/DlgPreferences.ui
index 35557edc1d..aa54ee4c1f 100644
--- a/src/Gui/DlgPreferences.ui
+++ b/src/Gui/DlgPreferences.ui
@@ -6,163 +6,95 @@
0
0
- 800
- 600
+ 570
+ 454
Preferences
-
-
-
true
true
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 120
- 0
-
-
-
-
- 128
- 16777215
-
-
-
- Reset All
-
-
-
- -
-
-
- QDialogButtonBox::Help
-
-
-
- -
-
-
- QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok
-
-
-
- -
-
-
- Reset Tab
-
-
-
- -
+
+
+ 9
+
+
+ 6
+
+
-
6
-
- 0
-
-
- 0
-
-
- 0
-
-
+
0
-
-
-
-
-
-
-
- 0
- 0
-
-
-
-
- 120
- 0
-
-
-
-
- 128
- 16777215
-
-
-
- QFrame::StyledPanel
-
-
- QFrame::Sunken
-
-
- Qt::ScrollBarAlwaysOff
-
-
-
- 96
- 96
-
-
-
- 12
-
-
- QListView::IconMode
-
-
- Qt::AlignVCenter
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 120
- 40
-
-
-
-
-
-
-
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 120
+ 0
+
+
+
+
+ 128
+ 16777215
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Sunken
+
+
+ Qt::ScrollBarAlwaysOff
+
+
+
+ 96
+ 96
+
+
+
+ 12
+
+
+ QListView::IconMode
+
+
-
+ -
+
+
+ QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok|QDialogButtonBox::Reset
+
+
+
+
+ listBox
+
diff --git a/src/Gui/DlgPreferencesImp.cpp b/src/Gui/DlgPreferencesImp.cpp
index 84990104f9..87c48f5879 100644
--- a/src/Gui/DlgPreferencesImp.cpp
+++ b/src/Gui/DlgPreferencesImp.cpp
@@ -28,14 +28,17 @@
# include
# include
# include
+# include
# include
-# include
+# include
# include
# include
# include
# include
# include
+# include
# include
+# include
#endif
#include
@@ -74,32 +77,16 @@ DlgPreferencesImp::DlgPreferencesImp(QWidget* parent, Qt::WindowFlags fl)
invalidParameter(false), canEmbedScrollArea(true), restartRequired(false)
{
ui->setupUi(this);
- setupConnections();
QFontMetrics fm(font());
int length = QtTools::horizontalAdvance(fm, longestGroupName());
ui->listBox->setFixedWidth(Base::clamp(length + 20, 108, 120));
ui->listBox->setGridSize(QSize(Base::clamp(length + 20, 108, 120), 75));
-
- ui->buttonResetGroup->setFixedWidth(Base::clamp(length + 20, 108, 120));
- ui->buttonResetGroup->setLayout(new QVBoxLayout(ui->buttonResetGroup));
- auto ResetGroup = new QLabel(ui->buttonResetGroup);
- ResetGroup->setAlignment(Qt::AlignCenter);
- ResetGroup->setWordWrap(true);
- ui->buttonResetGroup->layout()->setContentsMargins(0, 0, 0, 0);
- ui->buttonResetGroup->layout()->addWidget(ResetGroup);
-
- ui->buttonResetAll->setFixedWidth(Base::clamp(length + 20, 108, 120));
// remove unused help button
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
- connect(ui->buttonBox, &QDialogButtonBox::clicked,
- this, &DlgPreferencesImp::onButtonBoxClicked);
- connect(ui->buttonBox_2, &QDialogButtonBox::helpRequested,
- getMainWindow(), &MainWindow::whatsThis);
- connect(ui->listBox, &QListWidget::currentItemChanged,
- this, &DlgPreferencesImp::changeGroup);
+ setupConnections();
setupPages();
@@ -121,15 +108,19 @@ DlgPreferencesImp::~DlgPreferencesImp()
void DlgPreferencesImp::setupConnections()
{
- connect(ui->buttonResetTab, &QToolButton::clicked,
- this, &DlgPreferencesImp::onButtonResetTabClicked);
- connect(ui->buttonResetGroup, &QToolButton::clicked,
- this, &DlgPreferencesImp::onButtonResetGroupClicked);
- connect(ui->buttonResetAll, &QToolButton::clicked,
- this, &DlgPreferencesImp::restoreDefaults);
+ connect(ui->buttonBox, &QDialogButtonBox::clicked,
+ this, &DlgPreferencesImp::onButtonBoxClicked);
+ connect(ui->buttonBox, &QDialogButtonBox::helpRequested,
+ getMainWindow(), &MainWindow::whatsThis);
+ connect(ui->listBox, &QListWidget::currentItemChanged,
+ this, &DlgPreferencesImp::changeGroup);
+ if (auto reset = ui->buttonBox->button(QDialogButtonBox::Reset)) {
+ QString text = reset->text();
+ text.append(QLatin1String("..."));
+ reset->setText(text);
+ }
}
-
void DlgPreferencesImp::setupPages()
{
// make sure that pages are ready to create
@@ -229,37 +220,11 @@ void DlgPreferencesImp::createPageInGroup(QTabWidget *tabWidget, const std::stri
}
}
-void DlgPreferencesImp::relabelResetButtons()
-{
- int groupIndex = ui->listBox->currentRow();
- QFontMetrics fm(font());
- QString group = fm.elidedText(ui->listBox->item(groupIndex)->text(), Qt::ElideRight, ui->buttonResetGroup->width()-4);
-
- QTabWidget* tabWidget = static_cast(ui->tabWidgetStack->currentWidget());
- int tabIndex = tabWidget->currentIndex();
-
- static_cast(ui->buttonResetGroup->layout()->itemAt(0)->widget())->setText(tr("Reset Group %1").arg(group));
- ui->buttonResetTab->setText(tr("Reset Tab %1").arg(tabWidget->tabText(tabIndex)));
-}
-
-void DlgPreferencesImp::changeTab(int current)
-{
- Q_UNUSED(current);
-
- relabelResetButtons();
-}
-
void DlgPreferencesImp::changeGroup(QListWidgetItem *current, QListWidgetItem *previous)
{
if (!current)
current = previous;
ui->tabWidgetStack->setCurrentIndex(ui->listBox->row(current));
-
- auto tabWidget = static_cast(ui->tabWidgetStack->currentWidget());
- connect(tabWidget, &QTabWidget::currentChanged,
- this, &DlgPreferencesImp::changeTab);
-
- relabelResetButtons();
}
/**
@@ -401,8 +366,46 @@ void DlgPreferencesImp::reject()
void DlgPreferencesImp::onButtonBoxClicked(QAbstractButton* btn)
{
- if (ui->buttonBox->standardButton(btn) == QDialogButtonBox::Apply)
+ if (ui->buttonBox->standardButton(btn) == QDialogButtonBox::Apply) {
applyChanges();
+ }
+ else if (ui->buttonBox->standardButton(btn) == QDialogButtonBox::Reset) {
+ showResetOptions();
+ }
+}
+
+void DlgPreferencesImp::showResetOptions()
+{
+ // clang-format off
+ QMenu menu(this);
+
+ // Reset per tab
+ auto tabWidget = static_cast(ui->tabWidgetStack->currentWidget());
+ int tabIndex = tabWidget->currentIndex();
+ QString tabText = tabWidget->tabText(tabIndex);
+ QAction* tabAction = menu.addAction(tr("Reset tab '%1'...").arg(tabText), this,
+ &DlgPreferencesImp::onButtonResetTabClicked);
+ tabAction->setToolTip(tr("Resets the user settings for the tab '%1'").arg(tabText));
+
+ // Reset per group
+ int groupIndex = ui->listBox->currentRow();
+ QString group = ui->listBox->item(groupIndex)->text();
+ QAction* grpAction = menu.addAction(tr("Reset group '%1'...").arg(group), this,
+ &DlgPreferencesImp::onButtonResetGroupClicked);
+ grpAction->setToolTip(tr("Resets the user settings for the group '%1'").arg(group));
+
+ // Reset all
+ QAction* allAction = menu.addAction(tr("Reset all..."), this,
+ &DlgPreferencesImp::restoreDefaults);
+ allAction->setToolTip(tr("Resets the user settings entirely"));
+
+ connect(&menu, &QMenu::hovered, [&menu](QAction* hover){
+ QPoint pos = menu.pos();
+ pos.rx() += menu.width() + 10;
+ QToolTip::showText(pos, hover->toolTip());
+ });
+ menu.exec(QCursor::pos());
+ // clang-format on
}
void DlgPreferencesImp::restoreDefaults()
@@ -430,6 +433,88 @@ void DlgPreferencesImp::restoreDefaults()
}
}
+void DlgPreferencesImp::onButtonResetTabClicked()
+{
+ auto tabWidget = static_cast(ui->tabWidgetStack->widget(ui->listBox->currentRow()));
+
+ QMessageBox box(this);
+ box.setIcon(QMessageBox::Question);
+ box.setWindowTitle(tr("Reset Tab Settings"));
+ box.setText(tr("All the settings for the tab '%1' will be deleted.").arg(tabWidget->tabText(tabWidget->currentIndex())));
+ box.setInformativeText(tr("Do you want to continue?"));
+ box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ box.setDefaultButton(QMessageBox::No);
+
+ if (box.exec() == QMessageBox::Yes) {
+ int pageIndex = tabWidget->currentIndex();
+ QString pageText = tabWidget->tabText(pageIndex);
+ PreferencePage* page = qobject_cast(tabWidget->widget(pageIndex));
+
+ restorePageDefaults(&page);
+ page->setProperty("GroupName", tabWidget->property("GroupName"));
+
+ tabWidget->removeTab(pageIndex);
+ tabWidget->insertTab(pageIndex, page, pageText);
+ tabWidget->setCurrentIndex(pageIndex);
+
+ applyChanges();
+ }
+}
+
+void DlgPreferencesImp::onButtonResetGroupClicked()
+{
+ QMessageBox box(this);
+ box.setIcon(QMessageBox::Question);
+ box.setWindowTitle(tr("Reset Group Settings"));
+ box.setText(tr("All the settings for the group '%1' will be deleted.").arg(ui->listBox->currentItem()->text()));
+ box.setInformativeText(tr("Do you want to continue?"));
+ box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ box.setDefaultButton(QMessageBox::No);
+
+ if (box.exec() == QMessageBox::Yes) {
+ auto tabWidget = static_cast(ui->tabWidgetStack->widget(ui->listBox->currentRow()));
+ int pageIndex = tabWidget->currentIndex();
+
+ for (int i = 0; i < tabWidget->count(); i++) {
+ QString pageText = tabWidget->tabText(i);
+ PreferencePage* page = qobject_cast(tabWidget->widget(i));
+
+ restorePageDefaults(&page);
+ page->setProperty("GroupName", tabWidget->property("GroupName"));
+
+ tabWidget->removeTab(i);
+ tabWidget->insertTab(i, page, pageText);
+ }
+
+ tabWidget->setCurrentIndex(pageIndex);
+
+ applyChanges();
+ }
+}
+
+void DlgPreferencesImp::restorePageDefaults(PreferencePage** page)
+{
+ QList prefs = (*page)->findChildren();
+
+ for (const auto & pref : prefs) {
+ if (!pref->property("prefPath").isNull() && !pref->property("prefEntry").isNull()) {
+ std::string path = pref->property("prefPath").toString().toStdString();
+ std::string entry = pref->property("prefEntry").toString().toStdString();
+
+ ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(std::string("User parameter:BaseApp/Preferences/" + path).c_str());
+
+ for (const auto & pn : hGrp->GetParameterNames(entry.c_str())){
+ hGrp->RemoveAttribute(pn.first, pn.second.c_str());
+ }
+ }
+ }
+
+ std::string pageName = (*page)->property("PageName").toString().toStdString();
+ (*page) = WidgetFactory().createPreferencePage(pageName.c_str());
+ (*page)->loadSettings();
+ (*page)->setProperty("PageName", QVariant(QString::fromStdString(pageName)));
+}
+
/**
* If the dialog is currently showing and the static variable _pages changed, this function
* will rescan that list of pages and add any that are new to the current dialog. It will not
@@ -633,8 +718,6 @@ void DlgPreferencesImp::changeEvent(QEvent *e)
int length = QtTools::horizontalAdvance(fm, longestGroupName());
ui->listBox->setFixedWidth(Base::clamp(length + 20, 108, 120));
ui->listBox->setGridSize(QSize(Base::clamp(length + 20, 108, 120), 75));
- ui->buttonResetGroup->setFixedWidth(Base::clamp(length + 20, 108, 120));
- ui->buttonResetAll->setFixedWidth(Base::clamp(length + 20, 108, 120));
} else {
QWidget::changeEvent(e);
}
@@ -653,86 +736,4 @@ void DlgPreferencesImp::reload()
applyChanges();
}
-void DlgPreferencesImp::restorePageDefaults(PreferencePage** page)
-{
- QList prefs = (*page)->findChildren();
-
- for (const auto & pref : prefs) {
- if (!pref->property("prefPath").isNull() && !pref->property("prefEntry").isNull()) {
- std::string path = pref->property("prefPath").toString().toStdString();
- std::string entry = pref->property("prefEntry").toString().toStdString();
-
- ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(std::string("User parameter:BaseApp/Preferences/" + path).c_str());
-
- for (const auto & pn : hGrp->GetParameterNames(entry.c_str())){
- hGrp->RemoveAttribute(pn.first, pn.second.c_str());
- }
- }
- }
-
- std::string pageName = (*page)->property("PageName").toString().toStdString();
- (*page) = WidgetFactory().createPreferencePage(pageName.c_str());
- (*page)->loadSettings();
- (*page)->setProperty("PageName", QVariant(QString::fromStdString(pageName)));
-}
-
-void DlgPreferencesImp::onButtonResetTabClicked()
-{
- auto tabWidget = static_cast(ui->tabWidgetStack->widget(ui->listBox->currentRow()));
-
- QMessageBox box(this);
- box.setIcon(QMessageBox::Question);
- box.setWindowTitle(tr("Reset Tab Parameters"));
- box.setText(tr("All the parameters for the Tab %1 will be deleted.").arg(tabWidget->tabText(tabWidget->currentIndex())));
- box.setInformativeText(tr("Do you want to continue?"));
- box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- box.setDefaultButton(QMessageBox::No);
-
- if (box.exec() == QMessageBox::Yes) {
- int pageIndex = tabWidget->currentIndex();
- QString pageText = tabWidget->tabText(pageIndex);
- PreferencePage* page = qobject_cast(tabWidget->widget(pageIndex));
-
- restorePageDefaults(&page);
- page->setProperty("GroupName", tabWidget->property("GroupName"));
-
- tabWidget->removeTab(pageIndex);
- tabWidget->insertTab(pageIndex, page, pageText);
- tabWidget->setCurrentIndex(pageIndex);
-
- applyChanges();
- }
-}
-
-void DlgPreferencesImp::onButtonResetGroupClicked()
-{
- QMessageBox box(this);
- box.setIcon(QMessageBox::Question);
- box.setWindowTitle(tr("Reset Group Parameters"));
- box.setText(tr("All the parameters for the Group %1 will be deleted.").arg(ui->listBox->currentItem()->text()));
- box.setInformativeText(tr("Do you want to continue?"));
- box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- box.setDefaultButton(QMessageBox::No);
-
- if (box.exec() == QMessageBox::Yes) {
- auto tabWidget = static_cast(ui->tabWidgetStack->widget(ui->listBox->currentRow()));
- int pageIndex = tabWidget->currentIndex();
-
- for (int i = 0; i < tabWidget->count(); i++) {
- QString pageText = tabWidget->tabText(i);
- PreferencePage* page = qobject_cast(tabWidget->widget(i));
-
- restorePageDefaults(&page);
- page->setProperty("GroupName", tabWidget->property("GroupName"));
-
- tabWidget->removeTab(i);
- tabWidget->insertTab(i, page, pageText);
- }
-
- tabWidget->setCurrentIndex(pageIndex);
-
- applyChanges();
- }
-}
-
#include "moc_DlgPreferencesImp.cpp"
diff --git a/src/Gui/DlgPreferencesImp.h b/src/Gui/DlgPreferencesImp.h
index dd7486a2a2..18631e3869 100644
--- a/src/Gui/DlgPreferencesImp.h
+++ b/src/Gui/DlgPreferencesImp.h
@@ -136,11 +136,9 @@ protected:
void resizeEvent(QResizeEvent*) override;
void onButtonResetTabClicked();
void onButtonResetGroupClicked();
- void relabelResetButtons();
protected Q_SLOTS:
- void changeTab(int current);
void changeGroup(QListWidgetItem *current, QListWidgetItem *previous);
void onButtonBoxClicked(QAbstractButton*);
void resizeWindow(int w, int h);
@@ -153,6 +151,7 @@ private:
QTabWidget* createTabForGroup(const std::string& groupName);
void createPageInGroup(QTabWidget* tabWidget, const std::string& pageName);
void applyChanges();
+ void showResetOptions();
void restoreDefaults();
void restorePageDefaults(PreferencePage**);
QString longestGroupName() const;