[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: Re: [patch] remove row/columns from table
From: "Emmanuel Touzery" <emmanuel.touzery () wanadoo ! fr>
Date: 2002-05-27 6:37:56
[Download RAW message or body]
Hello,
Here we are. with the attached patch, if you move the mouse slightly above
or on the left of a table, the mouse cursor changes (to hand, maybe we could
find better?), and you can select rows/cols. the delete row/cols dialog is
updated.
emmanuel
["delrowcol2.diff" (application/octet-stream)]
? delrowcol2.tgz
? removerowcol.diff
? delrowcol2.diff
? old_kw.tgz
Index: deldia.cc
===================================================================
RCS file: /home/kde/koffice/kword/deldia.cc,v
retrieving revision 1.20
diff -u -3 -p -r1.20 deldia.cc
--- deldia.cc 13 Oct 2001 00:17:00 -0000 1.20
+++ deldia.cc 27 May 2002 06:25:35 -0000
@@ -41,6 +41,7 @@ KWDeleteDia::KWDeleteDia( QWidget *paren
table = _table;
doc = _doc;
canvas = _canvas;
+ m_toRemove.clear();
setupTab1();
setButtonOKText(i18n("&Delete"), type == ROW ?
@@ -55,44 +56,70 @@ void KWDeleteDia::setupTab1()
tab1 = plainPage();
grid1 = new QGridLayout( tab1, 4, 1, 0, spacingHint() );
- rc = new QLabel( type == ROW ? i18n( "Delete Row:" ) : i18n( "Delete Column:" ), \
tab1 ); + QString message =type == ROW ? i18n( "Delete Row(s):" ) : i18n( "Delete \
Column(s):" ); + bool firstSelectedCell = true; // used to know whether to add a \
", " to the message string. +
+ uint max = (type == ROW) ? table->getRows() : table->getCols(); // max row/col \
to loop up to + for (uint i=0;i<max; i++)
+ {
+ if ( ( (type == ROW) && table->isRowSelected(i)) ||
+ ( (type == COL) && table->isColSelected(i) ) )
+ {
+ if (!firstSelectedCell)
+ message += ", "; // i18n??
+ message += QString::number(i +1);
+ m_toRemove.push_back(i);
+ firstSelectedCell = false;
+ }
+ }
+ Q_ASSERT(m_toRemove.count() > 0);
+
+ if (m_toRemove.count() == ( (type == ROW) ? table->getRows() : table->getCols() \
) ) + // all the columns are selected and the user asked to remove columns or \
the same with rows + // => we want to delete the whole table
+ message = i18n("Delete the whole table");
+
+ // do not display hugely long dialogs if many rows/cells are selected
+ if (m_toRemove.count() > 10)
+ message = ROW ? i18n("Delete all selected rows") : i18n("Delete all selected \
cells"); +
+ rc = new QLabel( message , tab1 );
rc->resize( rc->sizeHint() );
rc->setAlignment( AlignLeft | AlignBottom );
grid1->addWidget( rc, 1, 0 );
-
- value = new QSpinBox( 1, type == ROW ? table->getRows() : table->getCols(), 1, \
tab1 );
- value->resize( value->sizeHint() );
- value->setValue( type == ROW ? table->getRows() : table->getCols() );
- grid1->addWidget( value, 2, 0 );
-
- grid1->addRowSpacing( 1, rc->height() );
- grid1->addRowSpacing( 2, value->height() );
- grid1->setRowStretch( 0, 1 );
- grid1->setRowStretch( 1, 0 );
- grid1->setRowStretch( 2, 0 );
- grid1->setRowStretch( 3, 1 );
-
- grid1->addColSpacing( 0, rc->width() );
- grid1->addColSpacing( 0, value->width() );
- grid1->setColStretch( 0, 1 );
}
bool KWDeleteDia::doDelete()
{
- unsigned int remove= value->value() - 1;
- if ( type == ROW )
- {
- KWRemoveRowCommand *cmd = new KWRemoveRowCommand( i18n("Remove row"), table, \
remove);
- cmd->execute();
- doc->addCommand(cmd);
- //table->deleteRow( value->value() - 1 );
+ KCommand *globalCommand;
+
+ if (m_toRemove.count() == ( (type == ROW) ? table->getRows() : table->getCols() \
) ) + { // we have to delete the whole table
+ //globalCommand = new KWDeleteTableCommand(i18n("Remove table"), table);
+ doc->deleteTable(table);
}
else
- {
- KWRemoveColumnCommand *cmd = new KWRemoveColumnCommand( i18n("Remove \
column"), table, remove);
- cmd->execute();
- doc->addCommand(cmd);
- //table->deleteCol( value->value() - 1 );
+ { // we will just delete some row/cols
+ if ( type == ROW )
+ {
+ globalCommand = new KMacroCommand(i18n("Remove rows"));
+ for (uint i=0;i<m_toRemove.count();i++)
+ {
+ KWRemoveRowCommand *cmd = new KWRemoveRowCommand( i18n("Remove \
row"), table, m_toRemove[i] ); + \
static_cast<KMacroCommand*>(globalCommand)->addCommand(cmd); + }
+ }
+ else
+ {
+ globalCommand = new KMacroCommand(i18n("Remove columns"));
+ for (uint i=0;i<m_toRemove.count();i++)
+ {
+ KWRemoveColumnCommand *cmd = new KWRemoveColumnCommand( i18n("Remove \
column"), table, m_toRemove[i] ); + \
static_cast<KMacroCommand*>(globalCommand)->addCommand(cmd); + }
+ }
+ globalCommand->execute();
+ doc->addCommand(globalCommand);
}
return true;
Index: deldia.h
===================================================================
RCS file: /home/kde/koffice/kword/deldia.h,v
retrieving revision 1.10
diff -u -3 -p -r1.10 deldia.h
--- deldia.h 14 Apr 2001 23:49:15 -0000 1.10
+++ deldia.h 27 May 2002 06:25:35 -0000
@@ -55,6 +55,8 @@ protected:
KWDocument *doc;
DeleteType type;
KWCanvas *canvas;
+
+ QValueList<uint> m_toRemove; // not really sure i should hold this here but ok.
protected slots:
virtual void slotOk();
Index: kwcanvas.cc
===================================================================
RCS file: /home/kde/koffice/kword/kwcanvas.cc,v
retrieving revision 1.333
diff -u -3 -p -r1.333 kwcanvas.cc
--- kwcanvas.cc 12 Apr 2002 07:03:58 -0000 1.333
+++ kwcanvas.cc 27 May 2002 06:25:36 -0000
@@ -318,6 +318,11 @@ void KWCanvas::mpEditFrame( QMouseEvent
KoPoint docPoint( m_doc->unzoomPoint( nPoint ) );
table->selectUntil( docPoint.x(), docPoint.y() );
}
+ else if ( ( e->state() & ShiftButton ) && \
(m_doc->positionToSelectRowcolTable( nPoint, &table) != \
KWDocument::TABLE_POSITION_NONE) ) // we are in position to select full row/cells of \
a table + hold shift + {
+ KoPoint docPoint( m_doc->unzoomPoint( nPoint ) );
+ table->selectUntil( table->boundingRect().right(), docPoint.y() );
+ }
else if ( frame && !frame->isSelected() ) // clicked on a frame that wasn't \
selected {
if ( ! ( e->state() & ShiftButton || e->state() & ControlButton ) )
@@ -512,8 +517,29 @@ void KWCanvas::contentsMousePressEvent(
m_frameInline=false;
}
}
+
+ KWTableFrameSet *table = 0L;
+ KWDocument::TableToSelectPosition ePositionTable = \
m_doc->positionToSelectRowcolTable(e->pos(), &table); + // are we in the \
situation to select row/cols of a table? + if (ePositionTable != \
KWDocument::TABLE_POSITION_NONE) + { // YES => select row/col
+ if (ePositionTable == KWDocument::TABLE_POSITION_RIGHT)
+ { // in position to select a ROW
+ // here the cursor is on the left of the table. the y is OK, but \
the x is not, + // hence finding a proper x with the table object
+ KWTableFrameSet::Cell *cell = table->getCellByPos( \
table->boundingRect().left(), m_doc->unzoomItY(e->pos().y()) ); + \
table->selectRow( cell->getRow() ); + }
+ else
+ { // in position to select a COLUMN
+ // here the cursor is on top of the table. the x is ok, but the y \
is not. + KWTableFrameSet::Cell *cell = table->getCellByPos( \
m_doc->unzoomItX(e->pos().x()), table->boundingRect().top() ); + \
table->selectCol( cell->getColumn() ); + }
+ }
m_scrollTimer->start( 50 );
}
+
break;
case MM_CREATE_TEXT: case MM_CREATE_PART: case MM_CREATE_TABLE:
case MM_CREATE_FORMULA:
Index: kwdoc.cc
===================================================================
RCS file: /home/kde/koffice/kword/kwdoc.cc,v
retrieving revision 1.378
diff -u -3 -p -r1.378 kwdoc.cc
--- kwdoc.cc 16 Apr 2002 07:00:20 -0000 1.378
+++ kwdoc.cc 27 May 2002 06:25:40 -0000
@@ -18,6 +18,7 @@
*/
#include <kmessagebox.h>
+#include <kcursor.h>
#include <qfileinfo.h>
#include <qregexp.h>
@@ -2527,14 +2528,66 @@ QString KWDocument::generateFramesetName
return name;
}
+/** if we are close on the left or the top of a table,
+ * the user can select rows/cols */
+KWDocument::TableToSelectPosition KWDocument::positionToSelectRowcolTable(const \
QPoint& nPoint, KWTableFrameSet **ppTable /*=0L*/) { + KWFrame *frameundermouse, \
*frameclosetomouseright, *frameclosetomouseunder; +
+ TableToSelectPosition result = TABLE_POSITION_NONE;
+
+ // now simply check the actual frame under the mouse
+ bool border=true;
+ frameundermouse = frameUnderMouse(nPoint, &border );
+
+ // now get a frame close to the mouse pointer
+ // slightly on the right (could it be that it is a table?)
+ QPoint pointTestTableSelect = nPoint;
+ pointTestTableSelect.rx() += KWDocument::DISTANCE_TABLE_SELECT_ROWCOL;
+ frameclosetomouseright = frameUnderMouse(pointTestTableSelect, &border);
+
+ pointTestTableSelect = nPoint;
+ pointTestTableSelect.ry() += KWDocument::DISTANCE_TABLE_SELECT_ROWCOL;
+ frameclosetomouseunder = frameUnderMouse(pointTestTableSelect, &border);
+
+ KWFrame *frameclosetomouse; // the frame that we are going to test to know \
whether it is a table +
+ if ( frameclosetomouseright && \
frameclosetomouseright->frameSet()->getGroupManager() ) { + // ok, we can test \
the right frame + frameclosetomouse = frameclosetomouseright;
+ result = TABLE_POSITION_RIGHT;
+ }
+ else {
+ // right frame is not good. maybe the one under?
+ frameclosetomouse = frameclosetomouseunder;
+ result = TABLE_POSITION_BOTTOM;
+ }
+
+ // is there a frame close to the cursor?
+ if (frameclosetomouse) {
+ if ( frameclosetomouse->frameSet()->getGroupManager() && (!frameundermouse \
|| !frameundermouse->frameSet()->getGroupManager()) ) { + // there is a \
frame, it is a table, and the cursor is NOT on a table ATM + if (ppTable)
+ *ppTable =frameclosetomouse->frameSet()->getGroupManager();
+ // place the cursor to say that we can select row/columns
+ return result;
+ }
+ }
+ return TABLE_POSITION_NONE;
+}
+
QCursor KWDocument::getMouseCursor( const QPoint &nPoint, bool controlPressed )
{
bool border=true;
- KWFrame *frame = frameUnderMouse(nPoint, &border );
- if (frame) {
+
+ if (positionToSelectRowcolTable(nPoint) != TABLE_POSITION_NONE)
+ return KCursor::handCursor();
+
+ KWFrame *frameundermouse = frameUnderMouse(nPoint, &border );
+
+ if (frameundermouse) {
QCursor cursor;
- KWFrameSet *frameSet = frame->frameSet();
- if ( frameSet->getMouseCursor(nPoint, controlPressed, cursor))
+ KWFrameSet *frameSet = frameundermouse->frameSet();
+ if ( frameSet->getMouseCursor(nPoint, controlPressed, cursor))
return cursor;
}
return ibeamCursor;
Index: kwdoc.h
===================================================================
RCS file: /home/kde/koffice/kword/kwdoc.h,v
retrieving revision 1.169
diff -u -3 -p -r1.169 kwdoc.h
--- kwdoc.h 15 Apr 2002 09:21:50 -0000 1.169
+++ kwdoc.h 27 May 2002 06:25:41 -0000
@@ -122,6 +122,12 @@ public:
static const int U_TABS = 512;
static const int U_SMART = 1024;
*/
+
+ /** when in position to select rows/cols from a table (slightly on the left/top \
of the table), + * where exactly is the table? if it's NONE, we are not in \
position to select rows/cols */ + enum TableToSelectPosition {TABLE_POSITION_NONE \
= 0, TABLE_POSITION_RIGHT = 1, TABLE_POSITION_BOTTOM = 2}; +
+ static const int DISTANCE_TABLE_SELECT_ROWCOL = 15;
static const int CURRENT_SYNTAX_VERSION = 2;
@@ -532,6 +538,8 @@ public:
void addIgnoreWordAll( const QString & );
void clearIgnoreWordAll( );
+ TableToSelectPosition positionToSelectRowcolTable(const QPoint& nPoint, \
KWTableFrameSet **ppTable =0L); +
signals:
void sig_insertObject( KWChild *_child, KWPartFrameSet* );
void newContentsSize();
@@ -660,7 +668,6 @@ private:
/** Page number -> section title array, for the Section variable.
* Note that pages without a section title don't appear in the array. */
QValueVector< QString > m_sectionTitles;
-
QStringList m_spellListIgnoreAll;
};
Index: kwframe.h
===================================================================
RCS file: /home/kde/koffice/kword/kwframe.h,v
retrieving revision 1.155
diff -u -3 -p -r1.155 kwframe.h
--- kwframe.h 10 Apr 2002 17:20:08 -0000 1.155
+++ kwframe.h 27 May 2002 06:25:41 -0000
@@ -97,7 +97,7 @@ public:
* - which is actually pretty bad in terms of doc/view design (DF)
*/
void setSelected( bool _selected );
- bool isSelected() { return selected; }
+ bool isSelected() const { return selected; }
QCursor getMouseCursor( const KoPoint& docPoint, bool table, QCursor \
defaultCursor );
Index: kwtableframeset.cc
===================================================================
RCS file: /home/kde/koffice/kword/kwtableframeset.cc,v
retrieving revision 1.191
diff -u -3 -p -r1.191 kwtableframeset.cc
--- kwtableframeset.cc 3 Apr 2002 06:11:15 -0000 1.191
+++ kwtableframeset.cc 27 May 2002 06:25:41 -0000
@@ -722,6 +722,22 @@ kdDebug(32004) << "KWTableFrameSet::move
}
}
+void KWTableFrameSet::selectRow(uint row)
+{
+ Q_ASSERT(row < m_rows);
+
+ for ( uint i = 0; i < getCols(); i++ )
+ getCell(row, i)->frame(0)->setSelected( true );
+}
+
+void KWTableFrameSet::selectCol(uint col)
+{
+ Q_ASSERT(col < m_colPositions.count()-1);
+
+ for ( uint i = 0; i < getRows(); i++ )
+ getCell(i, col)->frame(0)->setSelected( true );
+}
+
void KWTableFrameSet::deselectAll()
{
for ( unsigned int i = 0; i < m_cells.count(); i++ )
@@ -815,6 +831,54 @@ bool KWTableFrameSet::isOneSelected(unsi
row=m_cells.at(selectedCell)->m_row;
col=m_cells.at(selectedCell)->m_col;
return true;
+ }
+ return false;
+}
+
+bool KWTableFrameSet::isRowSelected(uint row) {
+ Q_ASSERT(row <= getRows());
+ // if just one cell of the row is not selected, the row is not selected
+ for ( uint i = 0; i < m_cells.count(); i++ ) {
+ if (!m_cells.at( i )->frame( 0 )->isSelected()) {
+ if (m_cells.at( i )->m_row == row)
+ {
+ kdDebug() << "row " << row << " row is not selected" << endl;
+ return false;
+ }
+ }
+ }
+ kdDebug() << "row " << row << " row is selected" << endl;
+ return true;
+}
+
+bool KWTableFrameSet::isColSelected(uint column) {
+ Q_ASSERT(column <= getCols());
+ // if just one cell of the col is not selected, the col is not selected
+ for ( uint i = 0; i < m_cells.count(); i++ ) {
+ if (!m_cells.at( i )->frame( 0 )->isSelected()) {
+ if (m_cells.at( i )->m_col == column)
+ {
+ kdDebug() << "column " << column << " column is not selected" << \
endl; + return false;
+ }
+ }
+ }
+ kdDebug() << "column " << column << " column is selected" << endl;
+ return true;
+}
+
+bool KWTableFrameSet::isRowsSelected() {
+ for (uint i=0;i<getRows();i++) {
+ if (isRowSelected(i))
+ return true;
+ }
+ return false;
+}
+
+bool KWTableFrameSet::isColsSelected() {
+ for (uint i=0;i<getCols();i++) {
+ if (isColSelected(i))
+ return true;
}
return false;
}
Index: kwtableframeset.h
===================================================================
RCS file: /home/kde/koffice/kword/kwtableframeset.h,v
retrieving revision 1.86
diff -u -3 -p -r1.86 kwtableframeset.h
--- kwtableframeset.h 5 Apr 2002 16:30:23 -0000 1.86
+++ kwtableframeset.h 27 May 2002 06:25:42 -0000
@@ -52,7 +52,6 @@ class KWordFrameSetIface;
* can be used to describe the same thing: one table-cell
*/
-
class KWTableFrameSet : public KWFrameSet
{
Q_OBJECT
@@ -74,6 +73,9 @@ public:
bool isAboveOrLeftOf( unsigned row, unsigned col );
+ uint getRow() const {return m_row;}
+ uint getColumn() const {return m_col;}
+
double leftBorder();
double rightBorder();
double topBorder();
@@ -145,17 +147,23 @@ public:
void recalcRows(int _col=-1,int _row=-1);
/** returns the number of rows */
- unsigned int getRows() { return m_rows; }
+ unsigned int getRows() const { return m_rows; }
/** returns the number of columns */
- unsigned int getCols() { return m_colPositions.count()-1; }
+ unsigned int getCols() const { return m_colPositions.count()-1; }
/** returns the number of cells the table contains, this includes
* temporary headers. */
- unsigned int getNumCells() { return m_cells.count(); }
+ unsigned int getNumCells() const { return m_cells.count(); }
/** returns the fact if one cell (==frame) has been selected */
bool hasSelectedFrame();
+ /** select a row */
+ void selectRow(uint number);
+
+ /** select a column */
+ void selectCol(uint number);
+
/** deselect all frames */
void deselectAll();
@@ -172,7 +180,16 @@ public:
/** convenience method */
void selectUntil( double x, double y);
- bool getFirstSelected(unsigned int &row, unsigned int &col );
+ bool isRowSelected(uint row);
+ bool isColSelected(uint column);
+
+ /** is at least one row selected on the whole table?*/
+ bool isRowsSelected();
+
+ /** is at least one col selected on the whole table?*/
+ bool isColsSelected();
+
+ bool getFirstSelected(unsigned int &row, unsigned int &col);
/** Return true if exactly one frame is selected. The parameters row
* and col will receive the values of the active row and col.<br>
* When no frame or more then one frame is selected row and col will
@@ -284,6 +301,7 @@ public:
virtual void printDebug( KWFrame * frame );
virtual void printDebug();
#endif
+ static const uint m_sDefaultColWidth = 60;
protected:
/* Overloaded methods, look for docu in kwframe.h */
virtual void deleteAnchors();
Index: kwview.cc
===================================================================
RCS file: /home/kde/koffice/kword/kwview.cc,v
retrieving revision 1.559
diff -u -3 -p -r1.559 kwview.cc
--- kwview.cc 17 Apr 2002 07:05:21 -0000 1.559
+++ kwview.cc 27 May 2002 06:25:46 -0000
@@ -771,17 +771,17 @@ void KWView::setupActions()
actionTableInsertCol->setToolTip( i18n( "Insert one or more columns into the \
current table." ) );
actionTableInsertCol->setWhatsThis( i18n( "Insert one or more columns into the \
current table." ) );
- actionTableDelRow = new KAction( i18n( "&Delete Row..." ), "delete_table_row", \
0, + actionTableDelRow = new KAction( i18n( "&Delete Selected Rows..." ), \
"delete_table_row", 0, this, SLOT( tableDeleteRow() ),
actionCollection(), "table_delrow" );
- actionTableDelRow->setToolTip( i18n( "Delete one row from the current table." ) \
);
- actionTableDelRow->setWhatsThis( i18n( "Delete one row from the current \
table.<p>Your cursor does not need to be in the row to be deleted. You will be given \
the opportunity to specify which row to delete." ) ); + \
actionTableDelRow->setToolTip( i18n( "Delete selected rows from the current table." ) \
); + actionTableDelRow->setWhatsThis( i18n( "Delete selected rows from the current \
table." ) );
- actionTableDelCol = new KAction( i18n( "D&elete Column..." ), \
"delete_table_col", 0, + actionTableDelCol = new KAction( i18n( "D&elete Selected \
Columns..." ), "delete_table_col", 0, this, SLOT( tableDeleteCol() ),
actionCollection(), "table_delcol" );
- actionTableDelCol->setToolTip( i18n( "Delete one column from the current table." \
) );
- actionTableDelCol->setWhatsThis( i18n( "Delete one column from the current \
table.<p>Your cursor does not need to be in the column to be deleted. You will be \
given the opportunity to specify which row to delete.." ) ); + \
actionTableDelCol->setToolTip( i18n( "Delete selected columns from the current \
table." ) ); + actionTableDelCol->setWhatsThis( i18n( "Delete selected column from \
the current table." ) );
actionTableJoinCells = new KAction( i18n( "&Join Cells" ), 0,
this, SLOT( tableJoinCells() ),
@@ -1633,6 +1633,8 @@ void KWView::setTool( int _mouseMode )
actionTableJoinCells->setEnabled( FALSE );
actionTableSplitCells->setEnabled( FALSE );
actionFormatFrameSet->setEnabled(FALSE);
+ actionTableDelRow->setEnabled( false );
+ actionTableDelCol->setEnabled( false );
}
void KWView::showStyle( const QString & styleName )
@@ -3112,7 +3114,6 @@ void KWView::tableInsertCol()
KWInsertDia dia( this, "", table, m_doc, KWInsertDia::COL, \
m_gui->canvasWidget() ); dia.setCaption( i18n( "Insert Column" ) );
dia.exec();
- }
}
void KWView::tableDeleteRow()
@@ -4496,6 +4497,8 @@ void KWView::frameSelectedChanged()
KWTableFrameSet *table = m_gui->canvasWidget()->getCurrentTable();
actionTableJoinCells->setEnabled( table && (nbFrame>1));
+ actionTableDelRow->setEnabled( table && table->isRowsSelected());
+ actionTableDelCol->setEnabled( table && table->isColsSelected());
bool state=(table && nbFrame==1);
@@ -4505,8 +4508,6 @@ void KWView::frameSelectedChanged()
actionTableInsertRow->setEnabled( state);
actionTableInsertCol->setEnabled( state);
- actionTableDelRow->setEnabled( state );
- actionTableDelCol->setEnabled( state );
actionTableDelete->setEnabled( state );
actionTableUngroup->setEnabled( state );
Index: kwview.h
===================================================================
RCS file: /home/kde/koffice/kword/kwview.h,v
retrieving revision 1.156
diff -u -3 -p -r1.156 kwview.h
--- kwview.h 16 Apr 2002 13:10:43 -0000 1.156
+++ kwview.h 27 May 2002 06:25:46 -0000
@@ -526,7 +526,7 @@ private:
QPtrList<KAction> m_variableActionList;
int m_currentPage; // 0-based current page number
-
+
// Statusbar items
QLabel * m_sbPageLabel; // 'Current page number and page count' label
QLabel * m_sbFramesLabel; // Info about selected frames
_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic