#include "support/gettext.h"
#include "support/lstrings.h"
-#include <QLineEdit>
-#include <QPushButton>
-#include <QValidator>
-
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")));
}
-void GuiPrintNomencl::change_adaptor()
-{
- changed();
-}
-
-
-void GuiPrintNomencl::on_setWidthCO_activated(int i)
+void GuiPrintNomencl::on_setWidthCO_activated(int /*i*/)
{
- bool const custom =
- (setWidthCO->itemData(i).toString()
- == "custom");
- valueLE->setEnabled(custom);
- unitLC->setEnabled(custom);
- valueLA->setEnabled(custom);
changed();
}
-void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & /*icp*/)
+void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & params)
{
setWidthCO->setCurrentIndex(
- setWidthCO->findData(toqstr(params_["set_width"])));
-
- lengthToWidgets(valueLE,
- unitLC,
- params_["width"],
- Length::defaultUnit());
-
- bc().setValid(isValid());
+ setWidthCO->findData(toqstr(params["set_width"])));
+
+ lengthToWidgets(valueLE, unitLC,
+ params["width"], Length::defaultUnit());
}
-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<InsetNomencl const *>(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(bool readonly) const
{
+ valueLE->setReadOnly(readonly);
+ if (readonly) {
+ setWidthCO->setEnabled(false);
+ unitLC->setEnabled(false);
+ valueLA->setEnabled(false);
+ } else {
+ bool const custom =
+ (setWidthCO->itemData(setWidthCO->currentIndex()).toString() == "custom");
+ valueLE->setEnabled(custom);
+ unitLC->setEnabled(custom);
+ valueLA->setEnabled(custom);
+ }
+
+ 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