Title block templates: improved span management

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1636 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2012-04-08 20:51:40 +00:00
parent e3eaed2314
commit ba7e030d9f
7 changed files with 112 additions and 53 deletions

View File

@@ -608,6 +608,9 @@ MergeCellsCommand::MergeCellsCommand(const TitleBlockTemplateCellsSet &merged_ce
// store the former values of the row_span and col_span attributes of the spanning cell
row_span_before_ = spanning_cell_ -> row_span;
col_span_before_ = spanning_cell_ -> col_span;
applied_row_span_before_ = spanning_cell_ -> applied_row_span;
applied_col_span_before_ = spanning_cell_ -> applied_col_span;
span_state_before_ = spanning_cell_ -> span_state;
// calculate their new values after the merge operation
TitleBlockCell *bottom_right_cell = getBottomRightCell(merged_cells);
@@ -671,9 +674,12 @@ void MergeCellsCommand::undo() {
cell -> spanner_cell = spanner_cells_before_merge_[cell];
}
// restore the row_span and col_span attributes of the spanning cell
// restore the span-related attributes of the spanning cell
spanning_cell_ -> row_span = row_span_before_;
spanning_cell_ -> col_span = col_span_before_;
spanning_cell_ -> applied_row_span = applied_row_span_before_;
spanning_cell_ -> applied_col_span = applied_col_span_before_;
spanning_cell_ -> span_state = span_state_before_;
if (view_) view_ -> updateLayout();
}
@@ -693,6 +699,9 @@ void MergeCellsCommand::redo() {
// set the new values of the row_span and col_span attributes
spanning_cell_ -> row_span = row_span_after_;
spanning_cell_ -> col_span = col_span_after_;
spanning_cell_ -> applied_row_span = row_span_after_;
spanning_cell_ -> applied_col_span = col_span_after_;
spanning_cell_ -> span_state = TitleBlockCell::Enabled;
if (view_) view_ -> updateLayout();
}
@@ -745,6 +754,9 @@ SplitCellsCommand::SplitCellsCommand(const TitleBlockTemplateCellsSet &splitted_
spanned_cells_ = tbtemplate_ -> spannedCells(spanning_cell_);
row_span_before_ = spanning_cell_ -> row_span;
col_span_before_ = spanning_cell_ -> col_span;
applied_row_span_before_ = spanning_cell_ -> row_span;
applied_col_span_before_ = spanning_cell_ -> col_span;
span_state_before_ = spanning_cell_ -> span_state;
setText(
QString(
@@ -805,6 +817,9 @@ void SplitCellsCommand::undo() {
// the spanning cell span again
spanning_cell_ -> row_span = row_span_before_;
spanning_cell_ -> col_span = col_span_before_;
spanning_cell_ -> applied_row_span = applied_row_span_before_;
spanning_cell_ -> applied_col_span = applied_col_span_before_;
spanning_cell_ -> span_state = span_state_before_;
if (view_) view_ -> updateLayout();
}
@@ -823,6 +838,7 @@ void SplitCellsCommand::redo() {
// the spanning cell does not span anymore
spanning_cell_ -> row_span = 0;
spanning_cell_ -> col_span = 0;
tbtemplate_ -> checkCellSpan(spanning_cell_);
if (view_) view_ -> updateLayout();
}
@@ -989,13 +1005,14 @@ void PasteTemplateCellsCommand::redo() {
if ((pasted_cell.row_span != cell -> row_span) || (pasted_cell.col_span != cell -> col_span)) {
tbtemplate_ -> forgetSpanning(cell);
// Note: the code below is similar to TitleBlockTemplate::checkCell() but is more aggressive (spans deletion).
// set the new/pasted span parameters
cell -> row_span = qBound(0, pasted_cell.row_span, tbtemplate_ -> rowsCount() - 1 - cell -> num_row);
cell -> col_span = qBound(0, pasted_cell.col_span, tbtemplate_ -> columnsCount() - 1 - cell -> num_col);
if (cell -> row_span || cell -> col_span) {
// browse newly spanned cells...
foreach (TitleBlockCell *spanned_cell, tbtemplate_ -> spannedCells(cell)) {
foreach (TitleBlockCell *spanned_cell, tbtemplate_ -> spannedCells(cell, true)) {
// ... to ensure they are not already spanned by other cells
if (spanned_cell -> spanner_cell && spanned_cell -> spanner_cell != cell) {
// if so, simply cancel the whole spanning

View File

@@ -198,6 +198,9 @@ class MergeCellsCommand : public TitleBlockTemplateCommand {
QHash<TitleBlockCell *, TitleBlockCell *> spanner_cells_before_merge_;
int row_span_before_; ///< the row_span attribute of the spanning cell before the merge
int col_span_before_; ///< the col_span attribute of the spanning cell before the merge
int applied_row_span_before_; ///< the applied_row_span attribute of the spanning cell before the merge
int applied_col_span_before_; ///< the applied_col_span attribute of the spanning cell before the merge
int span_state_before_; ///< the span_state attribute of the spanning cell before the merge
int row_span_after_; ///< the row_span attribute of the spanning cell after the merge
int col_span_after_; ///< the col_span attribute of the spanning cell after the merge
};
@@ -222,8 +225,11 @@ class SplitCellsCommand : public TitleBlockTemplateCommand {
private:
TitleBlockCell *spanning_cell_; ///< the cell spanning over the other ones
QSet<TitleBlockCell *> spanned_cells_; ///< the spanned cells
int row_span_before_; ///< the row_span attribute of the spanning cell after the merge
int col_span_before_; ///< the col_span attribute of the spanning cell after the merge
int row_span_before_; ///< the row_span attribute of the spanning cell before splitting
int col_span_before_; ///< the col_span attribute of the spanning cell before splitting
int applied_row_span_before_; ///< the applied_row_span attribute of the spanning cell before splitting
int applied_col_span_before_; ///< the applied_col_span attribute of the spanning cell before splitting
int span_state_before_; ///< the span_state attribute of the spanning cell before splitting
};
/**

View File

@@ -648,8 +648,10 @@ void TitleBlockTemplateView::updateRowsHelperCells() {
QList<int> heights = tbtemplate_ -> rowsHeights();
for (int i = 0 ; i < row_count ; ++ i) {
HelperCell *current_row_cell = static_cast<HelperCell *>(tbgrid_ -> itemAt(ROW_OFFSET + i, 0));
current_row_cell -> setType(QET::Absolute); // rows always have absolute heights
current_row_cell -> label = QString(tr("%1px", "format displayed in rows helper cells")).arg(heights.at(i));
if (current_row_cell) {
current_row_cell -> setType(QET::Absolute); // rows always have absolute heights
current_row_cell -> label = QString(tr("%1px", "format displayed in rows helper cells")).arg(heights.at(i));
}
}
}
@@ -661,8 +663,10 @@ void TitleBlockTemplateView::updateColumnsHelperCells() {
for (int i = 0 ; i < col_count ; ++ i) {
TitleBlockDimension current_col_dim = tbtemplate_ -> columnDimension(i);
HelperCell *current_col_cell = static_cast<HelperCell *>(tbgrid_ -> itemAt(1, COL_OFFSET + i));
current_col_cell -> setType(current_col_dim.type);
current_col_cell -> label = current_col_dim.toString();
if (current_col_cell) {
current_col_cell -> setType(current_col_dim.type);
current_col_cell -> label = current_col_dim.toString();
}
}
}
@@ -673,7 +677,6 @@ void TitleBlockTemplateView::updateColumnsHelperCells() {
void TitleBlockTemplateView::addCells() {
int col_count = tbtemplate_ -> columnsCount();
int row_count = tbtemplate_ -> rowsCount();
if (row_count < 1 || col_count < 1) return;
// we add a big cell to show the total width
total_width_helper_cell_ = new SplittedHelperCell();
@@ -725,7 +728,13 @@ void TitleBlockTemplateView::addCells() {
if (cell -> spanner_cell) continue;
TitleBlockTemplateVisualCell *cell_item = new TitleBlockTemplateVisualCell();
cell_item -> setTemplateCell(tbtemplate_, cell);
tbgrid_ -> addItem(cell_item, ROW_OFFSET + j, COL_OFFSET + i, cell -> row_span + 1, cell -> col_span + 1);
int row_span = 0, col_span = 0;
if (cell -> span_state != TitleBlockCell::Disabled) {
row_span = cell -> applied_row_span;
col_span = cell -> applied_col_span;
}
tbgrid_ -> addItem(cell_item, ROW_OFFSET + j, COL_OFFSET + i, row_span + 1, col_span + 1);
}
}
}
@@ -773,7 +782,6 @@ void TitleBlockTemplateView::fillWithEmptyCells() {
for (int i = 0 ; i < col_count ; ++ i) {
for (int j = 0 ; j < row_count ; ++ j) {
if (tbgrid_ -> itemAt(ROW_OFFSET + j, COL_OFFSET + i)) continue;
qDebug() << Q_FUNC_INFO << "looks like there is nothing there (" << j << "," << i << ")";
TitleBlockTemplateVisualCell *cell_item = new TitleBlockTemplateVisualCell();
if (TitleBlockCell *target_cell = tbtemplate_ -> cell(j, i)) {
qDebug() << Q_FUNC_INFO << "target_cell" << target_cell;