r24782 by jghali - Allow table and cell styles to be applied from style manager
scribus-commit
scribus-commit at lists.scribus.net
Sun Dec 26 17:34:08 UTC 2021
Author: jghali
Date: Sun Dec 26 17:34:08 2021
New Revision: 24782
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24782
Log:
Allow table and cell styles to be applied from style manager
Implement undo/redo for a few table/cell actions
Modified:
trunk/Scribus/scribus/pageitem_table.cpp
trunk/Scribus/scribus/pageitem_table.h
trunk/Scribus/scribus/scribusdoc.cpp
trunk/Scribus/scribus/scribusdoc.h
trunk/Scribus/scribus/scribusstructs.h
trunk/Scribus/scribus/tablecell.h
trunk/Scribus/scribus/ui/propertiespalette_table.cpp
trunk/Scribus/scribus/ui/propertiespalette_table.h
trunk/Scribus/scribus/ui/smcellstyle.cpp
trunk/Scribus/scribus/ui/smtablestyle.cpp
trunk/Scribus/scribus/ui/tablesideselector.cpp
trunk/Scribus/scribus/ui/tablesideselector.h
trunk/Scribus/scribus/undomanager.cpp
trunk/Scribus/scribus/undomanager.h
Modified: trunk/Scribus/scribus/pageitem_table.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/pageitem_table.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_table.cpp (original)
+++ trunk/Scribus/scribus/pageitem_table.cpp Sun Dec 26 17:34:08 2021
@@ -29,6 +29,8 @@
#include "styles/tablestyle.h"
#include "tablehandle.h"
#include "tableutils.h"
+#include "undomanager.h"
+#include "undostate.h"
#include "pageitem_table.h"
@@ -1014,6 +1016,25 @@
std::upper_bound(m_columnPositions.begin(), m_columnPositions.end(), gridPoint.x()) - m_columnPositions.begin() - 1);
}
+QSet<TableCell> PageItem_Table::cells() const
+{
+ QSet<TableCell> tableCells;
+
+ for (int row = 0; row < m_rows; ++row)
+ {
+ int colSpan = 0;
+ for (int col = 0; col < m_columns; col += colSpan)
+ {
+ TableCell currentCell = cellAt(row, col);
+ if (row == currentCell.row())
+ tableCells.insert(currentCell);
+ colSpan = currentCell.columnSpan();
+ }
+ }
+
+ return tableCells;
+}
+
void PageItem_Table::moveLeft()
{
if (m_activeCell.column() < 1)
@@ -1151,12 +1172,29 @@
void PageItem_Table::setFillColor(const QString& color)
{
+ if (UndoManager::undoEnabled())
+ {
+ auto *ss = new SimpleState(Um::TableFillColor, QString(), Um::ITable);
+ ss->set("SET_TABLE_FILLCOLOR");
+ ss->set("OLD_COLOR", m_style.fillColor());
+ ss->set("NEW_COLOR", color);
+ undoManager->action(this, ss);
+ }
+
m_style.setFillColor(color);
emit changed();
}
void PageItem_Table::unsetFillColor()
{
+ if (UndoManager::undoEnabled())
+ {
+ auto *ss = new SimpleState(Um::TableFillColorRst, QString(), Um::ITable);
+ ss->set("UNSET_TABLE_FILLCOLOR");
+ ss->set("OLD_COLOR", m_style.fillColor());
+ undoManager->action(this, ss);
+ }
+
m_style.resetFillColor();
emit changed();
}
@@ -1168,12 +1206,29 @@
void PageItem_Table::setFillShade(const double& shade)
{
+ if (UndoManager::undoEnabled())
+ {
+ auto *ss = new SimpleState(Um::TableFillShade, QString(), Um::ITable);
+ ss->set("SET_TABLE_FILLSHADE");
+ ss->set("OLD_SHADE", m_style.fillShade());
+ ss->set("NEW_SHADE", shade);
+ undoManager->action(this, ss);
+ }
+
m_style.setFillShade(shade);
emit changed();
}
void PageItem_Table::unsetFillShade()
{
+ if (UndoManager::undoEnabled())
+ {
+ auto *ss = new SimpleState(Um::TableFillShadeRst, QString(), Um::ITable);
+ ss->set("UNSET_TABLE_FILLSHADE");
+ ss->set("OLD_SHADE", m_style.fillShade());
+ undoManager->action(this, ss);
+ }
+
m_style.resetFillShade();
emit changed();
}
@@ -1185,6 +1240,17 @@
void PageItem_Table::setLeftBorder(const TableBorder& border)
{
+ if (UndoManager::undoEnabled())
+ {
+ QPair<TableBorder, TableBorder> oldNewBorders;
+ oldNewBorders.first = m_style.leftBorder();
+ oldNewBorders.second = border;
+ auto *ss = new ScItemState< QPair<TableBorder, TableBorder> >(Um::TableLeftBorder, QString(), Um::ITable);
+ ss->set("SET_TABLE_LEFTBORDER");
+ ss->setItem(oldNewBorders);
+ undoManager->action(this, ss);
+ }
+
m_style.setLeftBorder(border);
updateCells(0, 0, rows() - 1, 0);
emit changed();
@@ -1192,6 +1258,14 @@
void PageItem_Table::unsetLeftBorder()
{
+ if (UndoManager::undoEnabled())
+ {
+ auto *ss = new ScItemState<TableBorder>(Um::TableLeftBorderRst, QString(), Um::ITable);
+ ss->set("UNSET_TABLE_LEFTBORDER");
+ ss->setItem(m_style.leftBorder());
+ undoManager->action(this, ss);
+ }
+
m_style.resetLeftBorder();
updateCells(0, 0, rows() - 1, 0);
emit changed();
@@ -1204,6 +1278,17 @@
void PageItem_Table::setRightBorder(const TableBorder& border)
{
+ if (UndoManager::undoEnabled())
+ {
+ QPair<TableBorder, TableBorder> oldNewBorders;
+ oldNewBorders.first = m_style.rightBorder();
+ oldNewBorders.second = border;
+ auto *ss = new ScItemState< QPair<TableBorder, TableBorder> >(Um::TableRightBorder, QString(), Um::ITable);
+ ss->set("SET_TABLE_RIGHTBORDER");
+ ss->setItem(oldNewBorders);
+ undoManager->action(this, ss);
+ }
+
m_style.setRightBorder(border);
updateCells(0, columns() - 1, rows() - 1, columns() - 1);
emit changed();
@@ -1211,6 +1296,14 @@
void PageItem_Table::unsetRightBorder()
{
+ if (UndoManager::undoEnabled())
+ {
+ auto *ss = new ScItemState<TableBorder>(Um::TableLeftBorderRst, QString(), Um::ITable);
+ ss->set("UNSET_TABLE_RIGHTBORDER");
+ ss->setItem(m_style.rightBorder());
+ undoManager->action(this, ss);
+ }
+
m_style.resetRightBorder();
updateCells(0, columns() - 1, rows() - 1, columns() - 1);
emit changed();
@@ -1223,6 +1316,17 @@
void PageItem_Table::setTopBorder(const TableBorder& border)
{
+ if (UndoManager::undoEnabled())
+ {
+ QPair<TableBorder, TableBorder> oldNewBorders;
+ oldNewBorders.first = m_style.topBorder();
+ oldNewBorders.second = border;
+ auto *ss = new ScItemState< QPair<TableBorder, TableBorder> >(Um::TableTopBorder, QString(), Um::ITable);
+ ss->set("SET_TABLE_TOPBORDER");
+ ss->setItem(oldNewBorders);
+ undoManager->action(this, ss);
+ }
+
m_style.setTopBorder(border);
updateCells(0, 0, 0, columns() - 1);
emit changed();
@@ -1230,6 +1334,14 @@
void PageItem_Table::unsetTopBorder()
{
+ if (UndoManager::undoEnabled())
+ {
+ auto *ss = new ScItemState<TableBorder>(Um::TableTopBorderRst, QString(), Um::ITable);
+ ss->set("UNSET_TABLE_TOPBORDER");
+ ss->setItem(m_style.topBorder());
+ undoManager->action(this, ss);
+ }
+
m_style.resetTopBorder();
updateCells(0, 0, 0, columns() - 1);
emit changed();
@@ -1242,6 +1354,17 @@
void PageItem_Table::setBottomBorder(const TableBorder& border)
{
+ if (UndoManager::undoEnabled())
+ {
+ QPair<TableBorder, TableBorder> oldNewBorders;
+ oldNewBorders.first = m_style.bottomBorder();
+ oldNewBorders.second = border;
+ auto *ss = new ScItemState< QPair<TableBorder, TableBorder> >(Um::TableBottomBorder, QString(), Um::ITable);
+ ss->set("SET_TABLE_BOTTOMBORDER");
+ ss->setItem(oldNewBorders);
+ undoManager->action(this, ss);
+ }
+
m_style.setBottomBorder(border);
updateCells(rows() - 1, 0, rows() - 1, columns() - 1);
emit changed();
@@ -1249,6 +1372,14 @@
void PageItem_Table::unsetBottomBorder()
{
+ if (UndoManager::undoEnabled())
+ {
+ auto *ss = new ScItemState<TableBorder>(Um::TableBottomBorderRst, QString(), Um::ITable);
+ ss->set("UNSET_TABLE_BOTTOMBORDER");
+ ss->setItem(m_style.bottomBorder());
+ undoManager->action(this, ss);
+ }
+
m_style.resetBottomBorder();
updateCells(rows() - 1, 0, rows() - 1, columns() - 1);
emit changed();
@@ -1259,8 +1390,228 @@
return m_style.bottomBorder();
}
+void PageItem_Table::setBorders(const TableBorder& border, TableSides selectedSides)
+{
+ if (selectedSides == (int) TableSide::None)
+ return;
+
+ UndoTransaction activeTransaction;
+ if (UndoManager::undoEnabled())
+ {
+ activeTransaction = UndoManager::instance()->beginTransaction(getUName(), getUPixmap(), Um::TableBorders, QString(), Um::ITable);
+ auto borderTuple = std::make_tuple(m_style.leftBorder(), m_style.rightBorder(), m_style.bottomBorder(), m_style.topBorder(), border);
+ auto *ss = new ScItemState<TableBorderTuple>(Um::TableBorders, QString(), Um::ITable);
+ ss->set("SET_TABLE_BORDERS");
+ ss->set("SIDES", (int) selectedSides);
+ ss->setItem(borderTuple);
+ undoManager->action(this, ss);
+ }
+
+ if (selectedSides & TableSide::Left)
+ m_style.setLeftBorder(border);
+ if (selectedSides & TableSide::Right)
+ m_style.setRightBorder(border);
+ if (selectedSides & TableSide::Top)
+ m_style.setTopBorder(border);
+ if (selectedSides & TableSide::Bottom)
+ m_style.setBottomBorder(border);
+
+ updateCells();
+ adjustTable();
+
+ if (activeTransaction)
+ activeTransaction.commit();
+
+ emit changed();
+}
+
+void PageItem_Table::setCellBorders(const TableBorder& border, TableSides selectedSides)
+{
+ QSet<TableCell> tableCells;
+
+ if (m_Doc->appMode != modeEditTable)
+ tableCells = this->cells();
+ else
+ {
+ tableCells = this->selectedCells();
+ if (tableCells.isEmpty())
+ tableCells.insert(activeCell());
+ }
+
+ setCellBorders(tableCells, border, selectedSides);
+}
+
+void PageItem_Table::setCellBorders(const QSet<TableCell>& cells, const TableBorder& border, TableSides selectedSides)
+{
+ if (selectedSides == (int) TableSide::None)
+ return;
+
+ UndoTransaction activeTransaction;
+ if (UndoManager::undoEnabled())
+ {
+ activeTransaction = UndoManager::instance()->beginTransaction(getUName(), getUPixmap(), Um::CellBorders, QString(), Um::ITable);
+
+ QMap<TableCell, TableBorderTuple> cellBorderMap;
+ for (auto cellIter = cells.begin(); cellIter != cells.end(); cellIter++)
+ {
+ TableCell currentCell(*cellIter);
+ auto borderTuple = std::make_tuple(currentCell.leftBorder(), currentCell.rightBorder(), currentCell.bottomBorder(), currentCell.topBorder(), border);
+ cellBorderMap.insert(currentCell, borderTuple);
+ }
+ auto *ss = new ScItemState< QMap<TableCell, TableBorderTuple> >(Um::CellBorders, QString(), Um::ITable);
+ ss->set("SET_CELL_BORDERS");
+ ss->set("SIDES", (int) selectedSides);
+ ss->setItem(cellBorderMap);
+ undoManager->action(this, ss);
+ }
+
+ for (auto cellIter = cells.begin(); cellIter != cells.end(); cellIter++)
+ {
+ TableCell currentCell(*cellIter);
+ if (selectedSides & TableSide::Left)
+ currentCell.setLeftBorder(border);
+ if (selectedSides & TableSide::Right)
+ currentCell.setRightBorder(border);
+ if (selectedSides & TableSide::Top)
+ currentCell.setTopBorder(border);
+ if (selectedSides & TableSide::Bottom)
+ currentCell.setBottomBorder(border);
+ }
+
+ adjustTable();
+
+ if (activeTransaction)
+ activeTransaction.commit();
+}
+
+void PageItem_Table::setCellFillColor(const QString& fillColor)
+{
+ QSet<TableCell> tableCells;
+
+ if (m_Doc->appMode != modeEditTable)
+ tableCells = this->cells();
+ else
+ {
+ tableCells = this->selectedCells();
+ if (tableCells.isEmpty())
+ tableCells.insert(activeCell());
+ }
+
+ if (UndoManager::undoEnabled())
+ {
+ QMap<TableCell, QPair<QString, QString> > cellColorMap;
+ for (auto cellIter = tableCells.begin(); cellIter != tableCells.end(); cellIter++)
+ {
+ TableCell currentCell(*cellIter);
+ QString oldColor = currentCell.fillColor();
+ cellColorMap.insert(currentCell, qMakePair(oldColor, fillColor));
+ }
+ auto *ss = new ScItemState< QMap<TableCell, QPair<QString, QString> > >(Um::CellFillColor, "", Um::ITable);
+ ss->set("SET_CELL_FILLCOLOR");
+ ss->setItem(cellColorMap);
+ undoManager->action(this, ss);
+ }
+
+ m_Doc->dontResize = true;
+ for (auto cellIter = tableCells.begin(); cellIter != tableCells.end(); cellIter++)
+ {
+ TableCell currentCell(*cellIter);
+ currentCell.setFillColor(fillColor);
+ }
+ m_Doc->dontResize = false;
+
+ emit changed();
+}
+
+void PageItem_Table::setCellFillShade(double fillShade)
+{
+ QSet<TableCell> tableCells;
+
+ if (m_Doc->appMode != modeEditTable)
+ tableCells = this->cells();
+ else
+ {
+ tableCells = this->selectedCells();
+ if (tableCells.isEmpty())
+ tableCells.insert(activeCell());
+ }
+
+ if (UndoManager::undoEnabled())
+ {
+ QMap<TableCell, QPair<double, double> > cellShadeMap;
+ for (auto cellIter = tableCells.begin(); cellIter != tableCells.end(); cellIter++)
+ {
+ TableCell currentCell(*cellIter);
+ double oldShade = currentCell.fillShade();
+ cellShadeMap.insert(currentCell, qMakePair(oldShade, fillShade));
+ }
+ auto *ss = new ScItemState< QMap<TableCell, QPair<double, double> > >(Um::CellFillShade, "", Um::ITable);
+ ss->set("SET_CELL_FILLSHADE");
+ ss->setItem(cellShadeMap);
+ undoManager->action(this, ss);
+ }
+
+ m_Doc->dontResize = true;
+ for (auto cellIter = tableCells.begin(); cellIter != tableCells.end(); cellIter++)
+ {
+ TableCell currentCell(*cellIter);
+ currentCell.setFillShade(fillShade);
+ }
+ m_Doc->dontResize = false;
+
+ emit changed();
+}
+
+void PageItem_Table::setCellStyle(const QString& cellStyle)
+{
+ QSet<TableCell> tableCells;
+
+ if (m_Doc->appMode != modeEditTable)
+ tableCells = this->cells();
+ else
+ {
+ tableCells = this->selectedCells();
+ if (tableCells.isEmpty())
+ tableCells.insert(activeCell());
+ }
+
+ if (UndoManager::undoEnabled())
+ {
+ QMap<TableCell, QPair<QString, QString> > cellStyleMap;
+ for (auto cellIter = tableCells.begin(); cellIter != tableCells.end(); cellIter++)
+ {
+ TableCell currentCell(*cellIter);
+ QString oldStyle = currentCell.styleName();
+ cellStyleMap.insert(currentCell, qMakePair(oldStyle, cellStyle));
+ }
+ auto *ss = new ScItemState< QMap<TableCell, QPair<QString, QString> > >(Um::CellStyle, "", Um::ITable);
+ ss->set("SET_CELL_STYLE");
+ ss->setItem(cellStyleMap);
+ undoManager->action(this, ss);
+ }
+
+ m_Doc->dontResize = true;
+ for (auto cellIter = tableCells.begin(); cellIter != tableCells.end(); cellIter++)
+ {
+ TableCell currentCell(*cellIter);
+ currentCell.setStyle(cellStyle);
+ }
+ m_Doc->dontResize = false;
+
+ emit changed();
+}
+
void PageItem_Table::setStyle(const QString& style)
{
+ if (UndoManager::undoEnabled())
+ {
+ auto *ss = new SimpleState(Um::TableStyle, "", Um::ITable);
+ ss->set("SET_TABLE_STYLE");
+ ss->set("OLD_STYLE", m_style.parent());
+ ss->set("NEW_STYLE", style);
+ undoManager->action(this, ss);
+ }
+
doc()->dontResize = true;
m_style.setParent(style);
updateCells();
@@ -1270,6 +1621,15 @@
void PageItem_Table::unsetStyle()
{
+ if (UndoManager::undoEnabled())
+ {
+ auto *ss = new SimpleState(Um::ChangeFormula, "", Um::IChangeFormula);
+ ss->set("UNSET_TABLE_STYLE");
+ ss->set("OLD_STYLE", m_style.parent());
+ ss->set("NEW_STYLE", QString());
+ undoManager->action(this, ss);
+ }
+
doc()->dontResize = true;
m_style.setParent("");
updateCells();
@@ -1715,3 +2075,419 @@
Q_ASSERT(cell.row() == cellArea.row() && cell.column() == cellArea.column());
}
}
+
+void PageItem_Table::restore(UndoState *state, bool isUndo)
+{
+ auto *simpleState = dynamic_cast<SimpleState*>(state);
+ if (!simpleState)
+ {
+ PageItem::restore(state, isUndo);
+ return;
+ }
+
+ bool doUpdate = false;
+ if (simpleState->contains("SET_CELL_BORDERS"))
+ {
+ restoreCellBorders(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("SET_CELL_FILLCOLOR"))
+ {
+ restoreCellFillColor(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("SET_CELL_FILLSHADE"))
+ {
+ restoreCellFillShade(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("SET_CELL_STYLE"))
+ {
+ restoreCellStyle(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("SET_TABLE_FILLCOLOR"))
+ {
+ restoreTableFillColor(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("SET_TABLE_FILLSHADE"))
+ {
+ restoreTableFillShade(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("SET_TABLE_BORDERS"))
+ {
+ restoreTableBorders(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("SET_TABLE_LEFTBORDER"))
+ {
+ restoreTableLeftBorder(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("SET_TABLE_RIGHTBORDER"))
+ {
+ restoreTableRightBorder(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("SET_TABLE_BOTTOMBORDER"))
+ {
+ restoreTableBottomBorder(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("SET_TABLE_TOPBORDER"))
+ {
+ restoreTableTopBorder(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("SET_TABLE_STYLE"))
+ {
+ restoreTableStyle(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("UNSET_TABLE_FILLCOLOR"))
+ {
+ restoreTableFillColorReset(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("UNSET_TABLE_FILLSHADE"))
+ {
+ restoreTableFillShadeReset(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("UNSET_TABLE_LEFTBORDER"))
+ {
+ restoreTableLeftBorderReset(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("UNSET_TABLE_RIGHTBORDER"))
+ {
+ restoreTableRightBorderReset(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("UNSET_TABLE_BOTTOMBORDER"))
+ {
+ restoreTableBottomBorderReset(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("UNSET_TABLE_TOPBORDER"))
+ {
+ restoreTableTopBorderReset(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else if (simpleState->contains("UNSET_TABLE_STYLE"))
+ {
+ restoreTableStyleReset(simpleState, isUndo);
+ doUpdate = true;
+ }
+ else
+ {
+ PageItem::restore(state, isUndo);
+ }
+
+ if (doUpdate)
+ {
+ if (state->transactionCode == 0 || state->transactionCode == 2)
+ this->update();
+ }
+}
+
+void PageItem_Table::restoreCellBorders(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState<QMap<TableCell, TableBorderTuple > > *>(state);
+ if (!itemState)
+ return;
+
+ TableSides selectedSides;
+ selectedSides |= (TableSide) itemState->getInt("SIDES");
+
+ QMap<TableCell, TableBorderTuple> cellBorderMap = itemState->getItem();
+ if (isUndo)
+ {
+ for (auto iter = cellBorderMap.begin(); iter != cellBorderMap.end(); ++iter)
+ {
+ TableCell currentCell = iter.key();
+ TableBorderTuple currentBorders = iter.value();
+ currentCell.setLeftBorder( std::get<0>(currentBorders) );
+ currentCell.setRightBorder( std::get<1>(currentBorders) );
+ currentCell.setBottomBorder( std::get<2>(currentBorders) );
+ currentCell.setTopBorder( std::get<3>(currentBorders) );
+ }
+ }
+ else
+ {
+ for (auto iter = cellBorderMap.begin(); iter != cellBorderMap.end(); ++iter)
+ {
+ TableCell currentCell = iter.key();
+ TableBorder newBorder = std::get<4>(iter.value());
+ if (selectedSides & TableSide::Left)
+ currentCell.setLeftBorder(newBorder);
+ if (selectedSides & TableSide::Right)
+ currentCell.setRightBorder(newBorder);
+ if (selectedSides & TableSide::Bottom)
+ currentCell.setBottomBorder(newBorder);
+ if (selectedSides & TableSide::Top)
+ currentCell.setTopBorder(newBorder);
+ }
+ }
+
+ adjustTable();
+}
+
+void PageItem_Table::restoreCellFillColor(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState<QMap<TableCell, QPair<QString, QString> > > *>(state);
+ if (!itemState)
+ return;
+
+ QMap<TableCell, QPair<QString, QString> > cellColorMap = itemState->getItem();
+ for (auto iter = cellColorMap.begin(); iter != cellColorMap.end(); ++iter)
+ {
+ TableCell currentCell = iter.key();
+ QString restoredColor = isUndo ? iter.value().first : iter.value().second;
+ currentCell.setFillColor(restoredColor);
+ }
+}
+
+void PageItem_Table::restoreCellFillShade(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState<QMap<TableCell, QPair<double, double> > > *>(state);
+ if (!itemState)
+ return;
+
+ QMap<TableCell, QPair<double, double> > cellColorMap = itemState->getItem();
+ for (auto iter = cellColorMap.begin(); iter != cellColorMap.end(); ++iter)
+ {
+ TableCell currentCell = iter.key();
+ double restoredShade = isUndo ? iter.value().first : iter.value().second;
+ currentCell.setFillShade(restoredShade);
+ }
+}
+
+void PageItem_Table::restoreCellStyle(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState<QMap<TableCell, QPair<QString, QString> > > *>(state);
+ if (!itemState)
+ return;
+
+ QMap<TableCell, QPair<QString, QString> > cellStyleMap = itemState->getItem();
+ for (auto iter = cellStyleMap.begin(); iter != cellStyleMap.end(); ++iter)
+ {
+ TableCell currentCell = iter.key();
+ QString restoredStyle = isUndo ? iter.value().first : iter.value().second;
+ currentCell.setStyle(restoredStyle);
+ }
+}
+
+void PageItem_Table::restoreTableFillColor(SimpleState *state, bool isUndo)
+{
+ QString restoredFillColor = state->get(isUndo ? "OLD_COLOR" : "NEW_COLOR");
+ setFillColor(restoredFillColor);
+}
+
+void PageItem_Table::restoreTableFillColorReset(SimpleState *state, bool isUndo)
+{
+ if (isUndo)
+ {
+ QString restoredFillColor = state->get("OLD_COLOR");
+ setFillColor(restoredFillColor);
+ }
+ else
+ {
+ unsetFillColor();
+ }
+}
+
+void PageItem_Table::restoreTableFillShade(SimpleState *state, bool isUndo)
+{
+ double restoredFillShade = state->getDouble(isUndo ? "OLD_SHADE" : "NEW_SHADE");
+ setFillShade(restoredFillShade);
+}
+
+void PageItem_Table::restoreTableFillShadeReset(SimpleState *state, bool isUndo)
+{
+ if (isUndo)
+ {
+ double restoredFillShade = state->getDouble("OLD_SHADE");
+ setFillShade(restoredFillShade);
+ }
+ else
+ {
+ unsetFillShade();
+ }
+}
+
+void PageItem_Table::restoreTableBorders(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState<TableBorderTuple> *>(state);
+ if (!itemState)
+ return;
+
+ TableSides selectedSides;
+ selectedSides |= (TableSide) itemState->getInt("SIDES");
+
+ TableBorderTuple borderTuple = itemState->getItem();
+ if (isUndo)
+ {
+ m_style.setLeftBorder( std::get<0>(borderTuple) );
+ m_style.setRightBorder( std::get<1>(borderTuple) );
+ m_style.setBottomBorder( std::get<2>(borderTuple) );
+ m_style.setTopBorder( std::get<3>(borderTuple) );
+ }
+ else
+ {
+ TableBorder newBorder = std::get<4>(borderTuple);
+ if (selectedSides & TableSide::Left)
+ m_style.setLeftBorder(newBorder);
+ if (selectedSides & TableSide::Right)
+ m_style.setRightBorder(newBorder);
+ if (selectedSides & TableSide::Bottom)
+ m_style.setBottomBorder(newBorder);
+ if (selectedSides & TableSide::Top)
+ m_style.setTopBorder(newBorder);
+ }
+
+ updateCells();
+ adjustTable();
+}
+
+void PageItem_Table::restoreTableLeftBorder(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState< QPair<TableBorder, TableBorder> > *>(state);
+ if (!itemState)
+ return;
+
+ QPair<TableBorder, TableBorder> oldNewBorders = itemState->getItem();
+ TableBorder restoredBorder = isUndo ? oldNewBorders.first : oldNewBorders.second;
+ setLeftBorder(restoredBorder);
+
+ adjustTable();
+}
+
+void PageItem_Table::restoreTableLeftBorderReset(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState<TableBorder> *>(state);
+ if (!itemState)
+ return;
+
+ if (isUndo)
+ {
+ TableBorder oldBorder = itemState->getItem();
+ setLeftBorder(oldBorder);
+ }
+ else
+ {
+ unsetLeftBorder();
+ }
+
+ adjustTable();
+}
+
+void PageItem_Table::restoreTableRightBorder(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState< QPair<TableBorder, TableBorder> > *>(state);
+ if (!itemState)
+ return;
+
+ QPair<TableBorder, TableBorder> oldNewBorders = itemState->getItem();
+ TableBorder restoredBorder = isUndo ? oldNewBorders.first : oldNewBorders.second;
+ setRightBorder(restoredBorder);
+
+ adjustTable();
+}
+
+void PageItem_Table::restoreTableRightBorderReset(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState<TableBorder> *>(state);
+ if (!itemState)
+ return;
+
+ if (isUndo)
+ {
+ TableBorder oldBorder = itemState->getItem();
+ setRightBorder(oldBorder);
+ }
+ else
+ {
+ unsetRightBorder();
+ }
+
+ adjustTable();
+}
+
+void PageItem_Table::restoreTableBottomBorder(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState< QPair<TableBorder, TableBorder> > *>(state);
+ if (!itemState)
+ return;
+
+ QPair<TableBorder, TableBorder> oldNewBorders = itemState->getItem();
+ TableBorder restoredBorder = isUndo ? oldNewBorders.first : oldNewBorders.second;
+ setBottomBorder(restoredBorder);
+
+ adjustTable();
+}
+
+void PageItem_Table::restoreTableBottomBorderReset(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState<TableBorder> *>(state);
+ if (!itemState)
+ return;
+
+ if (isUndo)
+ {
+ TableBorder oldBorder = itemState->getItem();
+ setBottomBorder(oldBorder);
+ }
+ else
+ {
+ unsetBottomBorder();
+ }
+
+ adjustTable();
+}
+
+void PageItem_Table::restoreTableTopBorder(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState< QPair<TableBorder, TableBorder> > *>(state);
+ if (!itemState)
+ return;
+
+ QPair<TableBorder, TableBorder> oldNewBorders = itemState->getItem();
+ TableBorder restoredBorder = isUndo ? oldNewBorders.first : oldNewBorders.second;
+ setTopBorder(restoredBorder);
+
+ adjustTable();
+}
+
+void PageItem_Table::restoreTableTopBorderReset(SimpleState *state, bool isUndo)
+{
+ auto* itemState = dynamic_cast< ScItemState<TableBorder> *>(state);
+ if (!itemState)
+ return;
+
+ if (isUndo)
+ {
+ TableBorder oldBorder = itemState->getItem();
+ setTopBorder(oldBorder);
+ }
+ else
+ {
+ unsetTopBorder();
+ }
+
+ adjustTable();
+}
+
+void PageItem_Table::restoreTableStyle(SimpleState *state, bool isUndo)
+{
+ QString restoredStyle = state->get(isUndo ? "OLD_STYLE" : "NEW_STYLE");
+ setStyle(restoredStyle);
+}
+
+void PageItem_Table::restoreTableStyleReset(SimpleState *state, bool isUndo)
+{
+ QString restoredStyle = state->get(isUndo ? "OLD_STYLE" : "NEW_STYLE");
+ setStyle(restoredStyle);
+}
Modified: trunk/Scribus/scribus/pageitem_table.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/pageitem_table.h
==============================================================================
--- trunk/Scribus/scribus/pageitem_table.h (original)
+++ trunk/Scribus/scribus/pageitem_table.h Sun Dec 26 17:34:08 2021
@@ -9,6 +9,9 @@
#ifndef PAGEITEM_TABLE_H
#define PAGEITEM_TABLE_H
+#include <tuple>
+
+#include <QFlags>
#include <QList>
#include <QPointF>
#include <QRectF>
@@ -18,6 +21,7 @@
#include "cellarea.h"
#include "pageitem.h"
#include "scribusapi.h"
+#include "scribusstructs.h"
#include "styles/tablestyle.h"
#include "tablecell.h"
#include "tablehandle.h"
@@ -281,6 +285,11 @@
void splitCell(int row, int column, int numRows, int numCols);
/**
+ * Returns the set of table cells.
+ */
+ QSet<TableCell> cells() const;
+
+ /**
* Returns the set of selected cells.
*/
const QSet<TableCell>& selectedCells() const { return m_selection; }
@@ -461,6 +470,24 @@
/// Returns the bottom border of this table.
TableBorder bottomBorder() const;
+ /// Set tabme borders
+ void setBorders(const TableBorder& border, TableSides selectedSides);
+
+ /// Set cell borders
+ void setCellBorders(const TableBorder& border, TableSides selectedSides);
+
+ /// Set cell borders
+ void setCellBorders(const QSet<TableCell>& cells, const TableBorder& border, TableSides selectedSides);
+
+ /// Sets the cell fill color of this table to @a fillColor.
+ void setCellFillColor(const QString& fillColor);
+
+ /// Sets the cell fill color of this table to @a fillShade.
+ void setCellFillShade(double fillShade);
+
+ /// Sets the cell style of this table to @a cellStyle.
+ void setCellStyle(const QString& cellStyle);
+
/// Sets the table style of this table to @a style.
void setStyle(const QString& style);
@@ -529,6 +556,9 @@
/// creates valid layout information
void layout() override;
+
+ /** @brief Perform undo/redo action */
+ void restore(UndoState *state, bool isUndo) override;
signals:
/// This signal is emitted whenever the table changes.
@@ -554,6 +584,8 @@
ColumnsRemoved /**< Columns were removed. */
};
+ using TableBorderTuple = std::tuple<TableBorder, TableBorder, TableBorder, TableBorder, TableBorder>;
+
/**
* Initializes the table with @a numRows rows and @a numColumns columns.
*
@@ -610,6 +642,63 @@
/// Table sanity check. Very slow. For internal use.
void assertValid() const;
+ // Undo/redo setCellFillColor action
+ void restoreCellBorders(SimpleState *state, bool isUndo);
+
+ // Undo/redo setCellFillColor action
+ void restoreCellFillColor(SimpleState *state, bool isUndo);
+
+ // Undo/redo setCellFillColor action
+ void restoreCellFillShade(SimpleState *state, bool isUndo);
+
+ // Undo/redo setCellStyle action
+ void restoreCellStyle(SimpleState *state, bool isUndo);
+
+ // Undo/redo setFillColor action
+ void restoreTableFillColor(SimpleState *state, bool isUndo);
+
+ // Undo/redo unsetFillColor action
+ void restoreTableFillColorReset(SimpleState *state, bool isUndo);
+
+ // Undo/redo setFillShade action
+ void restoreTableFillShade(SimpleState *state, bool isUndo);
+
+ // Undo/redo unsetFillShade action
+ void restoreTableFillShadeReset(SimpleState *state, bool isUndo);
+
+ // Undo/redo setBorders action
+ void restoreTableBorders(SimpleState *state, bool isUndo);
+
+ // Undo/redo setLeftBorder action
+ void restoreTableLeftBorder(SimpleState *state, bool isUndo);
+
+ // Undo/redo unsetLeftBorder action
+ void restoreTableLeftBorderReset(SimpleState *state, bool isUndo);
+
+ // Undo/redo setRightBorder action
+ void restoreTableRightBorder(SimpleState *state, bool isUndo);
+
+ // Undo/redo unsetRightBorder action
+ void restoreTableRightBorderReset(SimpleState *state, bool isUndo);
+
+ // Undo/redo setBottomBorder action
+ void restoreTableBottomBorder(SimpleState *state, bool isUndo);
+
+ // Undo/redo unsetBottomBorder action
+ void restoreTableBottomBorderReset(SimpleState *state, bool isUndo);
+
+ // Undo/redo setTopBorder action
+ void restoreTableTopBorder(SimpleState *state, bool isUndo);
+
+ // Undo/redo unsetTopBorder action
+ void restoreTableTopBorderReset(SimpleState *state, bool isUndo);
+
+ // Undo/redo setStyle action
+ void restoreTableStyle(SimpleState *state, bool isUndo);
+
+ // Undo/redo unsetStyle action
+ void restoreTableStyleReset(SimpleState *state, bool isUndo);
+
private:
//<<Data we need to save
/// List of rows of cells in the table.
Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Sun Dec 26 17:34:08 2021
@@ -39,6 +39,7 @@
#include <QProgressBar>
#include <QRandomGenerator>
#include <QRegExp>
+#include <QScopedValueRollback>
#include <QtAlgorithms>
#include <QTime>
#include <QTransform>
@@ -7840,8 +7841,6 @@
itemSelection_ApplyCharStyle(newStyle, customSelection, "NAMED_STYLE");
}
-
-
void ScribusDoc::itemSelection_SetNamedParagraphStyle(const QString& name, Selection* customSelection)
{
ParagraphStyle newStyle;
@@ -7849,11 +7848,10 @@
itemSelection_ApplyParagraphStyle(newStyle, customSelection, false);
}
-
void ScribusDoc::itemSelection_SetNamedLineStyle(const QString &name, Selection* customSelection)
{
Selection* itemSelection = (customSelection != nullptr) ? customSelection : m_Selection;
- uint docSelectionCount = itemSelection->count();
+ int docSelectionCount = itemSelection->count();
if (docSelectionCount <= 0)
return;
@@ -7861,9 +7859,9 @@
m_updateManager.setUpdatesDisabled();
if (UndoManager::undoEnabled() && docSelectionCount > 1)
activeTransaction = m_undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::LineStyle, name, Um::ILineStyle);
- for (uint aa = 0; aa < docSelectionCount; ++aa)
- {
- PageItem *currItem = itemSelection->itemAt(aa);
+ for (int i = 0; i < docSelectionCount; ++i)
+ {
+ PageItem *currItem = itemSelection->itemAt(i);
currItem->setCustomLineStyle(name);
currItem->update();
}
@@ -7873,6 +7871,57 @@
changed();
}
+void ScribusDoc::itemSelection_SetNamedCellStyle(const QString & name, Selection* customSelection)
+{
+ Selection* itemSelection = (customSelection != nullptr) ? customSelection : m_Selection;
+ int docSelectionCount = itemSelection->count();
+ if (docSelectionCount <= 0)
+ return;
+
+ UndoTransaction activeTransaction;
+ m_updateManager.setUpdatesDisabled();
+ if (UndoManager::undoEnabled() && docSelectionCount > 1)
+ activeTransaction = m_undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::CellStyle, name, Um::ITable);
+ for (int i = 0; i < docSelectionCount; ++i)
+ {
+ PageItem *currItem = itemSelection->itemAt(i);
+ PageItem_Table* tableItem = currItem->asTable();
+ if (!tableItem)
+ continue;
+ tableItem->setCellStyle(name);
+ tableItem->update();
+ }
+ if (activeTransaction)
+ activeTransaction.commit();
+ m_updateManager.setUpdatesEnabled();
+ changed();
+}
+
+void ScribusDoc::itemSelection_SetNamedTableStyle(const QString & name, Selection* customSelection)
+{
+ Selection* itemSelection = (customSelection != nullptr) ? customSelection : m_Selection;
+ int docSelectionCount = itemSelection->count();
+ if (docSelectionCount <= 0)
+ return;
+
+ UndoTransaction activeTransaction;
+ m_updateManager.setUpdatesDisabled();
+ if (UndoManager::undoEnabled() && docSelectionCount > 1)
+ activeTransaction = m_undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::TableStyle, name, Um::ITable);
+ for (int i = 0; i < docSelectionCount; ++i)
+ {
+ PageItem *currItem = itemSelection->itemAt(i);
+ PageItem_Table* tableItem = currItem->asTable();
+ if (!tableItem)
+ continue;
+ tableItem->setStyle(name);
+ tableItem->update();
+ }
+ if (activeTransaction)
+ activeTransaction.commit();
+ m_updateManager.setUpdatesEnabled();
+ changed();
+}
void ScribusDoc::itemSelection_SetItemPen(QString color, Selection* customSelection)
{
@@ -8409,7 +8458,7 @@
QScopedPointer<InsertTableRowsDialog> dialog(new InsertTableRowsDialog(appMode, m_ScMW));
if (dialog->exec() == QDialog::Accepted)
{
- dontResize = true;
+ QScopedValueRollback<bool> dontResizeRb(dontResize, true);
/*
* In table edit mode we insert either before or after the active
* cell, otherwise we insert at beginning or end of table.
@@ -8445,7 +8494,7 @@
QPointer<InsertTableColumnsDialog> dialog = new InsertTableColumnsDialog(appMode, m_ScMW);
if (dialog->exec() == QDialog::Accepted)
{
- dontResize = true;
+ QScopedValueRollback<bool> dontResizeRb(dontResize, true);
/*
* In table edit mode we insert either before or after the active
* cell, otherwise we insert at beginning or end of table.
@@ -8486,7 +8535,8 @@
if (table->selectedRows().size() >= table->rows())
return;
- dontResize = true;
+ QScopedValueRollback<bool> dontResizeRb(dontResize, true);
+
if (table->selectedRows().isEmpty())
{
// Remove rows spanned by active cell.
@@ -8542,7 +8592,8 @@
if (table->selectedColumns().size() >= table->columns())
return;
- dontResize = true;
+ QScopedValueRollback<bool> dontResizeRb(dontResize, true);
+
if (table->selectedColumns().isEmpty())
{
// Remove columns spanned by active cell.
@@ -8608,7 +8659,7 @@
const int numRows = selectedRows.last() - row + 1;
const int numColumns = selectedColumns.last() - column + 1;
- dontResize = true;
+ QScopedValueRollback<bool> dontResizeRb(dontResize, true);
table->mergeCells(row, column, numRows, numColumns);
m_View->stopGesture(); // FIXME: Don't use m_View.
@@ -8634,7 +8685,8 @@
return;
const qreal rowHeight = dialog->rowHeight();
- dontResize = true;
+ QScopedValueRollback<bool> dontResizeRb(dontResize, true);
+
if (appMode == modeEditTable)
{
if (table->selectedCells().isEmpty())
@@ -8664,6 +8716,7 @@
table->adjustTable();
table->update();
+
changed();
}
@@ -8682,7 +8735,8 @@
return;
const qreal columnWidth = dialog->columnWidth();
- dontResize = true;
+ QScopedValueRollback<bool> dontResizeRb(dontResize, true);
+
if (appMode == modeEditTable)
{
if (table->selectedCells().isEmpty())
@@ -8724,8 +8778,8 @@
PageItem_Table* table = item->asTable();
if (!table)
return;
-
- dontResize = true;
+ QScopedValueRollback<bool> dontResizeRb(dontResize, true);
+
if (appMode == modeEditTable && !table->selectedRows().isEmpty())
{
// Distribute each contiguous range of selected rows.
@@ -8767,8 +8821,8 @@
PageItem_Table* table = item->asTable();
if (!table)
return;
-
- dontResize = true;
+ QScopedValueRollback<bool> dontResizeRb(dontResize, true);
+
if (appMode == modeEditTable && !table->selectedColumns().isEmpty())
{
// Distribute each contiguous range of selected columns.
Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Sun Dec 26 17:34:08 2021
@@ -1114,6 +1114,8 @@
void itemSelection_SetNamedParagraphStyle(const QString & name, Selection* customSelection = nullptr);
void itemSelection_SetNamedCharStyle(const QString & name, Selection* customSelection = nullptr);
void itemSelection_SetNamedLineStyle(const QString & name, Selection* customSelection = nullptr);
+ void itemSelection_SetNamedCellStyle(const QString & name, Selection* customSelection = nullptr);
+ void itemSelection_SetNamedTableStyle(const QString & name, Selection* customSelection = nullptr);
void itemSelection_SetSoftShadow(bool has, QString color, double dx, double dy, double radius, int shade, double opac, int blend, bool erase, bool objopa);
void itemSelection_SetLineWidth(double w, Selection* customSelection = nullptr);
void itemSelection_SetLineArt(Qt::PenStyle w, Selection* customSelection = nullptr);
Modified: trunk/Scribus/scribus/scribusstructs.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/scribusstructs.h
==============================================================================
--- trunk/Scribus/scribus/scribusstructs.h (original)
+++ trunk/Scribus/scribus/scribusstructs.h Sun Dec 26 17:34:08 2021
@@ -77,9 +77,6 @@
int FirstPage;
int Rows;
int Columns;
-// double GapHorizontal;
-// double GapVertical;
-// double GapBelow;
QStringList pageNames;
};
@@ -132,6 +129,22 @@
GradMask_PatternLumAlphaInverted = 7,
GradMask_PatternInverted = 8
};
+
+/**
+ * This enum describes the sides that can be selected. A selection can be
+ * expressed as an ORed combination of Left, Right, Top and Bottom.
+ */
+enum class TableSide
+{
+ None = 0, /**< None of the sides are selected. */
+ Left = 1, /**< The left side is selected. */
+ Right = 2, /**< The right side is selected. */
+ Top = 4, /**< The top side is selected. */
+ Bottom = 8, /**< The bottom side is selected. */
+ All = Left | Right | Top | Bottom
+};
+Q_DECLARE_FLAGS(TableSides, TableSide)
+Q_DECLARE_OPERATORS_FOR_FLAGS(TableSides)
struct SingleLine
{
@@ -163,6 +176,15 @@
}
};
+class multiLine : public QList<SingleLine> {
+public:
+ QString shortcut;
+ bool operator!=(const multiLine& other) const
+ {
+ return !(this->operator ==(other));
+ }
+};
+
struct Bullet //used by style reader while importing ODT files
{
QString name;
@@ -186,7 +208,7 @@
struct ArrowDesc
{
QString name;
- bool userArrow;
+ bool userArrow { false };
FPointArray points;
};
@@ -263,16 +285,6 @@
};
typedef QMap<QString,QString> ProfilesL;
-// typedef QValueVector<SingleLine> multiLine;
-
-class multiLine : public QList<SingleLine> {
-public:
- QString shortcut;
- bool operator!=(const multiLine& other) const
- {
- return !(this->operator ==(other));
- }
-};
enum PreflightError
{
@@ -361,13 +373,6 @@
//! \brief Common type for guides list
typedef QList<double> Guides;
-//! \brief from ols scribusXml
-struct Linked
-{
- int Start;
- int StPag;
-};
-
// this is a quick hack to combine runs until I've thought of something better -- AV
class LastStyles
{
Modified: trunk/Scribus/scribus/tablecell.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/tablecell.h
==============================================================================
--- trunk/Scribus/scribus/tablecell.h (original)
+++ trunk/Scribus/scribus/tablecell.h Sun Dec 26 17:34:08 2021
@@ -248,6 +248,8 @@
private:
friend class PageItem_Table;
+ friend bool operator<(const TableCell& cell1, const TableCell& cell2);
+
QExplicitlySharedDataPointer<TableCellData> d;
};
Q_DECLARE_TYPEINFO(TableCell, Q_MOVABLE_TYPE);
@@ -257,6 +259,15 @@
return (cell.row() << 16) ^ cell.column();
}
+inline bool operator<(const TableCell& cell1, const TableCell& cell2)
+{
+ if (cell1.row() < cell2.row())
+ return true;
+ if (cell1.row() > cell2.row())
+ return false;
+ return (cell1.column() < cell2.column());
+}
+
QDebug operator<<(QDebug debug, const TableCell& cell);
#endif // TABLECELL_H
Modified: trunk/Scribus/scribus/ui/propertiespalette_table.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/ui/propertiespalette_table.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette_table.cpp (original)
+++ trunk/Scribus/scribus/ui/propertiespalette_table.cpp Sun Dec 26 17:34:08 2021
@@ -25,6 +25,8 @@
#include "selection.h"
#include "tableborder.h"
#include "tablesideselector.h"
+#include "undomanager.h"
+#include "undotransaction.h"
#include "util.h"
#include "util_color.h"
@@ -139,12 +141,7 @@
else
m_item = nullptr;
- // HACK: Guard against "false" re-selections resulting from m_item->update().
- if (m_item == m_previousItem)
- return;
- m_previousItem = m_item;
-
- sideSelector->setSelection(TableSideSelector::All);
+ sideSelector->setSelection(TableSide::All);
updateFillControls();
updateStyleControls();
@@ -221,32 +218,7 @@
return;
QScopedValueRollback<bool> dontResizeRb(m_doc->dontResize, true);
- PageItem_Table* table = m_item->asTable();
- if (m_doc->appMode != modeEditTable)
- {
- for (int row = 0; row < table->rows(); ++row)
- {
- int colSpan = 0;
- for (int col = 0; col < table->columns(); col += colSpan)
- {
- TableCell currentCell = table->cellAt(row, col);
- if (row == currentCell.row())
- currentCell.setStyle(name);
- colSpan = currentCell.columnSpan();
- }
- }
- }
- else
- {
- QSet<TableCell> cells = table->selectedCells();
- if (cells.isEmpty())
- cells.insert(table->activeCell());
- for (auto cellIter = cells.begin(); cellIter != cells.end(); cellIter++)
- {
- TableCell currentCell(*cellIter);
- currentCell.setStyle(name);
- }
- }
+ m_doc->itemSelection_SetNamedCellStyle(name);
m_item->asTable()->update();
showCellStyle(name);
@@ -266,11 +238,11 @@
*/
State borderState = Unset;
m_currentBorder = TableBorder();
- TableSideSelector::Sides selectedSides = sideSelector->selection();
+ TableSides selectedSides = sideSelector->selection();
PageItem_Table* table = m_item->asTable();
bool tableEditMode = (m_doc->appMode == modeEditTable);
- if (selectedSides & TableSideSelector::Left)
+ if (selectedSides & TableSide::Left)
{
TableBorder leftBorder = tableEditMode ? table->activeCell().leftBorder() : table->leftBorder();
if (borderState == Unset && !leftBorder.isNull())
@@ -282,7 +254,7 @@
borderState = TriState;
}
- if (selectedSides & TableSideSelector::Right)
+ if (selectedSides & TableSide::Right)
{
TableBorder rightBorder = tableEditMode ? table->activeCell().rightBorder() : table->rightBorder();
if (borderState == Unset && !rightBorder.isNull())
@@ -294,7 +266,7 @@
borderState = TriState;
}
- if (selectedSides & TableSideSelector::Top)
+ if (selectedSides & TableSide::Top)
{
TableBorder topBorder = tableEditMode ? table->activeCell().topBorder() : table->topBorder();
if (borderState == Unset && !table->topBorder().isNull())
@@ -306,7 +278,7 @@
borderState = TriState;
}
- if (selectedSides & TableSideSelector::Bottom)
+ if (selectedSides & TableSide::Bottom)
{
TableBorder bottomBorder = tableEditMode ? table->activeCell().bottomBorder() : table->bottomBorder();
if (borderState == Unset && !bottomBorder.isNull())
@@ -381,6 +353,9 @@
void PropertiesPalette_Table::updateBorderLineListItem()
{
QListWidgetItem* item = borderLineList->currentItem();
+ if (!item)
+ return;
+
QString text = QString(" %1%2 %3").arg(borderLineWidth->getValue()).arg(borderLineWidth->suffix(), CommonStrings::translatePenStyleName(static_cast<Qt::PenStyle>(borderLineStyle->currentIndex() + 1)));
if (borderLineColor->currentColor() != CommonStrings::None)
{
@@ -551,28 +526,23 @@
{
if (!m_item || !m_item->isTable())
return;
+
+ UndoTransaction activeTransaction;
+ if (UndoManager::undoEnabled())
+ activeTransaction = UndoManager::instance()->beginTransaction(m_item->getUName(), m_item->getUPixmap(), Um::CellFillColor, QString(), Um::ITable);
+
QString color = colorName;
if (colorName == CommonStrings::tr_NoneColor)
color = CommonStrings::None;
+
PageItem_Table* table = m_item->asTable();
if (m_doc->appMode != modeEditTable)
- {
table->setFillColor(color);
- table->setFillShade(fillShade->value());
- }
- else
- {
- QSet<TableCell> cells = table->selectedCells();
- if (cells.isEmpty())
- cells.insert(table->activeCell());
- QSet<TableCell>::Iterator cellIter;
- for (cellIter = cells.begin(); cellIter != cells.end(); cellIter++)
- {
- TableCell currentCell(*cellIter);
- currentCell.setFillColor(color);
- currentCell.setFillShade(fillShade->value());
- }
- }
+ else
+ table->setCellFillColor(color);
+
+ if (activeTransaction)
+ activeTransaction.commit();
table->update();
}
@@ -581,29 +551,24 @@
{
if (!m_item || !m_item->isTable())
return;
+
+ UndoTransaction activeTransaction;
+ if (UndoManager::undoEnabled())
+ activeTransaction = UndoManager::instance()->beginTransaction(m_item->getUName(), m_item->getUPixmap(), Um::CellFillShade, QString(), Um::ITable);
QString color = fillColor->currentColor();
if (color == CommonStrings::tr_NoneColor)
color = CommonStrings::None;
+
PageItem_Table* table = m_item->asTable();
if (m_doc->appMode != modeEditTable)
- {
- table->setFillColor(color);
table->setFillShade(shade);
- }
- else
- {
- QSet<TableCell> cells = table->selectedCells();
- if (cells.isEmpty())
- cells.insert(table->activeCell());
- QSet<TableCell>::Iterator cellIter;
- for (cellIter = cells.begin(); cellIter != cells.end(); cellIter++)
- {
- TableCell currentCell(*cellIter);
- currentCell.setFillColor(color);
- currentCell.setFillShade(shade);
- }
- }
+ else
+ table->setCellFillShade(fillShade->value());
+
+ if (activeTransaction)
+ activeTransaction.commit();
+
table->update();
}
@@ -660,39 +625,18 @@
QScopedValueRollback<bool> dontResizeRb(m_doc->dontResize, true);
PageItem_Table* table = m_item->asTable();
- TableSideSelector::Sides selectedSides = sideSelector->selection();
+ TableSides selectedSides = sideSelector->selection();
if (m_doc->appMode != modeEditTable)
{
- if (selectedSides & TableSideSelector::Left)
- table->setLeftBorder(m_currentBorder);
- if (selectedSides & TableSideSelector::Right)
- table->setRightBorder(m_currentBorder);
- if (selectedSides & TableSideSelector::Top)
- table->setTopBorder(m_currentBorder);
- if (selectedSides & TableSideSelector::Bottom)
- table->setBottomBorder(m_currentBorder);
+ table->setBorders(m_currentBorder, selectedSides);
}
else
{
QSet<TableCell> cells = table->selectedCells();
if (cells.isEmpty())
cells.insert(table->activeCell());
- QSet<TableCell>::Iterator cellIter;
- for (cellIter = cells.begin(); cellIter != cells.end(); cellIter++)
- {
- TableCell currentCell(*cellIter);
- if (selectedSides & TableSideSelector::Left)
- currentCell.setLeftBorder(m_currentBorder);
- if (selectedSides & TableSideSelector::Right)
- currentCell.setRightBorder(m_currentBorder);
- if (selectedSides & TableSideSelector::Top)
- currentCell.setTopBorder(m_currentBorder);
- if (selectedSides & TableSideSelector::Bottom)
- currentCell.setBottomBorder(m_currentBorder);
- }
- }
-
- table->adjustTable();
+ table->setCellBorders(cells, m_currentBorder, selectedSides);
+ }
table->update();
}
Modified: trunk/Scribus/scribus/ui/propertiespalette_table.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/ui/propertiespalette_table.h
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette_table.h (original)
+++ trunk/Scribus/scribus/ui/propertiespalette_table.h Sun Dec 26 17:34:08 2021
@@ -123,8 +123,6 @@
ScGuardedPtr<ScribusDoc> m_doc;
/// The currently edited item.
PageItem* m_item {nullptr};
- /// The previous edited selected items.
- PageItem* m_previousItem {nullptr};
/// The currently edited border.
TableBorder m_currentBorder;
Modified: trunk/Scribus/scribus/ui/smcellstyle.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/ui/smcellstyle.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/smcellstyle.cpp (original)
+++ trunk/Scribus/scribus/ui/smcellstyle.cpp Sun Dec 26 17:34:08 2021
@@ -135,7 +135,21 @@
void SMCellStyle::toSelection(const QString &styleName) const
{
- // TODO: Implement this once we have cell items.
+ if (!m_doc)
+ return; // nowhere to apply or no doc
+
+ QString realName = styleName;
+ int styleIndex = m_cachedStyles.find(styleName);
+ if (styleIndex < 0 && (styleName == CommonStrings::trDefaultCellStyle))
+ {
+ styleIndex = m_cachedStyles.find(CommonStrings::DefaultCellStyle);
+ if (styleIndex >= 0)
+ realName = CommonStrings::DefaultCellStyle;
+ }
+ if (styleIndex >= 0)
+ {
+ m_doc->itemSelection_SetNamedCellStyle(realName);
+ }
}
QString SMCellStyle::newStyle()
Modified: trunk/Scribus/scribus/ui/smtablestyle.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/ui/smtablestyle.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/smtablestyle.cpp (original)
+++ trunk/Scribus/scribus/ui/smtablestyle.cpp Sun Dec 26 17:34:08 2021
@@ -135,7 +135,21 @@
void SMTableStyle::toSelection(const QString &styleName) const
{
- // TODO: Implement this once we have table items.
+ if (!m_doc)
+ return; // nowhere to apply or no doc
+
+ QString realName = styleName;
+ int styleIndex = m_cachedStyles.find(styleName);
+ if (styleIndex < 0 && (styleName == CommonStrings::trDefaultTableStyle))
+ {
+ styleIndex = m_cachedStyles.find(CommonStrings::DefaultTableStyle);
+ if (styleIndex >= 0)
+ realName = CommonStrings::DefaultTableStyle;
+ }
+ if (styleIndex >= 0)
+ {
+ m_doc->itemSelection_SetNamedTableStyle(realName);
+ }
}
QString SMTableStyle::newStyle()
Modified: trunk/Scribus/scribus/ui/tablesideselector.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/ui/tablesideselector.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/tablesideselector.cpp (original)
+++ trunk/Scribus/scribus/ui/tablesideselector.cpp Sun Dec 26 17:34:08 2021
@@ -26,7 +26,7 @@
TableSideSelector::TableSideSelector(QWidget* parent) : QFrame(parent)
{
- setSelection(All);
+ setSelection(TableSide::All);
setStyle(TableStyle);
setFrameShape(QFrame::StyledPanel);
setFrameShadow(QFrame::Sunken);
@@ -34,17 +34,17 @@
setMouseTracking(true);
}
-QList<TableSideSelector::Side> TableSideSelector::selectionList() const
+QList<TableSide> TableSideSelector::selectionList() const
{
- QList<Side> sides;
- if (m_selection & Left)
- sides.append(Left);
- if (m_selection & Right)
- sides.append(Right);
- if (m_selection & Top)
- sides.append(Top);
- if (m_selection & Bottom)
- sides.append(Bottom);
+ QList<TableSide> sides;
+ if (m_selection & TableSide::Left)
+ sides.append(TableSide::Left);
+ if (m_selection & TableSide::Right)
+ sides.append(TableSide::Right);
+ if (m_selection & TableSide::Top)
+ sides.append(TableSide::Top);
+ if (m_selection & TableSide::Bottom)
+ sides.append(TableSide::Bottom);
return sides;
}
@@ -67,10 +67,10 @@
// Paint selection.
painter.setPen(QPen(Qt::black, edgeWidth, Qt::SolidLine, Qt::RoundCap));
- if (m_selection & Left) painter.drawLine(m_left);
- if (m_selection & Right) painter.drawLine(m_right);
- if (m_selection & Top) painter.drawLine(m_top);
- if (m_selection & Bottom) painter.drawLine(m_bottom);
+ if (m_selection & TableSide::Left) painter.drawLine(m_left);
+ if (m_selection & TableSide::Right) painter.drawLine(m_right);
+ if (m_selection & TableSide::Top) painter.drawLine(m_top);
+ if (m_selection & TableSide::Bottom) painter.drawLine(m_bottom);
// Paint the dotted grid.
painter.setPen(QPen(Qt::gray, edgeWidth/4, Qt::DotLine));
@@ -82,16 +82,16 @@
painter.setPen(QPen(QColor(255, 255, 255, 60), edgeWidth, Qt::SolidLine, Qt::RoundCap));
switch (m_highlighted)
{
- case Left:
+ case TableSide::Left:
painter.drawLine(m_left);
break;
- case Right:
+ case TableSide::Right:
painter.drawLine(m_right);
break;
- case Top:
+ case TableSide::Top:
painter.drawLine(m_top);
break;
- case Bottom:
+ case TableSide::Bottom:
painter.drawLine(m_bottom);
break;
default:
@@ -115,17 +115,17 @@
void TableSideSelector::leaveEvent(QEvent* event)
{
Q_UNUSED(event);
- m_highlighted = None;
+ m_highlighted = TableSide::None;
update();
}
-TableSideSelector::Side TableSideSelector::closestSide(const QPointF& point) const
+TableSide TableSideSelector::closestSide(const QPointF& point) const
{
- QList<QPair<double, Side> > distances;
- distances.append(QPair<double, Side>(QLineF(point, m_left.pointAt(0.5)).length(), Left));
- distances.append(QPair<double, Side>(QLineF(point, m_right.pointAt(0.5)).length(), Right));
- distances.append(QPair<double, Side>(QLineF(point, m_top.pointAt(0.5)).length(), Top));
- distances.append(QPair<double, Side>(QLineF(point, m_bottom.pointAt(0.5)).length(), Bottom));
+ QList<QPair<double, TableSide> > distances;
+ distances.append(QPair<double, TableSide>(QLineF(point, m_left.pointAt(0.5)).length(), TableSide::Left));
+ distances.append(QPair<double, TableSide>(QLineF(point, m_right.pointAt(0.5)).length(), TableSide::Right));
+ distances.append(QPair<double, TableSide>(QLineF(point, m_top.pointAt(0.5)).length(), TableSide::Top));
+ distances.append(QPair<double, TableSide>(QLineF(point, m_bottom.pointAt(0.5)).length(), TableSide::Bottom));
std::sort(distances.begin(), distances.end());
return distances.first().second;
Modified: trunk/Scribus/scribus/ui/tablesideselector.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/ui/tablesideselector.h
==============================================================================
--- trunk/Scribus/scribus/ui/tablesideselector.h (original)
+++ trunk/Scribus/scribus/ui/tablesideselector.h Sun Dec 26 17:34:08 2021
@@ -14,6 +14,8 @@
#include <QList>
#include <QFrame>
+#include "scribusstructs.h"
+
class QPaintEvent;
class QMouseEvent;
class QEvent;
@@ -27,25 +29,10 @@
{
Q_OBJECT
- Q_PROPERTY(Sides selection READ selection WRITE setSelection RESET clearSelection NOTIFY selectionChanged)
+ Q_PROPERTY(TableSides selection READ selection WRITE setSelection RESET clearSelection NOTIFY selectionChanged)
Q_PROPERTY(Style style READ style WRITE setStyle)
public:
- /**
- * This enum describes the sides that can be selected. A selection can be
- * expressed as an ORed combination of Left, Right, Top and Bottom.
- */
- enum Side
- {
- None = 0, /**< None of the sides are selected. */
- Left = 1, /**< The left side is selected. */
- Right = 2, /**< The right side is selected. */
- Top = 4, /**< The top side is selected. */
- Bottom = 8, /**< The bottom side is selected. */
- All = Left | Right | Top | Bottom
- };
- Q_DECLARE_FLAGS(Sides, Side)
-
/**
* This enum describes two possible styles for the selector. If the cell style is used,
* the selector will resemble a cell. In the table style, a table.
@@ -60,16 +47,16 @@
TableSideSelector(QWidget* parent);
/// Returns the current selection as an ORed combination of enum flags.
- Sides selection() const { return m_selection; }
+ TableSides selection() const { return m_selection; }
/// Returns the current selection as a list of enum values.
- QList<TableSideSelector::Side> selectionList() const;
+ QList<TableSide> selectionList() const;
/// Sets the current selection to @a selection.
- void setSelection(Sides selection) { m_selection = selection; emit selectionChanged(); }
+ void setSelection(TableSides selection) { m_selection = selection; emit selectionChanged(); }
/// Clears the current selection.
- void clearSelection() { m_selection = None; emit selectionChanged(); }
+ void clearSelection() { m_selection = TableSide::None; emit selectionChanged(); }
/// Returns the current style of the selector.
Style style() const { return m_style; }
@@ -99,17 +86,17 @@
private:
/// Utility function to return the side closest to @a point.
- Side closestSide(const QPointF& point) const;
+ TableSide closestSide(const QPointF& point) const;
private:
/// The current selection.
- Sides m_selection;
+ TableSides m_selection;
/// The current style of the selector.
Style m_style;
/// The side currently closest to the mouse pointer.
- Side m_highlighted;
+ TableSide m_highlighted;
/// The left side line.
QLineF m_left;
@@ -124,6 +111,4 @@
QLineF m_bottom;
};
-Q_DECLARE_OPERATORS_FOR_FLAGS(TableSideSelector::Sides)
-
#endif // TABLESIDESELECTOR_H
Modified: trunk/Scribus/scribus/undomanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/undomanager.cpp
==============================================================================
--- trunk/Scribus/scribus/undomanager.cpp (original)
+++ trunk/Scribus/scribus/undomanager.cpp Sun Dec 26 17:34:08 2021
@@ -648,6 +648,24 @@
UndoManager::StartAndEndArrow = tr("Set start and end arrows");
UndoManager::CreateTable = tr("Create table");
UndoManager::RowsCols = tr("Rows: %1, Cols: %2");
+ UndoManager::CellBorders = tr("Set cell borders");
+ UndoManager::CellFillColor = tr("Set cell fill color");
+ UndoManager::CellFillShade = tr("Set cell fill shade");
+ UndoManager::CellStyle = tr("Set cell style");
+ UndoManager::TableFillColor = tr("Set table fill color");
+ UndoManager::TableFillColorRst = tr("Reset table fill color");
+ UndoManager::TableFillShade = tr("Set table fill shade");
+ UndoManager::TableFillShadeRst = tr("Reset table fill shade");
+ UndoManager::TableBorders = tr("Set table borders");
+ UndoManager::TableLeftBorder = tr("Set table left border");
+ UndoManager::TableLeftBorderRst = tr("Reset table left border");
+ UndoManager::TableRightBorder = tr("Set table right border");
+ UndoManager::TableRightBorderRst = tr("Reset table right border");
+ UndoManager::TableBottomBorder = tr("Set table bottom border");
+ UndoManager::TableBottomBorderRst = tr("Reset table bottom border");
+ UndoManager::TableTopBorder = tr("Set table top border");
+ UndoManager::TableTopBorderRst = tr("Reset table top border");
+ UndoManager::TableStyle = tr("Set table style");
UndoManager::SetFont = tr("Set font");
UndoManager::SetFontSize = tr("Set font size");
UndoManager::StartArrowScale = tr("Set start arrow scale");
@@ -968,6 +986,24 @@
QString UndoManager::StartAndEndArrow = "";
QString UndoManager::CreateTable = "";
QString UndoManager::RowsCols = "";
+QString UndoManager::CellBorders = "";
+QString UndoManager::CellFillColor = "";
+QString UndoManager::CellFillShade = "";
+QString UndoManager::CellStyle = "";
+QString UndoManager::TableFillColor = "";
+QString UndoManager::TableFillColorRst = "";
+QString UndoManager::TableFillShade = "";
+QString UndoManager::TableFillShadeRst = "";
+QString UndoManager::TableBorders = "";
+QString UndoManager::TableLeftBorder = "";
+QString UndoManager::TableLeftBorderRst = "";
+QString UndoManager::TableRightBorder = "";
+QString UndoManager::TableRightBorderRst = "";
+QString UndoManager::TableBottomBorder = "";
+QString UndoManager::TableBottomBorderRst = "";
+QString UndoManager::TableTopBorder = "";
+QString UndoManager::TableTopBorderRst = "";
+QString UndoManager::TableStyle = "";
QString UndoManager::SetFont = "";
QString UndoManager::SetFontSize = "";
QString UndoManager::SetFontWidth = "";
Modified: trunk/Scribus/scribus/undomanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24782&path=/trunk/Scribus/scribus/undomanager.h
==============================================================================
--- trunk/Scribus/scribus/undomanager.h (original)
+++ trunk/Scribus/scribus/undomanager.h Sun Dec 26 17:34:08 2021
@@ -429,6 +429,24 @@
static QString StartAndEndArrow;
static QString CreateTable;
static QString RowsCols;
+ static QString CellBorders;
+ static QString CellFillColor;
+ static QString CellFillShade;
+ static QString CellStyle;
+ static QString TableFillColor;
+ static QString TableFillColorRst;
+ static QString TableFillShade;
+ static QString TableFillShadeRst;
+ static QString TableBorders;
+ static QString TableLeftBorder;
+ static QString TableLeftBorderRst;
+ static QString TableRightBorder;
+ static QString TableRightBorderRst;
+ static QString TableBottomBorder;
+ static QString TableBottomBorderRst;
+ static QString TableTopBorder;
+ static QString TableTopBorderRst;
+ static QString TableStyle;
static QString SetFont;
static QString SetFontSize;
static QString SetFontWidth;
More information about the scribus-commit
mailing list