Fileformat increased to 287: support for optional arguments of package wrapfig that is used for wrap floats

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20462 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2007-09-24 13:43:58 +00:00
parent 63d05dbff4
commit b7d0510502
8 changed files with 432 additions and 224 deletions

View File

@ -1,6 +1,10 @@
LyX file-format changes LyX file-format changes
----------------------- -----------------------
2007-09-24 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 287: Add missing optional parameters
for wrapped figures.
2007-09-21 Pavel Sanda <ps@twin.jikos.cz> 2007-09-21 Pavel Sanda <ps@twin.jikos.cz>
* Format incremented to 286: LyX now supports hyperref and some * Format incremented to 286: LyX now supports hyperref and some
of its options. of its options.

View File

@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)),
("1_3", [221], minor_versions("1.3" , 7)), ("1_3", [221], minor_versions("1.3" , 7)),
("1_4", range(222,246), minor_versions("1.4" , 5)), ("1_4", range(222,246), minor_versions("1.4" , 5)),
("1_5", range(246,277), minor_versions("1.5" , 1)), ("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(): def formats_list():

View File

@ -258,6 +258,23 @@ def remove_inzip_options(document):
i = i + 1 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 # Conversion hub
# #
@ -273,10 +290,12 @@ convert = [
[283, [convert_flex]], [283, [convert_flex]],
[284, []], [284, []],
[285, []], # an empty manifest is automatically added [285, []], # an empty manifest is automatically added
[286, []] [286, []],
[287, []]
] ]
revert = [ revert = [
[286, [revert_wrapfig_options]],
[285, [revert_pdf_options]], [285, [revert_pdf_options]],
[284, [remove_manifest, remove_inzip_options]], [284, [remove_manifest, remove_inzip_options]],
[283, []], [283, []],

View File

@ -143,7 +143,7 @@ namespace fs = boost::filesystem;
namespace { namespace {
int const LYX_FORMAT = 286; int const LYX_FORMAT = 287;
} // namespace anon } // namespace anon

View File

@ -15,6 +15,7 @@
#include "ControlWrap.h" #include "ControlWrap.h"
#include "LengthCombo.h" #include "LengthCombo.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "Validator.h"
#include "insets/InsetWrap.h" #include "insets/InsetWrap.h"
@ -44,10 +45,21 @@ GuiWrapDialog::GuiWrapDialog(LyXView & lv)
connect(widthED, SIGNAL(textChanged(const QString &)), connect(widthED, SIGNAL(textChanged(const QString &)),
this, SLOT(change_adaptor())); this, SLOT(change_adaptor()));
connect(unitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)), connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
this, SLOT(change_adaptor())); this, SLOT(change_adaptor()));
connect(valignCO, SIGNAL(highlighted(const QString &)), connect(valignCO, SIGNAL(highlighted(const QString &)),
this, SLOT(change_adaptor())); 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().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
bc().setRestore(restorePB); bc().setRestore(restorePB);
@ -56,8 +68,15 @@ GuiWrapDialog::GuiWrapDialog(LyXView & lv)
bc().setCancel(closePB); bc().setCancel(closePB);
bc().addReadOnly(widthED); bc().addReadOnly(widthED);
bc().addReadOnly(unitsLC); bc().addReadOnly(widthUnitLC);
bc().addReadOnly(valignCO); 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() void GuiWrapDialog::applyView()
{ {
double const value = widthED->text().toDouble(); double const width_value = widthED->text().toDouble();
Length::UNIT unit = unitsLC->currentLengthItem(); Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
if (widthED->text().isEmpty()) 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(); 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()) { switch (valignCO->currentIndex()) {
case 0: case 0:
@ -112,11 +137,15 @@ void GuiWrapDialog::updateContents()
{ {
InsetWrapParams & params = controller().params(); InsetWrapParams & params = controller().params();
Length len(params.width);
//0pt is a legal width now, it yields a //0pt is a legal width now, it yields a
//wrapfloat just wide enough for the contents. //wrapfloat just wide enough for the contents.
widthED->setText(QString::number(len.value())); Length len_w(params.width);
unitsLC->setCurrentItem(len.unit()); 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; int item = 0;
if (params.placement == "i") if (params.placement == "i")

View File

@ -5,8 +5,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>369</width> <width>411</width>
<height>111</height> <height>199</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle" >
@ -15,222 +15,342 @@
<property name="sizeGripEnabled" > <property name="sizeGripEnabled" >
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" > <widget class="QWidget" name="layoutWidget" >
<property name="margin" > <property name="geometry" >
<number>11</number> <rect>
<x>10</x>
<y>110</y>
<width>221</width>
<height>22</height>
</rect>
</property> </property>
<property name="spacing" > <layout class="QHBoxLayout" >
<number>6</number> <property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="nlinesLA" >
<property name="text" >
<string>&amp;Number of needed lines (optional):</string>
</property>
<property name="buddy" >
<cstring>valignCO</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="linesSB" />
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget" >
<property name="geometry" >
<rect>
<x>10</x>
<y>140</y>
<width>392</width>
<height>45</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>390</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="restorePB" >
<property name="toolTip" >
<string/>
</property>
<property name="text" >
<string>&amp;Restore</string>
</property>
<property name="default" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="toolTip" >
<string/>
</property>
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="default" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPB" >
<property name="toolTip" >
<string/>
</property>
<property name="text" >
<string>&amp;Apply</string>
</property>
<property name="default" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="text" >
<string>&amp;Close</string>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QLabel" name="valignLA" >
<property name="geometry" >
<rect>
<x>292</x>
<y>11</y>
<width>98</width>
<height>16</height>
</rect>
</property>
<property name="text" >
<string>&amp;Placement:</string>
</property>
<property name="buddy" >
<cstring>valignCO</cstring>
</property>
</widget>
<widget class="QComboBox" name="valignCO" >
<property name="geometry" >
<rect>
<x>292</x>
<y>32</y>
<width>98</width>
<height>18</height>
</rect>
</property>
<property name="toolTip" >
<string>Vertical alignment</string>
</property> </property>
<item> <item>
<layout class="QGridLayout" > <property name="text" >
<property name="margin" > <string>Outer (default)</string>
<number>0</number> </property>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QLabel" name="widthLA" >
<property name="text" >
<string>&amp;Width:</string>
</property>
<property name="buddy" >
<cstring>widthED</cstring>
</property>
</widget>
</item>
<item row="1" column="2" >
<widget class="QComboBox" name="valignCO" >
<property name="toolTip" >
<string>Vertical alignment</string>
</property>
<item>
<property name="text" >
<string>Outer (default)</string>
</property>
</item>
<item>
<property name="text" >
<string>Inner</string>
</property>
</item>
<item>
<property name="text" >
<string>Left</string>
</property>
</item>
<item>
<property name="text" >
<string>Right</string>
</property>
</item>
</widget>
</item>
<item row="0" column="2" >
<widget class="QLabel" name="valignLA" >
<property name="text" >
<string>&amp;Placement:</string>
</property>
<property name="buddy" >
<cstring>valignCO</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="LengthCombo" native="1" name="unitsLC" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>40</width>
<height>22</height>
</size>
</property>
<property name="focusPolicy" >
<enum>Qt::StrongFocus</enum>
</property>
<property name="toolTip" >
<string>Units of width value</string>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLineEdit" name="widthED" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Width value</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLabel" name="unitsLA" >
<property name="text" >
<string>&amp;Units:</string>
</property>
<property name="buddy" >
<cstring>unitsLC</cstring>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<spacer> <property name="text" >
<property name="orientation" > <string>Inner</string>
<enum>Qt::Vertical</enum> </property>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <property name="text" >
<property name="margin" > <string>Left</string>
<number>0</number> </property>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="restorePB" >
<property name="toolTip" >
<string/>
</property>
<property name="text" >
<string>&amp;Restore</string>
</property>
<property name="default" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="toolTip" >
<string/>
</property>
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="default" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPB" >
<property name="toolTip" >
<string/>
</property>
<property name="text" >
<string>&amp;Apply</string>
</property>
<property name="default" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="text" >
<string>&amp;Close</string>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> <item>
<property name="text" >
<string>Right</string>
</property>
</item>
</widget>
<widget class="QWidget" name="layoutWidget" >
<property name="geometry" >
<rect>
<x>10</x>
<y>10</y>
<width>271</width>
<height>88</height>
</rect>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="1" column="0" >
<widget class="QLineEdit" name="widthED" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Width value</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="widthLA" >
<property name="text" >
<string>&amp;Width:</string>
</property>
<property name="buddy" >
<cstring>widthED</cstring>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QLabel" name="overhangUnitLA" >
<property name="text" >
<string>&amp;Unit:</string>
</property>
<property name="buddy" >
<cstring>widthUnitLC</cstring>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QLineEdit" name="overhangED" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Width value</string>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="overhangLA" >
<property name="text" >
<string>&amp;Overhang (optional):</string>
</property>
<property name="buddy" >
<cstring>widthED</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="LengthCombo" name="widthUnitLC" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>40</width>
<height>22</height>
</size>
</property>
<property name="focusPolicy" >
<enum>Qt::StrongFocus</enum>
</property>
<property name="toolTip" >
<string>Units of width value</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLabel" name="widthUnitLA" >
<property name="text" >
<string>&amp;Unit:</string>
</property>
<property name="buddy" >
<cstring>widthUnitLC</cstring>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="LengthCombo" name="overhangUnitLC" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>13</hsizetype>
<vsizetype>13</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy" >
<enum>Qt::StrongFocus</enum>
</property>
<property name="toolTip" >
<string>Units of width value</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>LengthCombo</class> <class>LengthCombo</class>
<extends>QWidget</extends> <extends>QComboBox</extends>
<header>LengthCombo.h</header> <header>LengthCombo.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>widthED</tabstop> <tabstop>widthED</tabstop>
<tabstop>unitsLC</tabstop> <tabstop>widthUnitLC</tabstop>
<tabstop>valignCO</tabstop> <tabstop>valignCO</tabstop>
<tabstop>restorePB</tabstop> <tabstop>restorePB</tabstop>
<tabstop>okPB</tabstop> <tabstop>okPB</tabstop>

View File

@ -52,6 +52,9 @@ InsetWrap::InsetWrap(BufferParams const & bp, string const & type)
font.setColor(Color::collapsable); font.setColor(Color::collapsable);
setLabelFont(font); setLabelFont(font);
params_.type = type; params_.type = type;
params_.lines = 0;
params_.placement = "o";
params_.overhang = Length(0, Length::PCW);
params_.width = Length(50, Length::PCW); params_.width = Length(50, Length::PCW);
} }
@ -68,8 +71,10 @@ void InsetWrap::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: { case LFUN_INSET_MODIFY: {
InsetWrapParams params; InsetWrapParams params;
InsetWrapMailer::string2params(to_utf8(cmd.argument()), params); InsetWrapMailer::string2params(to_utf8(cmd.argument()), params);
params_.lines = params.lines;
params_.placement = params.placement; params_.placement = params.placement;
params_.width = params.width; params_.overhang = params.overhang;
params_.width = params.width;
break; break;
} }
@ -126,10 +131,9 @@ void InsetWrap::updateLabels(Buffer const & buf, ParIterator const & it)
void InsetWrapParams::write(ostream & os) const void InsetWrapParams::write(ostream & os) const
{ {
os << "Wrap " << type << '\n'; os << "Wrap " << type << '\n';
os << "lines " << lines << "\n";
if (!placement.empty()) os << "placement " << placement << "\n";
os << "placement " << placement << "\n"; os << "overhang " << overhang.asString() << "\n";
os << "width \"" << width.asString() << "\"\n"; os << "width \"" << width.asString() << "\"\n";
} }
@ -137,11 +141,35 @@ void InsetWrapParams::write(ostream & os) const
void InsetWrapParams::read(Lexer & lex) void InsetWrapParams::read(Lexer & lex)
{ {
string token; 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; lex >> token;
if (token == "placement") if (token == "placement")
lex >> placement; lex >> placement;
else { 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); lex.pushToken(token);
} }
if (!lex) if (!lex)
@ -153,7 +181,6 @@ void InsetWrapParams::read(Lexer & lex)
} else { } else {
lyxerr << "InsetWrap::Read:: Missing 'width'-tag!" lyxerr << "InsetWrap::Read:: Missing 'width'-tag!"
<< endl; << endl;
// take countermeasures
lex.pushToken(token); lex.pushToken(token);
} }
} }
@ -196,9 +223,14 @@ int InsetWrap::latex(Buffer const & buf, odocstream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
os << "\\begin{wrap" << from_ascii(params_.type) << '}'; os << "\\begin{wrap" << from_ascii(params_.type) << '}';
if (!params_.placement.empty()) // no optional argument when lines are zero
os << '{' << from_ascii(params_.placement) << '}'; if (params_.lines != 0)
else os << "{o}"; //Outer is default in the current UI 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"; os << '{' << from_ascii(params_.width.asLatexString()) << "}%\n";
int const i = InsetText::latex(buf, os, runparams); int const i = InsetText::latex(buf, os, runparams);
os << "\\end{wrap" << from_ascii(params_.type) << "}%\n"; os << "\\end{wrap" << from_ascii(params_.type) << "}%\n";

View File

@ -30,8 +30,12 @@ public:
/// ///
std::string type; std::string type;
/// ///
int lines;
///
std::string placement; std::string placement;
/// ///
Length overhang;
///
Length width; Length width;
}; };