multirow(Tabular::CELL_NORMAL),
alignment(LYX_ALIGN_CENTER),
valignment(LYX_VALIGN_TOP),
+ voffset(0),
top_line(false),
bottom_line(false),
left_line(false),
int Tabular::textVOffset(idx_type cell) const
{
- row_type const r = cellRow(cell);
- int y = cellHeight(cell) - rowDescent(r) - rowAscent(r);
- switch (getVAlignment(cell)) {
- case LYX_VALIGN_TOP:
- y = 0;
- break;
- case LYX_VALIGN_MIDDLE:
- y = y/2;
- break;
- case LYX_VALIGN_BOTTOM:
- break;
- }
-
- return y;
+ return cellInfo(cell).voffset;
}
CellData & cs = cellInfo(cell);
cs.multirow = CELL_BEGIN_OF_MULTIROW;
cs.valignment = LYX_VALIGN_MIDDLE;
+ // FIXME: the horizontal alignment of multirow cells can only
+ // be changed for the whole table,
+ // support for this needs to be implemented but us a fileformat
+ // change (assigning this to uwestoehr)
+ // until LyX supports this, use the deault alignment of multirow
+ // cells: left
+ cs.alignment = LYX_ALIGN_LEFT;
// set the bottom row of the last selected cell
setBottomLine(cell, bottomLine(cell + (number - 1)*ncols()));
return;
cellInfo(cell).valignment = LYX_VALIGN_TOP;
+ cellInfo(cell).alignment = LYX_ALIGN_CENTER;
row_type const row = cellRow(cell);
col_type const col = cellColumn(cell);
row_type const span = rowSpan(cell);
if (!p_width.zero())
dim.wid = m.base.textwidth;
tabular.setCellWidth(cell, dim.wid);
- maxAsc = max(maxAsc, dim.asc);
- maxDesc = max(maxDesc, dim.des);
+
+ // FIXME?: do we need a second metrics call
+ // to get the descent of the text in last par?
+ TextMetrics const & tm =
+ mi.base.bv->textMetrics(tabular.cellInset(cell)->getText(0));
+ int const backdes = tm.last().second->descent();
+
+ switch (tabular.getVAlignment(cell)) {
+ case Tabular::LYX_VALIGN_TOP:
+ tabular.cell_info[r][c].voffset = 0;
+ break;
+ case Tabular::LYX_VALIGN_MIDDLE:
+ tabular.cell_info[r][c].voffset = -(dim.des - backdes - TEXT_TO_INSET_OFFSET)/2;
+ break;
+ case Tabular::LYX_VALIGN_BOTTOM:
+ tabular.cell_info[r][c].voffset = -(dim.des - backdes - TEXT_TO_INSET_OFFSET);
+ break;
+ }
+ maxAsc = max(maxAsc, dim.asc - tabular.cell_info[r][c].voffset);
+ maxDesc = max(maxDesc, dim.des + tabular.cell_info[r][c].voffset);
}
int const top_space = tabular.row_info[r].top_space_default ?
default_line_space :
void InsetTabular::drawCellLines(Painter & pain, int x, int y,
- row_type row, idx_type cell, Change const & change) const
+ row_type row, idx_type cell, Change const & change) const
{
- y = y - tabular.rowAscent(row);
+ y -= tabular.rowAscent(row);
int const w = tabular.columnWidth(cell);
int const h = tabular.cellHeight(cell);
- bool on_off = false;
- Color col = Color_tabularline;
- Color onoffcol = Color_tabularonoffline;
-
- if (change.changed()) {
- col = change.color();
- onoffcol = change.color();
- }
-
- bool topalreadydrawn = row > 0 && !tabular.rowTopLine(row)
- && tabular.bottomLine(tabular.cellAbove(cell));
-
- if (!topalreadydrawn) {
- on_off = !tabular.topLine(cell);
- pain.line(x, y, x + w, y,
- on_off ? onoffcol : col,
- on_off ? Painter::line_onoffdash : Painter::line_solid);
- }
- on_off = !tabular.bottomLine(cell);
+ Color linecolor = change.changed() ? change.color() : Color_tabularline;
+ Color gridcolor = change.changed() ? change.color() : Color_tabularonoffline;
+
+ // Top
+ bool drawline = tabular.topLine(cell)
+ || (row > 0 && tabular.bottomLine(tabular.cellAbove(cell)));
+ pain.line(x, y, x + w, y,
+ drawline ? linecolor : gridcolor,
+ drawline ? Painter::line_solid : Painter::line_onoffdash);
+
+ // Bottom
+ drawline = tabular.bottomLine(cell);
pain.line(x, y + h, x + w, y + h,
- on_off ? onoffcol : col,
- on_off ? Painter::line_onoffdash : Painter::line_solid);
-
- col_type const column = tabular.cellColumn(cell);
- bool leftalreadydrawn = column > 0 && !tabular.leftLine(cell)
- && tabular.rightLine(tabular.cellIndex(row, column - 1));
-
- if (!leftalreadydrawn) {
- on_off = !tabular.leftLine(cell);
- pain.line(x, y, x, y + h,
- on_off ? onoffcol : col,
- on_off ? Painter::line_onoffdash : Painter::line_solid);
- }
- on_off = !tabular.rightLine(cell);
- pain.line(x + w - tabular.interColumnSpace(cell), y,
- x + w - tabular.interColumnSpace(cell), y + h,
- on_off ? onoffcol : col,
- on_off ? Painter::line_onoffdash : Painter::line_solid);
+ drawline ? linecolor : gridcolor,
+ drawline ? Painter::line_solid : Painter::line_onoffdash);
+
+ // Left
+ col_type const col = tabular.cellColumn(cell);
+ drawline = tabular.leftLine(cell)
+ || (col > 0 && tabular.rightLine(tabular.cellIndex(row, col - 1)));
+ pain.line(x, y, x, y + h,
+ drawline ? linecolor : gridcolor,
+ drawline ? Painter::line_solid : Painter::line_onoffdash);
+
+ // Right
+ x -= tabular.interColumnSpace(cell);
+ drawline = tabular.rightLine(cell)
+ || (col + 1 < tabular.ncols()
+ && tabular.leftLine(tabular.cellIndex(row, col + 1)));
+ pain.line(x + w, y, x + w, y + h,
+ drawline ? linecolor : gridcolor,
+ drawline ? Painter::line_solid : Painter::line_onoffdash);
}