From 86b99f8f320ef5a46244b2a5d2686e7fa0aafe3a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Sun, 7 Nov 2010 05:32:28 +0000 Subject: [PATCH] GuiTabular: support for multirow offset; fileformat change git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36182 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 5 +++ lib/lyx2lyx/lyx_2_0.py | 70 ++++++++++++++++++++++++++++++- src/Buffer.cpp | 2 +- src/frontends/qt4/GuiTabular.cpp | 35 ++++++++++++++++ src/frontends/qt4/ui/TabularUi.ui | 47 +++++++++++++++++---- src/insets/InsetTabular.cpp | 28 ++++++++++++- src/insets/InsetTabular.h | 8 ++++ 7 files changed, 184 insertions(+), 11 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 21efb7611f..d621168fd0 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -7,6 +7,11 @@ The good example would be 2010-01-10 entry. ----------------------- +2010-11-07 Uwe Stöhr + * 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 and Jean-Marc Lasgouttes * Format incremented to 406: ?? diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 8b5b58b483..61f070fb98 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -2085,6 +2085,70 @@ def revert_passthru(document): 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, '", 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, ' DepClean; typedef map > RefCache; diff --git a/src/frontends/qt4/GuiTabular.cpp b/src/frontends/qt4/GuiTabular.cpp index f696d9d1fe..b69b8e5db9 100644 --- a/src/frontends/qt4/GuiTabular.cpp +++ b/src/frontends/qt4/GuiTabular.cpp @@ -49,11 +49,13 @@ GuiTabular::GuiTabular(QWidget * parent) 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()); @@ -92,6 +94,10 @@ GuiTabular::GuiTabular(QWidget * parent) 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()), @@ -156,6 +162,7 @@ GuiTabular::GuiTabular(QWidget * parent) // initialize the length validator addCheckedWidget(widthED, fixedWidthColLA); + addCheckedWidget(multirowOffsetED, multirowOffsetLA); addCheckedWidget(topspaceED, topspaceLA); addCheckedWidget(bottomspaceED, bottomspaceLA); addCheckedWidget(interlinespaceED, interlinespaceLA); @@ -237,6 +244,8 @@ void GuiTabular::checkEnabled() multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN)); multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW)); + multirowOffsetED->setEnabled(multirowCB->isChecked()); + multirowOffsetUnitCB->setEnabled(multirowCB->isChecked()); changed(); } @@ -461,6 +470,13 @@ docstring GuiTabular::dialogToParams() const 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); @@ -574,6 +590,14 @@ static Length getMColumnPWidth(Tabular const & t, size_t cell) } +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) @@ -638,6 +662,17 @@ void GuiTabular::paramsToDialog(Inset const * inset) 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)); /////////////////////////////////// diff --git a/src/frontends/qt4/ui/TabularUi.ui b/src/frontends/qt4/ui/TabularUi.ui index 7777252979..a0d0ac18c9 100644 --- a/src/frontends/qt4/ui/TabularUi.ui +++ b/src/frontends/qt4/ui/TabularUi.ui @@ -6,7 +6,7 @@ 0 0 439 - 376 + 416 @@ -34,8 +34,8 @@ &Table Settings - - + + Column settings @@ -231,12 +231,12 @@ - + Row setting - + @@ -247,10 +247,43 @@ + + + + + + optional vertical offset + + + &Vertical Offset: + + + widthED + + + + + + + true + + + value of the optional vertical offset + + + + + + + + + + + - + Cell setting @@ -269,7 +302,7 @@ - + true diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 7d642e9052..bf78fd0356 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -142,6 +142,7 @@ TabularFeature tabularFeature[] = { 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 }, @@ -573,6 +574,7 @@ Tabular::CellData::CellData(CellData const & cs) width(cs.width), multicolumn(cs.multicolumn), multirow(cs.multirow), + mroffset(cs.mroffset), alignment(cs.alignment), valignment(cs.valignment), decimal_hoffset(cs.decimal_hoffset), @@ -602,6 +604,7 @@ void Tabular::CellData::swap(CellData & rhs) 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); @@ -1130,6 +1133,14 @@ bool Tabular::setMColumnPWidth(Cursor & cur, idx_type cell, } +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) { @@ -1249,6 +1260,12 @@ Length const Tabular::getPWidth(idx_type cell) const } +Length const Tabular::getMROffset(idx_type cell) const +{ + return cellInfo(cell).mroffset; +} + + int Tabular::textHOffset(idx_type cell) const { // the LaTeX Way :-( @@ -1404,6 +1421,7 @@ void Tabular::write(ostream & os) const os << "