r17327 by fschmid - Tables: more work on making table editing working correctly.

scribus-commit scribus-commit at lists.scribus.net
Thu Feb 23 22:46:49 UTC 2012


Author: fschmid
Date: Thu Feb 23 22:46:49 2012
New Revision: 17327

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17327
Log:
Tables: more work on making table editing working correctly.

Modified:
    trunk/Scribus/scribus/canvasgesture_resize.cpp
    trunk/Scribus/scribus/pageitem_table.cpp
    trunk/Scribus/scribus/pageitem_table.h
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/ui/propertiespalette.cpp
    trunk/Scribus/scribus/ui/propertiespalette_table.cpp
    trunk/Scribus/scribus/ui/propertiespalette_table.h

Modified: trunk/Scribus/scribus/canvasgesture_resize.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17327&path=/trunk/Scribus/scribus/canvasgesture_resize.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasgesture_resize.cpp (original)
+++ trunk/Scribus/scribus/canvasgesture_resize.cpp Thu Feb 23 22:46:49 2012
@@ -31,6 +31,7 @@
 #include "undomanager.h"
 #include "pageitem_arc.h"
 #include "pageitem_spiral.h"
+#include "pageitem_table.h"
 #include "util_math.h"
 
 ResizeGesture::ResizeGesture (CanvasMode* parent) : CanvasGesture(parent)
@@ -371,6 +372,8 @@
 			PageItem_Spiral* item = currItem->asSpiral();
 			item->recalcPath();
 		}
+		if (currItem->isTable())
+			currItem->asTable()->adjustTable();
 		// rotation does not change
 	}
 	m_origBounds = m_bounds;

Modified: trunk/Scribus/scribus/pageitem_table.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17327&path=/trunk/Scribus/scribus/pageitem_table.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_table.cpp (original)
+++ trunk/Scribus/scribus/pageitem_table.cpp Thu Feb 23 22:46:49 2012
@@ -61,6 +61,14 @@
 	delete m_tablePainter;
 }
 
+void PageItem_Table::adjustTable()
+{
+	doc()->dontResize = true;
+	adjustTableToFrame();
+	adjustFrameToTable();
+	doc()->dontResize = false;
+}
+
 void PageItem_Table::resize(double width, double height)
 {
 	ASSERT_VALID();
@@ -504,6 +512,7 @@
 		return;
 
 	m_selection.insert(cellAt(row, column));
+	emit selectionChanged();
 }
 
 void PageItem_Table::selectCells(int startRow, int startColumn, int endRow, int endColumn)
@@ -525,7 +534,6 @@
 	for (int row = topRow; row <= bottomRow; ++row)
 		for (int col = leftCol; col <= rightCol; ++col)
 			selectCell(row, col);
-
 	emit selectionChanged();
 }
 
@@ -575,8 +583,8 @@
 		return;
 
 	// Move active position left and activate cell at new position.
-	m_activeColumn = m_activeCell.column() - 1;
-	activateCell(cellAt(m_activeRow, m_activeColumn));
+//	m_activeColumn = m_activeCell.column() - 1;
+	activateCell(cellAt(m_activeRow, m_activeCell.column() - 1));
 }
 
 void PageItem_Table::moveRight()
@@ -585,8 +593,8 @@
 		return;
 
 	// Move active position right and activate cell at new position.
-	m_activeColumn = m_activeCell.column() + m_activeCell.columnSpan();
-	activateCell(cellAt(m_activeRow, m_activeColumn));
+//	m_activeColumn = m_activeCell.column() + m_activeCell.columnSpan();
+	activateCell(cellAt(m_activeRow, m_activeCell.column() + m_activeCell.columnSpan()));
 }
 
 void PageItem_Table::moveUp()
@@ -595,34 +603,33 @@
 		return;
 
 	// Move active position up and activate cell at new position.
-	m_activeRow = m_activeCell.row() - 1;
-	activateCell(cellAt(m_activeRow, m_activeColumn));
+//	m_activeRow = m_activeCell.row() - 1;
+	activateCell(cellAt(m_activeCell.row() - 1, m_activeColumn));
 }
 
 void PageItem_Table::moveDown()
 {
 	if (m_activeCell.row() + m_activeCell.rowSpan() >= rows())
 		return;
+	activateCell(cellAt(m_activeCell.row() + m_activeCell.rowSpan(), m_activeColumn));
 
 	// Deselect previous active cell and its text.
-	m_activeCell.textFrame()->setSelected(false);
-	m_activeCell.textFrame()->itemText.deselectAll();
+//	m_activeCell.textFrame()->setSelected(false);
+//	m_activeCell.textFrame()->itemText.deselectAll();
 
 	// Move active logical position down.
-	m_activeRow = m_activeCell.row() + m_activeCell.rowSpan();
+//	m_activeRow = m_activeCell.row() + m_activeCell.rowSpan();
 
 	// Set the new active cell and select it.
-	m_activeCell = cellAt(m_activeRow, m_activeColumn);
-	m_activeCell.textFrame()->setSelected(true);
-	m_Doc->currentStyle = m_activeCell.textFrame()->currentStyle();
+//	m_activeCell = cellAt(m_activeRow, m_activeColumn);
+//	m_activeCell.textFrame()->setSelected(true);
+//	m_Doc->currentStyle = m_activeCell.textFrame()->currentStyle();
 }
 
 void PageItem_Table::moveTo(const TableCell& cell)
 {
 	// Activate the cell and move active position to its top left.
 	activateCell(cell);
-	m_activeRow = activeCell().row();
-	m_activeColumn = activeCell().column();
 }
 
 TableHandle PageItem_Table::hitTest(const QPointF& point, double threshold) const
@@ -930,6 +937,9 @@
 	m_activeCell = newActiveCell;
 	m_activeCell.textFrame()->setSelected(true);
 	m_Doc->currentStyle = m_activeCell.textFrame()->currentStyle();
+	m_activeRow = m_activeCell.row();
+	m_activeColumn = m_activeCell.column();
+	emit selectionChanged();
 
 	ASSERT_VALID();
 }

Modified: trunk/Scribus/scribus/pageitem_table.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17327&path=/trunk/Scribus/scribus/pageitem_table.h
==============================================================================
--- trunk/Scribus/scribus/pageitem_table.h (original)
+++ trunk/Scribus/scribus/pageitem_table.h Thu Feb 23 22:46:49 2012
@@ -88,6 +88,9 @@
 	/// Destructor.
 	~PageItem_Table();
 
+	/// Resizes the table to fit the frame.
+	void adjustTable();
+
 	/// Returns the number of rows in the table.
 	int rows() const { return m_rows; }
 

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17327&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Thu Feb 23 22:46:49 2012
@@ -10034,8 +10034,19 @@
 	scrActions["tableSplitCells"]->setEnabled(false); // Not implemented.
 	scrActions["tableSetRowHeights"]->setEnabled(tableEdited);
 	scrActions["tableSetColumnWidths"]->setEnabled(tableEdited);
-	scrActions["tableDistributeRowsEvenly"]->setEnabled(selectedRows > 1);
-	scrActions["tableDistributeColumnsEvenly"]->setEnabled(selectedColumns > 1);
+	if (doc)
+	{
+		if (doc->appMode == modeEditTable)
+		{
+			scrActions["tableDistributeRowsEvenly"]->setEnabled(selectedRows > 1);
+			scrActions["tableDistributeColumnsEvenly"]->setEnabled(selectedColumns > 1);
+		}
+		else
+		{
+			scrActions["tableDistributeRowsEvenly"]->setEnabled(table);
+			scrActions["tableDistributeColumnsEvenly"]->setEnabled(table);
+		}
+	}
 	scrActions["tableAdjustFrameToTable"]->setEnabled(table);
 	scrActions["tableAdjustTableToFrame"]->setEnabled(table);
 }

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17327&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Thu Feb 23 22:46:49 2012
@@ -7405,6 +7405,7 @@
 	QPointer<InsertTableRowsDialog> dialog = new InsertTableRowsDialog(appMode, m_ScMW);
 	if (dialog->exec() == QDialog::Accepted)
 	{
+		dontResize = true;
 		/*
 		 * In table edit mode we insert either before or after the active
 		 * cell, otherwise we insert at beginning or end of table.
@@ -7419,6 +7420,7 @@
 		// Insert the rows.
 		table->insertRows(index, dialog->numberOfRows());
 		table->clearSelection();
+		table->adjustTable();
 		table->update();
 
 		m_ScMW->updateTableMenuActions();
@@ -7441,6 +7443,7 @@
 	QPointer<InsertTableColumnsDialog> dialog = new InsertTableColumnsDialog(appMode, m_ScMW);
 	if (dialog->exec() == QDialog::Accepted)
 	{
+		dontResize = true;
 		/*
 		 * In table edit mode we insert either before or after the active
 		 * cell, otherwise we insert at beginning or end of table.
@@ -7455,6 +7458,7 @@
 		// Insert the columns.
 		table->insertColumns(index, dialog->numberOfColumns());
 		table->clearSelection();
+		table->adjustTable();
 		table->update();
 
 		m_ScMW->updateTableMenuActions();
@@ -7480,10 +7484,11 @@
 	if (table->selectedRows().size() >= table->rows())
 		return;
 
+	dontResize = true;
 	if (table->selectedRows().isEmpty())
 	{
 		// Remove rows spanned by active cell.
-	TableCell activeCell = table->activeCell();
+		TableCell activeCell = table->activeCell();
 		table->removeRows(activeCell.row(), activeCell.rowSpan());
 	}
 	else
@@ -7512,6 +7517,7 @@
 	}
 
 	m_View->stopGesture(); // FIXME: Don't use m_View.
+	table->adjustTable();
 	table->update();
 
 	m_ScMW->updateTableMenuActions();
@@ -7534,6 +7540,7 @@
 	if (table->selectedColumns().size() >= table->columns())
 		return;
 
+	dontResize = true;
 	if (table->selectedColumns().isEmpty())
 	{
 		// Remove columns spanned by active cell.
@@ -7566,6 +7573,7 @@
 	}
 
 	m_View->stopGesture(); // FIXME: Don't use m_View.
+	table->adjustTable();
 	table->update();
 
 	m_ScMW->updateTableMenuActions();
@@ -7598,9 +7606,11 @@
 	const int numRows = selectedRows.last() - row + 1;
 	const int numColumns = selectedColumns.last() - column + 1;
 
+	dontResize = true;
 	table->mergeCells(row, column, numRows, numColumns);
 
 	m_View->stopGesture(); // FIXME: Don't use m_View.
+	table->adjustTable();
 	table->update();
 
 	m_ScMW->updateTableMenuActions();
@@ -7622,6 +7632,7 @@
 		return;
 
 	const qreal rowHeight = dialog->rowHeight();
+	dontResize = true;
 	if (appMode == modeEditTable)
 	{
 		if (table->selectedCells().isEmpty())
@@ -7649,6 +7660,7 @@
 
 	delete dialog;
 
+	table->adjustTable();
 	table->update();
 	changed();
 }
@@ -7668,6 +7680,7 @@
 		return;
 
 	const qreal columnWidth = dialog->columnWidth();
+	dontResize = true;
 	if (appMode == modeEditTable)
 	{
 		if (table->selectedCells().isEmpty())
@@ -7695,6 +7708,7 @@
 
 	delete dialog;
 
+	table->adjustTable();
 	table->update();
 	changed();
 }
@@ -7709,6 +7723,7 @@
 	if (!table)
 		return;
 
+	dontResize = true;
 	if (appMode == modeEditTable && !table->selectedRows().isEmpty())
 	{
 		// Distribute each contigous range of selected rows.
@@ -7736,6 +7751,7 @@
 		table->distributeRows(0, table->rows() - 1);
 	}
 
+	table->adjustTable();
 	table->update();
 	changed();
 }
@@ -7750,6 +7766,7 @@
 	if (!table)
 		return;
 
+	dontResize = true;
 	if (appMode == modeEditTable && !table->selectedColumns().isEmpty())
 	{
 		// Distribute each contigous range of selected columns.
@@ -7777,6 +7794,7 @@
 		table->distributeColumns(0, table->columns() - 1);
 	}
 
+	table->adjustTable();
 	table->update();
 	changed();
 }
@@ -13909,7 +13927,12 @@
 	{
 		PageItem *item = m_Selection->itemAt(i);
 		if (item && item->isTable())
+		{
+			dontResize = true;
 			item->asTable()->adjustFrameToTable();
+			dontResize = false;
+			setRedrawBounding(item);
+		}
 	}
 
 	regionsChanged()->update(QRectF());
@@ -13923,12 +13946,16 @@
 
 	if (selectedItemCount < 1)
 		return;
-
 	for (int i = 0; i < selectedItemCount; ++i)
 	{
 		PageItem *item = m_Selection->itemAt(i);
 		if (item && item->isTable())
+		{
+			dontResize = true;
 			item->asTable()->adjustTableToFrame();
+			dontResize = false;
+			setRedrawBounding(item);
+		}
 	}
 
 	regionsChanged()->update(QRectF());

Modified: trunk/Scribus/scribus/ui/propertiespalette.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17327&path=/trunk/Scribus/scribus/ui/propertiespalette.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette.cpp (original)
+++ trunk/Scribus/scribus/ui/propertiespalette.cpp Thu Feb 23 22:46:49 2012
@@ -356,6 +356,7 @@
 	m_item     = NULL;
 	Cpal->setCurrentItem(NULL);
 	Tpal->setCurrentItem(NULL);
+	tablePal->unsetItem();
 	handleSelectionChanged();
 }
 
@@ -420,6 +421,8 @@
 
 	m_haveItem = false;
 	m_item = i;
+
+	tablePal->setItem(m_item);
 
 	/*xyzPal->handleSelectionChanged();
 	shapePal->handleSelectionChanged();

Modified: trunk/Scribus/scribus/ui/propertiespalette_table.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17327&path=/trunk/Scribus/scribus/ui/propertiespalette_table.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette_table.cpp (original)
+++ trunk/Scribus/scribus/ui/propertiespalette_table.cpp Thu Feb 23 22:46:49 2012
@@ -54,6 +54,7 @@
 	m_mainWindow = mainWindow;
 
 	connect(m_mainWindow, SIGNAL(UpdateRequest(int)), SLOT(handleUpdateRequest(int)));
+	connect(m_mainWindow, SIGNAL(AppModeChanged(int,int)), this, SLOT(updateFillControls()));
 }
 
 void PropertiesPalette_Table::setDocument(ScribusDoc *doc)
@@ -69,10 +70,13 @@
 void PropertiesPalette_Table::setItem(PageItem* item)
 {
 	m_item = item;
+	connect(m_item->asTable(), SIGNAL(selectionChanged()), this, SLOT(handleCellSelectionChanged()));
 }
 
 void PropertiesPalette_Table::unsetItem()
 {
+	if (m_item)
+		disconnect(m_item->asTable(), SIGNAL(selectionChanged()), this, SLOT(handleCellSelectionChanged()));
 	m_item = 0;
 }
 
@@ -94,6 +98,15 @@
 
 	sideSelector->setSelection(TableSideSelector::All);
 
+	updateFillControls();
+}
+
+void PropertiesPalette_Table::handleCellSelectionChanged()
+{
+	if (!m_doc)
+		return;
+	if (!m_item)
+		return;
 	updateFillControls();
 }
 
@@ -191,7 +204,7 @@
 
 	foreach (const TableBorderLine& borderLine, m_currentBorder.borderLines())
 	{
-		QPixmap *icon = getWidePixmap(getColor(borderLine.color(), 100.0)); // TODO: Support shade.
+		QPixmap *icon = getWidePixmap(getColor(borderLine.color(), borderLine.shade()));
 		QString text = QString(" %1%2 %3")
 			.arg(borderLine.width())
 			.arg(borderLineWidth->suffix())
@@ -208,7 +221,10 @@
 void PropertiesPalette_Table::updateBorderLineListItem()
 {
 	QListWidgetItem* item = borderLineList->currentItem();
-	QPixmap *icon = getWidePixmap(getColor(borderLineColor->currentColor(), 100.0)); // TODO: Support shade.
+	QString color = borderLineColor->currentColor();
+	if (color == CommonStrings::tr_NoneColor)
+		color = CommonStrings::None;
+	QPixmap *icon = getWidePixmap(getColor(color, borderLineShade->value()));
 	QString text = QString(" %1%2 %3")
 		.arg(borderLineWidth->getValue())
 		.arg(borderLineWidth->suffix())
@@ -229,24 +245,22 @@
 		fillShade->setEnabled(true);
 		fillShadeLabel->setEnabled(true);
 		// Fill in values.
-		if (table->selectedCells().count() == 0)
-		{
-			setCurrentComboItem(fillColor, table->fillColor());
+		if (m_doc->appMode != modeEditTable)
+		{
+			QString color = table->fillColor();
+			if (color == CommonStrings::None)
+				color = CommonStrings::tr_NoneColor;
+			setCurrentComboItem(fillColor, color);
 			fillShade->setValue(table->fillShade());
 		}
-		else if (table->selectedCells().count() == 1)
-		{
-			TableCell cell = table->selectedCells().toList().first();
-			setCurrentComboItem(fillColor, cell.fillColor());
+		else
+		{
+			TableCell cell = table->activeCell();
+			QString color = cell.fillColor();
+			if (color == CommonStrings::None)
+				color = CommonStrings::tr_NoneColor;
+			setCurrentComboItem(fillColor, color);
 			fillShade->setValue(cell.fillShade());
-		}
-		else
-		{
-			// Disable fill editing controls.
-			fillColor->setEnabled(false);
-			fillColorLabel->setEnabled(false);
-			fillShade->setEnabled(false);
-			fillShadeLabel->setEnabled(false);
 		}
 	}
 	else
@@ -374,17 +388,19 @@
 {
 	if (!m_item || !m_item->isTable())
 		return;
-
+	QString color = colorName;
+	if (colorName == CommonStrings::tr_NoneColor)
+		color = CommonStrings::None;
 	PageItem_Table* table = m_item->asTable();
-	if (table->selectedCells().count() == 0)
-	{
-		table->setFillColor(colorName);
+	if (m_doc->appMode != modeEditTable)
+	{
+		table->setFillColor(color);
 		table->setFillShade(fillShade->value());
 	}
-	else if (table->selectedCells().count() == 1)
-	{
-		TableCell cell = table->selectedCells().toList().first();
-		cell.setFillColor(colorName);
+	else
+	{
+		TableCell cell = table->activeCell();
+		cell.setFillColor(color);
 		cell.setFillShade(fillShade->value());
 	}
 
@@ -396,16 +412,19 @@
 	if (!m_item || !m_item->isTable())
 		return;
 
+	QString color = fillColor->currentColor();
+	if (color == CommonStrings::tr_NoneColor)
+		color = CommonStrings::None;
 	PageItem_Table* table = m_item->asTable();
-	if (table->selectedCells().count() == 0)
-	{
-		table->setFillColor(fillColor->currentColor());
+	if (m_doc->appMode != modeEditTable)
+	{
+		table->setFillColor(color);
 		table->setFillShade(shade);
 	}
-	else if (table->selectedCells().count() == 1)
-	{
-		TableCell cell = table->selectedCells().toList().first();
-		cell.setFillColor(fillColor->currentColor());
+	else
+	{
+		TableCell cell = table->activeCell();
+		cell.setFillColor(color);
 		cell.setFillShade(shade);
 	}
 	table->update();
@@ -419,6 +438,7 @@
 	PageItem_Table* table = m_item->asTable();
 	TableSideSelector::Sides selectedSides = sideSelector->selection();
 
+	m_doc->dontResize = true;
 	if (selectedSides & TableSideSelector::Left)
 		table->setLeftBorder(m_currentBorder);
 	if (selectedSides & TableSideSelector::Right)
@@ -427,7 +447,7 @@
 		table->setTopBorder(m_currentBorder);
 	if (selectedSides & TableSideSelector::Bottom)
 		table->setBottomBorder(m_currentBorder);
-
+	table->adjustTable();
 	table->update();
 }
 

Modified: trunk/Scribus/scribus/ui/propertiespalette_table.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17327&path=/trunk/Scribus/scribus/ui/propertiespalette_table.h
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette_table.h (original)
+++ trunk/Scribus/scribus/ui/propertiespalette_table.h Thu Feb 23 22:46:49 2012
@@ -51,12 +51,16 @@
 
 	/// Handles item selection changes.
 	void handleSelectionChanged();
+	/// Handles cell selection changes.
+	void handleCellSelectionChanged();
 	/// Handles update requests from the main window.
 	void handleUpdateRequest(int updateFlags);
 	/// Handles language changes.
 	void languageChange();
 	/// Handles unit changes.
 	void unitChange();
+	/// Updates the fill controls.
+	void updateFillControls();
 
 private slots:
 	/// Handles selection changes in the side selector.
@@ -95,8 +99,6 @@
 	void updateBorderLineList();
 	/// Updates the current item in the list of border lines.
 	void updateBorderLineListItem();
-	/// Updates the fill controls.
-	void updateFillControls();
 	/// Updates the selected table with the current border.
 	void updateBorders();
 	/// Returns the color with name @a colorName and shade @a shade as a QColor.




More information about the scribus-commit mailing list