support for tabular*

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37471 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Edwin Leuven 2011-02-03 23:11:26 +00:00
parent c0a727a9d4
commit 119ea9cd24
7 changed files with 674 additions and 559 deletions

View File

@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
-----------------------
2011-02-03 Edwin Leuven <e.leuven@gmail.com>
* Format incremented to 411 (r37471)
Support tabular* : add tabularwidth parameter to
tabular features
2011-02-03 Jürgen Spitzmüller <spitz@lyx.org>
* Format incremented to 411
New buffer param \language_package to allow per-document

View File

@ -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, "<features", i, j)
if features == -1:
document.warning("Can't find any features in Tabular inset at line " + str(i))
i = j
continue
if document.body[features].find('alignment="tabularwidth"') != -1:
remove_option(document.body, features, 'tabularwidth')
##
# Conversion hub
#
@ -2506,10 +2528,12 @@ convert = [[346, []],
[408, []],
[409, [convert_use_xetex]],
[410, []],
[411, [convert_langpack]]
[411, [convert_langpack]],
[410, []]
]
revert = [[410, [revert_langpack]],
revert = [[411, [revert_tabularwidth]],
[410, [revert_langpack]],
[409, [revert_labeling]],
[408, [revert_use_xetex]],
[407, [revert_script]],

View File

@ -127,7 +127,7 @@ namespace {
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
int const LYX_FORMAT = 411; // spitz: lang_package buffer param
int const LYX_FORMAT = 412; // edwin: set tabular width
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -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) {

File diff suppressed because it is too large Load Diff

View File

@ -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);

View File

@ -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;