From 5f038896093eb8d8e6c5804ef0a8d4a8d4d2d338 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Mon, 17 Dec 2018 12:59:40 +0100 Subject: [PATCH] GuiCharacter: Add "Reset" and "Restore Defaults" buttons Addresses #11415 --- src/frontends/qt4/GuiCharacter.cpp | 56 +++++++++++--- src/frontends/qt4/GuiCharacter.h | 2 + src/frontends/qt4/GuiDialog.cpp | 4 +- src/frontends/qt4/GuiDialog.h | 2 + src/frontends/qt4/ui/CharacterUi.ui | 112 ++++++++++++++-------------- 5 files changed, 109 insertions(+), 67 deletions(-) diff --git a/src/frontends/qt4/GuiCharacter.cpp b/src/frontends/qt4/GuiCharacter.cpp index 79398b89f7..54d90ccaac 100644 --- a/src/frontends/qt4/GuiCharacter.cpp +++ b/src/frontends/qt4/GuiCharacter.cpp @@ -34,6 +34,7 @@ #include "support/lstrings.h" #include +#include #include #include #include @@ -251,6 +252,7 @@ GuiCharacter::GuiCharacter(GuiView & lv) bc().setOK(buttonBox->button(QDialogButtonBox::Ok)); bc().setApply(buttonBox->button(QDialogButtonBox::Apply)); bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel)); + bc().setRestore(buttonBox->button(QDialogButtonBox::Reset)); bc().setAutoApply(autoapplyCB); bc().addReadOnly(familyCO); bc().addReadOnly(seriesCO); @@ -307,19 +309,12 @@ void GuiCharacter::on_nospellcheckCB_clicked() } - -void GuiCharacter::change_adaptor() +void GuiCharacter::slotRestoreDefaults() { - changed(); - - if (!autoapplyCB->isChecked()) - return; - - // to be really good here, we should set the combos to the values of - // the current text, and make it appear as "no change" if the values - // stay the same between applys. Might be difficult though wrt to a - // moved cursor - jbl - slotApply(); + Font font(inherit_font); + font.setLanguage(reset_language); + paramsToDialog(font); + change_adaptor(); } @@ -404,6 +399,41 @@ lyx::FontState setMarkupState(Qt::CheckState cs) } // end namespace anon +void GuiCharacter::change_adaptor() +{ + changed(); + + checkRestoreDefaults(); + + if (!autoapplyCB->isChecked()) + return; + + // to be really good here, we should set the combos to the values of + // the current text, and make it appear as "no change" if the values + // stay the same between applys. Might be difficult though wrt to a + // moved cursor - jbl + slotApply(); +} + + +void GuiCharacter::checkRestoreDefaults() +{ + // (De)Activate Restore Defaults button + buttonBox->button(QDialogButtonBox::RestoreDefaults)->setEnabled( + family[familyCO->currentIndex()].second != INHERIT_FAMILY + || series[seriesCO->currentIndex()].second != INHERIT_SERIES + || shape[shapeCO->currentIndex()].second != INHERIT_SHAPE + || size[sizeCO->currentIndex()].second != FONT_SIZE_INHERIT + || setMarkupState(emphCB->checkState()) != FONT_OFF + || setMarkupState(nounCB->checkState()) != FONT_OFF + || setMarkupState(nospellcheckCB->checkState()) != FONT_OFF + || bar[ulineCO->currentIndex()].second != INHERIT + || strike[strikeCO->currentIndex()].second != INHERIT + || lcolor.getFromLyXName(fromqstr(colorCO->itemData(colorCO->currentIndex()).toString())) != Color_inherit + || languages.getLanguage(fromqstr(language[langCO->currentIndex()].second)) != reset_language); +} + + void GuiCharacter::updateContents() { if (bufferview()->cursor().selection()) { @@ -458,6 +488,8 @@ void GuiCharacter::updateContents() font_.setLanguage(reset_language); paramsToDialog(font_); + + checkRestoreDefaults(); } diff --git a/src/frontends/qt4/GuiCharacter.h b/src/frontends/qt4/GuiCharacter.h index d26ca470f4..cece7ba4ad 100644 --- a/src/frontends/qt4/GuiCharacter.h +++ b/src/frontends/qt4/GuiCharacter.h @@ -66,6 +66,8 @@ protected Q_SLOTS: void on_emphCB_clicked(); void on_nounCB_clicked(); void on_nospellcheckCB_clicked(); + void slotRestoreDefaults(); + void checkRestoreDefaults(); private: /// \name Dialog inherited methods diff --git a/src/frontends/qt4/GuiDialog.cpp b/src/frontends/qt4/GuiDialog.cpp index 4fcff16a23..8778886e34 100644 --- a/src/frontends/qt4/GuiDialog.cpp +++ b/src/frontends/qt4/GuiDialog.cpp @@ -106,9 +106,11 @@ void GuiDialog::slotButtonBox(QAbstractButton * button) slotClose(); break; case QDialogButtonBox::Reset: - case QDialogButtonBox::RestoreDefaults: slotRestore(); break; + case QDialogButtonBox::RestoreDefaults: + slotRestoreDefaults(); + break; default: break; } diff --git a/src/frontends/qt4/GuiDialog.h b/src/frontends/qt4/GuiDialog.h index de71a780e0..d5f4227c08 100644 --- a/src/frontends/qt4/GuiDialog.h +++ b/src/frontends/qt4/GuiDialog.h @@ -49,6 +49,8 @@ public Q_SLOTS: */ // Restore button clicked void slotRestore(); + // Restore Defaults button clicked + virtual void slotRestoreDefaults() {} // OK button clicked void slotOK(); // Apply button clicked diff --git a/src/frontends/qt4/ui/CharacterUi.ui b/src/frontends/qt4/ui/CharacterUi.ui index d22868fefc..05a8214d8a 100644 --- a/src/frontends/qt4/ui/CharacterUi.ui +++ b/src/frontends/qt4/ui/CharacterUi.ui @@ -6,8 +6,8 @@ 0 0 - 523 - 372 + 545 + 428 @@ -17,58 +17,6 @@ true - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Apply each change automatically - - - Apply changes &immediately - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - @@ -369,6 +317,62 @@ + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + + + Apply each change automatically + + + Apply changes &immediately + + + + +