* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
+ * \author Abdelrazak Younes
* \author Uwe Stöhr
*
* Full author contact details are available in file CREDITS.
namespace lyx {
namespace frontend {
-GuiLine::GuiLine(GuiView & lv)
- : GuiDialog(lv, "line", qt_("Horizontal line")),
- params_(insetCode("line"))
+GuiLine::GuiLine(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(OffsetLE, SIGNAL(textChanged(QString)),
- this, SLOT(change_adaptor()));
+ this, SIGNAL(changed()));
connect(OffsetUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
- this, SLOT(change_adaptor()));
+ this, SIGNAL(changed()));
connect(WidthLE, SIGNAL(textChanged(QString)),
- this, SLOT(change_adaptor()));
+ this, SIGNAL(changed()));
connect(WidthUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
- this, SLOT(change_adaptor()));
+ this, SIGNAL(changed()));
connect(HeightLE, SIGNAL(textChanged(QString)),
- this, SLOT(change_adaptor()));
+ this, SIGNAL(changed()));
connect(HeightUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
- this, SLOT(change_adaptor()));
-
- // 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(OffsetLE);
- bc().addReadOnly(OffsetUnitCO);
- bc().addReadOnly(WidthLE);
- bc().addReadOnly(WidthUnitCO);
- bc().addReadOnly(HeightLE);
- bc().addReadOnly(HeightUnitCO);
+ this, SIGNAL(changed()));
// initialize the length validator
- bc().addCheckedLineEdit(OffsetLE, OffsetValueL);
- bc().addCheckedLineEdit(WidthLE, WidthValueL);
- bc().addCheckedLineEdit(HeightLE, HeightValueL);
+ addCheckedWidget(OffsetLE, OffsetValueL);
+ addCheckedWidget(WidthLE, WidthValueL);
+ addCheckedWidget(HeightLE, HeightValueL);
OffsetLE->setValidator(unsignedGlueLengthValidator(OffsetLE));
WidthLE->setValidator(unsignedGlueLengthValidator(WidthLE));
HeightLE->setValidator(unsignedGlueLengthValidator(HeightLE));
+
+ OffsetLE->setText("0.5");
+ OffsetUnitCO->setCurrentItem(Length::EX);
+ WidthLE->setText("100");
+ WidthUnitCO->setCurrentItem(Length::PCW);
+ HeightLE->setText("1");
+ HeightUnitCO->setCurrentItem(Length::PT);
+ setFocusProxy(WidthLE);
}
-void GuiLine::change_adaptor()
+docstring GuiLine::dialogToParams() const
{
- changed();
+ InsetCommandParams params(insetCode());
+ params["offset"] = from_utf8(widgetsToLength(OffsetLE, OffsetUnitCO));
+ params["width"] = from_utf8(widgetsToLength(WidthLE, WidthUnitCO));
+ params["height"] = from_utf8(widgetsToLength(HeightLE, HeightUnitCO));
+ params.setCmdName("rule");
+ return from_ascii(InsetLine::params2string(params));
}
-void GuiLine::paramsToDialog(InsetCommandParams const & /*icp*/)
+void GuiLine::paramsToDialog(Inset const * inset)
{
+ InsetLine const * line = static_cast<InsetLine const *>(inset);
+ InsetCommandParams const & params = line->params();
lengthToWidgets(OffsetLE,
OffsetUnitCO,
- params_["offset"],
+ params["offset"],
Length::defaultUnit());
lengthToWidgets(WidthLE,
WidthUnitCO,
- params_["width"],
+ params["width"],
Length::defaultUnit());
lengthToWidgets(HeightLE,
HeightUnitCO,
- params_["height"],
+ params["height"],
Length::defaultUnit());
-
- bc().setValid(isValid());
-}
-
-
-void GuiLine::applyView()
-{
- docstring offset = from_utf8(widgetsToLength(OffsetLE, OffsetUnitCO));
- params_["offset"] = offset;
-
- // negative widths are senseless
- string width_str = fromqstr(WidthLE->text());
- if (width_str[0] == '-')
- width_str.erase(0,1);
- WidthLE->setText(toqstr(width_str));
- docstring width = from_utf8(widgetsToLength(WidthLE, WidthUnitCO));
- params_["width"] = width;
-
- // negative heights are senseless
- string height_str = fromqstr(HeightLE->text());
- if (height_str[0] == '-')
- height_str.erase(0,1);
- HeightLE->setText(toqstr(height_str));
- docstring height = from_utf8(widgetsToLength(HeightLE, HeightUnitCO));
- params_["height"] = height;
-
- params_.setCmdName("rule");
-}
-
-
-bool GuiLine::isValid() const
-{
- return true;
}
-bool GuiLine::initialiseParams(std::string const & data)
+bool GuiLine::checkWidgets(bool readonly) const
{
- InsetCommand::string2params("line", data, params_);
- paramsToDialog(params_);
+ WidthLE->setReadOnly(readonly);
+ HeightLE->setReadOnly(readonly);
+ OffsetLE->setReadOnly(readonly);
+ OffsetUnitCO->setEnabled(!readonly);
+ HeightUnitCO->setEnabled(!readonly);
+ WidthUnitCO->setEnabled(!readonly);
+ if (!InsetParamsWidget::checkWidgets())
+ return false;
+ // FIXME: this should be handled in unsignedGlueLengthValidator!
+ if (WidthLE->text().startsWith('-'))
+ return false;
+ // FIXME: this should be handled in unsignedGlueLengthValidator!
+ if (HeightLE->text().startsWith('-'))
+ return false;
return true;
}
-
-void GuiLine::dispatchParams()
-{
- std::string const lfun = InsetCommand::params2string("line", params_);
- dispatch(FuncRequest(getLfun(), lfun));
-}
-
-
-
-Dialog * createGuiLine(GuiView & lv) { return new GuiLine(lv); }
-
-
} // namespace frontend
} // namespace lyx