The attached patch add the optional parameters "lines" and "overhang" for wrap
figures.
It furthermore fixes a current bug that the placement option was not predefined: Since we changed to
wrapfig from floatflt, the placement is now mandatory and must not be empty.
I tested it carefully, also the lyx2lyx stuff. If there are no objections, I'll
put it in trunk.
regards Uwe
Index: development/FORMAT
===================================================================
--- development/FORMAT (revision 20448)
+++ development/FORMAT (working copy)
@@ -1,13 +1,14 @@
LyX file-format changes
-----------------------
+2007-09-09 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.
-2007-09-xx ???
- * Format incremented to 285: ???
-
2007-09-09 Helge Hafting
* Format incremented to 284: LyX now implements wrapped figures
using wrapfig.sty instead of floatflt.sty. The latter
Index: lib/lyx2lyx/LyX.py
===================================================================
--- lib/lyx2lyx/LyX.py (revision 20447)
+++ lib/lyx2lyx/LyX.py (working copy)
@@ -80,7 +80,7 @@
("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():
Index: lib/lyx2lyx/lyx_1_6.py
===================================================================
--- lib/lyx2lyx/lyx_1_6.py (revision 20448)
+++ lib/lyx2lyx/lyx_1_6.py (working copy)
@@ -258,6 +258,23 @@
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 @@
[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, []],
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp (revision 20448)
+++ src/Buffer.cpp (working copy)
@@ -143,7 +143,7 @@
namespace {
-int const LYX_FORMAT = 286;
+int const LYX_FORMAT = 287;
} // namespace anon
Index: src/frontends/qt4/GuiWrap.cpp
===================================================================
--- src/frontends/qt4/GuiWrap.cpp (revision 20447)
+++ src/frontends/qt4/GuiWrap.cpp (working copy)
@@ -34,7 +34,7 @@
: GuiDialog(lv, "wrap")
{
setupUi(this);
- setViewTitle(_("Wrap Float Settings"));
+ setViewTitle(_("Wrap Figure Settings"));
setController(new ControlWrap(*this));
connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
@@ -44,10 +44,16 @@
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()));
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
bc().setRestore(restorePB);
@@ -56,8 +62,11 @@
bc().setCancel(closePB);
bc().addReadOnly(widthED);
- bc().addReadOnly(unitsLC);
+ bc().addReadOnly(widthUnitLC);
bc().addReadOnly(valignCO);
+ bc().addReadOnly(overhangED);
+ bc().addReadOnly(overhangUnitLC);
+ bc().addReadOnly(linesSB);
}
@@ -82,14 +91,20 @@
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 +127,15 @@
{
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")
Index: src/frontends/qt4/ui/WrapUi.ui
===================================================================
--- src/frontends/qt4/ui/WrapUi.ui (revision 20447)
+++ src/frontends/qt4/ui/WrapUi.ui (working copy)
@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>369</width>
- <height>111</height>
+ <width>411</width>
+ <height>199</height>
</rect>
</property>
<property name="windowTitle" >
@@ -15,211 +15,331 @@
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
- <layout class="QVBoxLayout" >
- <property name="margin" >
- <number>11</number>
+ <widget class="QWidget" name="layoutWidget" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>110</y>
+ <width>221</width>
+ <height>22</height>
+ </rect>
</property>
- <property name="spacing" >
- <number>6</number>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="nlinesLA" >
+ <property name="text" >
+ <string>&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>
- <item>
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>0</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item row="0" column="0" >
- <widget class="QLabel" name="widthLA" >
- <property name="text" >
- <string>&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>
+ <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>Outer (default)</string>
+ <string>&Restore</string>
</property>
- </item>
- <item>
+ <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>Inner</string>
+ <string>&OK</string>
</property>
- </item>
- <item>
+ <property name="default" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="applyPB" >
+ <property name="toolTip" >
+ <string/>
+ </property>
<property name="text" >
- <string>Left</string>
+ <string>&Apply</string>
</property>
- </item>
- <item>
+ <property name="default" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="closePB" >
<property name="text" >
- <string>Right</string>
+ <string>&Close</string>
</property>
- </item>
- </widget>
- </item>
- <item row="0" column="2" >
- <widget class="QLabel" name="valignLA" >
- <property name="text" >
- <string>&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>&Units:</string>
- </property>
- <property name="buddy" >
- <cstring>unitsLC</cstring>
- </property>
- </widget>
- </item>
- </layout>
+ <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>&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>
+ <item>
+ <property name="text" >
+ <string>Outer (default)</string>
+ </property>
</item>
<item>
- <spacer>
- <property name="orientation" >
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeType" >
- <enum>QSizePolicy::Expanding</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
+ <property name="text" >
+ <string>Inner</string>
+ </property>
</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>&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>&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>&Apply</string>
- </property>
- <property name="default" >
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="closePB" >
- <property name="text" >
- <string>&Close</string>
- </property>
- <property name="default" >
- <bool>true</bool>
- </property>
- </widget>
- </item>
- </layout>
+ <property name="text" >
+ <string>Left</string>
+ </property>
</item>
- </layout>
+ <item>
+ <property name="text" >
+ <string>Right</string>
+ </property>
+ </item>
+ </widget>
+ <widget class="QWidget" name="" >
+ <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>&Width:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>widthED</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QLabel" name="unitsLA_2" >
+ <property name="text" >
+ <string>&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_2" >
+ <property name="text" >
+ <string>&Overhang (optional):</string>
+ </property>
+ <property name="buddy" >
+ <cstring>widthED</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="LengthCombo" native="1" 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="unitsLA" >
+ <property name="text" >
+ <string>&Unit:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>widthUnitLC</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
+ <widget class="LengthCombo" native="1" 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>
<customwidgets>
<customwidget>
@@ -230,7 +350,7 @@
</customwidgets>
<tabstops>
<tabstop>widthED</tabstop>
- <tabstop>unitsLC</tabstop>
+ <tabstop>widthUnitLC</tabstop>
<tabstop>valignCO</tabstop>
<tabstop>restorePB</tabstop>
<tabstop>okPB</tabstop>
Index: src/insets/InsetWrap.cpp
===================================================================
--- src/insets/InsetWrap.cpp (revision 20447)
+++ src/insets/InsetWrap.cpp (working copy)
@@ -52,6 +52,9 @@
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 @@
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 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,23 +141,46 @@
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)
+ return;
+ lex >> token;
if (token == "width") {
lex.next();
width = Length(lex.getString());
} else {
lyxerr << "InsetWrap::Read:: Missing 'width'-tag!"
<< endl;
- // take countermeasures
lex.pushToken(token);
}
}
@@ -196,9 +223,14 @@
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";
Index: src/insets/InsetWrap.h
===================================================================
--- src/insets/InsetWrap.h (revision 20447)
+++ src/insets/InsetWrap.h (working copy)
@@ -30,8 +30,12 @@
///
std::string type;
///
+ int lines;
+ ///
std::string placement;
///
+ Length overhang;
+ ///
Length width;
};