diff --git a/development/FORMAT b/development/FORMAT index 7f620ee94a..eeb235469a 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,10 @@ LyX file-format changes ----------------------- +2007-09-24 Uwe Stöhr + * Format incremented to 287: Add missing optional parameters + for wrapped figures. + 2007-09-21 Pavel Sanda * Format incremented to 286: LyX now supports hyperref and some of its options. diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index 2ba866c90a..3d35bade6f 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)), ("1_3", [221], minor_versions("1.3" , 7)), ("1_4", range(222,246), minor_versions("1.4" , 5)), ("1_5", range(246,277), minor_versions("1.5" , 1)), - ("1_6", range(277,287), minor_versions("1.6" , 0))] + ("1_6", range(277,288), minor_versions("1.6" , 0))] def formats_list(): diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index 3d4f4f7940..b6dc8410cf 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -258,6 +258,23 @@ def remove_inzip_options(document): i = i + 1 +def revert_wrapfig_options(document): + "Revert optional options for wrap floats (wrapfig). " + i = 0 + while True: + i = find_tokens(document.body, "lines", i) + if i == -1: + return + del document.body[i] + j = find_tokens(document.body, "overhang", i+1) + if j != i + 1 and j != -1: + document.warning("Malformed LyX document: Couldn't find overhang parameter of wrap float.") + if j == -1: + return + del document.body[j] + i = i + 1 + + ## # Conversion hub # @@ -273,10 +290,12 @@ convert = [ [283, [convert_flex]], [284, []], [285, []], # an empty manifest is automatically added - [286, []] + [286, []], + [287, []] ] revert = [ + [286, [revert_wrapfig_options]], [285, [revert_pdf_options]], [284, [remove_manifest, remove_inzip_options]], [283, []], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index edf225bb3f..186bdb03c9 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -143,7 +143,7 @@ namespace fs = boost::filesystem; namespace { -int const LYX_FORMAT = 286; +int const LYX_FORMAT = 287; } // namespace anon diff --git a/src/frontends/qt4/GuiWrap.cpp b/src/frontends/qt4/GuiWrap.cpp index 727cb58978..ddbe458b1c 100644 --- a/src/frontends/qt4/GuiWrap.cpp +++ b/src/frontends/qt4/GuiWrap.cpp @@ -15,6 +15,7 @@ #include "ControlWrap.h" #include "LengthCombo.h" #include "qt_helpers.h" +#include "Validator.h" #include "insets/InsetWrap.h" @@ -44,10 +45,21 @@ GuiWrapDialog::GuiWrapDialog(LyXView & lv) connect(widthED, SIGNAL(textChanged(const QString &)), this, SLOT(change_adaptor())); - connect(unitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)), + connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)), this, SLOT(change_adaptor())); connect(valignCO, SIGNAL(highlighted(const QString &)), this, SLOT(change_adaptor())); + connect(overhangED, SIGNAL(textChanged(const QString &)), + this, SLOT(change_adaptor())); + connect(overhangUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)), + this, SLOT(change_adaptor())); + connect(linesSB, SIGNAL(valueChanged(int)), + this, SLOT(change_adaptor())); + + widthED->setValidator(unsignedLengthValidator(widthED)); + // FIXME: + // overhang can be negative, but the unsignedLengthValidator allows this + overhangED->setValidator(unsignedLengthValidator(overhangED)); bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); bc().setRestore(restorePB); @@ -56,8 +68,15 @@ GuiWrapDialog::GuiWrapDialog(LyXView & lv) bc().setCancel(closePB); bc().addReadOnly(widthED); - bc().addReadOnly(unitsLC); + bc().addReadOnly(widthUnitLC); bc().addReadOnly(valignCO); + bc().addReadOnly(overhangED); + bc().addReadOnly(overhangUnitLC); + bc().addReadOnly(linesSB); + + // initialize the length validator + bc().addCheckedLineEdit(widthED, widthLA); + bc().addCheckedLineEdit(overhangED, overhangLA); } @@ -82,14 +101,20 @@ void GuiWrapDialog::change_adaptor() void GuiWrapDialog::applyView() { - double const value = widthED->text().toDouble(); - Length::UNIT unit = unitsLC->currentLengthItem(); + double const width_value = widthED->text().toDouble(); + Length::UNIT widthUnit = widthUnitLC->currentLengthItem(); if (widthED->text().isEmpty()) - unit = Length::UNIT_NONE; - + widthUnit = Length::UNIT_NONE; + double const overhang_value = overhangED->text().toDouble(); + Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem(); + if (overhangED->text().isEmpty()) + overhangUnit = Length::UNIT_NONE; + InsetWrapParams & params = controller().params(); - params.width = Length(value, unit); + params.width = Length(width_value, widthUnit); + params.overhang = Length(overhang_value, overhangUnit); + params.lines = linesSB->value(); switch (valignCO->currentIndex()) { case 0: @@ -112,11 +137,15 @@ void GuiWrapDialog::updateContents() { InsetWrapParams & params = controller().params(); - Length len(params.width); //0pt is a legal width now, it yields a //wrapfloat just wide enough for the contents. - widthED->setText(QString::number(len.value())); - unitsLC->setCurrentItem(len.unit()); + Length len_w(params.width); + widthED->setText(QString::number(len_w.value())); + widthUnitLC->setCurrentItem(len_w.unit()); + Length len_o(params.overhang); + overhangED->setText(QString::number(len_o.value())); + overhangUnitLC->setCurrentItem(len_o.unit()); + linesSB->setValue(params.lines); int item = 0; if (params.placement == "i") diff --git a/src/frontends/qt4/ui/WrapUi.ui b/src/frontends/qt4/ui/WrapUi.ui index 22c6bd4378..6c3d47e1db 100644 --- a/src/frontends/qt4/ui/WrapUi.ui +++ b/src/frontends/qt4/ui/WrapUi.ui @@ -5,8 +5,8 @@ 0 0 - 369 - 111 + 411 + 199 @@ -15,222 +15,342 @@ true - - - 11 + + + + 10 + 110 + 221 + 22 + - - 6 + + + 0 + + + 6 + + + + + &Number of needed lines (optional): + + + valignCO + + + + + + + + + + + + 10 + 140 + 392 + 45 + + + + + 0 + + + 6 + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 390 + 10 + + + + + + + + 0 + + + 6 + + + + + + + + &Restore + + + false + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + + + + + + &OK + + + false + + + + + + + + + + &Apply + + + false + + + + + + + &Close + + + true + + + + + + + + + + + 292 + 11 + 98 + 16 + + + + &Placement: + + + valignCO + + + + + + 292 + 32 + 98 + 18 + + + + Vertical alignment - - - 0 - - - 6 - - - - - &Width: - - - widthED - - - - - - - Vertical alignment - - - - Outer (default) - - - - - Inner - - - - - Left - - - - - Right - - - - - - - - &Placement: - - - valignCO - - - - - - - - 3 - 0 - 0 - 0 - - - - - 40 - 22 - - - - Qt::StrongFocus - - - Units of width value - - - - - - - - 1 - 0 - 0 - 0 - - - - Width value - - - - - - - &Units: - - - unitsLC - - - - + + Outer (default) + - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 20 - - - + + Inner + - - - 0 - - - 6 - - - - - - - - &Restore - - - false - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - - - - &OK - - - false - - - - - - - - - - &Apply - - - false - - - - - - - &Close - - - true - - - - + + Left + - + + + Right + + + + + + + 10 + 10 + 271 + 88 + + + + + 0 + + + 6 + + + + + + 1 + 0 + 0 + 0 + + + + Width value + + + + + + + &Width: + + + widthED + + + + + + + &Unit: + + + widthUnitLC + + + + + + + + 1 + 0 + 0 + 0 + + + + Width value + + + + + + + &Overhang (optional): + + + widthED + + + + + + + + 3 + 0 + 0 + 0 + + + + + 40 + 22 + + + + Qt::StrongFocus + + + Units of width value + + + + + + + &Unit: + + + widthUnitLC + + + + + + + + 13 + 13 + 0 + 0 + + + + + 0 + 0 + + + + Qt::StrongFocus + + + Units of width value + + + + + LengthCombo - QWidget + QComboBox
LengthCombo.h
widthED - unitsLC + widthUnitLC valignCO restorePB okPB diff --git a/src/insets/InsetWrap.cpp b/src/insets/InsetWrap.cpp index 1d0eea89ed..64b7ccd55f 100644 --- a/src/insets/InsetWrap.cpp +++ b/src/insets/InsetWrap.cpp @@ -52,6 +52,9 @@ InsetWrap::InsetWrap(BufferParams const & bp, string const & type) font.setColor(Color::collapsable); setLabelFont(font); params_.type = type; + params_.lines = 0; + params_.placement = "o"; + params_.overhang = Length(0, Length::PCW); params_.width = Length(50, Length::PCW); } @@ -68,8 +71,10 @@ void InsetWrap::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_INSET_MODIFY: { InsetWrapParams params; InsetWrapMailer::string2params(to_utf8(cmd.argument()), params); + params_.lines = params.lines; params_.placement = params.placement; - params_.width = params.width; + params_.overhang = params.overhang; + params_.width = params.width; break; } @@ -126,10 +131,9 @@ void InsetWrap::updateLabels(Buffer const & buf, ParIterator const & it) void InsetWrapParams::write(ostream & os) const { os << "Wrap " << type << '\n'; - - if (!placement.empty()) - os << "placement " << placement << "\n"; - + os << "lines " << lines << "\n"; + os << "placement " << placement << "\n"; + os << "overhang " << overhang.asString() << "\n"; os << "width \"" << width.asString() << "\"\n"; } @@ -137,11 +141,35 @@ void InsetWrapParams::write(ostream & os) const void InsetWrapParams::read(Lexer & lex) { string token; + + lex >> token; + if (token == "lines") + lex >> lines; + else { + lyxerr << "InsetWrap::Read:: Missing 'lines'-tag!" + << endl; + // take countermeasures + lex.pushToken(token); + } + if (!lex) + return; lex >> token; if (token == "placement") lex >> placement; else { - // take countermeasures + lyxerr << "InsetWrap::Read:: Missing 'placement'-tag!" + << endl; + lex.pushToken(token); + } + if (!lex) + return; + lex >> token; + if (token == "overhang") { + lex.next(); + overhang = Length(lex.getString()); + } else { + lyxerr << "InsetWrap::Read:: Missing 'overhang'-tag!" + << endl; lex.pushToken(token); } if (!lex) @@ -153,7 +181,6 @@ void InsetWrapParams::read(Lexer & lex) } else { lyxerr << "InsetWrap::Read:: Missing 'width'-tag!" << endl; - // take countermeasures lex.pushToken(token); } } @@ -196,9 +223,14 @@ int InsetWrap::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { os << "\\begin{wrap" << from_ascii(params_.type) << '}'; - if (!params_.placement.empty()) - os << '{' << from_ascii(params_.placement) << '}'; - else os << "{o}"; //Outer is default in the current UI + // no optional argument when lines are zero + if (params_.lines != 0) + os << '[' << params_.lines << ']'; + os << '{' << from_ascii(params_.placement) << '}'; + Length over(params_.overhang); + // no optional argument when the value is zero + if (over.value() != 0) + os << '[' << from_ascii(params_.overhang.asLatexString()) << ']'; os << '{' << from_ascii(params_.width.asLatexString()) << "}%\n"; int const i = InsetText::latex(buf, os, runparams); os << "\\end{wrap" << from_ascii(params_.type) << "}%\n"; diff --git a/src/insets/InsetWrap.h b/src/insets/InsetWrap.h index f56bbf1987..a23944590c 100644 --- a/src/insets/InsetWrap.h +++ b/src/insets/InsetWrap.h @@ -30,8 +30,12 @@ public: /// std::string type; /// + int lines; + /// std::string placement; /// + Length overhang; + /// Length width; };