From 585f8b9fda48beb4454b3e568abddf8fef5e9548 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Wed, 27 Oct 2010 17:25:55 +0000 Subject: [PATCH] Migrate GuiLabel to InsetParamsDialog. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35868 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiLabel.cpp | 72 ++++------------- src/frontends/qt4/GuiLabel.h | 41 +++------- src/frontends/qt4/GuiView.cpp | 4 - src/frontends/qt4/InsetParamsDialog.cpp | 4 + src/frontends/qt4/ui/LabelUi.ui | 101 ++++++------------------ 5 files changed, 54 insertions(+), 168 deletions(-) diff --git a/src/frontends/qt4/GuiLabel.cpp b/src/frontends/qt4/GuiLabel.cpp index 8c46909f9e..6d9ee79dae 100644 --- a/src/frontends/qt4/GuiLabel.cpp +++ b/src/frontends/qt4/GuiLabel.cpp @@ -12,11 +12,9 @@ #include "GuiLabel.h" -#include "FuncRequest.h" #include "qt_helpers.h" -#include "support/debug.h" -#include "insets/InsetCommand.h" +#include "insets/InsetLabel.h" #include #include @@ -33,82 +31,40 @@ namespace frontend { // ///////////////////////////////////////////////////////////////// -GuiLabel::GuiLabel(GuiView & lv) - : GuiDialog(lv, "label", qt_("Label")), - params_(insetCode("label")) +GuiLabel::GuiLabel(QWidget * parent) : InsetParamsWidget(parent) { setupUi(this); - connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(keywordED, SIGNAL(textChanged(const QString &)), - this, SLOT(change_adaptor())); + this, SIGNAL(changed())); setFocusProxy(keywordED); - - bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); - bc().setOK(okPB); - bc().setCancel(closePB); - bc().addReadOnly(keywordED); } -void GuiLabel::change_adaptor() +void GuiLabel::paramsToDialog(Inset const * inset) { - changed(); + InsetLabel const * label = static_cast(inset); + InsetCommandParams const & params = label->params(); + keywordED->setText(toqstr(params["name"])); } -void GuiLabel::reject() +docstring GuiLabel::dialogToParams() const { - slotClose(); + InsetCommandParams params(insetCode()); + params["name"] = qstring_to_ucs4(keywordED->text()); + return from_ascii(InsetLabel::params2string("label", params)); } -void GuiLabel::updateContents() -{ - docstring const contents = params_["name"]; - keywordED->setText(toqstr(contents)); - bc().setValid(!contents.empty()); -} - - -void GuiLabel::applyView() -{ - params_["name"] = qstring_to_ucs4(keywordED->text()); -} - - - -void GuiLabel::enableView(bool enable) -{ - keywordED->setEnabled(enable); -} - - -bool GuiLabel::isValid() +bool GuiLabel::checkWidgets() const { + if (!InsetParamsWidget::checkWidgets()) + return false; return !keywordED->text().isEmpty(); } - -bool GuiLabel::initialiseParams(std::string const & data) -{ - InsetCommand::string2params("label", data, params_); - return true; -} - - -void GuiLabel::dispatchParams() -{ - std::string const lfun = InsetCommand::params2string("label", params_); - dispatch(FuncRequest(getLfun(), lfun)); -} - - -Dialog * createGuiLabel(GuiView & lv) { return new GuiLabel(lv); } - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiLabel.h b/src/frontends/qt4/GuiLabel.h index 64a9a0e8a1..4e7a63f05d 100644 --- a/src/frontends/qt4/GuiLabel.h +++ b/src/frontends/qt4/GuiLabel.h @@ -13,48 +13,29 @@ #ifndef GUILABEL_H #define GUILABEL_H -#include "GuiDialog.h" #include "ui_LabelUi.h" -#include "insets/InsetCommandParams.h" +#include "InsetParamsWidget.h" namespace lyx { namespace frontend { -class GuiLabel : public GuiDialog, public Ui::LabelUi +class GuiLabel : public InsetParamsWidget, public Ui::LabelUi { Q_OBJECT public: - GuiLabel(GuiView & lv); - -private Q_SLOTS: - void change_adaptor(); - void reject(); + GuiLabel(QWidget * parent = 0); private: - /// - bool isValid(); - /// Apply changes - void applyView(); - /// update - void updateContents(); - /// - bool initialiseParams(std::string const & data); - /// clean-up on hide. - void clearParams() { params_.clear(); } - /// clean-up on hide. - void dispatchParams(); - /// - bool isBufferDependent() const { return true; } - /// - void enableView(bool enable); - /// - bool canApply() const { return true; } - -private: - /// - InsetCommandParams params_; + /// \name InsetParamsWidget inherited methods + //@{ + InsetCode insetCode() const { return LABEL_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 4cc75d365e..b20d38e22b 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -3771,7 +3771,6 @@ Dialog * createGuiExternal(GuiView & lv); Dialog * createGuiGraphics(GuiView & lv); Dialog * createGuiInclude(GuiView & lv); Dialog * createGuiIndex(GuiView & lv); -Dialog * createGuiLabel(GuiView & lv); Dialog * createGuiListings(GuiView & lv); Dialog * createGuiLog(GuiView & lv); Dialog * createGuiMathMatrix(GuiView & lv); @@ -3794,7 +3793,6 @@ Dialog * createGuiTabularCreate(GuiView & lv); Dialog * createGuiTexInfo(GuiView & lv); Dialog * createGuiToc(GuiView & lv); Dialog * createGuiThesaurus(GuiView & lv); -Dialog * createGuiHyperlink(GuiView & lv); Dialog * createGuiViewSource(GuiView & lv); Dialog * createGuiWrap(GuiView & lv); Dialog * createGuiProgressView(GuiView & lv); @@ -3843,8 +3841,6 @@ Dialog * GuiView::build(string const & name) return createGuiIndex(*this); if (name == "index_print") return createGuiPrintindex(*this); - if (name == "label") - return createGuiLabel(*this); if (name == "listings") return createGuiListings(*this); if (name == "log") diff --git a/src/frontends/qt4/InsetParamsDialog.cpp b/src/frontends/qt4/InsetParamsDialog.cpp index bd7251bdd5..c262336f82 100644 --- a/src/frontends/qt4/InsetParamsDialog.cpp +++ b/src/frontends/qt4/InsetParamsDialog.cpp @@ -18,6 +18,7 @@ #include "GuiERT.h" #include "GuiHyperlink.h" #include "GuiInfo.h" +#include "GuiLabel.h" #include "GuiLine.h" #include "GuiHSpace.h" #include "GuiTabular.h" @@ -239,6 +240,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code) case INFO_CODE: widget = new GuiInfo; break; + case LABEL_CODE: + widget = new GuiLabel; + break; case LINE_CODE: widget = new GuiLine; break; diff --git a/src/frontends/qt4/ui/LabelUi.ui b/src/frontends/qt4/ui/LabelUi.ui index a32d96dda4..0679e2a689 100644 --- a/src/frontends/qt4/ui/LabelUi.ui +++ b/src/frontends/qt4/ui/LabelUi.ui @@ -1,101 +1,50 @@ - + + LabelUi - - + + 0 0 300 - 82 + 71 - + - - true - - - - 11 - - + + 6 + + 11 + - - - 0 - - + + 6 - - - - - - - &Label: - - - keywordED - - - - - - - - - - - - - - - + 0 - - 6 - - - - Qt::Horizontal + + + - - QSizePolicy::Expanding + + &Label: - - - 20 - 20 - - - - - - - - &OK - - - true + + keywordED - - - Cancel - - - false - - - false + + + @@ -104,7 +53,7 @@ - qt_i18n.h + qt_i18n.h