From 85c782bde8b99402657ed7267b17dce30e24f69e Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 23 Feb 2010 21:24:24 +0000 Subject: [PATCH] Migrate GuiBibitem to InsetParamsWidget. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33547 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiBibitem.cpp | 65 ++++---------- src/frontends/qt4/GuiBibitem.h | 36 +++----- src/frontends/qt4/GuiView.cpp | 3 - src/frontends/qt4/InsetParamsDialog.cpp | 4 + src/frontends/qt4/ui/BibitemUi.ui | 114 +++++++----------------- src/insets/Inset.cpp | 3 +- 6 files changed, 64 insertions(+), 161 deletions(-) diff --git a/src/frontends/qt4/GuiBibitem.cpp b/src/frontends/qt4/GuiBibitem.cpp index 20285f8daa..12ec4b0ea8 100644 --- a/src/frontends/qt4/GuiBibitem.cpp +++ b/src/frontends/qt4/GuiBibitem.cpp @@ -11,8 +11,8 @@ #include #include "GuiBibitem.h" + #include "qt_helpers.h" -#include "FuncRequest.h" #include "insets/InsetCommand.h" @@ -24,73 +24,42 @@ namespace lyx { namespace frontend { -GuiBibitem::GuiBibitem(GuiView & lv) - : GuiDialog(lv, "bibitem", qt_("Bibliography Entry Settings")), - params_(insetCode("bibitem")) +GuiBibitem::GuiBibitem(QWidget * parent) : InsetParamsWidget(parent) { setupUi(this); - connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); - connect(keyED, SIGNAL(textChanged(QString)), - this, SLOT(change_adaptor())); + this, SIGNAL(changed())); connect(labelED, SIGNAL(textChanged(QString)), - this, SLOT(change_adaptor())); - - bc().setPolicy(ButtonPolicy::OkCancelReadOnlyPolicy); - bc().setOK(okPB); - bc().setCancel(closePB); - bc().addReadOnly(keyED); - bc().addReadOnly(labelED); + this, SIGNAL(changed())); } -void GuiBibitem::change_adaptor() +void GuiBibitem::paramsToDialog(Inset const * inset) { - changed(); + InsetCommand const * ic = static_cast(inset); + InsetCommandParams const & params = ic->params(); + keyED->setText(toqstr(params["key"])); + labelED->setText(toqstr(params["label"])); } -void GuiBibitem::updateContents() +docstring GuiBibitem::dialogToParams() const { - keyED->setText(toqstr(params_["key"])); - labelED->setText(toqstr(params_["label"])); + InsetCommandParams params(insetCode()); + params["key"] = qstring_to_ucs4(keyED->text()); + params["label"] = qstring_to_ucs4(labelED->text()); + return from_utf8(InsetCommand::params2string("bibitem", params)); } -void GuiBibitem::applyView() -{ - params_["key"] = qstring_to_ucs4(keyED->text()); - params_["label"] = qstring_to_ucs4(labelED->text()); -} - - -bool GuiBibitem::isValid() +bool GuiBibitem::checkWidgets() const { + if (!InsetParamsWidget::checkWidgets()) + return false; return !keyED->text().isEmpty(); } - -bool GuiBibitem::initialiseParams(std::string const & data) -{ - // The name passed with LFUN_INSET_APPLY is also the name - // used to identify the mailer. - InsetCommand::string2params("bibitem", data, params_); - return true; -} - - -void GuiBibitem::dispatchParams() -{ - std::string const lfun = InsetCommand::params2string("bibitem", params_); - dispatch(FuncRequest(getLfun(), lfun)); -} - - -Dialog * createGuiBibitem(GuiView & lv) { return new GuiBibitem(lv); } - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiBibitem.h b/src/frontends/qt4/GuiBibitem.h index b0c34e79b7..a64ba72e88 100644 --- a/src/frontends/qt4/GuiBibitem.h +++ b/src/frontends/qt4/GuiBibitem.h @@ -13,44 +13,30 @@ #ifndef GUIBIBITEM_H #define GUIBIBITEM_H -#include "GuiDialog.h" +#include "InsetParamsWidget.h" #include "ui_BibitemUi.h" -#include "insets/InsetCommandParams.h" namespace lyx { namespace frontend { -class GuiBibitem : public GuiDialog, public Ui::BibitemUi +class GuiBibitem : public InsetParamsWidget, public Ui::BibitemUi { Q_OBJECT public: /// Constructor - GuiBibitem(GuiView & lv); - -private Q_SLOTS: - void change_adaptor(); + GuiBibitem(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; } - -private: - /// - InsetCommandParams params_; + /// \name DialogView inherited methods + //@{ + InsetCode insetCode() const { return BIBITEM_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 25540eaf03..279384057d 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -3452,7 +3452,6 @@ Dialog * createDialog(GuiView & lv, string const & name); // will be replaced by a proper factory... Dialog * createGuiAbout(GuiView & lv); -Dialog * createGuiBibitem(GuiView & lv); Dialog * createGuiBibtex(GuiView & lv); Dialog * createGuiChanges(GuiView & lv); Dialog * createGuiCharacter(GuiView & lv); @@ -3505,8 +3504,6 @@ Dialog * GuiView::build(string const & name) if (name == "aboutlyx") return createGuiAbout(*this); - if (name == "bibitem") - return createGuiBibitem(*this); if (name == "bibtex") return createGuiBibtex(*this); if (name == "changes") diff --git a/src/frontends/qt4/InsetParamsDialog.cpp b/src/frontends/qt4/InsetParamsDialog.cpp index aa5850677d..7a8ab9c329 100644 --- a/src/frontends/qt4/InsetParamsDialog.cpp +++ b/src/frontends/qt4/InsetParamsDialog.cpp @@ -14,6 +14,7 @@ #include "GuiBox.h" #include "GuiBranch.h" +#include "GuiBibitem.h" #include "GuiERT.h" #include "GuiInfo.h" #include "GuiHSpace.h" @@ -206,6 +207,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code) case FLOAT_CODE: widget = new FloatPlacement(true); break; + case BIBITEM_CODE: + widget = new GuiBibitem; + break; case BRANCH_CODE: widget = new GuiBranch; break; diff --git a/src/frontends/qt4/ui/BibitemUi.ui b/src/frontends/qt4/ui/BibitemUi.ui index a03c38298e..0dfc146bc3 100644 --- a/src/frontends/qt4/ui/BibitemUi.ui +++ b/src/frontends/qt4/ui/BibitemUi.ui @@ -1,134 +1,80 @@ - - - - + BibitemUi - - + + 0 0 - 197 - 134 + 211 + 74 - + - - true - - - + + 9 - + 6 - - - - - 7 - 0 + + + + 0 0 - + The bibliography key - - - - - 7 - 0 + + + + 0 0 - + The label as it appears in the document - - - + + + The label as it appears in the document - + &Label: - + labelED - - - + + + The bibliography key - + &Key: - + keyED - - - - 0 - - - 6 - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - &OK - - - true - - - - - - - &Close - - - - - - - qt_i18n.h + qt_i18n.h diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index c615b78ab9..c8c5d1d43b 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -80,7 +80,7 @@ static void build_translator() insetnames[NOMENCL_CODE] = InsetName("nomenclature"); insetnames[INCLUDE_CODE] = InsetName("include"); insetnames[GRAPHICS_CODE] = InsetName("graphics"); - insetnames[BIBITEM_CODE] = InsetName("bibitem"); + insetnames[BIBITEM_CODE] = InsetName("bibitem", _("Bibliography Entry")); insetnames[BIBTEX_CODE] = InsetName("bibtex"); insetnames[TEXT_CODE] = InsetName("text"); insetnames[ERT_CODE] = InsetName("ert", _("TeX Code")); @@ -296,6 +296,7 @@ bool Inset::showInsetDialog(BufferView * bv) const case ERT_CODE: case FLOAT_CODE: case BOX_CODE: + case BIBITEM_CODE: case BRANCH_CODE: case INFO_CODE: case MATH_SPACE_CODE: