From 4c9f0eb5e6c835f5cf9cd0b0f5380b4b375d2f7c Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Wed, 10 Feb 2010 17:33:39 +0000 Subject: [PATCH] * InsetFloat: - now accept a full parameter string at construction - LFUN_INSET_MODIFY now also interprets float type. * FloatPlacement: - The float type label is replace with a combo that can be used to change the type. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33412 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/factory.cpp | 30 +++++----------------- src/frontends/qt4/FloatPlacement.cpp | 32 +++++++++++++++++++++--- src/frontends/qt4/FloatPlacement.h | 5 +++- src/frontends/qt4/ui/FloatPlacementUi.ui | 29 +++++++++++---------- src/insets/InsetFloat.cpp | 22 ++++++++++------ src/insets/InsetFloat.h | 4 +-- 6 files changed, 68 insertions(+), 54 deletions(-) diff --git a/src/factory.cpp b/src/factory.cpp index 7d344c87d7..3f1bf64267 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -77,8 +77,6 @@ namespace Alert = frontend::Alert; Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd) { - BufferParams const & params = buf->params(); - try { switch (cmd.action) { @@ -148,27 +146,13 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd) case LFUN_OPTIONAL_INSERT: return new InsetOptArg(buf); - case LFUN_FLOAT_INSERT: { - // check if the float type exists - string const type = cmd.getArg(0); - //FIXME: only the float type (the first argument) is transmitted - // because of the InsetFloat ctor. - if (params.documentClass().floats().typeExist(type)) - return new InsetFloat(buf, type); - lyxerr << "Non-existent float type: " << type << endl; - return 0; - } + case LFUN_FLOAT_INSERT: + return new InsetFloat(buf, to_utf8(cmd.argument())); case LFUN_FLOAT_WIDE_INSERT: { - // check if the float type exists - string const argument = to_utf8(cmd.argument()); - if (params.documentClass().floats().typeExist(argument)) { - auto_ptr p(new InsetFloat(buf, argument)); - p->setWide(true); - return p.release(); - } - lyxerr << "Non-existent float type: " << argument << endl; - return 0; + InsetFloat * fl = new InsetFloat(buf, to_utf8(cmd.argument())); + fl->setWide(true); + return fl; } case LFUN_WRAP_INSERT: { @@ -574,9 +558,7 @@ Inset * readInset(Lexer & lex, Buffer * buf) } else if (tmptok == "OptArg") { inset.reset(new InsetOptArg(buf)); } else if (tmptok == "Float") { - lex.next(); - string tmptok = lex.getString(); - inset.reset(new InsetFloat(buf, tmptok)); + inset.reset(new InsetFloat(buf, string())); } else if (tmptok == "Wrap") { lex.next(); string tmptok = lex.getString(); diff --git a/src/frontends/qt4/FloatPlacement.cpp b/src/frontends/qt4/FloatPlacement.cpp index 875c3c0361..1e3bcbd8ad 100644 --- a/src/frontends/qt4/FloatPlacement.cpp +++ b/src/frontends/qt4/FloatPlacement.cpp @@ -14,6 +14,10 @@ #include "FloatPlacement.h" #include "qt_helpers.h" +#include "Buffer.h" +#include "BufferParams.h" +#include "FloatList.h" + #include "insets/InsetFloat.h" #include "support/lstrings.h" @@ -24,10 +28,11 @@ using namespace lyx::support; namespace lyx { FloatPlacement::FloatPlacement(bool show_options, QWidget * parent) - : QWidget(parent) + : QWidget(parent), float_list_(0) { setupUi(this); + connect(floatTypeCO, SIGNAL(activated(int)), this, SLOT(changedSlot())); connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot())); connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot())); connect(pageCB, SIGNAL(clicked()), this, SLOT(changedSlot())); @@ -45,7 +50,7 @@ FloatPlacement::FloatPlacement(bool show_options, QWidget * parent) docstring FloatPlacement::dialogToParams() const { InsetFloatParams params; - params.type = float_type_; + params.type = fromqstr(floatTypeCO->itemData(floatTypeCO->currentIndex()).toString()); params.placement = get(params.wide, params.sideways); return from_ascii(InsetFloat::params2string(params)); } @@ -106,13 +111,32 @@ void FloatPlacement::set(string const & placement) } +void FloatPlacement::initFloatTypeCO(FloatList const & floats) +{ + if (float_list_ == &floats) + return; + + float_list_ = &floats; + floatTypeCO->clear(); + FloatList::const_iterator it = floats.begin(); + FloatList::const_iterator const end = floats.end(); + for (; it != end; ++it) { + floatTypeCO->addItem(qt_(it->second.name()), + toqstr(it->second.type())); + } +} + + void FloatPlacement::paramsToDialog(Inset const * inset) { InsetFloat const * fl = static_cast(inset); InsetFloatParams const & params = fl->params(); - float_type_ = params.type; - floatType->setText(toqstr(fl->floatName(float_type_))); + BufferParams const & bp = fl->buffer().params(); + initFloatTypeCO(bp.documentClass().floats()); + + int const item = floatTypeCO->findData(toqstr(params.type)); + floatTypeCO->setCurrentIndex(item); set(params.placement); diff --git a/src/frontends/qt4/FloatPlacement.h b/src/frontends/qt4/FloatPlacement.h index 3d95db9da0..ba975ad09f 100644 --- a/src/frontends/qt4/FloatPlacement.h +++ b/src/frontends/qt4/FloatPlacement.h @@ -21,6 +21,7 @@ namespace lyx { +class FloatList; class Inset; class InsetFloatParams; @@ -54,11 +55,13 @@ private: void checkAllowed(); /// std::string const get(bool & wide, bool & sideways) const; + /// + void initFloatTypeCO(FloatList const & floats); /// one of figure or table? bool standardfloat_; /// - std::string float_type_; + FloatList const * float_list_; }; } // namespace lyx diff --git a/src/frontends/qt4/ui/FloatPlacementUi.ui b/src/frontends/qt4/ui/FloatPlacementUi.ui index 1fa0749417..8c998c1860 100644 --- a/src/frontends/qt4/ui/FloatPlacementUi.ui +++ b/src/frontends/qt4/ui/FloatPlacementUi.ui @@ -1,3 +1,4 @@ + FloatPlacementUi @@ -5,8 +6,8 @@ 0 0 - 203 - 295 + 207 + 382 @@ -23,14 +24,12 @@ Float Type: - - - TextLabel - - - + + + + Qt::Vertical @@ -43,14 +42,14 @@ - + Use &default placement - + Advanced Placement Options @@ -107,34 +106,34 @@ - + Qt::Horizontal - 21 + 12 20 - + &Span columns - + &Rotate sideways - + Qt::Vertical diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 99175fd64b..f8807f974c 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -39,6 +39,7 @@ #include "frontends/Application.h" using namespace std; +using namespace lyx::support; namespace lyx { @@ -111,17 +112,16 @@ namespace lyx { // Lgb //FIXME: why do we set in stone the type here? -InsetFloat::InsetFloat(Buffer * buf, string const & type) - : InsetCollapsable(buf), name_(from_utf8(type)) +InsetFloat::InsetFloat(Buffer * buf, string params_str) + : InsetCollapsable(buf) { - setLabel(_("float: ") + floatName(type)); - params_.type = type; + string2params(params_str, params_); } docstring InsetFloat::name() const { - return "Float:" + name_; + return "Float:" + from_utf8(params_.type); } @@ -149,8 +149,11 @@ void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd) params_.wide = params.wide; params_.sideways = params.sideways; } - setNewLabel(); + if (params_.type != params.type) { + params_.type = params.type; + buffer().updateLabels(); + } break; } @@ -243,6 +246,7 @@ void InsetFloatParams::write(ostream & os) const void InsetFloatParams::read(Lexer & lex) { lex.setContext("InsetFloatParams::read"); + lex >> type; if (lex.checkFor("placement")) lex >> placement; lex >> "wide" >> wide; @@ -262,6 +266,11 @@ void InsetFloat::read(Lexer & lex) { params_.read(lex); InsetCollapsable::read(lex); + // check if the float type exists + if (buffer().params().documentClass().floats().typeExist(params_.type)) + setLabel(_("float: ") + floatName(params_.type)); + else + setLabel(bformat(_("ERROR: Unknown float type: %1$s"), from_utf8(params_.type))); } @@ -497,7 +506,6 @@ void InsetFloat::string2params(string const & in, InsetFloatParams & params) Lexer lex; lex.setStream(data); lex.setContext("InsetFloat::string2params"); - lex >> params.type; // We have to read the type here! params.read(lex); } diff --git a/src/insets/InsetFloat.h b/src/insets/InsetFloat.h index b74faa0a6b..d656fdcbc2 100644 --- a/src/insets/InsetFloat.h +++ b/src/insets/InsetFloat.h @@ -51,7 +51,7 @@ class InsetFloat : public InsetCollapsable { public: /// - InsetFloat(Buffer *, std::string const &); + InsetFloat(Buffer * buffer, std::string params_str); /// static void string2params(std::string const &, InsetFloatParams &); @@ -108,8 +108,6 @@ private: docstring getCaption(OutputParams const &) const; /// InsetFloatParams params_; - /// - docstring name_; }; -- 2.39.5