- support for longtable alignment, fileformat change

- GUI support for table alignment

(all comments to the polished layout of the table dialog welcome)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30477 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2009-07-11 13:09:45 +00:00
parent fa76010250
commit 424943af89
9 changed files with 1001 additions and 663 deletions

View File

@ -1,6 +1,10 @@
LyX file-format changes
-----------------------
2009-07-11 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 363: support for horizontal longtable
alignment.
2009-06-11 Jürgen Spitzmüller <spitz@lyx.org>
* Format incremented to 362: support for the applemac encoding.

View File

@ -727,6 +727,23 @@ def revert_applemac(document):
document.header[i] = "\\encoding auto"
def revert_longtable_align(document):
" Remove longtable alignment setting "
i = 0
j = 0
while True:
i = find_token(document.body, "\\begin_inset Tabular", i)
if i == -1:
break
# the alignment is 2 lines below \\begin_inset Tabular
j = document.body[i+2].find("longtabularalignment")
if j == -1:
break
document.body[i+2] = document.body[i+2][:j-1]
document.body[i+2] = document.body[i+2] + '>'
i = i + 1
##
# Conversion hub
#
@ -748,10 +765,12 @@ convert = [[346, []],
[359, [convert_nomencl_width]],
[360, []],
[361, []],
[362, []]
[362, []],
[363, []]
]
revert = [[361, [revert_applemac]],
revert = [[362, [revert_longtable_align]],
[361, [revert_applemac]],
[360, []],
[359, [revert_nomencl_cwidth]],
[358, [revert_nomencl_width]],

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 = 362; // jspitzm: support applemac encoding
int const LYX_FORMAT = 363; // uwestoehr: support for longtable alignment
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -2045,9 +2045,10 @@ void LyXAction::init()
* \li Params: <FEATURE>: append-row|append-column|delete-row|delete-column|copy-row|copy-column|
toggle-line-top|toggle-line-bottom|toggle-line-left|toggle-line-right|
align-left|align-right|align-center|align-block|valign-top|valign-bottom|
valign-middle|m-align-left|m-align-right|m-align-center|m-valign-top|
m-valign-bottom|m-valign-middle|multicolumn|set-all-lines|unset-all-lines|
set-longtabular|unset-longtabular|set-pwidth|set-mpwidth|
valign-middle|longtabular-align-left|longtabular-align-center|
longtabular-align-right|m-align-left|m-align-right|m-align-center|
m-valign-top|m-valign-bottom|m-valign-middle|multicolumn|set-all-lines|
unset-all-lines|set-longtabular|unset-longtabular|set-pwidth|set-mpwidth|
set-rotate-tabular|unset-rotate-tabular|toggle-rotate-tabular|
set-rotate-cell|unset-rotate-cell|toggle-rotate-cell|set-usebox|set-lthead|
unset-lthead|set-ltfirsthead|unset-ltfirsthead|set-ltfoot|unset-ltfoot|

View File

@ -82,6 +82,8 @@ GuiTabular::GuiTabular(GuiView & lv)
longtableGB, SLOT(setEnabled(bool)));
connect(longTabularCB, SIGNAL(toggled(bool)),
newpageCB, SLOT(setEnabled(bool)));
connect(longTabularCB, SIGNAL(toggled(bool)),
alignmentGB, SLOT(setEnabled(bool)));
connect(hAlignCB, SIGNAL(activated(int)),
this, SLOT(hAlign_changed(int)));
connect(vAlignCB, SIGNAL(activated(int)),
@ -138,9 +140,17 @@ GuiTabular::GuiTabular(GuiView & lv)
this, SLOT(rotateTabular()));
connect(rotateCellCB, SIGNAL(clicked()),
this, SLOT(rotateCell()));
connect(TableAlignCB, SIGNAL(activated(int)),
this, SLOT(tableAlignment_changed(int)));
connect(longTabularCB, SIGNAL(clicked()),
this, SLOT(longTabular()));
connect(leftRB, SIGNAL(clicked()),
this, SLOT(ltAlignment_clicked()));
connect(centerRB, SIGNAL(clicked()),
this, SLOT(ltAlignment_clicked()));
connect(rightRB, SIGNAL(clicked()),
this, SLOT(ltAlignment_clicked()));
bc().setPolicy(ButtonPolicy::IgnorantPolicy);
bc().addReadOnly(topspaceED);
@ -163,6 +173,7 @@ GuiTabular::GuiTabular(GuiView & lv)
bc().addReadOnly(widthUnit);
bc().addReadOnly(hAlignCB);
bc().addReadOnly(vAlignCB);
bc().addReadOnly(TableAlignCB);
bc().addReadOnly(borderSetPB);
bc().addReadOnly(borderUnsetPB);
bc().addReadOnly(borders);
@ -182,7 +193,10 @@ GuiTabular::GuiTabular(GuiView & lv)
bc().addReadOnly(lastfooterBorderBelowCB);
bc().addReadOnly(lastfooterNoContentsCB);
bc().addReadOnly(newpageCB);
bc().addReadOnly(leftRB);
bc().addReadOnly(centerRB);
bc().addReadOnly(rightRB);
// initialize the length validator
bc().addCheckedLineEdit(widthED, fixedWidthColLA);
bc().addCheckedLineEdit(topspaceED, topspaceLA);
@ -420,6 +434,19 @@ void GuiTabular::vAlign_changed(int align)
}
void GuiTabular::tableAlignment_changed(int align)
{
switch (align) {
case 0: set(Tabular::TABULAR_VALIGN_TOP);
break;
case 1: set(Tabular::TABULAR_VALIGN_MIDDLE);
break;
case 2: set(Tabular::TABULAR_VALIGN_BOTTOM);
break;
}
}
void GuiTabular::longTabular()
{
longTabular(longTabularCB->isChecked());
@ -587,6 +614,18 @@ void GuiTabular::ltLastFooterEmpty_clicked()
}
void GuiTabular::ltAlignment_clicked()
{
if (leftRB->isChecked())
set(Tabular::LONGTABULAR_ALIGN_LEFT);
else if (centerRB->isChecked())
set(Tabular::LONGTABULAR_ALIGN_CENTER);
else if (rightRB->isChecked())
set(Tabular::LONGTABULAR_ALIGN_RIGHT);
changed();
}
void GuiTabular::update_borders()
{
Tabular::idx_type const cell = getActiveCell();
@ -787,6 +826,23 @@ void GuiTabular::updateContents()
hAlignCB->setEnabled(true);
vAlignCB->setEnabled(!pwidth.zero());
int tableValign = 0;
switch (tabular_.tabular_valignment) {
case Tabular::LYX_VALIGN_TOP:
tableValign = 0;
break;
case Tabular::LYX_VALIGN_MIDDLE:
tableValign = 1;
break;
case Tabular::LYX_VALIGN_BOTTOM:
tableValign = 2;
break;
default:
tableValign = 0;
break;
}
TableAlignCB->setCurrentIndex(tableValign);
if (!tabular_.is_long_tabular) {
headerStatusCB->setChecked(false);
headerBorderAboveCB->setChecked(false);
@ -809,6 +865,21 @@ void GuiTabular::updateContents()
captionStatusCB->blockSignals(false);
return;
}
switch (tabular_.longtabular_alignment) {
case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
leftRB->setChecked(true);
break;
case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
centerRB->setChecked(true);
break;
case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
rightRB->setChecked(true);
break;
default:
centerRB->setChecked(true);
break;
}
captionStatusCB->blockSignals(true);
captionStatusCB->setChecked(tabular_.ltCaption(row));
captionStatusCB->blockSignals(false);

View File

@ -49,6 +49,7 @@ private Q_SLOTS:
void rotateCell();
void hAlign_changed(int align);
void vAlign_changed(int align);
void tableAlignment_changed(int align);
void specialAlignment_changed();
void width_changed();
void longTabular();
@ -67,6 +68,7 @@ private Q_SLOTS:
void ltLastFooterBorderAbove_clicked();
void ltLastFooterBorderBelow_clicked();
void ltLastFooterEmpty_clicked();
void ltAlignment_clicked();
void on_captionStatusCB_toggled();
private:

File diff suppressed because it is too large Load Diff

View File

@ -163,6 +163,9 @@ TabularFeature tabularFeature[] =
{ Tabular::TABULAR_VALIGN_TOP, "tabular-valign-top"},
{ Tabular::TABULAR_VALIGN_MIDDLE, "tabular-valign-middle"},
{ Tabular::TABULAR_VALIGN_BOTTOM, "tabular-valign-bottom"},
{ Tabular::LONGTABULAR_ALIGN_LEFT, "longtabular-align-left" },
{ Tabular::LONGTABULAR_ALIGN_CENTER, "longtabular-align-center" },
{ Tabular::LONGTABULAR_ALIGN_RIGHT, "longtabular-align-right" },
{ Tabular::LAST_ACTION, "" }
};
@ -257,6 +260,20 @@ string const tostr(LyXAlignment const & num)
}
string const tostr(Tabular::HAlignment const & num)
{
switch (num) {
case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
return "left";
case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
return "center";
case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
return "right";
}
return string();
}
string const tostr(Tabular::VAlignment const & num)
{
switch (num) {
@ -304,6 +321,20 @@ bool string2type(string const str, LyXAlignment & num)
}
bool string2type(string const str, Tabular::HAlignment & num)
{
if (str == "left")
num = Tabular::LYX_LONGTABULAR_ALIGN_LEFT;
else if (str == "center" )
num = Tabular::LYX_LONGTABULAR_ALIGN_CENTER;
else if (str == "right")
num = Tabular::LYX_LONGTABULAR_ALIGN_RIGHT;
else
return false;
return true;
}
bool string2type(string const str, Tabular::VAlignment & num)
{
if (str == "top")
@ -393,6 +424,14 @@ bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
}
bool getTokenValue(string const & str, char const * token,
Tabular::HAlignment & num)
{
string tmp;
return getTokenValue(str, token, tmp) && string2type(tmp, num);
}
bool getTokenValue(string const & str, char const * token,
Tabular::VAlignment & num)
{
@ -598,6 +637,7 @@ void Tabular::init(Buffer & buf, row_type rows_arg,
updateIndexes();
is_long_tabular = false;
tabular_valignment = LYX_VALIGN_MIDDLE;
longtabular_alignment = LYX_LONGTABULAR_ALIGN_CENTER;
rotate = false;
use_booktabs = false;
size_t row_count = row_info.size();
@ -1288,6 +1328,7 @@ void Tabular::write(ostream & os) const
<< write_attribute("booktabs", use_booktabs)
<< write_attribute("islongtable", is_long_tabular)
<< write_attribute("tabularvalignment", tabular_valignment)
<< write_attribute("longtabularalignment", longtabular_alignment)
<< write_attribute("firstHeadTopDL", endfirsthead.topDL)
<< write_attribute("firstHeadBottomDL", endfirsthead.bottomDL)
<< write_attribute("firstHeadEmpty", endfirsthead.empty)
@ -1387,6 +1428,7 @@ void Tabular::read(Lexer & lex)
getTokenValue(line, "booktabs", use_booktabs);
getTokenValue(line, "islongtable", is_long_tabular);
getTokenValue(line, "tabularvalignment", tabular_valignment);
getTokenValue(line, "longtabularalignment", longtabular_alignment);
getTokenValue(line, "firstHeadTopDL", endfirsthead.topDL);
getTokenValue(line, "firstHeadBottomDL", endfirsthead.bottomDL);
getTokenValue(line, "firstHeadEmpty", endfirsthead.empty);
@ -2313,20 +2355,30 @@ int Tabular::latex(odocstream & os, OutputParams const & runparams) const
os << "\\begin{sideways}\n";
++ret;
}
if (is_long_tabular)
if (is_long_tabular) {
os << "\\begin{longtable}";
else
switch (longtabular_alignment) {
case LYX_LONGTABULAR_ALIGN_LEFT:
os << "[l]";
break;
case LYX_LONGTABULAR_ALIGN_CENTER:
break;
case LYX_LONGTABULAR_ALIGN_RIGHT:
os << "[r]";
break;
}
} else {
os << "\\begin{tabular}";
switch (tabular_valignment) {
switch (tabular_valignment) {
case LYX_VALIGN_TOP:
os << "[t]";
break;
case LYX_VALIGN_MIDDLE:
break;
case LYX_VALIGN_BOTTOM:
os << "[b]";
break;
case LYX_VALIGN_MIDDLE:
break;
}
}
os << "{";
@ -3083,7 +3135,7 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
BufferView * bv = pi.base.bv;
Cursor & cur = pi.base.bv->cursor();
// FIXME: As the full backrgound is painted in drawSelection(),
// FIXME: As the full background is painted in drawSelection(),
// we have no choice but to do a full repaint for the Text cells.
pi.full_repaint = true;
@ -3915,6 +3967,19 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
== Tabular::LYX_VALIGN_BOTTOM);
break;
case Tabular::LONGTABULAR_ALIGN_LEFT:
status.setOnOff(tabular.longtabular_alignment
== Tabular::LYX_LONGTABULAR_ALIGN_LEFT);
break;
case Tabular::LONGTABULAR_ALIGN_CENTER:
status.setOnOff(tabular.longtabular_alignment
== Tabular::LYX_LONGTABULAR_ALIGN_CENTER);
break;
case Tabular::LONGTABULAR_ALIGN_RIGHT:
status.setOnOff(tabular.longtabular_alignment
== Tabular::LYX_LONGTABULAR_ALIGN_RIGHT);
break;
case Tabular::UNSET_ROTATE_TABULAR:
status.setOnOff(!tabular.rotate);
break;
@ -4091,6 +4156,22 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
}
Inset::DisplayType InsetTabular::display() const
{
if (tabular.is_long_tabular) {
switch (tabular.longtabular_alignment) {
case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
return AlignLeft;
case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
return AlignCenter;
case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
return AlignRight;
}
} else
return Inline;
}
int InsetTabular::latex(odocstream & os, OutputParams const & runparams) const
{
return tabular.latex(os, runparams);
@ -4703,6 +4784,20 @@ void InsetTabular::tabularFeatures(Cursor & cur,
tabular.tabular_valignment = Tabular::LYX_VALIGN_BOTTOM;
break;
case Tabular::LONGTABULAR_ALIGN_LEFT:
tabular.longtabular_alignment = Tabular::LYX_LONGTABULAR_ALIGN_LEFT;
break;
case Tabular::LONGTABULAR_ALIGN_CENTER:
tabular.longtabular_alignment = Tabular::LYX_LONGTABULAR_ALIGN_CENTER;
break;
case Tabular::LONGTABULAR_ALIGN_RIGHT:
tabular.longtabular_alignment = Tabular::LYX_LONGTABULAR_ALIGN_RIGHT;
break;
case Tabular::SET_ROTATE_CELL:
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
for (col_type j = sel_col_start; j <= sel_col_end; ++j)

View File

@ -184,6 +184,12 @@ public:
///
TABULAR_VALIGN_BOTTOM,
///
LONGTABULAR_ALIGN_LEFT,
///
LONGTABULAR_ALIGN_CENTER,
///
LONGTABULAR_ALIGN_RIGHT,
///
LAST_ACTION
};
///
@ -205,6 +211,15 @@ public:
///
LYX_VALIGN_MIDDLE = 2
};
///
enum HAlignment {
///
LYX_LONGTABULAR_ALIGN_LEFT = 0,
///
LYX_LONGTABULAR_ALIGN_CENTER = 1,
///
LYX_LONGTABULAR_ALIGN_RIGHT = 2
};
enum BoxType {
///
@ -569,6 +584,8 @@ public:
VAlignment tabular_valignment;
//
// for long tabulars
///
HAlignment longtabular_alignment;
//
bool is_long_tabular;
/// endhead data
@ -750,7 +767,7 @@ public:
insets that may contain several paragraphs */
bool noFontChange() const { return true; }
///
DisplayType display() const { return tabular.is_long_tabular ? AlignCenter : Inline; }
DisplayType display() const;
///
int latex(odocstream &, OutputParams const &) const;
///