[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: =?utf-8?q?=5Bkoffice/koffice/change-tracking=5D_/=3A_Code_for_ed?=
From: Ganesh Paramasivam <ganesh () crystalfab ! com>
Date: 2011-02-03 9:51:18
Message-ID: 20110203095118.F259DA609B () git ! kde ! org
[Download RAW message or body]
Git commit b0c814eae08cd75df9db271a63b8839d5ab5ef76 by Ganesh Paramasivam.
Committed on 03/02/11 at 10:40.
Pushed by ganeshp into branch 'koffice/change-tracking'.
Code for editing table from Calligra master
M +1 -0 libs/kotext/CMakeLists.txt
M +96 -2 libs/kotext/KoTableColumnAndRowStyleManager.cpp
M +58 -3 libs/kotext/KoTableColumnAndRowStyleManager.h
M +174 -0 libs/kotext/KoTextEditor.cpp
M +40 -0 libs/kotext/KoTextEditor.h
M +52 -635 libs/kotext/styles/KoTableCellStyle.cpp
M +4 -186 libs/kotext/styles/KoTableCellStyle.h
M +1 -0 libs/kotext/styles/KoTableColumnStyle.cpp
M +2 -2 libs/kotext/styles/KoTableStyle.cpp
M +1 -1 libs/kotext/styles/KoTableStyle.h
M +47 -1 libs/kotext/tests/TestKoTableColumnAndRowStyleManager.cpp
M +4 -3 libs/kotext/tests/TestKoTableColumnAndRowStyleManager.h
M +2 -0 plugins/textshape/CMakeLists.txt
M +4 -3 plugins/textshape/Layout.cpp
M +135 -79 plugins/textshape/TableLayout.cpp
M +28 -5 plugins/textshape/TableLayout.h
M +3 -0 plugins/textshape/TableLayoutData.cpp
M +3 -0 plugins/textshape/TableLayoutData.h
M +78 -2 plugins/textshape/TextTool.cpp
M +16 -0 plugins/textshape/TextTool.h
M +3 -0 plugins/textshape/tests/CMakeLists.txt
M +7 -11 plugins/textshape/tests/TestTableLayout.cpp
M +2 -1 plugins/textshape/tests/TestTableLayout.h
http://commits.kde.org/koffice/b0c814eae08cd75df9db271a63b8839d5ab5ef76
diff --git a/libs/kotext/CMakeLists.txt b/libs/kotext/CMakeLists.txt
index a606cdb..f7ca9a7 100644
--- a/libs/kotext/CMakeLists.txt
+++ b/libs/kotext/CMakeLists.txt
@@ -61,6 +61,7 @@ set(kotext_LIB_SRCS
styles/KoListStyle.cpp
styles/KoListLevelProperties.cpp
styles/ChangeFollower.cpp
+ styles/KoTableBorderStyle.cpp
styles/KoTableStyle.cpp
styles/KoTableColumnStyle.cpp
styles/KoTableRowStyle.cpp
diff --git a/libs/kotext/KoTableColumnAndRowStyleManager.cpp \
b/libs/kotext/KoTableColumnAndRowStyleManager.cpp index 8ee93dd..b3b791a 100644
--- a/libs/kotext/KoTableColumnAndRowStyleManager.cpp
+++ b/libs/kotext/KoTableColumnAndRowStyleManager.cpp
@@ -22,12 +22,16 @@
#include "styles/KoTableColumnStyle.h"
#include "styles/KoTableRowStyle.h"
#include "styles/KoTableCellStyle.h"
+#include "styles/KoTableStyle.h"
#include <QVector>
#include <QSet>
+#include <QVariant>
+#include <QTextTable>
+
#include <QDebug>
-class KoTableColumnAndRowStyleManager::Private
+class KoTableColumnAndRowStyleManager::Private : public QSharedData
{
public:
Private() { }
@@ -45,9 +49,37 @@ KoTableColumnAndRowStyleManager::KoTableColumnAndRowStyleManager()
{
}
+KoTableColumnAndRowStyleManager::KoTableColumnAndRowStyleManager(const \
KoTableColumnAndRowStyleManager &rhs) + : d(rhs.d)
+{
+}
+
+KoTableColumnAndRowStyleManager &KoTableColumnAndRowStyleManager::operator=(const \
KoTableColumnAndRowStyleManager &rhs) +{
+ d = rhs.d;
+
+ return *this;
+}
+
KoTableColumnAndRowStyleManager::~KoTableColumnAndRowStyleManager()
{
- delete d;
+}
+
+KoTableColumnAndRowStyleManager \
KoTableColumnAndRowStyleManager::getManager(QTextTable *table) +{
+ QTextTableFormat tableFormat = table->format();
+
+ if (tableFormat.hasProperty(KoTableStyle::ColumnAndRowStyleManager)) {
+ return tableFormat.property(KoTableStyle::ColumnAndRowStyleManager).value<KoTableColumnAndRowStyleManager>();
+ } else {
+ KoTableColumnAndRowStyleManager carsManager;
+
+ QVariant var;
+ var.setValue(carsManager);
+ tableFormat.setProperty(KoTableStyle::ColumnAndRowStyleManager, var);
+ table->setFormat(tableFormat);
+ return carsManager;
+ }
}
void KoTableColumnAndRowStyleManager::setColumnStyle(int column, const \
KoTableColumnStyle &columnStyle) @@ -64,9 +96,40 @@ void \
KoTableColumnAndRowStyleManager::setColumnStyle(int column, const KoTableCo
while (column > d->tableColumnStyles.size())
d->tableColumnStyles.append(KoTableColumnStyle());
+
d->tableColumnStyles.insert(column, columnStyle);
}
+void KoTableColumnAndRowStyleManager::insertColumns(int column, int numberColumns, \
const KoTableColumnStyle &columnStyle) +{
+ Q_ASSERT(column >= 0);
+ Q_ASSERT(numberColumns >= 0);
+
+ if (column < 0 || numberColumns < 0) {
+ return;
+ }
+
+ while (column > d->tableColumnStyles.size())
+ d->tableColumnStyles.append(KoTableColumnStyle());
+
+ d->tableColumnStyles.insert(column, numberColumns, columnStyle);
+}
+
+void KoTableColumnAndRowStyleManager::removeColumns(int column, int numberColumns)
+{
+ Q_ASSERT(column >= 0);
+ Q_ASSERT(numberColumns >= 0);
+
+ if (column >= d->tableColumnStyles.size() || column < 0 || numberColumns < 0) {
+ return;
+ }
+
+ while (column > d->tableColumnStyles.size())
+ d->tableColumnStyles.append(KoTableColumnStyle());
+
+ d->tableColumnStyles.remove(column, numberColumns);
+}
+
KoTableColumnStyle KoTableColumnAndRowStyleManager::columnStyle(int column) const
{
Q_ASSERT(column >= 0);
@@ -92,9 +155,40 @@ void KoTableColumnAndRowStyleManager::setRowStyle(int row, const \
KoTableRowStyle
while (row > d->tableRowStyles.size())
d->tableRowStyles.append(KoTableRowStyle());
+
d->tableRowStyles.insert(row, rowStyle);
}
+void KoTableColumnAndRowStyleManager::insertRows(int row, int numberRows, const \
KoTableRowStyle &rowStyle) +{
+ Q_ASSERT(row >= 0);
+ Q_ASSERT(numberRows >= 0);
+
+ if (row < 0 || numberRows < 0) {
+ return;
+ }
+
+ while (row > d->tableRowStyles.size())
+ d->tableRowStyles.append(KoTableRowStyle());
+
+ d->tableRowStyles.insert(row, numberRows, rowStyle);
+}
+
+void KoTableColumnAndRowStyleManager::removeRows(int row, int numberRows)
+{
+ Q_ASSERT(row >= 0);
+ Q_ASSERT(numberRows >= 0);
+
+ if (row >= d->tableRowStyles.size() || row < 0 || numberRows < 0) {
+ return;
+ }
+
+ while (row > d->tableRowStyles.size())
+ d->tableRowStyles.append(KoTableRowStyle());
+
+ d->tableRowStyles.remove(row, numberRows);
+}
+
KoTableRowStyle KoTableColumnAndRowStyleManager::rowStyle(int row) const
{
Q_ASSERT(row >= 0);
diff --git a/libs/kotext/KoTableColumnAndRowStyleManager.h \
b/libs/kotext/KoTableColumnAndRowStyleManager.h index 6bb67b7..4573711 100644
--- a/libs/kotext/KoTableColumnAndRowStyleManager.h
+++ b/libs/kotext/KoTableColumnAndRowStyleManager.h
@@ -22,9 +22,13 @@
#include "kotext_export.h"
+#include <QMetaType>
+#include <QExplicitlySharedDataPointer>
+
class KoTableColumnStyle;
class KoTableRowStyle;
class KoTableCellStyle;
+class QTextTable;
/**
* Manages all column and row styles for a single table.
@@ -35,14 +39,25 @@ class KoTableCellStyle;
* The main purpose of this manager is simply to keep track of which styles are in
* which column (and in which row).
*
+ * It's explicitly shared (for the same table)
* TODO:
* - Eliminate duplicates.
*/
class KOTEXT_EXPORT KoTableColumnAndRowStyleManager
{
public:
+ /// constructor @see getManager for how to create a class the correct way
explicit KoTableColumnAndRowStyleManager();
- ~KoTableColumnAndRowStyleManager();
+
+ virtual ~KoTableColumnAndRowStyleManager();
+
+ /// Convenience function to get the KoTableColumnAndRowStyleManager for a table \
(or create one) + static KoTableColumnAndRowStyleManager getManager(QTextTable \
*table); +
+ /// Constructor
+ KoTableColumnAndRowStyleManager(const KoTableColumnAndRowStyleManager &rhs);
+ /// assign operator
+ KoTableColumnAndRowStyleManager &operator=(const KoTableColumnAndRowStyleManager \
&rhs);
/**
* Set the column style for the column \a column to \a columnStyle.
@@ -53,6 +68,25 @@ public:
void setColumnStyle(int column, const KoTableColumnStyle &columnStyle);
/**
+ * Insert a number of columns before the column \a column to \a columnStyle.
+ *
+ * @param column the columns are inserted before this column.
+ * @param numberColumns how many columns to insert.
+ * @param columnStyle the column style of the new columns.
+ * @see QTextTable::insertColumns for the analog method for the table data.
+ */
+ void insertColumns(int column, int numberColumns, const KoTableColumnStyle \
&columnStyle); +
+ /**
+ * Remove a number of columns \a column to \a columnStyle.
+ *
+ * @param column this and possibly following columns are removed.
+ * @param numberColumns how many columns to remove.
+ * @see QTextTable::removeColumns for the analog method for the table data.
+ */
+ void removeColumns(int column, int numberColumns);
+
+ /**
* Get the column style for the column \a column.
*
* @param column the column to get the style for.
@@ -69,6 +103,25 @@ public:
void setRowStyle(int row, const KoTableRowStyle &rowStyle);
/**
+ * Insert a number of rows above the row \a row to \a rowStyle.
+ *
+ * @param row the rows are inserted above this row.
+ * @param numberRows how many rows to insert.
+ * @param rowStyle the row style of the new rows.
+ * @see QTextTable::insertRows for the analog method for the table data.
+ */
+ void insertRows(int row, int numberRows, const KoTableRowStyle &rowStyle);
+
+ /**
+ * Remove a number of rows \a row to \a rowStyle.
+ *
+ * @param row this and possibly following rows are removed.
+ * @param numberRows how many rows to remove.
+ * @see QTextTable::removeRows for the analog method for the table data.
+ */
+ void removeRows(int row, int numberRows);
+
+ /**
* Get the row style for the row \a column.
*
* @param row the row to get the style for.
@@ -99,7 +152,7 @@ public:
* @return the default cell style for \a column.
*/
KoTableCellStyle* defaultColumnCellStyle(int column) const;
-
+
/**
* Set the default cell style for the column \a column.
*
@@ -110,8 +163,10 @@ public:
private:
class Private;
- Private* const d;
+ QExplicitlySharedDataPointer<Private> d;
};
+Q_DECLARE_METATYPE(KoTableColumnAndRowStyleManager)
+
#endif // KOTABLECOLUMNANDROWSTYLEMANAGER_H
diff --git a/libs/kotext/KoTextEditor.cpp b/libs/kotext/KoTextEditor.cpp
index f8dc73c..e82da51 100644
--- a/libs/kotext/KoTextEditor.cpp
+++ b/libs/kotext/KoTextEditor.cpp
@@ -37,6 +37,9 @@
#include "styles/KoParagraphStyle.h"
#include "styles/KoStyleManager.h"
#include "styles/KoTableCellStyle.h"
+#include "styles/KoTableColumnStyle.h"
+#include "styles/KoTableRowStyle.h"
+#include "KoTableColumnAndRowStyleManager.h"
#include <KLocale>
#include <KUndoStack>
@@ -920,8 +923,179 @@ void KoTextEditor::insertTable(int rows, int columns)
cellStyle.applyStyle(format);
cell.setFormat(format);
+ }
+ }
+
+ d->updateState(KoTextEditor::Private::NoOp);
+}
+
+void KoTextEditor::insertTableRowAbove()
+{
+ d->updateState(KoTextEditor::Private::Custom, i18n("Insert Row Above"));
+
+ QTextTable *table = d->caret.currentTable();
+
+ if (table) {
+ KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(table); + QTextTableCell cell = \
table->cellAt(d->caret); + int row = cell.row();
+ table->insertRows(row, 1);
+ carsManager.insertRows(row, 1, carsManager.rowStyle(row));
+ }
+
+ d->updateState(KoTextEditor::Private::NoOp);
+}
+
+void KoTextEditor::insertTableRowBelow()
+{
+ d->updateState(KoTextEditor::Private::Custom, i18n("Insert Row Below"));
+
+ QTextTable *table = d->caret.currentTable();
+
+ if (table) {
+ KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(table); + QTextTableCell cell = \
table->cellAt(d->caret); + int row = cell.row() +1;
+ if (row == table->rows()) {
+ table->appendRows(1);
+ carsManager.setRowStyle(row, carsManager.rowStyle(row-1));
+
+ // Copy the cells styles.
+ for (int col = 0; col < table->columns(); ++col) {
+ QTextTableCell cell = table->cellAt(row-1, col);
+ QTextCharFormat format = cell.format();
+ cell = table->cellAt(row, col);
+ cell.setFormat(format);
+ }
+ } else {
+ table->insertRows(row, 1);
+ carsManager.insertRows(row, 1, carsManager.rowStyle(row-1));
+ }
+ }
+
+ d->updateState(KoTextEditor::Private::NoOp);
+}
+
+void KoTextEditor::insertTableColumnLeft()
+{
+ d->updateState(KoTextEditor::Private::Custom, i18n("Insert Column Left"));
+
+ QTextTable *table = d->caret.currentTable();
+
+ if (table) {
+ KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(table); + QTextTableCell cell = \
table->cellAt(d->caret); + int column = cell.column();
+ table->insertColumns(column, 1);
+ carsManager.insertColumns(column, 1, carsManager.columnStyle(column));
+ }
+
+ d->updateState(KoTextEditor::Private::NoOp);
+}
+
+void KoTextEditor::insertTableColumnRight()
+{
+ d->updateState(KoTextEditor::Private::Custom, i18n("Insert Column Right"));
+
+ QTextTable *table = d->caret.currentTable();
+
+ if (table) {
+ KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(table); + QTextTableCell cell = \
table->cellAt(d->caret); + int column = cell.column()+1;
+ if (column == table->columns()) {
+ table->appendColumns(1);
+ carsManager.setColumnStyle(column, carsManager.columnStyle(column-1));
+ // Copy the cells style. for the bottomright cell which Qt doesn't
+ QTextTableCell cell = table->cellAt(table->rows()-1, column-1);
+ QTextCharFormat format = cell.format();
+ cell = table->cellAt(table->rows()-1, column);
+ cell.setFormat(format);
+ } else {
+ table->insertColumns(column, 1);
+ carsManager.insertColumns(column, 1, carsManager.columnStyle(column-1));
}
}
+
+ d->updateState(KoTextEditor::Private::NoOp);
+}
+
+void KoTextEditor::deleteTableColumn()
+{
+ d->updateState(KoTextEditor::Private::Custom, i18n("Delete Column"));
+
+ QTextTable *table = d->caret.currentTable();
+
+ if (table) {
+ KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(table); + int selectionRow;
+ int selectionColumn;
+ int selectionRowSpan;
+ int selectionColumnSpan;
+ if(d->caret.hasComplexSelection()) {
+ d->caret.selectedTableCells(&selectionRow, &selectionRowSpan, \
&selectionColumn, &selectionColumnSpan); + } else {
+ QTextTableCell cell = table->cellAt(d->caret);
+ selectionColumn = cell.column();
+ selectionColumnSpan = 1;
+ }
+ table->removeColumns(selectionColumn, selectionColumnSpan);
+ carsManager.removeColumns(selectionColumn, selectionColumnSpan);
+ }
+
+ d->updateState(KoTextEditor::Private::NoOp);
+}
+
+void KoTextEditor::deleteTableRow()
+{
+ d->updateState(KoTextEditor::Private::Custom, i18n("Delete Row"));
+
+ QTextTable *table = d->caret.currentTable();
+
+ if (table) {
+ KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(table); + int selectionRow;
+ int selectionColumn;
+ int selectionRowSpan;
+ int selectionColumnSpan;
+ if(d->caret.hasComplexSelection()) {
+ d->caret.selectedTableCells(&selectionRow, &selectionRowSpan, \
&selectionColumn, &selectionColumnSpan); + } else {
+ QTextTableCell cell = table->cellAt(d->caret);
+ selectionRow = cell.row();
+ selectionRowSpan = 1;
+ }
+ table->removeRows(selectionRow, selectionRowSpan);
+ carsManager.removeRows(selectionRow, selectionRowSpan);
+ }
+
+ d->updateState(KoTextEditor::Private::NoOp);
+}
+
+void KoTextEditor::mergeTableCells()
+{
+ d->updateState(KoTextEditor::Private::Custom, i18n("Merge Cells"));
+
+ QTextTable *table = d->caret.currentTable();
+
+ if (table) {
+ table->mergeCells(d->caret);
+ }
+
+ d->updateState(KoTextEditor::Private::NoOp);
+}
+
+void KoTextEditor::splitTableCells()
+{
+ d->updateState(KoTextEditor::Private::Custom, i18n("Split Cells"));
+
+ QTextTable *table = d->caret.currentTable();
+
+ if (table) {
+ QTextTableCell cell = table->cellAt(d->caret);
+ table->splitCell(cell.row(), cell.column(), cell.rowSpan(), \
cell.columnSpan()); + }
+
d->updateState(KoTextEditor::Private::NoOp);
}
diff --git a/libs/kotext/KoTextEditor.h b/libs/kotext/KoTextEditor.h
index f55e755..38f078a 100644
--- a/libs/kotext/KoTextEditor.h
+++ b/libs/kotext/KoTextEditor.h
@@ -195,6 +195,46 @@ public slots:
*/
void insertTable(int rows, int columns);
+ /**
+ * Insert a table row above the current cursor position (if in a table).
+ */
+ void insertTableRowAbove();
+
+ /**
+ * Insert a table row below the current cursor position (if in a table).
+ */
+ void insertTableRowBelow();
+
+ /**
+ * Insert a table column to the left of the current cursor position (if in a \
table). + */
+ void insertTableColumnLeft();
+
+ /**
+ * Insert a table column to the right of the current cursor position (if in a \
table). + */
+ void insertTableColumnRight();
+
+ /**
+ * Delete a table column where the cursor is (if in a table).
+ */
+ void deleteTableColumn();
+
+ /**
+ * Delete a table row where the cursor is (if in a table).
+ */
+ void deleteTableRow();
+
+ /**
+ * Merge table cells (selected by the cursor).
+ */
+ void mergeTableCells();
+
+ /**
+ * Split table cells (selected by the cursor) that were previously merged.
+ */
+ void splitTableCells();
+
void insertText(const QString &text);
void insertText(const QString &text, const QTextCharFormat &format);
diff --git a/libs/kotext/styles/KoTableCellStyle.cpp \
b/libs/kotext/styles/KoTableCellStyle.cpp index 46cce6e..b9376f6 100644
--- a/libs/kotext/styles/KoTableCellStyle.cpp
+++ b/libs/kotext/styles/KoTableCellStyle.cpp
@@ -26,6 +26,7 @@
#include <KoGenStyles.h>
#include "Styles_p.h"
#include "KoTextDocument.h"
+#include "KoTableCellStyle_p.h"
#include <KDebug>
@@ -38,109 +39,35 @@
#include <KoXmlNS.h>
#include <KoXmlWriter.h>
-struct Edge {
- Edge() : innerPen(), outerPen(), spacing(0.0) { }
- QPen innerPen;
- QPen outerPen;
- qreal spacing;
-};
-
-class KoTableCellStyle::Private
+KoTableCellStylePrivate::KoTableCellStylePrivate()
+ : parentStyle(0)
+ , next(0)
{
-public:
- Private() : parentStyle(0), next(0) {}
-
- ~Private() {
- }
-
- void setProperty(int key, const QVariant &value) {
- stylesPrivate.add(key, value);
- }
+}
- Edge edges[6];
- BorderStyle borderstyle[6];
- QString name;
- KoTableCellStyle *parentStyle;
- int next;
- StylePrivate stylesPrivate;
-};
+KoTableCellStylePrivate::~KoTableCellStylePrivate()
+{
+}
-KoTableCellStyle::KoTableCellStyle(QObject *parent)
- : QObject(parent), d(new Private())
+void KoTableCellStylePrivate::setProperty(int key, const QVariant &value)
{
- //d->edges[Top].outerPen = format.penProperty(TopBorderOuterPen);
- d->edges[Top].spacing = 0;
- // d->edges[Top].innerPen = format.penProperty(TopBorderInnerPen);
- d->borderstyle[Top] = BorderNone;
-
- // d->edges[Left].outerPen = format.penProperty(LeftBorderOuterPen);
- d->edges[Left].spacing = 0;
- // d->edges[Left].innerPen = format.penProperty(LeftBorderInnerPen);
- d->borderstyle[Left] = BorderNone;
-
- //d->edges[Bottom].outerPen =format.penProperty(BottomBorderOuterPen);
- d->edges[Bottom].spacing = 0;
- //d->edges[Bottom].innerPen = format.penProperty(BottomBorderInnerPen);
- d->borderstyle[Bottom] = BorderNone;
-
- //d->edges[Right].outerPen = format.penProperty(RightBorderOuterPen);
- d->edges[Right].spacing = 0;
- //d->edges[Right].innerPen = format.penProperty(RightBorderInnerPen);
- d->borderstyle[Right] = BorderNone;
-
- d->edges[TopLeftToBottomRight].spacing = 0;
- d->borderstyle[TopLeftToBottomRight] = BorderNone;
-
- d->edges[BottomLeftToTopRight].spacing = 0;
- d->borderstyle[BottomLeftToTopRight] = BorderNone;
+ stylesPrivate.add(key, value);
}
-bool KoTableCellStyle::isDrawn(BorderStyle style) const
+KoTableCellStyle::KoTableCellStyle(QObject *parent)
+ : KoTableBorderStyle(*new KoTableCellStylePrivate(), parent)
{
- if (style == BorderWave)
- return true;
- if (style == BorderDoubleWave)
- return true;
- if (style == BorderSlash)
- return true;
- return false;
}
KoTableCellStyle::KoTableCellStyle(const QTextTableCellFormat &format, QObject \
*parent)
- : QObject(parent),
- d(new Private())
+ : KoTableBorderStyle(*new KoTableCellStylePrivate(), format, parent)
{
+ Q_D(KoTableCellStyle);
d->stylesPrivate = format.properties();
+}
- d->edges[Top].outerPen = format.penProperty(TopBorderOuterPen);
- d->edges[Top].spacing = format.doubleProperty(TopBorderSpacing);
- d->edges[Top].innerPen = format.penProperty(TopBorderInnerPen);
- d->borderstyle[Top] = BorderStyle(format.intProperty(TopBorderStyle));
-
- d->edges[Left].outerPen = format.penProperty(LeftBorderOuterPen);
- d->edges[Left].spacing = format.doubleProperty(LeftBorderSpacing);
- d->edges[Left].innerPen = format.penProperty(LeftBorderInnerPen);
- d->borderstyle[Left] = BorderStyle(format.intProperty(LeftBorderStyle));
-
- d->edges[Bottom].outerPen =format.penProperty(BottomBorderOuterPen);
- d->edges[Bottom].spacing = format.doubleProperty(BottomBorderSpacing);
- d->edges[Bottom].innerPen = format.penProperty(BottomBorderInnerPen);
- d->borderstyle[Bottom] = BorderStyle(format.intProperty(BottomBorderStyle));
-
- d->edges[Right].outerPen = format.penProperty(RightBorderOuterPen);
- d->edges[Right].spacing = format.doubleProperty(RightBorderSpacing);
- d->edges[Right].innerPen = format.penProperty(RightBorderInnerPen);
- d->borderstyle[Right] = BorderStyle(format.intProperty(RightBorderStyle));
-
- d->edges[TopLeftToBottomRight].outerPen = \
format.penProperty(TopLeftToBottomRightBorderOuterPen);
- d->edges[TopLeftToBottomRight].spacing = \
format.doubleProperty(TopLeftToBottomRightBorderSpacing);
- d->edges[TopLeftToBottomRight].innerPen = \
format.penProperty(TopLeftToBottomRightBorderInnerPen);
- d->borderstyle[TopLeftToBottomRight] = \
BorderStyle(format.intProperty(TopLeftToBottomRightBorderStyle));
-
- d->edges[BottomLeftToTopRight].outerPen = \
format.penProperty(BottomLeftToTopRightBorderOuterPen);
- d->edges[BottomLeftToTopRight].spacing = \
format.doubleProperty(BottomLeftToTopRightBorderSpacing);
- d->edges[BottomLeftToTopRight].innerPen = \
format.penProperty(BottomLeftToTopRightBorderInnerPen);
- d->borderstyle[BottomLeftToTopRight] = \
BorderStyle(format.intProperty(BottomLeftToTopRightBorderStyle)); \
+KoTableCellStyle::~KoTableCellStyle() +{
}
KoTableCellStyle *KoTableCellStyle::fromTableCell(const QTextTableCell &tableCell, \
QObject *parent) @@ -149,13 +76,9 @@ KoTableCellStyle \
*KoTableCellStyle::fromTableCell(const QTextTableCell &tableCel return new \
KoTableCellStyle(tableCellFormat, parent); }
-KoTableCellStyle::~KoTableCellStyle()
-{
- delete d;
-}
-
QRectF KoTableCellStyle::contentRect(const QRectF &boundingRect) const
{
+ Q_D(const KoTableCellStyle);
return boundingRect.adjusted(
d->edges[Left].outerPen.widthF() + d->edges[Left].spacing + \
d->edges[Left].innerPen.widthF() + \
propertyDouble(QTextFormat::TableCellLeftPadding),
d->edges[Top].outerPen.widthF() + d->edges[Top].spacing + \
d->edges[Top].innerPen.widthF() + propertyDouble(QTextFormat::TableCellTopPadding), \
@@ -166,6 +89,7 @@ QRectF KoTableCellStyle::contentRect(const QRectF &boundingRect) \
const
QRectF KoTableCellStyle::boundingRect(const QRectF &contentRect) const
{
+ Q_D(const KoTableCellStyle);
return contentRect.adjusted(
- d->edges[Left].outerPen.widthF() - d->edges[Left].spacing - \
d->edges[Left].innerPen.widthF() - \
propertyDouble(QTextFormat::TableCellLeftPadding),
- d->edges[Top].outerPen.widthF() - d->edges[Top].spacing - \
d->edges[Top].innerPen.widthF() - propertyDouble(QTextFormat::TableCellTopPadding), \
@@ -174,93 +98,6 @@ QRectF KoTableCellStyle::boundingRect(const QRectF &contentRect) \
const );
}
-void KoTableCellStyle::setEdge(Side side, BorderStyle style, qreal width, QColor \
color)
-{
- Edge edge;
- qreal innerWidth = 0;
- qreal middleWidth = 0;
- qreal space = 0;
- switch (style) {
- case BorderNone:
- width = 0.0;
- break;
- case BorderDouble:
- innerWidth = space = width/4; //some nice default look
- width -= (space + innerWidth);
- edge.outerPen.setStyle(Qt::SolidLine);
- break;
- case BorderDotted:
- edge.outerPen.setStyle(Qt::DotLine);
- break;
- case BorderDashed:
- edge.outerPen.setStyle(Qt::DashLine);
- break;
- case BorderDashedLong: {
- QVector<qreal> dashes;
- dashes << 6 << 6;
- edge.outerPen.setDashPattern(dashes);
- break;
- }
- case BorderTriple:
- innerWidth = middleWidth = space = width/6;
- width -= (space + innerWidth);
- edge.outerPen.setStyle(Qt::SolidLine);
- break;
- case BorderDashDot:
- edge.outerPen.setStyle(Qt::DashDotLine);
- break;
- case BorderDashDotDot:
- edge.outerPen.setStyle(Qt::DashDotDotLine);
- break;
- case BorderWave:
- edge.outerPen.setStyle(Qt::SolidLine);
- break;
- case BorderSlash:
- edge.outerPen.setStyle(Qt::SolidLine);
- break;
- case BorderDoubleWave:
- innerWidth = space = width/4; //some nice default look
- width -= (space + innerWidth);
- edge.outerPen.setStyle(Qt::SolidLine);
- break;
- default:
- edge.outerPen.setStyle(Qt::SolidLine);
- break;
- }
- edge.outerPen.setColor(color);
- edge.outerPen.setJoinStyle(Qt::MiterJoin);
- edge.outerPen.setCapStyle(Qt::FlatCap);
- edge.outerPen.setWidthF(width);
-
- edge.spacing = space;
- edge.innerPen = edge.outerPen;
- edge.innerPen.setWidthF(innerWidth);
- QPen middlePen;
- middlePen = edge.outerPen;
- middlePen.setWidthF(middleWidth);
-
- d->edges[side] = edge;
- d->borderstyle[side] = style;
-}
-
-void KoTableCellStyle::setEdgeDoubleBorderValues(Side side, qreal innerWidth, qreal \
space)
-{
- qreal totalWidth = d->edges[side].outerPen.widthF() + d->edges[side].spacing + \
d->edges[side].innerPen.widthF();
- if (d->edges[side].innerPen.widthF() > 0.0) {
- d->edges[side].outerPen.setWidthF(totalWidth - innerWidth - space);
- d->edges[side].spacing = space;
- d->edges[side].innerPen.setWidthF(innerWidth);
- }
-}
-
-bool KoTableCellStyle::hasBorders() const
-{
- for (int i = Top; i <= BottomLeftToTopRight; i++)
- if (d->edges[i].outerPen.widthF() > 0.0)
- return true;
- return false;
-}
-
void KoTableCellStyle::paintBackground(QPainter &painter, const QRectF &bounds) \
const {
QRectF innerBounds = bounds;
@@ -270,426 +107,6 @@ void KoTableCellStyle::paintBackground(QPainter &painter, const \
QRectF &bounds) }
}
-void KoTableCellStyle::drawHorizontalWave(BorderStyle style, QPainter &painter, \
qreal x, qreal w, qreal t) const
-{
- QPen pen = painter.pen();
- const qreal linewidth = pen.width();
- const qreal penwidth = linewidth/6;
- pen.setWidth(penwidth);
- painter.setPen(pen);
- if (style == BorderSlash) {
- for (qreal sx=x; sx<x+w-linewidth; sx+=linewidth*0.5) {
- painter.drawLine(QLineF(sx, t-penwidth*2, sx+linewidth, t+penwidth*2));
- }
- } else {
- for (qreal sx=x; sx<x+w-2*linewidth; sx+=linewidth) {
- painter.drawLine(QLineF(sx, t-penwidth*2, sx+linewidth, t+penwidth*2));
- sx+=linewidth;
- painter.drawLine(QLineF(sx, t+penwidth*2, sx+linewidth, t-penwidth*2));
- }
- }
-}
-
-void KoTableCellStyle::drawVerticalWave(BorderStyle style, QPainter &painter, qreal \
y, qreal h, qreal t) const
-{
- QPen pen = painter.pen();
- const qreal linewidth = pen.width();
- const qreal penwidth = linewidth/6;
- pen.setWidth(penwidth);
- painter.setPen(pen);
- if (style == BorderSlash) {
- for (qreal sy=y; sy<y+h-linewidth; sy+=linewidth*0.5) {
- painter.drawLine(QLineF(t-penwidth*2, sy, t+penwidth*2, sy+linewidth));
- }
- } else {
- for (qreal sy=y; sy<y+h-2*linewidth; sy+=linewidth) {
- painter.drawLine(QLineF(t-penwidth*2, sy, t+penwidth*2, sy+linewidth));
- sy+=linewidth;
- painter.drawLine(QLineF(t+penwidth*2, sy, t-penwidth*2, sy+linewidth));
- }
- }
-}
-
-void KoTableCellStyle::paintBorders(QPainter &painter, const QRectF &bounds) const
-{
- QRectF innerBounds = bounds;
-
- if (d->edges[Top].outerPen.widthF() > 0) {
- QPen pen = d->edges[Top].outerPen;
-
- painter.setPen(pen);
- const qreal t = bounds.top() + pen.widthF() / 2.0;
- innerBounds.setTop(bounds.top() + d->edges[Top].spacing + pen.widthF());
- if(isDrawn(d->borderstyle[Top])) {
-#if 0 // Unfinished code?
- const qreal width = pen.widthF()/6;
- qreal x;
- //for (
-#endif
- } else {
- painter.drawLine(QLineF(bounds.left(), t, bounds.right(), t));
- }
- }
- if (d->edges[Bottom].outerPen.widthF() > 0) {
- QPen pen = d->edges[Bottom].outerPen;
- painter.setPen(pen);
- const qreal b = bounds.bottom() - pen.widthF() / 2.0;
- innerBounds.setBottom(bounds.bottom() - d->edges[Bottom].spacing - \
pen.widthF());
- painter.drawLine(QLineF(bounds.left(), b, bounds.right(), b));
- }
- if (d->edges[Left].outerPen.widthF() > 0) {
- QPen pen = d->edges[Left].outerPen;
- painter.setPen(pen);
- const qreal l = bounds.left() + pen.widthF() / 2.0;
- innerBounds.setLeft(bounds.left() + d->edges[Left].spacing + pen.widthF());
- painter.drawLine(QLineF(l, bounds.top() + d->edges[Top].outerPen.widthF(), \
l, bounds.bottom() - d->edges[Bottom].outerPen.widthF()));
- }
- if (d->edges[Right].outerPen.widthF() > 0) {
- QPen pen = d->edges[Right].outerPen;
- painter.setPen(pen);
- const qreal r = bounds.right() - pen.widthF() / 2.0;
- innerBounds.setRight(bounds.right() - d->edges[Right].spacing - \
pen.widthF());
- painter.drawLine(QLineF(r, bounds.top() + d->edges[Top].outerPen.widthF(), \
r, bounds.bottom() - d->edges[Bottom].outerPen.widthF()));
- }
- paintDiagonalBorders(painter, bounds);
-
- // inner lines
- if (d->edges[Top].innerPen.widthF() > 0) {
- QPen pen = d->edges[Top].innerPen;
- painter.setPen(pen);
- const qreal t = innerBounds.top() + pen.widthF() / 2.0;
- painter.drawLine(QLineF(innerBounds.left(), t, innerBounds.right(), t));
- }
- if (d->edges[Bottom].innerPen.widthF() > 0) {
- QPen pen = d->edges[Bottom].innerPen;
- painter.setPen(pen);
- const qreal b = innerBounds.bottom() - pen.widthF() / 2.0;
- painter.drawLine(QLineF(innerBounds.left(), b, innerBounds.right(), b));
- }
- if (d->edges[Left].innerPen.widthF() > 0) {
- QPen pen = d->edges[Left].innerPen;
- painter.setPen(pen);
- const qreal l = innerBounds.left() + pen.widthF() / 2.0;
- painter.drawLine(QLineF(l, innerBounds.top() + \
d->edges[Top].innerPen.widthF(), l, innerBounds.bottom() - \
d->edges[Bottom].innerPen.widthF()));
- }
- if (d->edges[Right].innerPen.widthF() > 0) {
- QPen pen = d->edges[Right].innerPen;
- painter.setPen(pen);
- const qreal r = innerBounds.right() - pen.widthF() / 2.0;
- painter.drawLine(QLineF(r, innerBounds.top() + \
d->edges[Top].innerPen.widthF(), r, innerBounds.bottom() - \
d->edges[Bottom].innerPen.widthF()));
- }
-}
-
-void KoTableCellStyle::paintDiagonalBorders(QPainter &painter, const QRectF &bounds) \
const
-{
- if (d->edges[TopLeftToBottomRight].outerPen.widthF() > 0) {
- QPen diagonalPen = d->edges[TopLeftToBottomRight].outerPen;
- painter.setPen(diagonalPen);
-
- QPen topPen = d->edges[Top].outerPen;
- const qreal top = bounds.top() + topPen.widthF() / 2.0;
- QPen leftPen = d->edges[Left].outerPen;
- const qreal left = bounds.left() + leftPen.widthF() / 2.0;
- QPen bottomPen = d->edges[Bottom].outerPen;
- const qreal bottom = bounds.bottom() - bottomPen.widthF() / 2.0;
- QPen rightPen = d->edges[Right].outerPen;
- const qreal right = bounds.right() - rightPen.widthF() / 2.0;
-
- painter.drawLine(QLineF(left, top, right, bottom));
- }
- if (d->edges[BottomLeftToTopRight].outerPen.widthF() > 0) {
- QPen pen = d->edges[BottomLeftToTopRight].outerPen;
- painter.setPen(pen);
-
- QPen topPen = d->edges[Top].outerPen;
- const qreal top = bounds.top() + topPen.widthF() / 2.0;
- QPen leftPen = d->edges[Left].outerPen;
- const qreal left = bounds.left() + leftPen.widthF() / 2.0;
- QPen bottomPen = d->edges[Bottom].outerPen;
- const qreal bottom = bounds.bottom() - bottomPen.widthF() / 2.0;
- QPen rightPen = d->edges[Right].outerPen;
- const qreal right = bounds.right() - rightPen.widthF() / 2.0;
-
- painter.drawLine(QLineF(left, bottom, right, top));
- }
-}
-
-void KoTableCellStyle::drawTopHorizontalBorder(QPainter &painter, qreal x, qreal y, \
qreal w, QPainterPath *accumulatedBlankBorders) const
-{
- qreal t=y;
- if (d->edges[Top].outerPen.widthF() > 0) {
- QPen pen = d->edges[Top].outerPen;
-
- painter.setPen(pen);
- t += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Top])) {
- drawHorizontalWave(d->borderstyle[Top], painter,x,w,t);
- } else {
- painter.drawLine(QLineF(x, t, x+w, t));
- }
- t = y + d->edges[Top].spacing + pen.widthF();
- } else if (accumulatedBlankBorders) {
- // No border but we'd like to draw one for user convenience when on screen
- accumulatedBlankBorders->moveTo(x, t);
- accumulatedBlankBorders->lineTo(x+w, t);
- }
-
- // inner line
- if (d->edges[Top].innerPen.widthF() > 0) {
- QPen pen = d->edges[Top].innerPen;
- painter.setPen(pen);
- t += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Top])) {
- drawHorizontalWave(d->borderstyle[Top], painter,x,w,t);
- } else {
- painter.drawLine(QLineF(x, t, x+w, t));
- }
- }
-}
-
-void KoTableCellStyle::drawSharedHorizontalBorder(QPainter &painter, const \
KoTableCellStyle &styleBelow, qreal x, qreal y, qreal w, QPainterPath \
*accumulatedBlankBorders) const
-{
- // First determine which style "wins" by comparing total width
- qreal thisWidth = d->edges[Bottom].outerPen.widthF() + d->edges[Bottom].spacing \
+ d->edges[Bottom].innerPen.widthF();
- qreal thatWidth = styleBelow.d->edges[Top].outerPen.widthF() + \
styleBelow.d->edges[Top].spacing
- + styleBelow.d->edges[Top].innerPen.widthF();
- if(thisWidth >= thatWidth) {
- // bottom style wins
- qreal t=y;
- if (d->edges[Bottom].outerPen.widthF() > 0) {
- QPen pen = d->edges[Bottom].outerPen;
- const qreal linewidth = pen.widthF();
-
- painter.setPen(pen);
- t += linewidth / 2.0;
- if(isDrawn(d->borderstyle[Bottom])) {
- drawHorizontalWave(d->borderstyle[Bottom], painter,x,w,t);
- } else {
- painter.drawLine(QLineF(x, t, x+w, t));
- }
- t = y + d->edges[Bottom].spacing + linewidth;
- } else if (accumulatedBlankBorders) {
- // No border but we'd like to draw one for user convenience when on \
screen
- accumulatedBlankBorders->moveTo(x, t);
- accumulatedBlankBorders->lineTo(x+w, t);
-
- }
- // inner line
- if (d->edges[Bottom].innerPen.widthF() > 0) {
- QPen pen = d->edges[Bottom].innerPen;
- painter.setPen(pen);
- t += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Bottom])) {
- drawHorizontalWave(d->borderstyle[Bottom], painter,x,w,t);
- } else {
- painter.drawLine(QLineF(x, t, x+w, t));
- }
- }
- } else {
- // top style wins
- qreal t=y;
- if (styleBelow.d->edges[Top].outerPen.widthF() > 0) {
- QPen pen = styleBelow.d->edges[Top].outerPen;
-
- painter.setPen(pen);
- t += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Top])) {
- drawHorizontalWave(d->borderstyle[Top], painter,x,w,t);
- } else {
- painter.drawLine(QLineF(x, t, x+w, t));
- }
- t = y + styleBelow.d->edges[Top].spacing + pen.widthF();
- }
- // inner line
- if (styleBelow.d->edges[Top].innerPen.widthF() > 0) {
- QPen pen = styleBelow.d->edges[Top].innerPen;
- painter.setPen(pen);
- t += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Top])) {
- drawHorizontalWave(d->borderstyle[Top], painter,x,w,t);
- } else {
- painter.drawLine(QLineF(x, t, x+w, t));
- }
- }
- }
-}
-
-void KoTableCellStyle::drawBottomHorizontalBorder(QPainter &painter, qreal x, qreal \
y, qreal w, QPainterPath *accumulatedBlankBorders) const
-{
- qreal t=y;
- if (d->edges[Bottom].outerPen.widthF() > 0) {
- QPen pen = d->edges[Bottom].outerPen;
-
- painter.setPen(pen);
- t -= pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Bottom])) {
- drawHorizontalWave(d->borderstyle[Bottom], painter,x,w,t);
- } else {
- painter.drawLine(QLineF(x, t, x+w, t));
- }
- t = y - d->edges[Bottom].spacing - pen.widthF();
- } else if (accumulatedBlankBorders) {
- // No border but we'd like to draw one for user convenience when on screen
- accumulatedBlankBorders->moveTo(x, t);
- accumulatedBlankBorders->lineTo(x+w, t);
-
- }
-
- // inner line
- if (d->edges[Bottom].innerPen.widthF() > 0) {
- QPen pen = d->edges[Bottom].innerPen;
- painter.setPen(pen);
- t -= pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Bottom])) {
- drawHorizontalWave(d->borderstyle[Bottom], painter,x,w,t);
- } else {
- painter.drawLine(QLineF(x, t, x+w, t));
- }
- }
-}
-
-void KoTableCellStyle::drawLeftmostVerticalBorder(QPainter &painter, qreal x, qreal \
y, qreal h, QPainterPath *accumulatedBlankBorders) const
-{
- qreal thisWidth = d->edges[Left].outerPen.widthF() + d->edges[Left].spacing + \
d->edges[Left].innerPen.widthF();
- qreal l = x - thisWidth / 2.0;
-
- if (d->edges[Left].outerPen.widthF() > 0) {
- QPen pen = d->edges[Left].outerPen;
-
- painter.setPen(pen);
- l += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Left])) {
- drawVerticalWave(d->borderstyle[Left], painter,y,h,l);
- } else {
- painter.drawLine(QLineF(l, y, l, y+h));
- }
- l += d->edges[Left].spacing + pen.widthF() / 2.0;
- } else if (accumulatedBlankBorders) {
- // No border but we'd like to draw one for user convenience when on screen
- accumulatedBlankBorders->moveTo(l, y);
- accumulatedBlankBorders->lineTo(l, y+h);
-
- }
-
- // inner line
- if (d->edges[Left].innerPen.widthF() > 0) {
- QPen pen = d->edges[Left].innerPen;
- painter.setPen(pen);
- l += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Left])) {
- drawVerticalWave(d->borderstyle[Left], painter,y,h,l);
- } else {
- painter.drawLine(QLineF(l, y, l, y+h));
- }
- }
-}
-
-void KoTableCellStyle::drawSharedVerticalBorder(QPainter &painter, const \
KoTableCellStyle &styleRight, qreal x, qreal y, qreal h, QPainterPath \
*accumulatedBlankBorders) const
-{
- // First determine which style "wins" by comparing total width
- qreal thisWidth = d->edges[Right].outerPen.widthF() + d->edges[Right].spacing + \
d->edges[Right].innerPen.widthF();
- qreal thatWidth = styleRight.d->edges[Left].outerPen.widthF() + \
styleRight.d->edges[Left].spacing
- + styleRight.d->edges[Left].innerPen.widthF();
-
- qreal l=x;
-
- if(thisWidth >= thatWidth) {
- // left style wins
- l -= thisWidth / 2.0;
- if (d->edges[Right].outerPen.widthF() > 0) {
- QPen pen = d->edges[Right].outerPen;
-
- painter.setPen(pen);
- l += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Right])) {
- drawVerticalWave(d->borderstyle[Right], painter,y,h,l);
- } else {
- painter.drawLine(QLineF(l, y, l, y+h));
- }
- l += d->edges[Right].spacing + pen.widthF() / 2.0;
- } else if (accumulatedBlankBorders) {
- // No border but we'd like to draw one for user convenience when on \
screen
- accumulatedBlankBorders->moveTo(l, y);
- accumulatedBlankBorders->lineTo(l, y+h);
-
- }
-
- // inner line
- if (d->edges[Right].innerPen.widthF() > 0) {
- QPen pen = d->edges[Right].innerPen;
- painter.setPen(pen);
- l += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Right])) {
- drawVerticalWave(d->borderstyle[Right], painter,y,h,l);
- } else {
- painter.drawLine(QLineF(l, y, l, y+h));
- }
- }
- } else {
- // right style wins
- l -= thatWidth/2.0;
- if (styleRight.d->edges[Left].outerPen.widthF() > 0) {
- QPen pen = styleRight.d->edges[Left].outerPen;
-
- painter.setPen(pen);
- l += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Left])) {
- drawVerticalWave(d->borderstyle[Left], painter,y,h,l);
- } else {
- painter.drawLine(QLineF(l, y, l, y+h));
- }
- l += styleRight.d->edges[Left].spacing + pen.widthF() / 2.0;
- }
- // inner line
- if (styleRight.d->edges[Left].innerPen.widthF() > 0) {
- QPen pen = styleRight.d->edges[Left].innerPen;
- painter.setPen(pen);
- l += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Left])) {
- drawVerticalWave(d->borderstyle[Left], painter,y,h,l);
- } else {
- painter.drawLine(QLineF(l, y, l, y+h));
- }
- }
- }
-}
-
-void KoTableCellStyle::drawRightmostVerticalBorder(QPainter &painter, qreal x, qreal \
y, qreal h, QPainterPath *accumulatedBlankBorders) const
-{
- qreal thisWidth = d->edges[Right].outerPen.widthF() + d->edges[Right].spacing + \
d->edges[Right].innerPen.widthF();
- qreal l = x - thisWidth / 2.0;
-
- if (d->edges[Right].outerPen.widthF() > 0) {
- QPen pen = d->edges[Right].outerPen;
-
- painter.setPen(pen);
- l += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Right])) {
- drawVerticalWave(d->borderstyle[Right], painter,y,h,l);
- } else {
- painter.drawLine(QLineF(l, y, l, y+h));
- }
- l += d->edges[Right].spacing - pen.widthF() / 2.0;
- } else if (accumulatedBlankBorders) {
- // No border but we'd like to draw one for user convenience when on screen
- accumulatedBlankBorders->moveTo(l, y);
- accumulatedBlankBorders->lineTo(l, y+h);
-
- }
-
- // inner line
- if (d->edges[Right].innerPen.widthF() > 0) {
- QPen pen = d->edges[Right].innerPen;
- painter.setPen(pen);
- l += pen.widthF() / 2.0;
- if(isDrawn(d->borderstyle[Right])) {
- drawVerticalWave(d->borderstyle[Right], painter,y,h,l);
- } else {
- painter.drawLine(QLineF(l, y, l, y+h));
- }
- }
-}
-
KoTableCellStyle::BorderStyle KoTableCellStyle::oasisBorderStyle(const QString \
&borderstyle) {
if (borderstyle == "none")
@@ -734,6 +151,7 @@ QString KoTableCellStyle::odfBorderStyleString(const \
KoTableCellStyle::BorderSty
void KoTableCellStyle::setParentStyle(KoTableCellStyle *parent)
{
+ Q_D(KoTableCellStyle);
d->parentStyle = parent;
}
@@ -777,31 +195,6 @@ qreal KoTableCellStyle::bottomPadding() const
return propertyDouble(QTextFormat::TableCellBottomPadding);
}
-qreal KoTableCellStyle::leftBorderWidth() const
-{
- const Edge &edge = d->edges[Left];
- return edge.spacing + edge.innerPen.widthF() + edge.outerPen.widthF();
-}
-
-qreal KoTableCellStyle::rightBorderWidth() const
-{
- const Edge &edge = d->edges[Right];
- return edge.spacing + edge.innerPen.widthF() + edge.outerPen.widthF();
-}
-
-qreal KoTableCellStyle::topBorderWidth() const
-{
- const Edge &edge = d->edges[Top];
- return edge.spacing + edge.innerPen.widthF() + edge.outerPen.widthF();
-}
-
-qreal KoTableCellStyle::bottomBorderWidth() const
-{
- const Edge &edge = d->edges[Bottom];
- return edge.spacing + edge.innerPen.widthF() + edge.outerPen.widthF();
-}
-
-
void KoTableCellStyle::setPadding(qreal padding)
{
setBottomPadding(padding);
@@ -812,6 +205,7 @@ void KoTableCellStyle::setPadding(qreal padding)
void KoTableCellStyle::setProperty(int key, const QVariant &value)
{
+ Q_D(KoTableCellStyle);
if (d->parentStyle) {
QVariant var = d->parentStyle->value(key);
if (!var.isNull() && var == value) { // same as parent, so its actually a \
reset. @@ -824,11 +218,13 @@ void KoTableCellStyle::setProperty(int key, const \
QVariant &value)
void KoTableCellStyle::remove(int key)
{
+ Q_D(KoTableCellStyle);
d->stylesPrivate.remove(key);
}
QVariant KoTableCellStyle::value(int key) const
{
+ Q_D(const KoTableCellStyle);
QVariant var = d->stylesPrivate.value(key);
if (var.isNull() && d->parentStyle)
var = d->parentStyle->value(key);
@@ -837,6 +233,7 @@ QVariant KoTableCellStyle::value(int key) const
bool KoTableCellStyle::hasProperty(int key) const
{
+ Q_D(const KoTableCellStyle);
return d->stylesPrivate.contains(key);
}
@@ -875,6 +272,7 @@ QColor KoTableCellStyle::propertyColor(int key) const
void KoTableCellStyle::applyStyle(QTextTableCellFormat &format) const
{
+ Q_D(const KoTableCellStyle);
if (d->parentStyle) {
d->parentStyle->applyStyle(format);
}
@@ -917,11 +315,13 @@ void KoTableCellStyle::setBackground(const QBrush &brush)
void KoTableCellStyle::clearBackground()
{
+ Q_D(KoTableCellStyle);
d->stylesPrivate.remove(CellBackgroundBrush);
}
QBrush KoTableCellStyle::background() const
{
+ Q_D(const KoTableCellStyle);
QVariant variant = d->stylesPrivate.value(CellBackgroundBrush);
if (variant.isNull()) {
@@ -942,16 +342,19 @@ Qt::Alignment KoTableCellStyle::alignment() const
KoTableCellStyle *KoTableCellStyle::parentStyle() const
{
+ Q_D(const KoTableCellStyle);
return d->parentStyle;
}
QString KoTableCellStyle::name() const
{
+ Q_D(const KoTableCellStyle);
return d->name;
}
void KoTableCellStyle::setName(const QString &name)
{
+ Q_D(KoTableCellStyle);
if (name == d->name)
return;
d->name = name;
@@ -965,6 +368,7 @@ int KoTableCellStyle::styleId() const
void KoTableCellStyle::setStyleId(int id)
{
+ Q_D(KoTableCellStyle);
setProperty(StyleId, id); if (d->next == 0) d->next = id;
}
@@ -980,6 +384,7 @@ void KoTableCellStyle::setMasterPageName(const QString &name)
void KoTableCellStyle::loadOdf(const KoXmlElement *element, KoOdfLoadingContext \
&context) {
+ Q_D(KoTableCellStyle);
if (element->hasAttributeNS(KoXmlNS::style, "display-name"))
d->name = element->attributeNS(KoXmlNS::style, "display-name", QString());
@@ -994,8 +399,14 @@ void KoTableCellStyle::loadOdf(const KoXmlElement *element, \
KoOdfLoadingContext
QString family = element->attributeNS(KoXmlNS::style, "family", "table-cell");
context.addStyles(element, family.toLocal8Bit().constData()); // Load all \
parents - only because we don't support inheritance.
- context.styleStack().setTypeProperties("table-cell"); // load all style \
attributes from "style:table-properties"
- loadOdfProperties(context.styleStack()); // load the KoTableCellStyle from the \
stylestack + context.styleStack().setTypeProperties("table-cell");
+ loadOdfProperties(context.styleStack());
+
+ context.styleStack().setTypeProperties("graphic");
+ loadOdfProperties(context.styleStack());
+
+ context.styleStack().setTypeProperties("paragraph");
+ loadOdfProperties(context.styleStack());
context.styleStack().restore();
}
@@ -1138,10 +549,13 @@ void KoTableCellStyle::loadOdfProperties(KoStyleStack \
&styleStack)
void KoTableCellStyle::copyProperties(const KoTableCellStyle *style)
{
- d->stylesPrivate = style->d->stylesPrivate;
+ Q_D(KoTableCellStyle);
+ const KoTableCellStylePrivate *styleD = static_cast<const \
KoTableCellStylePrivate*>(style->d_func()); +
+ d->stylesPrivate = styleD->stylesPrivate;
setName(style->name()); // make sure we emit property change
- d->next = style->d->next;
- d->parentStyle = style->d->parentStyle;
+ d->next = styleD->next;
+ d->parentStyle = styleD->parentStyle;
}
KoTableCellStyle *KoTableCellStyle::clone(QObject *parent)
@@ -1154,13 +568,16 @@ KoTableCellStyle *KoTableCellStyle::clone(QObject *parent)
bool KoTableCellStyle::operator==(const KoTableCellStyle &other) const
{
-
- return other.d->stylesPrivate == d->stylesPrivate;
+ Q_D(const KoTableCellStyle);
+ const KoTableCellStylePrivate *otherD = static_cast<const \
KoTableCellStylePrivate*>(other.d_func()); + return otherD->stylesPrivate == \
d->stylesPrivate; }
void KoTableCellStyle::removeDuplicates(const KoTableCellStyle &other)
{
- d->stylesPrivate.removeDuplicates(other.d->stylesPrivate);
+ Q_D(KoTableCellStyle);
+ const KoTableCellStylePrivate *otherD = static_cast<const \
KoTableCellStylePrivate*>(other.d_func()); + \
d->stylesPrivate.removeDuplicates(otherD->stylesPrivate); }
void KoTableCellStyle::saveOdf(KoGenStyle &style)
diff --git a/libs/kotext/styles/KoTableCellStyle.h \
b/libs/kotext/styles/KoTableCellStyle.h index 6b205ff..9e6d22c 100644
--- a/libs/kotext/styles/KoTableCellStyle.h
+++ b/libs/kotext/styles/KoTableCellStyle.h
@@ -22,6 +22,7 @@
#ifndef KOTABLECELLSTYLE_H
#define KOTABLECELLSTYLE_H
+#include "KoTableBorderStyle.h"
#include "KoText.h"
#include "kotext_export.h"
@@ -43,6 +44,7 @@ class KoGenStyle;
class KoGenStyles;
#include "KoXmlReaderForward.h"
class KoOdfLoadingContext;
+class KoTableCellStylePrivate;
/**
* A container for all properties for the table cell style.
@@ -52,68 +54,10 @@ class KoOdfLoadingContext;
* a specific KoTableCellStyle.
* @see KoStyleManager
*/
-class KOTEXT_EXPORT KoTableCellStyle : public QObject
+class KOTEXT_EXPORT KoTableCellStyle : public KoTableBorderStyle
{
Q_OBJECT
public:
- enum Property {
- StyleId = QTextTableCellFormat::UserProperty + 7001,
- TopBorderOuterPen, ///< the top border pen
- TopBorderSpacing, ///< the top border spacing between inner and \
outer border
- TopBorderInnerPen, ///< the top border inner pen
- TopBorderStyle, ///< the top border borderstyle
- LeftBorderOuterPen, ///< the left border outer pen
- LeftBorderSpacing, ///< the left border spacing between inner and \
outer border
- LeftBorderInnerPen, ///< the left border inner pen
- LeftBorderStyle, ///< the left border borderstyle
- BottomBorderOuterPen, ///< the bottom border outer pen
- BottomBorderSpacing, ///< the bottom border spacing between inner and \
outer border
- BottomBorderInnerPen, ///< the bottom border inner pen
- BottomBorderStyle, ///< the bottom border borderstyle
- RightBorderOuterPen, ///< the right border outer pen
- RightBorderSpacing, ///< the right border spacing between inner and \
outer border
- RightBorderInnerPen, ///< the right border inner pen
- RightBorderStyle, ///< the right border borderstyle
- TopLeftToBottomRightBorderOuterPen, ///< the top left to bottom right \
diagonal border pen
- TopLeftToBottomRightBorderSpacing, ///< the top left to bottom right \
diagonal spacing
- TopLeftToBottomRightBorderInnerPen, ///< the top left to bottom right \
diagonal inner pen
- TopLeftToBottomRightBorderStyle, ///< the top left to bottom right \
borderstyle
- BottomLeftToTopRightBorderOuterPen, ///< the bottom letf to top right \
diagonal border pen
- BottomLeftToTopRightBorderSpacing, ///< the bottom letf to top right \
diagonal spacing
- BottomLeftToTopRightBorderInnerPen, ///< the bottom letf to top right \
diagonal inner pen
- BottomLeftToTopRightBorderStyle, ///< the bottom letf to top right \
borderstyle
- CellBackgroundBrush, ///< the cell background brush, as \
QTextFormat::BackgroundBrush is used by paragraphs
- VerticalAlignment, ///< the vertical alignment oinside the cell
- MasterPageName, ///< Optional name of the master-page
- InlineRdf ///< Optional KoTextInlineRdf object
- };
-
- enum Side {
- Top = 0, ///< References the border at the top of the cell
- Left, ///< References the border at the left side of the cell
- Bottom, ///< References the border at the bottom of the cell
- Right, ///< References the border at the right side of the paragraph
- TopLeftToBottomRight, ///< References the border from top, left corner to \
bottom, right corner of cell
- BottomLeftToTopRight ///< References the border from bottom, left corner to \
top, right corner of cell
- };
-
- /// Enum used to differentiate between the 3 types of border styles
- enum BorderStyle {
- BorderNone = 0, ///< No line border
- BorderSolid, ///< Solid line border
- BorderDotted, ///< Dotted single border
- BorderDashDot, ///< Dot Dashsingle border
- BorderDashDotDot, ///< Dot Dot Dash single border
- BorderDashed, ///< Dashed single border
- BorderDashedLong, ///< Dashed single border with long spaces
- BorderDouble, ///< Double lined border
- BorderTriple, ///< Triple lined border
- BorderSlash, ///< slash border
- BorderWave, ///< wave border
- BorderDoubleWave ///< double wave border
- };
-
-
/// Constructor
KoTableCellStyle(QObject *parent = 0);
/// Creates a KoTableCellStyle with the given table cell format, and \a parent
@@ -127,15 +71,6 @@ public:
/// creates a clone of this style with the specified parent
KoTableCellStyle *clone(QObject *parent = 0);
- /// returns if the borderstyle needs to be specially drawn
- bool isDrawn(BorderStyle style) const;
-
- /// draws a horizontal wave line
- void drawHorizontalWave(BorderStyle style, QPainter &painter, qreal x, qreal w, \
qreal t) const;
-
- /// draws a vertical wave line
- void drawVerticalWave(BorderStyle style, QPainter &painter, qreal y, qreal h, \
qreal t) const;
-
/**
* Adjust the bounding rectange \boundingRect according to the paddings and \
margins
* of this border data. The inverse of this function is boundingRect().
@@ -157,34 +92,6 @@ public:
*/
QRectF boundingRect(const QRectF &contentRect) const;
- /**
- * Set the properties of an edge.
- *
- * @param side defines which edge this is for.
- * @param style the border style for this side.
- * @param totalWidth the thickness of the border. Sum of outerwidth, spacing and \
innerwidth for double borders
- * @param color the color of the border line(s).
- */
- void setEdge(Side side, BorderStyle style, qreal totalWidth, QColor color);
-
- /**
- * Set the properties of an double border.
- * Note: you need to set the edge first or that would overwrite these values.
- *
- * The values will not be set if the border doesn't have a double style
- *
- * @param side defines which edge this is for.
- * @param space the amount of spacing between the outer border and the inner \
border in case of style being double
- * @param innerWidth the thickness of the inner border line in case of style \
being double
- */
- void setEdgeDoubleBorderValues(Side side, qreal innerWidth, qreal space);
-
- /**
- * Check if the border data has any borders.
- *
- * @return true if there has been at least one border set.
- */
- bool hasBorders() const;
/**
* Paint the background.
@@ -194,90 +101,6 @@ public:
*/
void paintBackground(QPainter &painter, const QRectF &bounds) const;
- /**
- * Paint the borders.
- *
- * @painter the painter to draw with.
- * @bounds the bounding rectangle to draw.
- */
- void paintBorders(QPainter &painter, const QRectF &bounds) const;
-
- /**
- * Paint the diagonal borders.
- *
- * @painter the painter to draw with.
- * @bounds the bounding rectangle to draw.
- */
- void paintDiagonalBorders(QPainter &painter, const QRectF &bounds) const;
-
- /**
- * Paint the top border.
- *
- * @painter the painter to draw with.
- * @x the x position.
- * @y the y position.
- * @w the width.
- * @blanks a painterpath where blank borders should be added to.
- */
- void drawTopHorizontalBorder(QPainter &painter, qreal x, qreal y, qreal w, \
QPainterPath *blanks = 0) const;
-
- /**
- * Paint the border that is shared.
- * It only draws the thickest and it always draws it below the y position.
- *
- * @painter the painter to draw with.
- * @x the x position.
- * @y the y position.
- * @w the width.
- * @blanks a painterpath where blank borders should be added to.
- */
- void drawSharedHorizontalBorder(QPainter &painter, const KoTableCellStyle \
&styleBelow, qreal x, qreal y, qreal w, QPainterPath *blanks = 0) \
const;
-
- /**
- * Paint the bottom border.
- *
- * @painter the painter to draw with.
- * @x the x position.
- * @y the y position.
- * @w the width.
- * @blanks a painterpath where blank borders should be added to.
- */
- void drawBottomHorizontalBorder(QPainter &painter, qreal x, qreal y, qreal w, \
QPainterPath *blanks = 0) const;
-
- /**
- * Paint the leftmost border.
- *
- * @painter the painter to draw with.
- * @x the x position.
- * @y the y position.
- * @h the height.
- * @blanks a painterpath where blank borders should be added to.
- */
- void drawLeftmostVerticalBorder(QPainter &painter, qreal x, qreal y, qreal h, \
QPainterPath *blanks = 0) const;
-
- /**
- * Paint the border that is shared.
- * It only draws the thickest and it always draws it below the y position.
- *
- * @painter the painter to draw with.
- * @x the x position.
- * @y the y position.
- * @h the height.
- * @blanks a painterpath where blank borders should be added to.
- */
- void drawSharedVerticalBorder(QPainter &painter, const KoTableCellStyle \
&styleRight, qreal x, qreal y, qreal h, QPainterPath *blanks = 0) \
const;
-
- /**
- * Paint the rightmost border.
- *
- * @painter the painter to draw with.
- * @x the x position.
- * @y the y position.
- * @h the height.
- * @blanks a painterpath where blank borders should be added to.
- */
- void drawRightmostVerticalBorder(QPainter &painter, qreal x, qreal y, qreal h, \
QPainterPath *blanks = 0) const;
-
void setBackground(const QBrush &brush);
/// See similar named method on QTextBlockFormat
QBrush background() const;
@@ -295,10 +118,6 @@ public:
qreal topPadding() const;
qreal bottomPadding() const;
- qreal leftBorderWidth() const;
- qreal rightBorderWidth() const;
- qreal topBorderWidth() const;
- qreal bottomBorderWidth() const;
void setAlignment(Qt::Alignment alignment);
Qt::Alignment alignment() const;
@@ -392,8 +211,7 @@ private:
BorderStyle oasisBorderStyle(const QString &borderstyle);
QString odfBorderStyleString(const BorderStyle borderstyle);
- class Private;
- Private * const d;
+ Q_DECLARE_PRIVATE(KoTableCellStyle)
};
#endif
diff --git a/libs/kotext/styles/KoTableColumnStyle.cpp \
b/libs/kotext/styles/KoTableColumnStyle.cpp index de1642a..69977bb 100644
--- a/libs/kotext/styles/KoTableColumnStyle.cpp
+++ b/libs/kotext/styles/KoTableColumnStyle.cpp
@@ -60,6 +60,7 @@ public:
KoTableColumnStyle::KoTableColumnStyle()
: d(new Private())
{
+ Q_ASSERT (d);
}
KoTableColumnStyle::KoTableColumnStyle(const KoTableColumnStyle &rhs)
diff --git a/libs/kotext/styles/KoTableStyle.cpp \
b/libs/kotext/styles/KoTableStyle.cpp index a431bc3..0ae8475 100644
--- a/libs/kotext/styles/KoTableStyle.cpp
+++ b/libs/kotext/styles/KoTableStyle.cpp
@@ -446,9 +446,9 @@ void KoTableStyle::loadOdfProperties(KoStyleStack &styleStack)
}
// border-model
- if (styleStack.hasProperty(KoXmlNS::style, "border-model")) {
+ if (styleStack.hasProperty(KoXmlNS::table, "border-model")) {
// OASIS spec says it's "auto"/"always", not a boolean.
- QString val = styleStack.property(KoXmlNS::style, "border-model");
+ QString val = styleStack.property(KoXmlNS::table, "border-model");
setCollapsingBorderModel(val =="collapsing");
}
}
diff --git a/libs/kotext/styles/KoTableStyle.h b/libs/kotext/styles/KoTableStyle.h
index 4008cbd..6bc7f8d 100644
--- a/libs/kotext/styles/KoTableStyle.h
+++ b/libs/kotext/styles/KoTableStyle.h
@@ -57,7 +57,7 @@ public:
BreakBefore, ///< If true, insert a frame break before this table
BreakAfter, ///< If true, insert a frame break after this table
MayBreakBetweenRows, ///< If true, then the table is allowed to break \
between rows
- ColumnAndRowStyleManager, ///< QMetaType::VoidStar pointer to a \
KoColumnAndRowStyleManager + ColumnAndRowStyleManager, ///< QVariant of a \
KoColumnAndRowStyleManager
/// It's not really a \
property of KoTableStyle but defined here for convenience
CollapsingBorders, ///< If true, then the table has collapsing border \
model MasterPageName ///< Optional name of the master-page
diff --git a/libs/kotext/tests/TestKoTableColumnAndRowStyleManager.cpp \
b/libs/kotext/tests/TestKoTableColumnAndRowStyleManager.cpp index ff258b8..ab43719 \
100644
--- a/libs/kotext/tests/TestKoTableColumnAndRowStyleManager.cpp
+++ b/libs/kotext/tests/TestKoTableColumnAndRowStyleManager.cpp
@@ -20,20 +20,66 @@
#include "TestKoTableColumnAndRowStyleManager.h"
#include "styles/KoTableColumnStyle.h"
+#include "styles/KoTableRowStyle.h"
#include "../KoTableColumnAndRowStyleManager.h"
-void TestKoTableColumnAndRowStyleManager::testManager()
+void TestKoTableColumnAndRowStyleManager::testColumns()
{
KoTableColumnAndRowStyleManager manager;
KoTableColumnStyle *style1 = new KoTableColumnStyle();
KoTableColumnStyle *style2 = new KoTableColumnStyle();
+ KoTableColumnStyle *style3 = new KoTableColumnStyle();
manager.setColumnStyle(0, *style1);
manager.setColumnStyle(2, *style2);
QVERIFY(manager.columnStyle(0) == *style1);
+ //column 1 is a default inited style
QVERIFY(manager.columnStyle(2) == *style2);
+
+ manager.insertColumns(1, 2, *style3);
+
+ QVERIFY(manager.columnStyle(0) == *style1);
+ QVERIFY(manager.columnStyle(1) == *style3);
+ QVERIFY(manager.columnStyle(2) == *style3);
+ //column 3 is a default inited style
+ QVERIFY(manager.columnStyle(4) == *style2);
+
+ manager.removeColumns(2, 2);
+
+ QVERIFY(manager.columnStyle(0) == *style1);
+ QVERIFY(manager.columnStyle(1) == *style3);
+ QVERIFY(manager.columnStyle(2) == *style2);
+}
+
+void TestKoTableColumnAndRowStyleManager::testRows()
+{
+ KoTableColumnAndRowStyleManager manager;
+
+ KoTableRowStyle *style1 = new KoTableRowStyle();
+ KoTableRowStyle *style2 = new KoTableRowStyle();
+ KoTableRowStyle *style3 = new KoTableRowStyle();
+
+ manager.setRowStyle(0, *style1);
+ manager.setRowStyle(2, *style2);
+
+ QVERIFY(manager.rowStyle(0) == *style1);
+ QVERIFY(manager.rowStyle(2) == *style2);
+
+ manager.insertRows(1, 2, *style3);
+
+ QVERIFY(manager.rowStyle(0) == *style1);
+ QVERIFY(manager.rowStyle(1) == *style3);
+ QVERIFY(manager.rowStyle(2) == *style3);
+ //row 3 is a default inited style
+ QVERIFY(manager.rowStyle(4) == *style2);
+
+ manager.removeRows(2, 2);
+
+ QVERIFY(manager.rowStyle(0) == *style1);
+ QVERIFY(manager.rowStyle(1) == *style3);
+ QVERIFY(manager.rowStyle(2) == *style2);
}
QTEST_MAIN(TestKoTableColumnAndRowStyleManager)
diff --git a/libs/kotext/tests/TestKoTableColumnAndRowStyleManager.h \
b/libs/kotext/tests/TestKoTableColumnAndRowStyleManager.h index 938abf5..a2efb05 \
100644
--- a/libs/kotext/tests/TestKoTableColumnAndRowStyleManager.h
+++ b/libs/kotext/tests/TestKoTableColumnAndRowStyleManager.h
@@ -30,9 +30,10 @@ public:
TestKoTableColumnAndRowStyleManager() {}
private slots:
- // basic testing of the manager.
- void testManager();
-
+ // basic testing of the colums insertion and removal
+ void testColumns();
+ // basic testing of the rows insertion and removal
+ void testRows();
};
#endif // TESTKOTABLECOLUMNANDROWSTYLEMANAGER_H
diff --git a/plugins/textshape/CMakeLists.txt b/plugins/textshape/CMakeLists.txt
index bd11ad6..3ef70e7 100644
--- a/plugins/textshape/CMakeLists.txt
+++ b/plugins/textshape/CMakeLists.txt
@@ -60,6 +60,7 @@ SET ( textshape_SRCS
dialogs/TrackedChangeModel.cpp
dialogs/TrackedChangeManager.cpp
dialogs/ChangeTrackingOptionsWidget.cpp
+ dialogs/SimpleTableWidget.cpp
commands/ChangeListCommand.cpp
commands/ChangeListLevelCommand.cpp
@@ -95,6 +96,7 @@ kde4_add_ui_files(textshape_SRCS
dialogs/ChangeConfigureDialog.ui
dialogs/TrackedChangeManager.ui
dialogs/ChangeTrackingOptionsWidget.ui
+ dialogs/SimpleTableWidget.ui
)
kde4_add_plugin(textshape ${textshape_SRCS})
diff --git a/plugins/textshape/Layout.cpp b/plugins/textshape/Layout.cpp
index e8c0be1..9ef93e6 100644
--- a/plugins/textshape/Layout.cpp
+++ b/plugins/textshape/Layout.cpp
@@ -1119,11 +1119,12 @@ void Layout::drawFrame(QTextFrame *frame, QPainter *painter, \
const KoTextDocumen
if (table) {
m_tableLayout.setTable(table);
- m_tableLayout.drawBackground(painter);
+ m_tableLayout.drawBackground(painter, context);
drawFrame(table, painter, context, inTable+1); // this actually only \
draws the text inside
- QPainterPath accuBlankBorders;
+ QVector<QLineF> accuBlankBorders;
m_tableLayout.drawBorders(painter, &accuBlankBorders);
- painter->strokePath(accuBlankBorders, QPen(QColor(0,0,0,96)));
+ painter->setPen(QPen(QColor(0,0,0,96)));
+ painter->drawLines(accuBlankBorders);
continue;
} else if (subFrame) {
drawFrame(subFrame, painter, context, inTable);
diff --git a/plugins/textshape/TableLayout.cpp b/plugins/textshape/TableLayout.cpp
index cb61679..b630b69 100644
--- a/plugins/textshape/TableLayout.cpp
+++ b/plugins/textshape/TableLayout.cpp
@@ -23,6 +23,7 @@
#include "TableLayoutData.h"
#include <KoTableStyle.h>
+#include <KoTableBorderStyle.h>
#include <KoTableCellStyle.h>
#include <KoTableColumnStyle.h>
#include <KoTableRowStyle.h>
@@ -43,15 +44,14 @@
#include <kdebug.h>
-TableLayout::TableLayout(QTextTable *table) : m_dirty(true)
+TableLayout::TableLayout(QTextTable *table)
{
setTable(table);
}
TableLayout::TableLayout() :
m_table(0),
- m_tableLayoutData(0),
- m_dirty(true)
+ m_tableLayoutData(0)
{
}
@@ -59,23 +59,23 @@ void TableLayout::setTable(QTextTable *table)
{
Q_ASSERT(table);
- if (table == m_table)
- return; // we are already set
+ if (table != m_table) {
+ // We are not already set
+ TableLayoutData *tableLayoutData;
+ if (!m_tableLayoutDataMap.contains(table)) {
+ // Set up new table layout data.
+ tableLayoutData = new TableLayoutData();
+ m_tableLayoutDataMap.insert(table, tableLayoutData);
+ connect(table, SIGNAL(destroyed(QObject *)), this, \
SLOT(tableDestroyed(QObject *))); + } else {
+ // Table layout data already in map.
+ tableLayoutData = m_tableLayoutDataMap.value(table);
+ }
- TableLayoutData *tableLayoutData;
- if (!m_tableLayoutDataMap.contains(table)) {
- // Set up new table layout data.
- tableLayoutData = new TableLayoutData();
- m_tableLayoutDataMap.insert(table, tableLayoutData);
- connect(table, SIGNAL(destroyed(QObject *)), this, \
SLOT(tableDestroyed(QObject *)));
- } else {
- // Table layout data already in map.
- tableLayoutData = m_tableLayoutDataMap.value(table);
+ m_table = table;
+ m_tableLayoutData = tableLayoutData;
}
- m_table = table;
- m_tableLayoutData = tableLayoutData;
-
// Resize geometry vectors for the table.
m_tableLayoutData->m_rowPositions.resize(m_table->rows());
m_tableLayoutData->m_rowHeights.resize(m_table->rows());
@@ -83,8 +83,6 @@ void TableLayout::setTable(QTextTable *table)
for (int row = 0; row < m_table->rows(); ++row) {
m_tableLayoutData->m_contentHeights[row].resize(m_table->columns());
}
-
- m_dirty = true;
}
QTextTable *TableLayout::table() const
@@ -142,11 +140,7 @@ void TableLayout::startNewTableRect(QPointF position, qreal \
parentWidth, int fro tableRect.columnWidths.resize(m_table->columns());
// Get the column and row style manager.
- KoTableColumnAndRowStyleManager *carsManager =
- reinterpret_cast<KoTableColumnAndRowStyleManager *>(
- tableFormat.property(KoTableStyle::ColumnAndRowStyleManager).value<void \
*>());
- if (!carsManager)
- carsManager = new KoTableColumnAndRowStyleManager();
+ KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(m_table);
// Column widths.
qreal availableWidth = tableWidth; // Width available for columns.
@@ -154,7 +148,7 @@ void TableLayout::startNewTableRect(QPointF position, qreal \
parentWidth, int fro qreal relativeWidthSum = 0; // Sum of relative column width \
values. int numNonStyleColumns = 0;
for (int col = 0; col < tableRect.columnPositions.size(); ++col) {
- KoTableColumnStyle columnStyle = carsManager->columnStyle(col);
+ KoTableColumnStyle columnStyle = carsManager.columnStyle(col);
if (columnStyle.hasProperty(KoTableColumnStyle::RelativeColumnWidth)) {
// Relative width specified. Will be handled in the next loop.
relativeWidthColumns.append(col);
@@ -165,7 +159,6 @@ void TableLayout::startNewTableRect(QPointF position, qreal \
parentWidth, int fro availableWidth -= columnStyle.columnWidth();
} else {
// Neither width nor relative width specified.
- kWarning(32600) << "Neither column-width nor rel-column-width \
specified"; tableRect.columnWidths[col] = 0.0;
relativeWidthColumns.append(col); // handle it as a relative width \
column without asking for anything ++numNonStyleColumns;
@@ -180,7 +173,7 @@ void TableLayout::startNewTableRect(QPointF position, qreal \
parentWidth, int fro
// Relative column widths have now been summed up and can be distributed.
foreach (int col, relativeWidthColumns) {
- KoTableColumnStyle columnStyle = carsManager->columnStyle(col);
+ KoTableColumnStyle columnStyle = carsManager.columnStyle(col);
if (columnStyle.hasProperty(KoTableColumnStyle::RelativeColumnWidth) || \
columnStyle.hasProperty(KoTableColumnStyle::ColumnWidth)) { \
tableRect.columnWidths[col] =
qMax<qreal>(columnStyle.relativeColumnWidth() * availableWidth / \
relativeWidthSum, 0.0); @@ -206,10 +199,10 @@ void \
TableLayout::startNewTableRect(QPointF position, qreal parentWidth, int fro \
columnPosition += tableRect.columnWidths[col]; }
+ m_tableLayoutData->m_minX = qMin(m_tableLayoutData->m_minX, \
tableRect.columnPositions[0]); + m_tableLayoutData->m_maxX = \
qMax(m_tableLayoutData->m_maxX, columnPosition); \
m_tableLayoutData->m_tableRects.append(tableRect);
m_tableLayoutData->m_rowPositions[fromRow] = tableRect.rect.top(); //Initialize \
the position of first row of tableRect
-
- m_dirty = false;
}
void TableLayout::layoutRow(int row)
@@ -221,7 +214,6 @@ void TableLayout::layoutRow(int row)
if (!isValid()) {
return;
}
-
if (row < 0 || row >= m_table->rows()) {
return;
}
@@ -235,12 +227,7 @@ void TableLayout::layoutRow(int row)
QTextTableFormat tableFormat = m_table->format();
// Get the column and row style manager.
- KoTableColumnAndRowStyleManager *carsManager =
- reinterpret_cast<KoTableColumnAndRowStyleManager *>(
- tableFormat.property(KoTableStyle::ColumnAndRowStyleManager).value<void \
*>());
-
- if (!carsManager)
- carsManager = new KoTableColumnAndRowStyleManager();
+ KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(m_table);
/*
* Implementation Note:
@@ -264,7 +251,7 @@ void TableLayout::layoutRow(int row)
* cells that should contribute to the row height.
*/
- KoTableRowStyle rowStyle = carsManager->rowStyle(row);
+ KoTableRowStyle rowStyle = carsManager.rowStyle(row);
// Adjust row height.
qreal minimumRowHeight = rowStyle.minimumRowHeight();
@@ -314,7 +301,8 @@ void TableLayout::layoutRow(int row)
m_tableLayoutData->m_rowPositions[row+1] =
m_tableLayoutData->m_rowPositions[row ] + // Position of this row.
m_tableLayoutData->m_rowHeights[row]; // Height of this row.
- }
+ } else
+ m_tableLayoutData->m_dirty = false; //we have reached the end and the table \
should now be fully laied out
// Adjust table rect height for new height.
m_tableLayoutData->m_tableRects.last().rect.setHeight(m_tableLayoutData->m_rowPositions[row]
@@ -322,19 +310,23 @@ void TableLayout::layoutRow(int row)
- m_tableLayoutData->m_rowPositions[m_tableLayoutData->m_tableRects.last().fromRow]);//FIXME \
review when breaking inside a row }
-void TableLayout::drawBackground(QPainter *painter) const
+void TableLayout::drawBackground(QPainter *painter, const \
KoTextDocumentLayout::PaintContext &context) const {
if (m_tableLayoutData->m_tableRects.isEmpty()) {
return;
}
-
painter->save();
-
- // Draw table background.
+ // Draw table background and row backgrounds
+ KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(m_table); foreach (TableRect tRect, \
m_tableLayoutData->m_tableRects) { painter->fillRect(tRect.rect, \
m_table->format().background()); + QRectF tableRect = tRect.rect;
+ for (int row = tRect.fromRow; row < m_table->rows() && \
m_tableLayoutData->m_rowPositions[row] < tableRect.bottom(); ++row) { + \
QRectF rowRect(tableRect.x(), m_tableLayoutData->m_rowPositions[row], \
tableRect.width(), m_tableLayoutData->m_rowHeights[row]); + \
KoTableRowStyle rowStyle = carsManager.rowStyle(row); + \
painter->fillRect(rowRect, rowStyle.background()); + }
}
-
// Draw cell backgrounds using their styles.
for (int row = 0; row < m_table->rows(); ++row) {
for (int column = 0; column < m_table->columns(); ++column) {
@@ -346,9 +338,30 @@ void TableLayout::drawBackground(QPainter *painter) const
*/
if (row == tableCell.row() && column == tableCell.column()) {
// This is an actual cell we want to draw, and not a covered one.
-
- KoTableCellStyle cellStyle(tableCell.format().toTableCellFormat());
- cellStyle.paintBackground(*painter, cellBoundingRect(tableCell));
+ QTextTableCellFormat tfm(tableCell.format().toTableCellFormat());
+ QRectF bRect(cellBoundingRect(tableCell,tfm));
+ QVariant \
background(tfm.property(KoTableBorderStyle::CellBackgroundBrush)); + \
if (!background.isNull()) { + painter->fillRect(bRect, \
qvariant_cast<QBrush>(background)); + }
+ // possibly draw the selection of the entire cell
+ foreach(const QAbstractTextDocumentLayout::Selection & selection, \
context.textContext.selections) { + if \
(selection.cursor.hasComplexSelection()) { + int selectionRow;
+ int selectionColumn;
+ int selectionRowSpan;
+ int selectionColumnSpan;
+ selection.cursor.selectedTableCells(&selectionRow, \
&selectionRowSpan, &selectionColumn, &selectionColumnSpan); + \
if (row >= selectionRow && column>=selectionColumn + && \
row < selectionRow + selectionRowSpan + && column < \
selectionColumn + selectionColumnSpan) { + \
painter->fillRect(bRect, selection.format.background()); + }
+ } else if (selection.cursor.selectionStart() < \
m_table->firstPosition() + && selection.cursor.selectionEnd() \
> m_table->lastPosition()) { + painter->fillRect(bRect, \
> selection.format.background());
+ }
+ }
}
}
}
@@ -380,7 +393,7 @@ void TableLayout::drawBackground(QPainter *painter) const
painter->restore();
}
-void TableLayout::drawBorders(QPainter *painter, QPainterPath *accuBlankBorders) \
const +void TableLayout::drawBorders(QPainter *painter, QVector<QLineF> \
*accuBlankBorders) const {
if (m_tableLayoutData->m_tableRects.isEmpty()) {
return;
@@ -402,29 +415,30 @@ void TableLayout::drawBorders(QPainter *painter, QPainterPath \
*accuBlankBorders)
*/
if (row == tableCell.row() && column == tableCell.column()) {
// This is an actual cell we want to draw, and not a covered one.
- KoTableCellStyle cellStyle(tableCell.format().toTableCellFormat());
+ QTextTableCellFormat tfm(tableCell.format().toTableCellFormat());
+ KoTableBorderStyle cellStyle(tfm);
+ QRectF bRect = cellBoundingRect(tableCell,tfm);
if (collapsing) {
- QRectF bRect = cellBoundingRect(tableCell);
// First the horizontal borders
if (row == 0) {
cellStyle.drawTopHorizontalBorder(*painter, bRect.x(), \
bRect.y(), bRect.width(), accuBlankBorders); }
- if (row + tableCell.rowSpan() == m_table->rows()) {
+ if (row + tfm.tableCellRowSpan() == m_table->rows()) {
// we hit the bottom of the table so just draw the bottom \
border
cellStyle.drawBottomHorizontalBorder(*painter, bRect.x(), \
bRect.bottom(), bRect.width(), accuBlankBorders); } else {
- // we have cells below so draw sharedborders
- QTextTableCell tableCellBelow;
- for (int c = column; c < column + tableCell.columnSpan();
- c = \
tableCellBelow.column()+tableCellBelow.columnSpan()) {
- tableCellBelow = m_table->cellAt(row + \
tableCell.rowSpan()-1+1, c);
- QRectF belowBRect = cellBoundingRect(tableCellBelow);
+ int c = column;
+ while (c < column + tfm.tableCellColumnSpan()) {
+ QTextTableCell tableCellBelow = m_table->cellAt(row + \
tfm.tableCellRowSpan(), c); + QTextTableCellFormat \
belowTfm(tableCellBelow.format().toTableCellFormat()); + \
QRectF belowBRect = cellBoundingRect(tableCellBelow, belowTfm); qreal x = \
qMax(bRect.x(), belowBRect.x());
qreal x2 = qMin(bRect.right(), belowBRect.right());
- KoTableCellStyle \
cellBelowStyle(tableCellBelow.format().toTableCellFormat()); + \
KoTableBorderStyle cellBelowStyle(belowTfm);
cellStyle.drawSharedHorizontalBorder(*painter, \
cellBelowStyle, x, bRect.bottom(), x2 - x, accuBlankBorders); + \
c = tableCellBelow.column() + belowTfm.tableCellColumnSpan(); }
}
@@ -432,27 +446,27 @@ void TableLayout::drawBorders(QPainter *painter, QPainterPath \
*accuBlankBorders) if (column == 0) {
cellStyle.drawLeftmostVerticalBorder(*painter, bRect.x(), \
bRect.y(), bRect.height(), accuBlankBorders); }
- if (column + tableCell.columnSpan() == m_table->columns()) {
+ if (column + tfm.tableCellColumnSpan() == m_table->columns()) {
// we hit the rightmost edge of the table so draw the \
rightmost border
cellStyle.drawRightmostVerticalBorder(*painter, \
bRect.right(), bRect.y(), bRect.height(), accuBlankBorders); } else {
// we have cells to the right so draw sharedborders
- QTextTableCell tableCellRight;
- for (int r = row; r < row + tableCell.rowSpan();
- r = tableCellRight.row() + \
tableCellRight.rowSpan()) {
- tableCellRight = m_table->cellAt(r, column + \
tableCell.columnSpan()-1+1);
- QRectF rightBRect = cellBoundingRect(tableCellRight);
+ int r = row;
+ while (r < row + tfm.tableCellRowSpan()) {
+ QTextTableCell tableCellRight = m_table->cellAt(r, \
column + tfm.tableCellColumnSpan()); + \
QTextTableCellFormat rightTfm(tableCellRight.format().toTableCellFormat()); + \
QRectF rightBRect = cellBoundingRect(tableCellRight, rightTfm); qreal y = \
qMax(bRect.y(), rightBRect.y());
qreal y2 = qMin(bRect.bottom(), rightBRect.bottom());
-
- KoTableCellStyle \
cellBelowRight(tableCellRight.format().toTableCellFormat()); + \
KoTableBorderStyle cellBelowRight(rightTfm);
cellStyle.drawSharedVerticalBorder(*painter, \
cellBelowRight, bRect.right(), y, y2-y, accuBlankBorders); + \
r = tableCellRight.row() + rightTfm.tableCellRowSpan(); }
}
// Paint diagonal borders for current cell
cellStyle.paintDiagonalBorders(*painter, bRect);
} else { // separating border model
- cellStyle.paintBorders(*painter, cellBoundingRect(tableCell));
+ cellStyle.paintBorders(*painter, bRect, accuBlankBorders);
}
}
}
@@ -484,17 +498,52 @@ QTextTableCell TableLayout::hitTestTable(const QPointF &point) \
const return QTextTableCell();
}
+qreal TableLayout::tableMinX() const
+{
+ return m_tableLayoutData->m_minX-10; //-10 is just to add potential penwidths
+}
+
+qreal TableLayout::tableMaxX() const
+{
+ return m_tableLayoutData->m_maxX+10; //10 is just to add potential penwidths
+}
+
qreal TableLayout::cellContentY(const QTextTableCell &cell) const
{
Q_ASSERT(isValid());
Q_ASSERT(cell.isValid());
/*
+ * Get the cell style and return the y pos adjusted for
+ * borders and paddings.
+ */
+ KoTableCellStyle cellStyle(cell.format().toTableCellFormat());
+ return m_tableLayoutData->m_rowPositions[cell.row()] + cellStyle.topPadding() + \
cellStyle.topBorderWidth(); +}
+
+qreal TableLayout::cellContentX(const QTextTableCell &cell) const
+{
+ Q_ASSERT(isValid());
+ Q_ASSERT(cell.isValid());
+ Q_ASSERT(cell.row() < m_tableLayoutData->m_rowPositions.size());
+
+ if (m_tableLayoutData->m_tableRects.isEmpty())
+ return 0.0;
+
+ TableRect tableRect = m_tableLayoutData->m_tableRects.last();
+ int i = m_tableLayoutData->m_tableRects.size()-1;
+ while (tableRect.fromRow > cell.row()) {
+ --i;
+ tableRect = m_tableLayoutData->m_tableRects[i];
+ }
+ Q_ASSERT(cell.column() + cell.columnSpan() <= \
tableRect.columnPositions.size()); +
+ /*
* Get the cell style and return the bounding rect adjusted for
* borders and paddings by calling KoTableCellStyle::contentRect().
*/
KoTableCellStyle cellStyle(cell.format().toTableCellFormat());
- return m_tableLayoutData->m_rowPositions[cell.row()] + cellStyle.topPadding() + \
cellStyle.topBorderWidth(); + return tableRect.columnPositions[cell.column()] + \
cellStyle.topPadding() + cellStyle.topBorderWidth(); }
QRectF TableLayout::cellContentRect(const QTextTableCell &cell) const
@@ -512,34 +561,41 @@ QRectF TableLayout::cellContentRect(const QTextTableCell &cell) \
const
QRectF TableLayout::cellBoundingRect(const QTextTableCell &cell) const
{
+ return cellBoundingRect(cell, cell.format());
+}
+
+QRectF TableLayout::cellBoundingRect(const QTextTableCell &cell, const \
QTextCharFormat &fmt) const +{
Q_ASSERT(isValid());
- Q_ASSERT(cell.row() < m_tableLayoutData->m_rowPositions.size());
-
- if (m_tableLayoutData->m_tableRects.isEmpty())
- return QRectF(QPointF(0.0,0.0), QSizeF(0.0,0.0));
+ const int row = cell.row();
+ const int column = cell.column();
+ const int rowSpan = fmt.tableCellRowSpan();
+ const int columnSpan = fmt.tableCellColumnSpan();
+
+ Q_ASSERT(row < m_tableLayoutData->m_rowPositions.size());
TableRect tableRect = m_tableLayoutData->m_tableRects.last();
int i = m_tableLayoutData->m_tableRects.size()-1;
- while (tableRect.fromRow > cell.row()) {
+ while (tableRect.fromRow > row) {
--i;
tableRect = m_tableLayoutData->m_tableRects[i];
}
- Q_ASSERT(cell.column() + cell.columnSpan() <= \
tableRect.columnPositions.size()); + Q_ASSERT(column + columnSpan <= \
tableRect.columnPositions.size());
// Cell width.
qreal width = 0;
- for (int col = 0; col < cell.columnSpan(); ++col) {
- width += tableRect.columnWidths[cell.column() + col];
+ for (int col = 0; col < columnSpan; ++col) {
+ width += tableRect.columnWidths[column + col];
}
// Cell height.
qreal height = 0;
- for (int r = 0; r < cell.rowSpan(); ++r) {
- height += m_tableLayoutData->m_rowHeights[cell.row() + r];
+ for (int r = 0; r < rowSpan; ++r) {
+ height += m_tableLayoutData->m_rowHeights[row + r];
// TODO when breaking within a row the tableRect needs to be switched at \
some point }
- return QRectF(tableRect.columnPositions[cell.column()], \
m_tableLayoutData->m_rowPositions[cell.row()], + return \
QRectF(tableRect.columnPositions[column], m_tableLayoutData->m_rowPositions[row], \
width, height); }
@@ -598,7 +654,7 @@ qreal TableLayout::yAfterTable() const
bool TableLayout::isDirty() const
{
- return m_dirty;
+ return isValid() && m_tableLayoutData->m_dirty;
}
bool TableLayout::isValid() const
diff --git a/plugins/textshape/TableLayout.h b/plugins/textshape/TableLayout.h
index bd5cb9a..f65931f 100644
--- a/plugins/textshape/TableLayout.h
+++ b/plugins/textshape/TableLayout.h
@@ -193,7 +193,7 @@ public:
*
* @param painter a pointer to the QPainter to draw the table with.
*/
- void drawBackground(QPainter *painter) const;
+ void drawBackground(QPainter *painter, const KoTextDocumentLayout::PaintContext \
&context) const;
/**
* Draw the table borders using the given QPainter.
@@ -201,7 +201,7 @@ public:
* @param painter a pointer to the QPainter to draw the table with.
* @param accuBlankBorders a painterpath that should accumulate blank borders.
*/
- void drawBorders(QPainter *painter, QPainterPath *accuBlankBorders) const;
+ void drawBorders(QPainter *painter, QVector<QLineF> *accuBlankBorders) const;
/**
* Figures outDraw the table borders using the given QPainter.
@@ -222,7 +222,21 @@ public:
*
* @return the list of rectangles.
*/
- QList<QRectF> tableRects() const;
+// QList<QRectF> tableRects() const;
+
+ /**
+ * Get the left edge position of the table minimum if spanning several \
tableRects + *
+ * @return x.
+ */
+ qreal tableMinX() const;
+
+ /**
+ * Get the right edge position of the table maximum if spanning several \
tableRects + *
+ * @return x.
+ */
+ qreal tableMaxX() const;
/**
* Get the bounding rectangle of a given cell.
@@ -231,6 +245,7 @@ public:
* @return the bounding rectangle of the cell.
*/
QRectF cellBoundingRect(const QTextTableCell &cell) const;
+ QRectF cellBoundingRect(const QTextTableCell &cell, const QTextCharFormat &fmt) \
const;
/**
* Get the content rectangle of a given cell.
@@ -253,6 +268,16 @@ public:
qreal cellContentY(const QTextTableCell &cell) const;
/**
+ * Get the content X of a given cell.
+ *
+ * @param cell the cell.
+ * @return the x pos where content starts.
+ *
+ * \sa position(), setPosition()
+ */
+ qreal cellContentX(const QTextTableCell &cell) const;
+
+ /**
* Get the bounding rectangle of a given row.
*
* @param row the row.
@@ -310,8 +335,6 @@ private:
TableLayoutData *m_tableLayoutData; /**< The current table layout data. */
QMap<QTextTable *, TableLayoutData *> m_tableLayoutDataMap; /**< The map of \
table layout data objects. */
-
- bool m_dirty; /**< Table layout is dirty. */
};
#endif // TABLELAYOUT_H
diff --git a/plugins/textshape/TableLayoutData.cpp \
b/plugins/textshape/TableLayoutData.cpp index 448adf5..605dc08 100644
--- a/plugins/textshape/TableLayoutData.cpp
+++ b/plugins/textshape/TableLayoutData.cpp
@@ -20,6 +20,9 @@
#include "TableLayoutData.h"
TableLayoutData::TableLayoutData()
+ : m_dirty(true)
+ ,m_minX(0)
+ ,m_maxX(0)
{
}
diff --git a/plugins/textshape/TableLayoutData.h \
b/plugins/textshape/TableLayoutData.h index 6378d36..4b9a9e2 100644
--- a/plugins/textshape/TableLayoutData.h
+++ b/plugins/textshape/TableLayoutData.h
@@ -62,6 +62,9 @@ private:
QVector<QVector<qreal> > m_contentHeights; /**< Cell content heights. */
QList<TableRect> m_tableRects; /**< Rects occupied by table, typically one per \
shape the table is in. */ + bool m_dirty;
+ qreal m_minX;
+ qreal m_maxX;
};
#endif // TABLELAYOUTDATA_H
diff --git a/plugins/textshape/TextTool.cpp b/plugins/textshape/TextTool.cpp
index 91870e1..764cfc3 100644
--- a/plugins/textshape/TextTool.cpp
+++ b/plugins/textshape/TextTool.cpp
@@ -32,6 +32,7 @@
#include "dialogs/TableDialog.h"
#include "dialogs/ChangeConfigureDialog.h"
#include "dialogs/ChangeTrackingOptionsWidget.h"
+#include "dialogs/SimpleTableWidget.h"
#include "commands/TextCutCommand.h"
#include "commands/TextPasteCommand.h"
#include "commands/ChangeListCommand.h"
@@ -356,11 +357,46 @@ TextTool::TextTool(KoCanvasBase *canvas)
}
setPopupActionList(list);
-
action = new KAction(i18n("Table..."), this);
addAction("insert_table", action);
action->setToolTip(i18n("Insert a table into the document."));
connect(action, SIGNAL(triggered()), this, SLOT(insertTable()));
+ action = new KAction(KIcon("edit-table-insert-row-above"), i18n("Row Above"), \
this); + action->setToolTip(i18n("Insert Row Above"));
+ addAction("insert_tablerow_above", action);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(insertTableRowAbove()));
+
+ action = new KAction(KIcon("edit-table-insert-row-below"), i18n("Row Below"), \
this); + action->setToolTip(i18n("Insert Row Below"));
+ addAction("insert_tablerow_below", action);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(insertTableRowBelow()));
+
+ action = new KAction(KIcon("edit-table-insert-column-left"), i18n("Column \
Left"), this); + action->setToolTip(i18n("Insert Column Left"));
+ addAction("insert_tablecolumn_left", action);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(insertTableColumnLeft()));
+
+ action = new KAction(KIcon("edit-table-insert-column-right"), i18n("Column \
Right"), this); + action->setToolTip(i18n("Insert Column Right"));
+ addAction("insert_tablecolumn_right", action);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(insertTableColumnRight()));
+ action = new KAction(KIcon("edit-table-delete-column"), i18n("Column"), this);
+ action->setToolTip(i18n("Delete Column"));
+ addAction("delete_tablecolumn", action);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(deleteTableColumn()));
+
+ action = new KAction(KIcon("edit-table-delete-row"), i18n("Row"), this);
+ action->setToolTip(i18n("Delete Row"));
+ addAction("delete_tablerow", action);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(deleteTableRow()));
+
+ action = new KAction(KIcon("merge"), i18n("Merge Cells"), this);
+ addAction("merge_tablecells", action);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(mergeTableCells()));
+
+ action = new KAction(KIcon("split"), i18n("Split Cells"), this);
+ addAction("split_tablecells", action);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(splitTableCells()));
action = new KAction(i18n("Paragraph..."), this);
addAction("format_paragraph", action);
@@ -1478,6 +1514,8 @@ QWidget *TextTool::createOptionWidget()
widget->addTab(styles, i18n("Styles"));
ChangeTrackingOptionsWidget *changeTrackingOptions = new \
ChangeTrackingOptionsWidget(this, widget); widget->addTab(changeTrackingOptions, \
i18n("Change Tracking")); + SimpleTableWidget *stw = new SimpleTableWidget(this, \
0); + widget->addTab(stw, i18n("Table"));
connect(this, SIGNAL(styleManagerChanged(KoStyleManager *)), ssw, \
SLOT(setStyleManager(KoStyleManager *)));
connect(this, SIGNAL(blockChanged(const QTextBlock&)), ssw, \
SLOT(setCurrentBlock(const QTextBlock&))); @@ -1746,10 +1784,48 @@ void \
TextTool::insertTable() TableDialog *dia = new TableDialog(0);
if (dia->exec() == TableDialog::Accepted)
m_textEditor.data()->insertTable(dia->rows(), dia->columns());
-
delete dia;
}
+void TextTool::insertTableRowAbove()
+{
+ m_textEditor.data()->insertTableRowAbove();
+}
+
+void TextTool::insertTableRowBelow()
+{
+ m_textEditor.data()->insertTableRowBelow();
+}
+
+void TextTool::insertTableColumnLeft()
+{
+ m_textEditor.data()->insertTableColumnLeft();
+}
+
+void TextTool::insertTableColumnRight()
+{
+ m_textEditor.data()->insertTableColumnRight();
+}
+
+void TextTool::deleteTableColumn()
+{
+ m_textEditor.data()->deleteTableColumn();
+}
+
+void TextTool::deleteTableRow()
+{
+ m_textEditor.data()->deleteTableRow();
+}
+
+void TextTool::mergeTableCells()
+{
+ m_textEditor.data()->mergeTableCells();
+}
+
+void TextTool::splitTableCells()
+{
+ m_textEditor.data()->splitTableCells();
+}
void TextTool::formatParagraph()
{
diff --git a/plugins/textshape/TextTool.h b/plugins/textshape/TextTool.h
index e6db6a0..d9ef88f 100644
--- a/plugins/textshape/TextTool.h
+++ b/plugins/textshape/TextTool.h
@@ -198,6 +198,22 @@ private slots:
void insertIndexMarker();
/// shows a dialog to insert a table
void insertTable();
+ /// insert a row above
+ void insertTableRowAbove();
+ /// insert a row below
+ void insertTableRowBelow();
+ /// insert a column left
+ void insertTableColumnLeft();
+ /// insert a column right
+ void insertTableColumnRight();
+ /// delete a column
+ void deleteTableColumn();
+ /// delete a row
+ void deleteTableRow();
+ /// merge table cells
+ void mergeTableCells();
+ /// split previous merged table cells
+ void splitTableCells();
/// shows a dialog to alter the paragraph properties
void formatParagraph();
/// select all text in the current document.
diff --git a/plugins/textshape/tests/CMakeLists.txt \
b/plugins/textshape/tests/CMakeLists.txt index 95fd648..16d22c8 100644
--- a/plugins/textshape/tests/CMakeLists.txt
+++ b/plugins/textshape/tests/CMakeLists.txt
@@ -71,6 +71,7 @@ set(TestChangeListCommand_test_SRCS
../dialogs/TrackedChangeModel.cpp
../dialogs/ChangeConfigureDialog.cpp
../dialogs/ChangeTrackingOptionsWidget.cpp
+ ../dialogs/SimpleTableWidget.cpp
../ListItemsHelper.cpp
../TextShape.cpp
../Layout.cpp
@@ -174,6 +175,7 @@ set(TestTextTool_test_SRCS
../dialogs/TrackedChangeManager.cpp
../dialogs/TrackedChangeModel.cpp
../dialogs/ChangeTrackingOptionsWidget.cpp
+ ../dialogs/SimpleTableWidget.cpp
../Layout.cpp
../ListItemsHelper.cpp
../TableLayout.cpp
@@ -232,6 +234,7 @@ set(TestChangeTrackedDelete_test_SRCS
../dialogs/TrackedChangeModel.cpp
../dialogs/ChangeConfigureDialog.cpp
../dialogs/ChangeTrackingOptionsWidget.cpp
+ ../dialogs/SimpleTableWidget.cpp
../ListItemsHelper.cpp
../TextShape.cpp
../Layout.cpp
diff --git a/plugins/textshape/tests/TestTableLayout.cpp \
b/plugins/textshape/tests/TestTableLayout.cpp index 8381119..133601a 100644
--- a/plugins/textshape/tests/TestTableLayout.cpp
+++ b/plugins/textshape/tests/TestTableLayout.cpp
@@ -24,7 +24,6 @@ void TestTableLayout::init()
m_table = 0;
m_layout = 0;
m_styleManager = 0;
- m_tableColumnAndRowStyleManager = 0;
m_textLayout = 0;
m_shape = 0;
m_defaultTableStyle = 0;
@@ -74,32 +73,30 @@ void TestTableLayout::initTest(int rows, int columns,
m_defaultTableStyle->applyStyle(tableFormat);
}
- // Column and row style manager.
- m_tableColumnAndRowStyleManager = new KoTableColumnAndRowStyleManager();
- Q_ASSERT(m_tableColumnAndRowStyleManager);
- tableFormat.setProperty(KoTableStyle::ColumnAndRowStyleManager, \
QVariant::fromValue(reinterpret_cast<void \
*>(m_tableColumnAndRowStyleManager)));
-
// Table.
QTextCursor cursor(m_doc);
m_table = cursor.insertTable(rows, columns, tableFormat);
Q_ASSERT(m_table);
+ // Column and row style manager.
+ m_tableColumnAndRowStyleManager = \
KoTableColumnAndRowStyleManager::getManager(m_table); +
// Column styles.
m_defaultColumnStyle.setRelativeColumnWidth(50.0);
for (int col = 0; col < columns; ++col) {
if (columnStyles.value(col)) {
- m_tableColumnAndRowStyleManager->setColumnStyle(col, \
*(columnStyles.at(col))); + \
m_tableColumnAndRowStyleManager.setColumnStyle(col, *(columnStyles.at(col))); } else \
{
- m_tableColumnAndRowStyleManager->setColumnStyle(col, \
m_defaultColumnStyle); + \
m_tableColumnAndRowStyleManager.setColumnStyle(col, m_defaultColumnStyle); }
}
// Row styles.
for (int row = 0; row < rows; ++row) {
if (rowStyles.value(row)) {
- m_tableColumnAndRowStyleManager->setRowStyle(row, *(rowStyles.at(row)));
+ m_tableColumnAndRowStyleManager.setRowStyle(row, *(rowStyles.at(row)));
} else {
- m_tableColumnAndRowStyleManager->setRowStyle(row, m_defaultRowStyle);
+ m_tableColumnAndRowStyleManager.setRowStyle(row, m_defaultRowStyle);
}
}
@@ -149,7 +146,6 @@ void TestTableLayout::cleanupTest()
{
delete m_table;
delete m_styleManager;
- delete m_tableColumnAndRowStyleManager;
delete m_defaultTableStyle;
delete m_defaultCellStyle;
}
diff --git a/plugins/textshape/tests/TestTableLayout.h \
b/plugins/textshape/tests/TestTableLayout.h index f6572ef..f6cb4d2 100644
--- a/plugins/textshape/tests/TestTableLayout.h
+++ b/plugins/textshape/tests/TestTableLayout.h
@@ -3,6 +3,7 @@
#include <KoTableColumnStyle.h>
#include <KoTableRowStyle.h>
+#include <KoTableColumnAndRowStyleManager.h>
#include <QObject>
#include <QHash>
@@ -104,7 +105,7 @@ private:
QTextTable *m_table;
KoTextDocumentLayout *m_layout;
KoStyleManager *m_styleManager;
- KoTableColumnAndRowStyleManager *m_tableColumnAndRowStyleManager;
+ KoTableColumnAndRowStyleManager m_tableColumnAndRowStyleManager;
Layout *m_textLayout;
MockTextShape *m_shape;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic