-----------------------
+2010-11-07 Uwe Stöhr <uwestoehr@web.de>
+ * Format incremented to 407: support for vertical offset of
+ multirow cells
+ new tag "mroffset" for multirow chells with an offset
+
2010-11-06 Richard Heck <rgheck@comcast.net> and
Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* Format incremented to 406: ??
end = newend
beg = end + 1
+
+def revert_multirowOffset(document):
+ " Revert multirow cells with offset in tables to TeX-code"
+ i = 0
+ multirowOffset = False
+ while True:
+ # cell type 3 is multirow begin cell
+ i = find_token(document.body, '<cell multirow="3" mroffset=', i)
+ if i == -1:
+ break
+ # a multirow cell with offset was found
+ multirowOffset = True
+ # remove the multirow tag, set the valignment to top
+ # the the bottom line and offset
+ document.body[i] = document.body[i].replace(' multirow="3" ', ' ')
+ document.body[i] = document.body[i].replace('valignment="middle"', 'valignment="top"')
+ document.body[i] = document.body[i].replace(' bottomline="true" ', ' ')
+ document.body[i] = document.body[i].replace(' mroffset=', '')
+ # store the offset and remove it
+ begin = document.body[i].find('"')
+ end = document.body[i].find('" ', begin)
+ offset = document.body[i][begin + 1:end]
+ document.body[i] = document.body[i].replace(document.body[i][begin:end + 1], '')
+ # write ERT to create the multirow cell
+ # use 2 rows and 2cm as default with because the multirow span
+ # and the column width is only hardly accessible
+ cend = find_token(document.body, "</cell>", i)
+ if cend == -1:
+ document.warning("Malformed LyX document: Could not find end of tabular cell.")
+ i += 1
+ continue
+ blay = find_token(document.body, "\\begin_layout", i, cend)
+ if blay == -1:
+ document.warning("Can't find layout for cell!")
+ i = j
+ continue
+ bend = find_end_of_layout(document.body, blay)
+ if blay == -1:
+ document.warning("Can't find end of layout for cell!")
+ i = cend
+ continue
+ # do the later one first, so as not to mess up the numbering
+ # we are wrapping the whole cell in this ert
+ # so before the end of the layout...
+ document.body[bend:bend] = put_cmd_in_ert("}")
+ # ...and after the beginning
+ document.body[blay+1:blay+1] = put_cmd_in_ert("\\multirow{2}{2cm}[" + offset + "]{")
+ while True:
+ # cell type 4 is multirow part cell
+ k = find_token(document.body, '<cell multirow="4"', cend)
+ if k == -1:
+ break
+ # remove the multirow tag, set the valignment to top
+ # and remove the top line
+ document.body[k] = document.body[k].replace(' multirow="4" ', ' ')
+ document.body[k] = document.body[k].replace('valignment="middle"', 'valignment="top"')
+ document.body[k] = document.body[k].replace(' topline="true" ', ' ')
+ k += 1
+ # this will always be ok
+ i = cend
+ if multirowOffset == True:
+ add_to_preamble(document, ["\\usepackage{multirow}"])
+
+
##
# Conversion hub
#
[403, [convert_flexnames]],
[404, [convert_prettyref]],
[405, []],
- [406, [convert_passthru]]
+ [406, [convert_passthru]],
+ [407, []]
]
-revert = [[405, [revert_passthru]],
+revert = [[406, [revert_multirowOffset]],
+ [405, [revert_passthru]],
[404, []],
[403, [revert_refstyle]],
[402, [revert_flexnames]],
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
-int const LYX_FORMAT = 406; // rgh: passthru changes
+int const LYX_FORMAT = 407; // uwestoehr: support for multirow offset
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
setupUi(this);
widthED->setValidator(unsignedLengthValidator(widthED));
+ multirowOffsetED->setValidator(new LengthValidator(multirowOffsetED));
topspaceED->setValidator(new LengthValidator(topspaceED));
bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
widthUnitCB->setCurrentItem(Length::defaultUnit());
+ multirowOffsetUnitCB->setCurrentItem(Length::defaultUnit());
topspaceUnitCB->setCurrentItem(Length::defaultUnit());
bottomspaceUnitCB->setCurrentItem(Length::defaultUnit());
interlinespaceUnitCB->setCurrentItem(Length::defaultUnit());
this, SLOT(checkEnabled()));
connect(multirowCB, SIGNAL(clicked()),
this, SLOT(checkEnabled()));
+ connect(multirowOffsetED, SIGNAL(textEdited(QString)),
+ this, SLOT(checkEnabled()));
+ connect(multirowOffsetUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ this, SLOT(checkEnabled()));
connect(newpageCB, SIGNAL(clicked()),
this, SLOT(checkEnabled()));
connect(headerStatusCB, SIGNAL(clicked()),
// initialize the length validator
addCheckedWidget(widthED, fixedWidthColLA);
+ addCheckedWidget(multirowOffsetED, multirowOffsetLA);
addCheckedWidget(topspaceED, topspaceLA);
addCheckedWidget(bottomspaceED, bottomspaceLA);
addCheckedWidget(interlinespaceED, interlinespaceLA);
multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW));
+ multirowOffsetED->setEnabled(multirowCB->isChecked());
+ multirowOffsetUnitCB->setEnabled(multirowCB->isChecked());
changed();
}
setParam(param_str, Tabular::SET_MULTICOLUMN);
else
setParam(param_str, Tabular::UNSET_MULTICOLUMN);
+
+ // apply the multirow offset
+ string mroffset = widgetsToLength(multirowOffsetED, multirowOffsetUnitCB);
+ if (mroffset.empty())
+ mroffset = "0pt";
+ if (multirowCB->isChecked())
+ setParam(param_str, Tabular::SET_MROFFSET, mroffset);
//
if (multirowCB->isChecked())
setParam(param_str, Tabular::SET_MULTIROW);
}
+static Length getMROffset(Tabular const & t, size_t cell)
+{
+ if (t.isMultiRow(cell))
+ return t.cellInfo(cell).mroffset;
+ return Length();
+}
+
+
static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
{
if (what == Tabular::SET_SPECIAL_MULTICOLUMN)
lengthToWidgets(widthED, widthUnitCB,
colwidth, default_unit);
}
+ Length mroffset;
+ if (multirow)
+ mroffset = getMROffset(tabular, cell);
+ string offset;
+ if (mroffset.zero())
+ multirowOffsetED->clear();
+ else {
+ offset = mroffset.asString();
+ lengthToWidgets(multirowOffsetED, multirowOffsetUnitCB,
+ offset, default_unit);
+ }
specialAlignmentED->setText(toqstr(special));
///////////////////////////////////
<x>0</x>
<y>0</y>
<width>439</width>
- <height>376</height>
+ <height>416</height>
</rect>
</property>
<property name="windowTitle">
<attribute name="title">
<string>&Table Settings</string>
</attribute>
- <layout class="QGridLayout" name="gridLayout_6">
- <item row="0" column="0" colspan="2">
+ <layout class="QGridLayout" name="gridLayout_10">
+ <item row="0" column="0" colspan="3">
<widget class="QGroupBox" name="GroupBox12">
<property name="title">
<string>Column settings</string>
</layout>
</widget>
</item>
- <item row="1" column="0">
+ <item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Row setting</string>
</property>
- <layout class="QGridLayout" name="gridLayout_3">
+ <layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QCheckBox" name="multirowCB">
<property name="toolTip">
</property>
</widget>
</item>
+ <item row="1" column="0">
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="0" column="0">
+ <widget class="QLabel" name="multirowOffsetLA">
+ <property name="toolTip">
+ <string>optional vertical offset</string>
+ </property>
+ <property name="text">
+ <string>&Vertical Offset:</string>
+ </property>
+ <property name="buddy">
+ <cstring>widthED</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="multirowOffsetED">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="toolTip">
+ <string>value of the optional vertical offset</string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="LengthCombo" name="multirowOffsetUnitCB"/>
+ </item>
+ </layout>
+ </item>
</layout>
</widget>
</item>
- <item row="1" column="1">
+ <item row="1" column="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Cell setting</string>
</layout>
</widget>
</item>
- <item row="2" column="0" colspan="2">
+ <item row="2" column="0" colspan="3">
<widget class="QGroupBox" name="tabAlignmentGB">
<property name="enabled">
<bool>true</bool>
{ Tabular::MULTIROW, "multirow", false },
{ Tabular::SET_MULTIROW, "set-multirow", false },
{ Tabular::UNSET_MULTIROW, "unset-multirow", false },
+ { Tabular::SET_MROFFSET, "set-mroffset", true },
{ Tabular::SET_ALL_LINES, "set-all-lines", false },
{ Tabular::UNSET_ALL_LINES, "unset-all-lines", false },
{ Tabular::SET_LONGTABULAR, "set-longtabular", false },
width(cs.width),
multicolumn(cs.multicolumn),
multirow(cs.multirow),
+ mroffset(cs.mroffset),
alignment(cs.alignment),
valignment(cs.valignment),
decimal_hoffset(cs.decimal_hoffset),
std::swap(width, rhs.width);
std::swap(multicolumn, rhs.multicolumn);
std::swap(multirow, rhs.multirow);
+ std::swap(mroffset, rhs.mroffset);
std::swap(alignment, rhs.alignment);
std::swap(valignment, rhs.valignment);
std::swap(decimal_hoffset, rhs.decimal_hoffset);
}
+bool Tabular::setMROffset(Cursor & cur, idx_type cell,
+ Length const & mroffset)
+{
+ cellInfo(cell).mroffset = mroffset;
+ return true;
+}
+
+
void Tabular::setAlignSpecial(idx_type cell, docstring const & special,
Tabular::Feature what)
{
}
+Length const Tabular::getMROffset(idx_type cell) const
+{
+ return cellInfo(cell).mroffset;
+}
+
+
int Tabular::textHOffset(idx_type cell) const
{
// the LaTeX Way :-(
os << "<cell"
<< write_attribute("multicolumn", cell_info[r][c].multicolumn)
<< write_attribute("multirow", cell_info[r][c].multirow)
+ << write_attribute("mroffset", cell_info[r][c].mroffset)
<< write_attribute("alignment", cell_info[r][c].alignment)
<< write_attribute("valignment", cell_info[r][c].valignment)
<< write_attribute("topline", cell_info[r][c].top_line)
}
getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
getTokenValue(line, "multirow", cell_info[i][j].multirow);
+ getTokenValue(line, "mroffset", cell_info[i][j].mroffset);
getTokenValue(line, "alignment", cell_info[i][j].alignment);
getTokenValue(line, "valignment", cell_info[i][j].valignment);
getTokenValue(line, "topline", cell_info[i][j].top_line);
else
// we need to set a default value
os << "*";
- os << "}{";
+ os << "}";
+ if (!getMROffset(cell).zero())
+ os << "[" << from_ascii(getMROffset(cell).asLatexString()) << "]";
+ os << "{";
} // end if ismultirow
if (getRotateCell(cell)) {
tabular.setMColumnPWidth(cur, cur.idx(), Length(value));
break;
+ case Tabular::SET_MROFFSET:
+ tabular.setMROffset(cur, cur.idx(), Length(value));
+ break;
+
case Tabular::SET_SPECIAL_COLUMN:
case Tabular::SET_SPECIAL_MULTICOLUMN:
if (value == "none")
///
UNSET_MULTIROW,
///
+ SET_MROFFSET,
+ ///
SET_ALL_LINES,
///
UNSET_ALL_LINES,
///
bool setMColumnPWidth(Cursor &, idx_type, Length const &);
///
+ bool setMROffset(Cursor &, idx_type, Length const &);
+ ///
void setAlignSpecial(idx_type cell, docstring const & special,
Feature what);
///
///
Length const getPWidth(idx_type cell) const;
///
+ Length const getMROffset(idx_type cell) const;
+ ///
int textHOffset(idx_type cell) const;
///
int textVOffset(idx_type cell) const;
///
int multirow;
///
+ Length mroffset;
+ ///
LyXAlignment alignment;
///
VAlignment valignment;