From 4db2685cbe065c1ee3166761adde4beef01a0765 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 19 Feb 2010 20:57:25 +0000 Subject: [PATCH] Migrate Branch dialog to InsetParamsWidget git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33521 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiBranch.cpp | 57 +++------------- src/frontends/qt4/GuiBranch.h | 33 +++------ src/frontends/qt4/GuiView.cpp | 3 - src/frontends/qt4/InsetParamsDialog.cpp | 4 ++ src/frontends/qt4/ui/BranchUi.ui | 90 +++++-------------------- src/insets/Inset.cpp | 4 +- src/insets/InsetBranch.cpp | 21 ------ src/insets/InsetBranch.h | 5 -- 8 files changed, 43 insertions(+), 174 deletions(-) diff --git a/src/frontends/qt4/GuiBranch.cpp b/src/frontends/qt4/GuiBranch.cpp index 57484c86f1..3124314401 100644 --- a/src/frontends/qt4/GuiBranch.cpp +++ b/src/frontends/qt4/GuiBranch.cpp @@ -19,7 +19,6 @@ #include "Buffer.h" #include "BufferParams.h" #include "BranchList.h" -#include "FuncRequest.h" #include "insets/InsetBranch.h" @@ -30,36 +29,21 @@ using namespace std; namespace lyx { namespace frontend { -GuiBranch::GuiBranch(GuiView & lv) - : GuiDialog(lv, "branch", qt_("Branch Settings")) +GuiBranch::GuiBranch(QWidget * parent) : InsetParamsWidget(parent) { setupUi(this); - - connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); - connect(branchCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); - - bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); - bc().setOK(okPB); - bc().setCancel(closePB); + connect(branchCO, SIGNAL(activated(int)), this, SIGNAL(changed())); } -void GuiBranch::change_adaptor() -{ - changed(); -} - - -void GuiBranch::updateContents() +void GuiBranch::paramsToDialog(Inset const * inset) { + InsetBranch const * ib = static_cast(inset); typedef BranchList::const_iterator const_iterator; - - BranchList const & branchlist = buffer().params().branchlist(); - docstring const cur_branch = params_.branch; + BranchList const & branchlist = ib->buffer().params().branchlist(); + docstring const cur_branch = ib->branch(); branchCO->clear(); - const_iterator const begin = branchlist.begin(); const_iterator const end = branchlist.end(); int id = 0; @@ -67,7 +51,6 @@ void GuiBranch::updateContents() for (const_iterator it = begin; it != end; ++it, ++count) { docstring const & branch = it->branch(); branchCO->addItem(toqstr(branch)); - if (cur_branch == branch) id = count; } @@ -75,34 +58,12 @@ void GuiBranch::updateContents() } -void GuiBranch::applyView() +docstring GuiBranch::dialogToParams() const { - params_.branch = qstring_to_ucs4(branchCO->currentText()); + InsetBranchParams params(qstring_to_ucs4(branchCO->currentText())); + return from_utf8(InsetBranch::params2string(params)); } - -bool GuiBranch::initialiseParams(string const & data) -{ - InsetBranch::string2params(data, params_); - return true; -} - - -void GuiBranch::clearParams() -{ - params_ = InsetBranchParams(); -} - - -void GuiBranch::dispatchParams() -{ - dispatch(FuncRequest(getLfun(), InsetBranch::params2string(params_))); -} - - -Dialog * createGuiBranch(GuiView & lv) { return new GuiBranch(lv); } - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiBranch.h b/src/frontends/qt4/GuiBranch.h index b491d738be..62f2ecaa2a 100644 --- a/src/frontends/qt4/GuiBranch.h +++ b/src/frontends/qt4/GuiBranch.h @@ -14,40 +14,27 @@ #ifndef GUIBRANCH_H #define GUIBRANCH_H -#include "GuiDialog.h" +#include "InsetParamsWidget.h" #include "ui_BranchUi.h" -#include "insets/InsetBranch.h" - namespace lyx { namespace frontend { -class GuiBranch : public GuiDialog, public Ui::BranchUi +class GuiBranch : public InsetParamsWidget, public Ui::BranchUi { Q_OBJECT public: - GuiBranch(GuiView & lv); - -private Q_SLOTS: - void change_adaptor(); + GuiBranch(QWidget * parent = 0); private: - /// Apply changes - void applyView(); - /// Update dialog before showing it - void updateContents(); - /// - bool initialiseParams(std::string const & data); - /// - void clearParams(); - /// - void dispatchParams(); - /// - bool isBufferDependent() const { return true; } - - /// - InsetBranchParams params_; + /// \name DialogView inherited methods + //@{ + InsetCode insetCode() const { return BRANCH_CODE; } + FuncCode creationCode() const { return LFUN_BRANCH_INSERT; } + void paramsToDialog(Inset const *); + docstring dialogToParams() const; + //@} }; } // namespace frontend diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index d440b6c114..0c1100d9e4 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -3443,7 +3443,6 @@ Dialog * createDialog(GuiView & lv, string const & name); Dialog * createGuiAbout(GuiView & lv); Dialog * createGuiBibitem(GuiView & lv); Dialog * createGuiBibtex(GuiView & lv); -Dialog * createGuiBranch(GuiView & lv); Dialog * createGuiChanges(GuiView & lv); Dialog * createGuiCharacter(GuiView & lv); Dialog * createGuiCitation(GuiView & lv); @@ -3501,8 +3500,6 @@ Dialog * GuiView::build(string const & name) return createGuiBibitem(*this); if (name == "bibtex") return createGuiBibtex(*this); - if (name == "branch") - return createGuiBranch(*this); if (name == "changes") return createGuiChanges(*this); if (name == "character") diff --git a/src/frontends/qt4/InsetParamsDialog.cpp b/src/frontends/qt4/InsetParamsDialog.cpp index e366bcbce1..16f29ca8e0 100644 --- a/src/frontends/qt4/InsetParamsDialog.cpp +++ b/src/frontends/qt4/InsetParamsDialog.cpp @@ -13,6 +13,7 @@ #include "InsetParamsDialog.h" #include "GuiBox.h" +#include "GuiBranch.h" #include "GuiERT.h" #include "GuiInfo.h" #include "GuiTabular.h" @@ -204,6 +205,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code) case FLOAT_CODE: widget = new FloatPlacement(true); break; + case BRANCH_CODE: + widget = new GuiBranch; + break; case BOX_CODE: widget = new GuiBox; break; diff --git a/src/frontends/qt4/ui/BranchUi.ui b/src/frontends/qt4/ui/BranchUi.ui index 4266f2084e..44700a70c7 100644 --- a/src/frontends/qt4/ui/BranchUi.ui +++ b/src/frontends/qt4/ui/BranchUi.ui @@ -1,84 +1,32 @@ - + BranchUi - - + + 0 0 - 219 - 99 + 259 + 38 - + - - true - - - - 9 - - - 6 - - - - - 0 + + + + + &Available branches: - - 6 - - - - - &Available branches: - - - branchCO - - - - - - - Select your branch - - - - - - - - - Qt::Horizontal - - - - 31 - 20 - - - - - - - - &Close - - - true + + branchCO - - - - &OK - - - false + + + + Select your branch @@ -86,11 +34,9 @@ branchCO - okPB - closePB - qt_i18n.h + qt_i18n.h diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index b3fdf6fd94..119c1c4cd7 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -100,7 +100,7 @@ static void build_translator() insetnames[OPTARG_CODE] = InsetName("optarg"); insetnames[NEWLINE_CODE] = InsetName("newline"); insetnames[LINE_CODE] = InsetName("line"); - insetnames[BRANCH_CODE] = InsetName("branch"); + insetnames[BRANCH_CODE] = InsetName("branch", _("Branch")); insetnames[BOX_CODE] = InsetName("box", _("Box")); insetnames[FLEX_CODE] = InsetName("flex"); insetnames[SPACE_CODE] = InsetName("space"); @@ -296,8 +296,8 @@ bool Inset::showInsetDialog(BufferView * bv) const case ERT_CODE: case FLOAT_CODE: case BOX_CODE: + case BRANCH_CODE: case INFO_CODE: - //FIXME: not ready yet. case TABULAR_CODE: case VSPACE_CODE: bv->showDialog(insetName(code)); diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 900cd8b54f..fa238674b3 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -46,12 +46,6 @@ InsetBranch::InsetBranch(Buffer * buf, InsetBranchParams const & params) {} -InsetBranch::~InsetBranch() -{ - hideDialogs("branch", this); -} - - void InsetBranch::write(ostream & os) const { params_.write(os); @@ -116,14 +110,6 @@ ColorCode InsetBranch::backgroundColor(PainterInfo const & pi) const } -bool InsetBranch::showInsetDialog(BufferView * bv) const -{ - bv->showDialog("branch", params2string(params()), - const_cast(this)); - return true; -} - - void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action) { @@ -133,11 +119,6 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd) params_.branch = params.branch; break; } - - case LFUN_INSET_DIALOG_UPDATE: - cur.bv().updateDialog("branch", params2string(params())); - break; - case LFUN_BRANCH_ACTIVATE: case LFUN_BRANCH_DEACTIVATE: { // FIXME: I do not like this cast, but have no other idea... @@ -153,7 +134,6 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd) our_branch->setSelected(cmd.action == LFUN_BRANCH_ACTIVATE); break; } - case LFUN_INSET_TOGGLE: if (cmd.argument() == "assign") setStatus(cur, isBranchSelected() ? Open : Collapsed); @@ -173,7 +153,6 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd, { switch (cmd.action) { case LFUN_INSET_MODIFY: - case LFUN_INSET_DIALOG_UPDATE: flag.setEnabled(true); break; diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h index bcebd00e1a..4100a631cc 100644 --- a/src/insets/InsetBranch.h +++ b/src/insets/InsetBranch.h @@ -14,7 +14,6 @@ #include "InsetCollapsable.h" - namespace lyx { class InsetBranchParams { @@ -44,8 +43,6 @@ class InsetBranch : public InsetCollapsable public: /// InsetBranch(Buffer *, InsetBranchParams const &); - /// - ~InsetBranch(); /// static std::string params2string(InsetBranchParams const &); @@ -68,8 +65,6 @@ private: /// ColorCode backgroundColor(PainterInfo const &) const; /// - bool showInsetDialog(BufferView *) const; - /// int latex(odocstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const;