From 18b52e7bc50790539383e6b04c386071e233ca29 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 7 Sep 2010 14:13:28 +0000 Subject: [PATCH] Migrate GuiLine to InsetParamsWidget. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35320 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiLine.cpp | 116 ++++++++---------------- src/frontends/qt4/GuiLine.h | 37 +++----- src/frontends/qt4/GuiView.cpp | 3 - src/frontends/qt4/InsetParamsDialog.cpp | 4 + src/frontends/qt4/ui/LineUi.ui | 55 +---------- 5 files changed, 56 insertions(+), 159 deletions(-) diff --git a/src/frontends/qt4/GuiLine.cpp b/src/frontends/qt4/GuiLine.cpp index bec4438d8c..e411835b47 100644 --- a/src/frontends/qt4/GuiLine.cpp +++ b/src/frontends/qt4/GuiLine.cpp @@ -33,47 +33,27 @@ using namespace std; 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)); @@ -81,43 +61,19 @@ GuiLine::GuiLine(GuiView & lv) } -void GuiLine::change_adaptor() -{ - changed(); -} - - -void GuiLine::paramsToDialog(InsetCommandParams const & /*icp*/) -{ - lengthToWidgets(OffsetLE, - OffsetUnitCO, - params_["offset"], - Length::defaultUnit()); - lengthToWidgets(WidthLE, - WidthUnitCO, - params_["width"], - Length::defaultUnit()); - lengthToWidgets(HeightLE, - HeightUnitCO, - params_["height"], - Length::defaultUnit()); - - bc().setValid(isValid()); -} - - -void GuiLine::applyView() +docstring GuiLine::dialogToParams() const { docstring offset = from_utf8(widgetsToLength(OffsetLE, OffsetUnitCO)); - params_["offset"] = offset; - + InsetCommandParams params(insetCode()); + 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; + params["width"] = width; // negative heights are senseless string height_str = fromqstr(HeightLE->text()); @@ -125,37 +81,41 @@ void GuiLine::applyView() height_str.erase(0,1); HeightLE->setText(toqstr(height_str)); docstring height = from_utf8(widgetsToLength(HeightLE, HeightUnitCO)); - params_["height"] = height; + params["height"] = height; - params_.setCmdName("rule"); + params.setCmdName("rule"); + return from_ascii(InsetLine::params2string("line", params)); } -bool GuiLine::isValid() const +void GuiLine::paramsToDialog(Inset const * inset) { - return true; + InsetLine const * line = static_cast(inset); + InsetCommandParams const & params = line->params(); + lengthToWidgets(OffsetLE, + OffsetUnitCO, + params["offset"], + Length::defaultUnit()); + lengthToWidgets(WidthLE, + WidthUnitCO, + params["width"], + Length::defaultUnit()); + lengthToWidgets(HeightLE, + HeightUnitCO, + params["height"], + Length::defaultUnit()); } -bool GuiLine::initialiseParams(std::string const & data) +bool GuiLine::checkWidgets() const { - InsetCommand::string2params("line", data, params_); - paramsToDialog(params_); + if (!InsetParamsWidget::checkWidgets()) + return false; + // FIXME: Is there something else to check? + // Transfer some code from dialogToParams()? 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 diff --git a/src/frontends/qt4/GuiLine.h b/src/frontends/qt4/GuiLine.h index 46a8079e12..b0518182f7 100644 --- a/src/frontends/qt4/GuiLine.h +++ b/src/frontends/qt4/GuiLine.h @@ -12,43 +12,28 @@ #ifndef GUILINE_H #define GUILINE_H -#include "GuiDialog.h" +#include "InsetParamsWidget.h" #include "ui_LineUi.h" -#include "insets/InsetCommandParams.h" - - namespace lyx { namespace frontend { -class GuiLine : public GuiDialog, public Ui::LineUi +class GuiLine : public InsetParamsWidget, public Ui::LineUi { Q_OBJECT public: - GuiLine(GuiView & lv); - -private Q_SLOTS: - void change_adaptor(); + GuiLine(QWidget * parent = 0); private: - /// Apply changes - void applyView(); - /// Update dialog before showing it - 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 LINE_CODE; } + FuncCode creationCode() const { return LFUN_INSET_INSERT; } + void paramsToDialog(Inset const *); + docstring dialogToParams() const; + bool checkWidgets() const; + //@} }; } // namespace frontend diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 7879d8ce06..bb3d3d1856 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -3647,7 +3647,6 @@ Dialog * createGuiGraphics(GuiView & lv); Dialog * createGuiInclude(GuiView & lv); Dialog * createGuiIndex(GuiView & lv); Dialog * createGuiLabel(GuiView & lv); -Dialog * createGuiLine(GuiView & lv); Dialog * createGuiListings(GuiView & lv); Dialog * createGuiLog(GuiView & lv); Dialog * createGuiMathMatrix(GuiView & lv); @@ -3721,8 +3720,6 @@ Dialog * GuiView::build(string const & name) return createGuiIndex(*this); if (name == "index_print") return createGuiPrintindex(*this); - if (name == "line") - return createGuiLine(*this); if (name == "label") return createGuiLabel(*this); if (name == "listings") diff --git a/src/frontends/qt4/InsetParamsDialog.cpp b/src/frontends/qt4/InsetParamsDialog.cpp index 7a8ab9c329..30a546aa5d 100644 --- a/src/frontends/qt4/InsetParamsDialog.cpp +++ b/src/frontends/qt4/InsetParamsDialog.cpp @@ -17,6 +17,7 @@ #include "GuiBibitem.h" #include "GuiERT.h" #include "GuiInfo.h" +#include "GuiLine.h" #include "GuiHSpace.h" #include "GuiTabular.h" #include "GuiVSpace.h" @@ -219,6 +220,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code) case INFO_CODE: widget = new GuiInfo; break; + case LINE_CODE: + widget = new GuiLine; + break; case MATH_SPACE_CODE: widget = new GuiHSpace(true); break; diff --git a/src/frontends/qt4/ui/LineUi.ui b/src/frontends/qt4/ui/LineUi.ui index bdfd70f2c4..659ef2770c 100644 --- a/src/frontends/qt4/ui/LineUi.ui +++ b/src/frontends/qt4/ui/LineUi.ui @@ -1,3 +1,4 @@ + LineUi @@ -5,8 +6,8 @@ 0 0 - 325 - 126 + 311 + 85 @@ -118,56 +119,6 @@ - - - - Qt::Horizontal - - - - 59 - 20 - - - - - - - - - - &OK - - - false - - - true - - - - - - - &Apply - - - false - - - - - - - &Close - - - false - - - - - -- 2.39.2