#include "ControlWrap.h"
#include "LengthCombo.h"
#include "qt_helpers.h"
+#include "Validator.h"
#include "insets/InsetWrap.h"
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);
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);
}
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:
{
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")
<rect>
<x>0</x>
<y>0</y>
- <width>369</width>
- <height>111</height>
+ <width>411</width>
+ <height>199</height>
</rect>
</property>
<property name="windowTitle" >
<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>
+ <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>
- </item>
- <item>
<property name="text" >
- <string>Inner</string>
+ <string>&OK</string>
+ </property>
+ <property name="default" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="applyPB" >
+ <property name="toolTip" >
+ <string/>
</property>
- </item>
- <item>
<property name="text" >
- <string>Left</string>
+ <string>&Apply</string>
+ </property>
+ <property name="default" >
+ <bool>false</bool>
</property>
- </item>
- <item>
+ </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="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>&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>&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>&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>&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>
<customwidgets>
<customwidget>
<class>LengthCombo</class>
- <extends>QWidget</extends>
+ <extends>QComboBox</extends>
<header>LengthCombo.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>widthED</tabstop>
- <tabstop>unitsLC</tabstop>
+ <tabstop>widthUnitLC</tabstop>
<tabstop>valignCO</tabstop>
<tabstop>restorePB</tabstop>
<tabstop>okPB</tabstop>
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);
}
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;
}
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";
}
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)
} else {
lyxerr << "InsetWrap::Read:: Missing 'width'-tag!"
<< endl;
- // take countermeasures
lex.pushToken(token);
}
}
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";