From 766e300f420bfdcf5b3375cf5497ac51106309ff Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sat, 30 Oct 2010 20:14:57 +0000 Subject: [PATCH] Migrate GuiPrintNomencl to InsetParamsDialog. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35938 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiPrintNomencl.cpp | 87 +++++-------------------- src/frontends/qt4/GuiPrintNomencl.h | 38 ++++------- src/frontends/qt4/GuiView.cpp | 3 - src/frontends/qt4/InsetParamsDialog.cpp | 4 ++ src/frontends/qt4/ui/PrintNomenclUi.ui | 65 ++---------------- 5 files changed, 39 insertions(+), 158 deletions(-) diff --git a/src/frontends/qt4/GuiPrintNomencl.cpp b/src/frontends/qt4/GuiPrintNomencl.cpp index 3c5bd95b46..2054f59944 100644 --- a/src/frontends/qt4/GuiPrintNomencl.cpp +++ b/src/frontends/qt4/GuiPrintNomencl.cpp @@ -25,44 +25,24 @@ #include "support/gettext.h" #include "support/lstrings.h" -#include -#include -#include - using namespace std; namespace lyx { namespace frontend { -GuiPrintNomencl::GuiPrintNomencl(GuiView & lv) - : GuiDialog(lv, "nomencl_print", qt_("Nomenclature settings")), - params_(insetCode("nomencl_print")) +GuiPrintNomencl::GuiPrintNomencl(QWidget * parent) : InsetParamsWidget(parent) { setupUi(this); - connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); - connect(valueLE, SIGNAL(textChanged(QString)), - this, SLOT(change_adaptor())); + this, SIGNAL(changed())); connect(unitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)), - this, SLOT(change_adaptor())); + this, SIGNAL(changed())); valueLE->setValidator(unsignedLengthValidator(valueLE)); - // Manage the ok, apply, restore and cancel/close buttons - bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); - bc().setOK(okPB); - bc().setApply(applyPB); - bc().setCancel(closePB); - - // disable for read-only documents - bc().addReadOnly(valueLE); - bc().addReadOnly(unitLC); - // initialize the length validator - bc().addCheckedLineEdit(valueLE, valueLA); + addCheckedWidget(valueLE, valueLA); setWidthCO->addItem(qt_("Default"), QVariant(toqstr("none"))); @@ -73,12 +53,6 @@ GuiPrintNomencl::GuiPrintNomencl(GuiView & lv) } -void GuiPrintNomencl::change_adaptor() -{ - changed(); -} - - void GuiPrintNomencl::on_setWidthCO_activated(int i) { bool const custom = @@ -91,73 +65,48 @@ void GuiPrintNomencl::on_setWidthCO_activated(int i) } -void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & /*icp*/) +void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & params) { setWidthCO->setCurrentIndex( - setWidthCO->findData(toqstr(params_["set_width"]))); + setWidthCO->findData(toqstr(params["set_width"]))); lengthToWidgets(valueLE, unitLC, - params_["width"], + params["width"], Length::defaultUnit()); - - bc().setValid(isValid()); } -void GuiPrintNomencl::updateContents() +void GuiPrintNomencl::paramsToDialog(Inset const * inset) { - bool const custom = (setWidthCO->itemData( - setWidthCO->currentIndex()).toString() - == "custom"); - valueLE->setEnabled(custom); - unitLC->setEnabled(custom); - valueLA->setEnabled(custom); + InsetNomencl const * nomencl = static_cast(inset); + paramsToDialog(nomencl->params()); } -void GuiPrintNomencl::applyView() +docstring GuiPrintNomencl::dialogToParams() const { + InsetCommandParams params(insetCode()); docstring const set_width = qstring_to_ucs4(setWidthCO->itemData( setWidthCO->currentIndex()).toString()); - params_["set_width"] = set_width; + params["set_width"] = set_width; docstring width; if (set_width == from_ascii("custom")) width = from_utf8(widgetsToLength(valueLE, unitLC)); - params_["width"] = width; + params["width"] = width; + return from_ascii(InsetNomencl::params2string(params)); } -bool GuiPrintNomencl::isValid() const +bool GuiPrintNomencl::checkWidgets() const { + if (!InsetParamsWidget::checkWidgets()) + return false; return setWidthCO->itemData( setWidthCO->currentIndex()).toString() != "custom" || !valueLE->text().isEmpty(); } - -bool GuiPrintNomencl::initialiseParams(std::string const & data) -{ - InsetCommand::string2params(data, params_); - paramsToDialog(params_); - return true; -} - - -void GuiPrintNomencl::dispatchParams() -{ - std::string const lfun = InsetCommand::params2string(params_); - dispatch(FuncRequest(getLfun(), lfun)); -} - - - -Dialog * createGuiPrintNomencl(GuiView & lv) -{ - return new GuiPrintNomencl(lv); -} - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiPrintNomencl.h b/src/frontends/qt4/GuiPrintNomencl.h index a037140616..d4c0f88126 100644 --- a/src/frontends/qt4/GuiPrintNomencl.h +++ b/src/frontends/qt4/GuiPrintNomencl.h @@ -13,46 +13,32 @@ #ifndef GUIPRINTNOMENCL_H #define GUIPRINTNOMENCL_H -#include "GuiDialog.h" +#include "InsetParamsWidget.h" #include "ui_PrintNomenclUi.h" -#include "insets/InsetCommandParams.h" - - namespace lyx { namespace frontend { -class GuiPrintNomencl : public GuiDialog, public Ui::PrintNomenclUi +class GuiPrintNomencl : public InsetParamsWidget, public Ui::PrintNomenclUi { Q_OBJECT public: - GuiPrintNomencl(GuiView & lv); + GuiPrintNomencl(QWidget * parent = 0); private Q_SLOTS: - void change_adaptor(); void on_setWidthCO_activated(int); private: - /// Apply changes - void applyView(); - /// Update dialog before showing it - void updateContents(); - /// - bool initialiseParams(std::string const & data); - /// - void paramsToDialog(InsetCommandParams const & icp); - /// - void clearParams() { params_.clear(); } - /// - void dispatchParams(); - /// - bool isBufferDependent() const { return true; } - /// - bool isValid() const; - - /// - InsetCommandParams params_; + /// \name InsetParamsWidget inherited methods + //@{ + InsetCode insetCode() const { return NOMENCL_PRINT_CODE; } + FuncCode creationCode() const { return LFUN_INSET_INSERT; } + void paramsToDialog(Inset const *); + void paramsToDialog(InsetCommandParams const &); + docstring dialogToParams() const; + bool checkWidgets() const; + //@} }; } // namespace frontend diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index bc79914c01..eb689ce56b 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -3754,7 +3754,6 @@ Dialog * createGuiPhantom(GuiView & lv); Dialog * createGuiPreferences(GuiView & lv); Dialog * createGuiPrint(GuiView & lv); Dialog * createGuiPrintindex(GuiView & lv); -Dialog * createGuiPrintNomencl(GuiView & lv); Dialog * createGuiRef(GuiView & lv); Dialog * createGuiSearch(GuiView & lv); Dialog * createGuiSearchAdv(GuiView & lv); @@ -3822,8 +3821,6 @@ Dialog * GuiView::build(string const & name) return createGuiDelimiter(*this); if (name == "mathmatrix") return createGuiMathMatrix(*this); - if (name == "nomencl_print") - return createGuiPrintNomencl(*this); if (name == "note") return createGuiNote(*this); if (name == "paragraph") diff --git a/src/frontends/qt4/InsetParamsDialog.cpp b/src/frontends/qt4/InsetParamsDialog.cpp index 17b4108019..698cf899bf 100644 --- a/src/frontends/qt4/InsetParamsDialog.cpp +++ b/src/frontends/qt4/InsetParamsDialog.cpp @@ -22,6 +22,7 @@ #include "GuiLabel.h" #include "GuiLine.h" #include "GuiNomenclature.h" +#include "GuiPrintNomencl.h" #include "GuiTabular.h" #include "GuiVSpace.h" #include "FloatPlacement.h" @@ -255,6 +256,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code) case NOMENCL_CODE: widget = new GuiNomenclature; break; + case NOMENCL_PRINT_CODE: + widget = new GuiPrintNomencl; + break; case SPACE_CODE: widget = new GuiHSpace(false); break; diff --git a/src/frontends/qt4/ui/PrintNomenclUi.ui b/src/frontends/qt4/ui/PrintNomenclUi.ui index b352270a78..d5f2cd625a 100644 --- a/src/frontends/qt4/ui/PrintNomenclUi.ui +++ b/src/frontends/qt4/ui/PrintNomenclUi.ui @@ -1,19 +1,17 @@ + PrintNomenclUi - + 0 0 - 280 - 119 + 336 + 80 - - - - true + "Nomenclature settings" @@ -59,56 +57,6 @@ - - - - Qt::Horizontal - - - - 74 - 20 - - - - - - - - - - &OK - - - false - - - true - - - - - - - &Apply - - - false - - - - - - - &Close - - - false - - - - - @@ -120,9 +68,6 @@ valueLE - okPB - applyPB - closePB qt_i18n.h -- 2.39.2