From 119ea9cd241e82c291e6ea06c90f5a61a707571d Mon Sep 17 00:00:00 2001 From: Edwin Leuven Date: Thu, 3 Feb 2011 23:11:26 +0000 Subject: [PATCH] support for tabular* git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37471 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 5 + lib/lyx2lyx/lyx_2_0.py | 28 +- src/Buffer.cpp | 2 +- src/frontends/qt4/GuiTabular.cpp | 38 +- src/frontends/qt4/ui/TabularUi.ui | 1118 +++++++++++++++-------------- src/insets/InsetTabular.cpp | 34 +- src/insets/InsetTabular.h | 8 + 7 files changed, 674 insertions(+), 559 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index b6bf232572..dd6c79802f 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- +2011-02-03 Edwin Leuven + * Format incremented to 411 (r37471) + Support tabular* : add tabularwidth parameter to + tabular features + 2011-02-03 Jürgen Spitzmüller * Format incremented to 411 New buffer param \language_package to allow per-document diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 1c021ab7aa..cdac01bdb9 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -2436,6 +2436,28 @@ def convert_langpack(document): document.header.insert(i + 1, "\\language_package default") + +def revert_tabularwidth(document): + i = 0 + while True: + i = find_token(document.body, "\\begin_inset Tabular", i) + if i == -1: + return + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Unable to find end of Tabular inset at line " + str(i)) + i += 1 + continue + i += 1 + features = find_token(document.body, " DepClean; typedef map > RefCache; diff --git a/src/frontends/qt4/GuiTabular.cpp b/src/frontends/qt4/GuiTabular.cpp index b65d2ea5a6..f9ae5527ca 100644 --- a/src/frontends/qt4/GuiTabular.cpp +++ b/src/frontends/qt4/GuiTabular.cpp @@ -48,12 +48,14 @@ GuiTabular::GuiTabular(QWidget * parent) { setupUi(this); + tabularWidthED->setValidator(unsignedLengthValidator(tabularWidthED)); widthED->setValidator(unsignedLengthValidator(widthED)); multirowOffsetED->setValidator(new LengthValidator(multirowOffsetED)); topspaceED->setValidator(new LengthValidator(topspaceED)); bottomspaceED->setValidator(new LengthValidator(bottomspaceED)); interlinespaceED->setValidator(new LengthValidator(interlinespaceED)); + tabularWidthUnitCB->setCurrentItem(Length::defaultUnit()); widthUnitCB->setCurrentItem(Length::defaultUnit()); multirowOffsetUnitCB->setCurrentItem(Length::defaultUnit()); topspaceUnitCB->setCurrentItem(Length::defaultUnit()); @@ -152,6 +154,8 @@ GuiTabular::GuiTabular(QWidget * parent) this, SLOT(checkEnabled())); connect(rightRB, SIGNAL(clicked()), this, SLOT(checkEnabled())); + connect(tabularWidthED, SIGNAL(textEdited(const QString &)), + this, SLOT(checkEnabled())); decimalPointLE->setInputMask("X; "); decimalPointLE->setMaxLength(1); @@ -199,15 +203,25 @@ void GuiTabular::checkEnabled() hAlignCB->setEnabled(!(multirowCB->isChecked() && !widgetsToLength(widthED, widthUnitCB).empty()) && specialAlignmentED->text().isEmpty()); - bool dalign = + bool const dalign = hAlignCB->itemData(hAlignCB->currentIndex()).toString() == QString("decimal"); decimalPointLE->setEnabled(dalign); decimalL->setEnabled(dalign); + bool const setwidth = TableAlignCB->currentText() == qt_("Middle") + && !longTabularCB->isChecked() && !rotateTabularCB->isChecked(); + tabularWidthL->setEnabled(setwidth); + tabularWidthED->setEnabled(setwidth); + tabularWidthUnitCB->setEnabled(setwidth); + + bool const is_tabular_star = !tabularWidthED->text().isEmpty(); + rotateTabularCB->setDisabled(is_tabular_star); + vAlignCB->setEnabled(!multirowCB->isChecked() && !widgetsToLength(widthED, widthUnitCB).empty() && specialAlignmentED->text().isEmpty()); + topspaceED->setEnabled(topspaceCO->currentIndex() == 2); topspaceED->setEnabled(topspaceCO->currentIndex() == 2); topspaceUnitCB->setEnabled(topspaceCO->currentIndex() == 2); bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2); @@ -216,13 +230,15 @@ void GuiTabular::checkEnabled() interlinespaceUnitCB->setEnabled(interlinespaceCO->currentIndex() == 2); // setting as longtable is not allowed when table is inside a float - longTabularCB->setEnabled(funcEnabled(Tabular::SET_LONGTABULAR)); + longTabularCB->setEnabled(!is_tabular_star && funcEnabled(Tabular::SET_LONGTABULAR)); bool const longtabular = longTabularCB->isChecked(); longtableGB->setEnabled(true); newpageCB->setEnabled(longtabular); alignmentGB->setEnabled(longtabular); - // longtables cannot have a vertical alignment - TableAlignCB->setDisabled(longtabular); + // longtables and tabular* cannot have a vertical alignment + TableAlignCB->setDisabled(is_tabular_star || longtabular); + TableAlignCO->setDisabled(is_tabular_star || longtabular); + TableAlignCB->setDisabled(is_tabular_star || longtabular); // FIXME: This Dialog is really horrible, disabling/enabling a checkbox // depending on the cursor position is very very unintuitive... @@ -394,6 +410,12 @@ docstring GuiTabular::dialogToParams() const // FIXME: We should use Tabular directly. string param_str = "tabular"; + // table width + string tabwidth = widgetsToLength(tabularWidthED, tabularWidthUnitCB); + if (tabwidth.empty()) + tabwidth = "0pt"; + setParam(param_str, Tabular::SET_TABULAR_WIDTH, tabwidth); + // apply the fixed width values // this must be done before applying the column alignment // because its value influences the alignment of multirow cells @@ -674,6 +696,14 @@ void GuiTabular::paramsToDialog(Inset const * inset) /////////////////////////////////// // Set width and alignment + + Length const tabwidth = tabular.tabularWidth(); + if (tabwidth.zero()) + tabularWidthED->clear(); + else + lengthToWidgets(widthED, widthUnitCB, + tabwidth.asString(), default_unit); + Length pwidth; docstring special; if (multicol) { diff --git a/src/frontends/qt4/ui/TabularUi.ui b/src/frontends/qt4/ui/TabularUi.ui index 2f3c17491f..79756dbed9 100644 --- a/src/frontends/qt4/ui/TabularUi.ui +++ b/src/frontends/qt4/ui/TabularUi.ui @@ -1,97 +1,97 @@ - + TabularUi - - + + 0 0 - 427 - 429 + 433 + 400 - + - + false - - + + 0 - - - + + + - + QTabWidget::Rounded - + 0 - - + + &Table Settings - - - - + + + + Column settings - - - - + + + + &Horizontal alignment: - + hAlignCB - - - + + + Horizontal alignment in column - + QComboBox::AdjustToContents - + Justified - + Left - + Center - + Right - + At Decimal Separator - - - + + + Qt::Horizontal - + 4 20 @@ -99,90 +99,90 @@ - - + + - - + + false - + &Decimal separator: - + decimalPointLE - - + + false - - + + 0 0 - + 20 16777215 - + - + - + 32767 - + Qt::AlignCenter - - - + + + &Width: - + widthED - - + + - - + + true - + Fixed width of the column - + - + - - - + + + Qt::Horizontal - + 109 20 @@ -190,44 +190,44 @@ - - - + + + &Vertical alignment in row: - + vAlignCB - - - + + + Specifies the vertical alignment of this cell in relation to the baseline of the row. - + Top - + Middle - + Bottom - - - + + + Merge cells of different columns - + &Multicolumn @@ -235,70 +235,70 @@ - - - + + + Row setting - - - - + + + + Merge cells of different rows - + M&ultirow - - - - - + + + + + - + &Vertical Offset: - + widthED - - - + + + true - + Optional vertical offset - + - - + + - - - + + + Cell setting - - - - + + + + Rotate this cell by 90 degrees - + Rotate &cell 90 degrees @@ -306,59 +306,92 @@ - - - + + + + LaTe&X argument: + + + specialAlignmentED + + + + + + + Custom column format (LaTeX) + + + + + + true - + Table-wide settings - - - - + + + + + Table w&idth: + + + tabularWidthED + + + + + + + + + + + + Verti&cal alignment: - + vAlignCB - - - + + + Vertical alignment of the table - + 1 - + Top - + Middle - + Bottom - - - + + + Qt::Horizontal - + QSizePolicy::Expanding - + 153 20 @@ -366,15 +399,15 @@ - - - + + + true - + Rotate the table by 90 degrees - + &Rotate table 90 degrees @@ -382,194 +415,177 @@ - - - - LaTe&X argument: - - - specialAlignmentED - - - - - - - Custom column format (LaTeX) - - - - - + + &Borders - - - - + + + + Set Borders - - - - - + + + + + 0 0 - + - - - + + + 0 0 0 - - - + + + 230 240 249 - - - + + + 255 255 255 - - - + + + 242 247 252 - - - + + + 115 120 124 - - - + + + 154 160 166 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 255 255 255 - - - + + + 0 0 0 - - - + + + 16 145 210 - - - + + + 255 255 255 - - - + + + 0 0 255 - - - + + + 255 0 255 - - - + + + 232 232 232 @@ -578,153 +594,153 @@ - - - + + + 0 0 0 - - - + + + 230 240 249 - - - + + + 255 255 255 - - - + + + 255 255 255 - - - + + + 115 120 124 - - - + + + 154 160 166 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 255 255 255 - - - + + + 0 0 0 - - - + + + 16 145 210 - - - + + + 255 255 255 - - - + + + 0 0 255 - - - + + + 255 0 255 - - - + + + 232 232 232 @@ -733,153 +749,153 @@ - - - + + + 128 128 128 - - - + + + 230 240 249 - - - + + + 255 255 255 - - - + + + 255 255 255 - - - + + + 115 120 124 - - - + + + 154 160 166 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 128 128 128 - - - + + + 255 255 255 - - - + + + 255 255 255 - - - + + + 0 0 0 - - - + + + 16 145 210 - - - + + + 255 255 255 - - - + + + 0 0 255 - - - + + + 255 0 255 - - - + + + 232 232 232 @@ -889,22 +905,22 @@ - + QFrame::StyledPanel - + QFrame::Sunken - - - - - + + + + + 0 0 - + Set borders of the current (selected) cell(s) @@ -915,28 +931,28 @@ - - - + + + All Borders - - - - + + + + Set all borders of the current (selected) cell(s) - + &Set - - - + + + Unset all borders of the current (selected) cell(s) - + C&lear @@ -944,31 +960,31 @@ - - - + + + Style - - - - + + + + Use formal (a.k.a. booktabs) border style (no vertical borders) - + Fo&rmal - + true - - - + + + Use default (grid-like) border style - + De&fault @@ -976,15 +992,15 @@ - + - + Qt::Horizontal - + QSizePolicy::Expanding - + 63 20 @@ -992,126 +1008,126 @@ - - - + + + Additional Space - - - - + + + + T&op of row: - + topspaceCO - - + + - - + + - - + + - + None - + Default - + Custom - - + + - + None - + Default - + Custom - - + + - - + + - - - + + + Botto&m of row: - + bottomspaceCO - - + + - - - + + + Bet&ween rows: - + interlinespaceCO - - + + - + None - + Default - + Custom - - + + - - - + + + Qt::Vertical - + 20 90 @@ -1121,231 +1137,231 @@ - - + + &Longtable - - - - + + + + Select for tables that span multiple pages - + &Use long table - - - + + + false - + Row settings - - - - + + + + Status - - - + + + Border above - - - + + + Border below - - - + + + Contents - - - + + + Header: - - - + + + Repeat this row as header on every (except the first) page - + on - - - + + + - + double - - - + + + double - - - + + + First header: - - - + + + This row is the header of the first page - + - + on - - - + + + double - - - + + + double - - - + + + Don't output the first header - + is empty - - - + + + Footer: - - - + + + Repeat this row as footer on every (except the last) page - + on - - - + + + double - - - + + + double - - - + + + Last footer: - - - + + + This row is the footer of the last page - + on - - - + + + double - - - + + + double - - - + + + Don't output the last footer - + is empty - - - + + + Caption: - - - + + + on - - - + + + false - + Set a page break on the current row - + Page &break on current row @@ -1353,38 +1369,38 @@ - - - + + + false - + Horizontal alignment of the longtable - + Longtable alignment - - - - + + + + Left - - - + + + Center - + true - - - + + + Right @@ -1392,12 +1408,12 @@ - - - + + + Qt::Vertical - + 20 91 @@ -1409,68 +1425,68 @@ - - + + - - + + Current cell: - - - + + + 0 0 - + 40 32767 - + Qt::NoFocus - + Current row position - - - + + + 0 0 - + 40 32767 - + Qt::NoFocus - + Current column position - + Qt::Horizontal - + QSizePolicy::Expanding - + 20 20 @@ -1503,46 +1519,50 @@ vAlignCB multicolumnCB multirowCB + multirowOffsetED + multirowOffsetUnitCB rotateCellCB + tabularWidthED + tabularWidthUnitCB TableAlignCB rotateTabularCB specialAlignmentED + borderSetPB borderDefaultRB + borderUnsetPB booktabsRB topspaceCO - bottomspaceUnitCB topspaceED topspaceUnitCB bottomspaceCO bottomspaceED - interlinespaceED + bottomspaceUnitCB interlinespaceCO - longTabularCB + interlinespaceED interlinespaceUnitCB + longTabularCB headerStatusCB - firstheaderNoContentsCB headerBorderAboveCB headerBorderBelowCB firstheaderStatusCB firstheaderBorderAboveCB firstheaderBorderBelowCB - footerBorderAboveCB + firstheaderNoContentsCB footerStatusCB - newpageCB + footerBorderAboveCB footerBorderBelowCB lastfooterStatusCB lastfooterBorderAboveCB lastfooterBorderBelowCB lastfooterNoContentsCB captionStatusCB + newpageCB leftRB - borderSetPB centerRB rightRB - borderUnsetPB - qt_i18n.h + qt_i18n.h diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 48229d413a..4aadb170fe 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -183,6 +183,7 @@ TabularFeature tabularFeature[] = { Tabular::LONGTABULAR_ALIGN_CENTER, "longtabular-align-center", false }, { Tabular::LONGTABULAR_ALIGN_RIGHT, "longtabular-align-right", false }, { Tabular::SET_DECIMAL_POINT, "set-decimal-point", true }, + { Tabular::SET_TABULAR_WIDTH, "set-tabular-width", true }, { Tabular::LAST_ACTION, "", false } }; @@ -678,6 +679,7 @@ void Tabular::init(Buffer * buf, row_type rows_arg, updateIndexes(); is_long_tabular = false; tabular_valignment = LYX_VALIGN_MIDDLE; + tabular_width = Length(); longtabular_alignment = LYX_LONGTABULAR_ALIGN_CENTER; rotate = false; use_booktabs = false; @@ -1391,8 +1393,10 @@ void Tabular::write(ostream & os) const << write_attribute("lastFootBottomDL", endlastfoot.bottomDL) << write_attribute("lastFootEmpty", endlastfoot.empty); // longtables cannot be aligned vertically - if (!is_long_tabular) + if (!is_long_tabular) { os << write_attribute("tabularvalignment", tabular_valignment); + os << write_attribute("tabularwidth", tabular_width); + } if (is_long_tabular) os << write_attribute("longtabularalignment", longtabular_alignment); @@ -1489,6 +1493,7 @@ void Tabular::read(Lexer & lex) getTokenValue(line, "booktabs", use_booktabs); getTokenValue(line, "islongtable", is_long_tabular); getTokenValue(line, "tabularvalignment", tabular_valignment); + getTokenValue(line, "tabularwidth", tabular_width); getTokenValue(line, "longtabularalignment", longtabular_alignment); getTokenValue(line, "firstHeadTopDL", endfirsthead.topDL); getTokenValue(line, "firstHeadBottomDL", endfirsthead.bottomDL); @@ -2594,6 +2599,7 @@ int Tabular::TeXRow(otexstream & os, row_type row, int Tabular::latex(otexstream & os, OutputParams const & runparams) const { int ret = 0; + bool const is_tabular_star = !tabular_width.zero(); //+--------------------------------------------------------------------- //+ first the opening preamble + @@ -2616,7 +2622,10 @@ int Tabular::latex(otexstream & os, OutputParams const & runparams) const break; } } else { - os << "\\begin{tabular}"; + if (is_tabular_star) + os << "\\begin{tabular*}{" << from_ascii(tabular_width.asLatexString()) << "}"; + else + os << "\\begin{tabular}"; switch (tabular_valignment) { case LYX_VALIGN_TOP: os << "[t]"; @@ -2631,6 +2640,9 @@ int Tabular::latex(otexstream & os, OutputParams const & runparams) const os << "{"; + if (is_tabular_star) + os << "@{\\extracolsep{\\fill}}"; + for (col_type c = 0; c < ncols(); ++c) { if (columnLeftLine(c)) os << '|'; @@ -2716,7 +2728,10 @@ int Tabular::latex(otexstream & os, OutputParams const & runparams) const if (is_long_tabular) os << "\\end{longtable}"; else - os << "\\end{tabular}"; + if (is_tabular_star) + os << "\\end{tabular*}"; + else + os << "\\end{tabular}"; if (rotate) { // clear counter os.countLines(); @@ -4360,6 +4375,11 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, status.clear(); return true; + case Tabular::SET_TABULAR_WIDTH: + status.setEnabled(!tabular.rotate && !tabular.is_long_tabular + && tabular.tabular_valignment == Tabular::LYX_VALIGN_MIDDLE); + break; + case Tabular::SET_DECIMAL_POINT: status.setEnabled( tabular.getAlignment(cur.idx()) == LYX_ALIGN_DECIMAL); @@ -4498,18 +4518,22 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, case Tabular::TOGGLE_ROTATE_TABULAR: case Tabular::SET_ROTATE_TABULAR: + status.setEnabled(tabular.tabular_width.zero()); status.setOnOff(tabular.rotate); break; case Tabular::TABULAR_VALIGN_TOP: + status.setEnabled(tabular.tabular_width.zero()); status.setOnOff(tabular.tabular_valignment == Tabular::LYX_VALIGN_TOP); break; case Tabular::TABULAR_VALIGN_MIDDLE: + status.setEnabled(tabular.tabular_width.zero()); status.setOnOff(tabular.tabular_valignment == Tabular::LYX_VALIGN_MIDDLE); break; case Tabular::TABULAR_VALIGN_BOTTOM: + status.setEnabled(tabular.tabular_width.zero()); status.setOnOff(tabular.tabular_valignment == Tabular::LYX_VALIGN_BOTTOM); break; @@ -5187,6 +5211,10 @@ void InsetTabular::tabularFeatures(Cursor & cur, switch (feature) { + case Tabular::SET_TABULAR_WIDTH: + tabular.setTabularWidth(Length(value)); + break; + case Tabular::SET_PWIDTH: { Length const len(value); tabular.setColumnPWidth(cur, cur.idx(), len); diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 9cc8adcb37..dbcfcfe2bc 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -270,6 +270,8 @@ public: /// SET_DECIMAL_POINT, /// + SET_TABULAR_WIDTH, + /// LAST_ACTION }; /// @@ -402,6 +404,10 @@ public: void setVAlignment(idx_type cell, VAlignment align, bool onlycolumn = false); /// + void setTabularWidth(Length const & l) { tabular_width = l; } + /// + Length tabularWidth() const { return tabular_width; } + /// void setColumnPWidth(Cursor &, idx_type, Length const &); /// bool setMColumnPWidth(Cursor &, idx_type, Length const &); @@ -675,6 +681,8 @@ public: /// mutable cell_vvector cell_info; /// + Length tabular_width; + /// bool use_booktabs; /// bool rotate; -- 2.39.2