Source Code (Use browser search to find items of interest.)
Class Index
kspread'KSpreadCanvas (./koffice/kspread/kspread_canvas.h:68)
class KSpreadCanvas : public QWidget
{
friend KSpreadHBorder;
friend KSpreadVBorder;
friend KSpreadView;
Q_OBJECT
public:
/**
* The current action associated with the mouse.
* Default is 'NoAction'.
*/
enum MouseActions { NoAction = 0, Mark = 1, ResizeCell = 2, AutoFill = 3 };
enum EditorType { CellEditor, FormulaEditor, EditWidget };
KSpreadCanvas( QWidget *_parent, KSpreadView *_view, KSpreadDoc* _doc );
/**
* Called from @ref KSpreadView to complete the construction. Has to
* be called before any other method on this object may be invoced.
*/
void init();
void insertFormulaChar(int c);
KSpreadCellEditor* editor() { return m_pEditor ; }
// ###### Torben: Many of these functions are not used or can be made private
QPoint chooseMarker() const { return QPoint( m_i_chooseMarkerColumn, m_i_chooseMarkerRow ); }
int chooseMarkerColumn() const { return m_i_chooseMarkerColumn; }
int chooseMarkerRow() const { return m_i_chooseMarkerRow; }
/**
* Sets the marker and redraws it if it is visible.
* It does not scroll the canvas. If you want to do that, use
* @ref #chooseGotoLocation.
*
* In addition it does not handel selection
* of multiple cells. After calling setChooseMarker() the selection will
* consist of the single cell given by @p p.
*/
void setChooseMarker( const QPoint& p );
/**
* Internal. DONT USE.
*/
void setChooseMarkerColumn( int _c ) { m_i_chooseMarkerColumn = _c; }
/**
* Internal. DONT USE.
*/
void setChooseMarkerRow( int _r ) { m_i_chooseMarkerRow = _r; }
/**
* Move the choose selection. That may include switching the table.
* The canvas is scrolled to the appropriate position if needed.
*
* @param make_select determines wether this move if the marker is part of a
* selection, that means: The user holds the shift key and
* moves the cursor keys.
*/
void chooseGotoLocation( int x, int y, KSpreadTable* table = 0, bool make_select = FALSE );
/**
* Internal. DONT USE.
*/
void showChooseMarker(){if(choose_visible==true) {return;}
drawChooseMarker();choose_visible=true;}
/**
* Internal. DONT USE.
*/
void hideChooseMarker(){if(choose_visible==false) {return;}
drawChooseMarker();choose_visible=false;}
/**
* Internal. DONT USE.
*/
bool isChooseMarkerVisible() const { return choose_visible; }
/**
* Called from @ref KSpreadView::slotChangeChooseSelection to
* draw the selection with a rubber band.
*/
void updateChooseMarker( const QRect& _old, const QRect& _new );
/**
* If the user chooses some cells during editing a formular, then
* this function returns the length of the textual representation.
* For example the user selects "Table1!A1:B2" then this function
* returns 12.
*/
int chooseTextLen() const { return length_namecell; }
/**
* Changes the position of the marker. if it is visible, it is hidden, moved and shown again.
* This method does not scroll the canvas so that the cell is visible. In this case you may
* want to use @ref #gotoLocation
*/
void setMarker( const QPoint& marker );
QPoint marker() const { return QPoint( m_iMarkerColumn, m_iMarkerRow ); }
bool isMarkerVisible() { return ( m_iMarkerVisible == 1 ); }
int markerColumn() { return m_iMarkerColumn; }
int markerRow() { return m_iMarkerRow; }
/**
* Changes the position of the marker. if it is visible, it is hidden, moved and shown again.
* This method does not scroll the canvas so that the cell is visible. In this case you may
* want to use @ref #gotoLocation
*
* @see #setMarker
*/
void setMarkerColumn( int _c );
/**
* Changes the position of the marker. if it is visible, it is hidden, moved and shown again.
* This method does not scroll the canvas so that the cell is visible. In this case you may
* want to use @ref #gotoLocation
*
* @see #setMarker
*/
void setMarkerRow( int _r );
/**
* Hides the marker. Hiding it multiple times means that it has to be shown ( using @ref #showMarker ) multiple times
* to become visible again.
*/
void hideMarker() { if ( m_iMarkerVisible == 1 ) drawMarker(); m_iMarkerVisible--; }
/**
* @ref #hideMarker
*/
void showMarker() { if ( m_iMarkerVisible == 1 ) return; m_iMarkerVisible++; if ( m_iMarkerVisible == 1 ) drawMarker(); }
/**
* Redraws a single object.
* This is a convenience function that
* creates a new @ref QPainter for you. Dont use if another @ref QPainter is active!
*
* @param _cell is the @ref KSpreadCell to draw.
* @param _col is the column this object is assumed to reside in.
* @param _row is the row this object is assumed to reside in.
*/
void drawCell( KSpreadCell *_cell, int _col, int _row );
void updateCellRect( const QRect &_rect );
const QPen& defaultGridPen() { return m_defaultGridPen; }
float zoom() { return m_fZoom; }
int xOffset() { return m_iXOffset; }
int yOffset() { return m_iYOffset; }
KSpreadTable* activeTable();
KSpreadTable* findTable( const QString& _name );
/**
* A convenience function.
*/
void gotoLocation( const KSpreadPoint& _cell );
/**
* Move the cursor to the specified cell. This may include switching
* the table. In addition @ref #KSpreadView::updateEditWidget is called.
*
* @param make_select determines wether this move of the marker is part of a
* selection, that means: The user holds the shift key and
* moves the cursor keys. In this case the selection is
* updated accordingly.
*/
void gotoLocation( int x, int y, KSpreadTable* table = 0, bool make_select = FALSE );
/**
* Chooses the correct @ref #EditorType by looking at
* the current cells value. By default CellEditor is chosen.
*/
void createEditor();
void createEditor( EditorType type );
/**
* Deletes the current cell editor.
*
* @see #createEditor
* @see #editor
* @param saveChanges if true, the edited text is stored in the cell.
* if false, the changes are discarded.
*/
void deleteEditor( bool saveChanges );
/**
* Called from @ref KSpreadEditWidget and KSpreadCellEditor
* if they loose the focus becuase the user started a "choose selection".
* This is done because the editor wants to get its focus back afterwards.
* But somehow KSpreadCanvas must know whether the EditWidget or the CellEditor
* lost the focus when the user clicked on the canvas.
*/
void setLastEditorWithFocus( EditorType type ) { m_focusEditorType = type; }
/**
* Switches to choose mode and sets the inital selection to the
* position returned by @ref #marker.
*/
void startChoose();
/**
* Switches to choose mode and sets the inital @p selection.
*/
void startChoose( const QRect& selection );
void endChoose();
/**
* Adjust a area in height and width
*/
void adjustArea();
// Created by the view since it's layout is managed there,
// but is in fact a sibling of the canvas, which needs to know about it.
void setEditWidget( KSpreadEditWidget * ew ) { m_pEditWidget = ew; }
KSpreadView* view() { return m_pView; }
KSpreadDoc* doc() { return m_pDoc; }
public slots:
void slotScrollVert( int _value );
void slotScrollHorz( int _value );
void slotMaxColumn( int _max_column );
void slotMaxRow( int _max_row );
protected:
virtual void keyPressEvent ( QKeyEvent* _ev );
virtual void paintEvent ( QPaintEvent* _ev );
virtual void mousePressEvent( QMouseEvent* _ev );
virtual void mouseReleaseEvent( QMouseEvent* _ev );
virtual void mouseMoveEvent( QMouseEvent* _ev );
virtual void mouseDoubleClickEvent( QMouseEvent*);
virtual void focusInEvent( QFocusEvent* );
virtual void focusOutEvent( QFocusEvent* );
private:
virtual void chooseMousePressEvent( QMouseEvent* _ev );
virtual void chooseMouseReleaseEvent( QMouseEvent* _ev );
virtual void chooseMouseMoveEvent( QMouseEvent* _ev );
KSpreadHBorder* hBorderWidget();
KSpreadVBorder* vBorderWidget();
QScrollBar* horzScrollBar();
QScrollBar* vertScrollBar();
KSpreadEditWidget* editWidget() { return m_pEditWidget; }
void drawChooseMarker( );
void drawChooseMarker( const QRect& );
/**
* @see #setLastEditorWithFocus
*/
EditorType lastEditorWithFocus() const { return m_focusEditorType; }
/**
* Hides the marker. Hiding it multiple times means that it has to be shown ( using @ref #showMarker ) multiple times
* to become visible again. This function is optimized since it does not create a new painter.
*/
void hideMarker( QPainter& );
void showMarker( QPainter& );
void drawMarker( QPainter * _painter = 0L );
/**
* Redraws a single object.
*/
void drawCell( QPainter &_painter, KSpreadCell *_cell, int _col, int _row );
bool choose_visible;
int length_namecell;
int length_text;
KSpreadView *m_pView;
KSpreadDoc* m_pDoc;
/**
* If the user is dragging around with the mouse then this tells us what he is doing.
* The user may want to mark cells or he started in the lower right corner
* of the marker which is something special. The values for the 2 above
* methods are called 'Mark' and 'ResizeCell' or 'AutoFill' depending
* on the mouse button used. By default this variable holds
* the value 'NoAction'.
*/
MouseActions m_eMouseAction;
/**
* Used to indicate whether the user started drawing a rubber band rectangle.
*/
bool m_bGeometryStarted;
QPoint m_ptGeometryStart;
QPoint m_ptGeometryEnd;
/**
* The column in which a mouse drag started.
*/
int m_iMouseStartColumn;
/**
* The row in which a mouse drag started.
*/
int m_iMouseStartRow;
/**
* Tells whether the user selected more than one cell.
* If the user presses the left mouse button and if he marks more
* than one cell until he releases the button again, then this flag
* is set. If this flag is set, then one should repaint all visible
* cells once the button is released.
*/
bool m_bMouseMadeSelection;
/**
* True when the mouse button is pressed
*/
bool m_bMousePressed;
/**
* If we use the lower right corner of the marker to start autofilling, then this
* rectangle conatins all cells that were already marker when the user started
* to mark the rectangle which he wants to become autofilled.
*
* @see #mousePressEvent
* @see #mouseReleeaseEvent
*/
QRect m_rctAutoFillSrc;
/**
* If the mouse is over some anchor ( in the sense of HTML anchors )
* then this one is stored here.
*/
QString m_strAnchor;
float m_fZoom;
/**
* Horizontal scroll offset of the view.
*/
int m_iXOffset;
/**
* Vertical scroll offset of the view.
*/
int m_iYOffset;
QLabel *m_pPosWidget;
KSpreadEditWidget *m_pEditWidget;
KSpreadCellEditor *m_pEditor;
/**
* Used to draw the grey grid that is usually only visible on the
* screen, but not by printing on paper.
*/
QPen m_defaultGridPen;
int m_iMarkerColumn;
int m_iMarkerRow;
/**
* A value of 1 means that it is visible, every lower value means it is
* made invisible multiple times.
*
* @see #hideMarker
* @see #showMarker
*/
int m_iMarkerVisible;
int m_i_chooseMarkerRow;
int m_i_chooseMarkerColumn;
/**
* Is true if the user is to choose a cell.
*
* @see #startChoose
* @see #endChoose
* @see KSpreadAssistant2
*/
bool m_bChoose;
/**
* If a choose selection is started (@ref #startChoose) the current
* table is saved here.
*/
KSpreadTable* m_chooseStartTable;
// int m_choosePos;
/**
* @see #setLastEditorWithFocus
* @see #lastEditorWithFocus
*/
EditorType m_focusEditorType;
};
/**
*/
kspread'KSpreadCanvas::KSpreadCanvas() (./koffice/kspread/kspread_canvas.cc:135)
KSpreadCanvas::KSpreadCanvas( QWidget *_parent, KSpreadView *_view, KSpreadDoc* _doc )
: QWidget( _parent, "", WNorthWestGravity )
{
length_namecell = 0;
m_chooseStartTable = 0;
m_pEditor = 0;
m_bChoose = FALSE;
m_iMarkerColumn = 1;
m_iMarkerRow = 1;
m_iMarkerVisible = 1;
QWidget::setFocusPolicy( QWidget::StrongFocus );
m_defaultGridPen.setColor( lightGray );
m_defaultGridPen.setWidth( 1 );
m_defaultGridPen.setStyle( SolidLine );
m_iXOffset = 0;
m_iYOffset = 0;
m_fZoom = 1.0;
m_pView = _view;
m_pDoc = _doc;
// m_eAction = DefaultAction;
m_eMouseAction = NoAction;
m_bGeometryStarted = false;
// m_bEditDirtyFlag = false;
//Now built afterwards(David)
//m_pEditWidget = m_pView->editWidget();
m_pPosWidget = m_pView->posWidget();
setBackgroundColor( white );
setMouseTracking( TRUE );
setBackgroundMode( NoBackground );
m_bMousePressed = false;
choose_visible = false;
setFocus();
}
kspread'KSpreadCanvas::startChoose() (./koffice/kspread/kspread_canvas.cc:179)
void KSpreadCanvas::startChoose()
{
if ( m_bChoose )
return;
// Clear a selection if there is any
m_i_chooseMarkerColumn = markerColumn();
m_i_chooseMarkerRow = markerRow();
activeTable()->setChooseRect( QRect( 0, 0, 0, 0 ) );
// It is important to enable this AFTER we set the rect!
m_bChoose = TRUE;
m_chooseStartTable = activeTable();
}
kspread'KSpreadCanvas::startChoose() (./koffice/kspread/kspread_canvas.cc:194)
void KSpreadCanvas::startChoose( const QRect& rect )
{
activeTable()->setChooseRect( rect );
m_i_chooseMarkerColumn = rect.right();
m_i_chooseMarkerRow = rect.bottom();
// It is important to enable this AFTER we set the rect!
m_bChoose = TRUE;
m_chooseStartTable = activeTable();
}
kspread'KSpreadCanvas::endChoose() (./koffice/kspread/kspread_canvas.cc:206)
void KSpreadCanvas::endChoose()
{
if ( !m_bChoose )
return;
activeTable()->setChooseRect( QRect( 0, 0, 0, 0 ) );
m_pView->setActiveTable( m_chooseStartTable );
qDebug("endChoose len=0");
length_namecell = 0;
m_bChoose = FALSE;
m_chooseStartTable = 0;
}
kspread'KSpreadCanvas::hBorderWidget() (./koffice/kspread/kspread_canvas.cc:219)
KSpreadHBorder* KSpreadCanvas::hBorderWidget()
{
return m_pView->hBorderWidget();
}
kspread'KSpreadCanvas::vBorderWidget() (./koffice/kspread/kspread_canvas.cc:224)
KSpreadVBorder* KSpreadCanvas::vBorderWidget()
{
return m_pView->vBorderWidget();
}
kspread'KSpreadCanvas::horzScrollBar() (./koffice/kspread/kspread_canvas.cc:229)
QScrollBar* KSpreadCanvas::horzScrollBar()
{
return m_pView->horzScrollBar();
}
kspread'KSpreadCanvas::vertScrollBar() (./koffice/kspread/kspread_canvas.cc:234)
QScrollBar* KSpreadCanvas::vertScrollBar()
{
return m_pView->vertScrollBar();
}
kspread'KSpreadCanvas::findTable() (./koffice/kspread/kspread_canvas.cc:239)
KSpreadTable* KSpreadCanvas::findTable( const QString& _name )
{
return m_pDoc->map()->findTable( _name );
}
kspread'KSpreadCanvas::insertFormulaChar() (./koffice/kspread/kspread_canvas.cc:244)
void KSpreadCanvas::insertFormulaChar(int c)
{
m_pEditor->insertFormulaChar(c);
}
kspread'KSpreadCanvas::activeTable() (./koffice/kspread/kspread_canvas.cc:249)
KSpreadTable* KSpreadCanvas::activeTable()
{
return m_pView->activeTable();
}
kspread'KSpreadCanvas::gotoLocation() (./koffice/kspread/kspread_canvas.cc:254)
void KSpreadCanvas::gotoLocation( const KSpreadPoint& _cell )
{
if ( !_cell.isValid() )
{
KMessageBox::error( this, i18n("Invalid cell reference") );
return;
}
KSpreadTable* table = activeTable();
if ( _cell.isTableKnown() )
table = _cell.table;
if ( !table )
{
KMessageBox::error( this, i18n("Unknown table name %1").arg( _cell.tableName ) );
return;
}
gotoLocation( _cell.pos.x(), _cell.pos.y(), table );
}
kspread'KSpreadCanvas::gotoLocation() (./koffice/kspread/kspread_canvas.cc:274)
void KSpreadCanvas::gotoLocation( int x, int y, KSpreadTable* table, bool make_select )
{
kdDebug() << "KSpreadCanvas::gotoLocation" << " x=" << x << " y=" << y <<
" table=" << table << " make_select=" << (make_select ? "true" : "false" ) << endl;
if ( table )
m_pView->setActiveTable( table );
else
table = activeTable();
KSpreadCell* cell = table->cellAt( x, y );
if ( cell->isObscured() && cell->isObscuringForced() )
{
y = cell->obscuringCellsRow();
x = cell->obscuringCellsColumn();
}
int xpos = table->columnPos( x, this );
int ypos = table->rowPos( y, this );
int minX = (int) (100 * zoom()); // less than that, we scroll
int minY = (int) (50 * zoom());
int maxX = (int) (width() - 100 * zoom()); // more than that, we scroll
int maxY = (int) (height() - 50 * zoom());
if ( xpos < minX )
horzScrollBar()->setValue( xOffset() + xpos - minX );
else if ( xpos > maxX )
horzScrollBar()->setValue( xOffset() + xpos - maxX );
if ( ypos < minY )
vertScrollBar()->setValue( yOffset() + ypos - minY );
else if ( ypos > maxY )
vertScrollBar()->setValue( yOffset() + ypos - maxY );
QRect selection = activeTable()->selectionRect();
if ( !make_select )
{
if ( selection.left() != 0 )
activeTable()->unselect();
setMarker( QPoint( x, y ) );
}
else
{
if ( selection.left() == 0 )
selection.setCoords( markerColumn(), markerRow(), markerColumn(), markerRow() );
if ( markerColumn() == selection.left() )
selection.setLeft( x );
else
selection.setRight( x );
if ( markerRow() == selection.top() )
selection.setTop( y );
else
selection.setBottom( y );
selection = selection.normalize();
m_iMarkerColumn = x;
m_iMarkerRow = y;
activeTable()->setSelection( selection );
}
// Perhaps the user is entering a value in the cell.
// In this case we may not touch the EditWidget
if ( !m_pEditor )
m_pView->updateEditWidget();
}
kspread'KSpreadCanvas::chooseGotoLocation() (./koffice/kspread/kspread_canvas.cc:342)
void KSpreadCanvas::chooseGotoLocation( int x, int y, KSpreadTable* table, bool make_select )
{
if ( table )
m_pView->setActiveTable( table );
else
table = activeTable();
KSpreadCell* cell = table->cellAt( x, y );
if ( cell->isObscured() && cell->isObscuringForced() )
{
x = cell->obscuringCellsRow();
y = cell->obscuringCellsColumn();
}
int xpos = table->columnPos( x, this );
int ypos = table->rowPos( y, this );
int minX = (int) (100 * zoom()); // less than that, we scroll
int minY = (int) (50 * zoom());
int maxX = (int) (width() - 100 * zoom()); // more than that, we scroll
int maxY = (int) (height() - 50 * zoom());
if ( xpos < minX )
horzScrollBar()->setValue( xOffset() + xpos - minX);
else if ( xpos > maxX )
horzScrollBar()->setValue( xOffset() + xpos - maxX );
if ( ypos < minY )
vertScrollBar()->setValue( yOffset() + ypos - minY );
else if ( ypos > maxY )
vertScrollBar()->setValue( yOffset() + ypos - maxY );
if ( !make_select )
setChooseMarker( QPoint( x, y ) );
else
{
QRect selection = activeTable()->chooseRect();
if ( chooseMarkerColumn() == selection.left() )
selection.setLeft( x );
else
selection.setRight( x );
if ( chooseMarkerRow() == selection.top() )
selection.setTop( y );
else
selection.setBottom( y );
selection = selection.normalize();
m_i_chooseMarkerColumn = x;
m_i_chooseMarkerRow = y;
activeTable()->setChooseRect( selection );
}
}
kspread'KSpreadCanvas::slotScrollHorz() (./koffice/kspread/kspread_canvas.cc:395)
void KSpreadCanvas::slotScrollHorz( int _value )
{
if ( activeTable() == 0L )
return;
if ( _value < 0 )
_value = 0;
activeTable()->enableScrollBarUpdates( false );
hideMarker();
// Relative movement
int dx = m_iXOffset - _value;
// New absolute position
m_iXOffset = _value;
scroll( dx, 0 );
hBorderWidget()->scroll( dx, 0 );
/* if(isgotohorz()==true)
{
setgotohorz(false);
m_pView->horzScrollBar()->setValue(_value);
} */
showMarker();
activeTable()->enableScrollBarUpdates( true );
}
kspread'KSpreadCanvas::slotScrollVert() (./koffice/kspread/kspread_canvas.cc:425)
void KSpreadCanvas::slotScrollVert( int _value )
{
if ( activeTable() == 0L )
return;
if ( _value < 0 )
_value = 0;
activeTable()->enableScrollBarUpdates( false );
hideMarker();
// Relative movement
int dy = m_iYOffset - _value;
// New absolute position
m_iYOffset = _value;
scroll( 0, dy );
vBorderWidget()->scroll( 0, dy );
/* if(isgotovert()==true)
{
setgotovert(false);
m_pView->vertScrollBar()->setValue(_value);
} */
showMarker();
activeTable()->enableScrollBarUpdates( true );
}
kspread'KSpreadCanvas::slotMaxColumn() (./koffice/kspread/kspread_canvas.cc:454)
void KSpreadCanvas::slotMaxColumn( int _max_column )
{
int xpos = activeTable()->columnPos( _max_column + 10, this );
horzScrollBar()->setRange( 0, xpos + xOffset() );
}
kspread'KSpreadCanvas::slotMaxRow() (./koffice/kspread/kspread_canvas.cc:461)
void KSpreadCanvas::slotMaxRow( int _max_row )
{
int ypos = activeTable()->rowPos( _max_row + 10, this );
vertScrollBar()->setRange( 0, ypos + yOffset() );
}
/*
void KSpreadCanvas::setAction( Actions _act )
{
QRect selection( activeTable()->selectionRect() );
if ( _act == InsertChart )
{
// Something must be selected
if ( selection.right() == 0x7fff || selection.bottom() == 0x7fff || selection.left() == 0 )
{
QMessageBox::critical( this, i18n("KSpread Error" ), i18n("You must first select the cells\n"
"which contain the data." ),
i18n( "Ok" ) );
return;
}
}
m_eAction = _act;
}
void KSpreadCanvas::setAction( Actions _act, KoDocumentEntry& _e )
{
m_actionArgument = _e;
setAction( _act );
}
*/
kspread'KSpreadCanvas::mouseMoveEvent() (./koffice/kspread/kspread_canvas.cc:493)
void KSpreadCanvas::mouseMoveEvent( QMouseEvent * _ev )
{
if ( !m_pView->koDocument()->isReadWrite() )
return;
if( m_bChoose )
{
chooseMouseMoveEvent( _ev );
return;
}
KSpreadTable *table = activeTable();
if ( !table )
return;
QRect selection( table->selectionRect() );
int ypos, xpos;
int row = table->topRow( _ev->pos().y(), ypos, this );
int col = table->leftColumn( _ev->pos().x(), xpos, this );
// Test whether the mouse is over some anchor
KSpreadCell* cell = table->visibleCellAt( col, row );
if ( cell )
m_strAnchor = cell->testAnchor( _ev->pos().x() - xpos, _ev->pos().y() - ypos, this );
// Test whether we are in the lower right corner of the marker
// if so => change the cursor
{
int xpos;
int ypos;
int w, h;
// No selection or just complete rows/columns ?
if ( selection.left() == 0 || selection.right() == 0x7fff || selection.bottom() == 0x7fff )
{
xpos = table->columnPos( markerColumn(), this );
ypos = table->rowPos( markerRow(), this );
KSpreadCell *cell = table->cellAt( markerColumn(), markerRow() );
w = cell->width( markerColumn(), this );
h = cell->height( markerRow(), this );
}
else // if we have a rectangular selection ( not complete rows or columns )
{
xpos = table->columnPos( selection.left(), this );
ypos = table->rowPos( selection.top(), this );
int x = table->columnPos( selection.right(), this );
KSpreadCell *cell = table->cellAt( selection.right(), selection.top() );
int tw = cell->width( selection.right(), this );
w = ( x - xpos ) + tw;
cell = table->cellAt( selection.left(), selection.bottom() );
int y = table->rowPos( selection.bottom(), this );
int th = cell->height( selection.bottom(), this );
h = ( y - ypos ) + th;
}
if ( _ev->pos().x() >= xpos + w - 2 && _ev->pos().x() <= xpos + w + 3 &&
_ev->pos().y() >= ypos + h - 1 && _ev->pos().y() <= ypos + h + 4 )
setCursor( sizeFDiagCursor );
else if ( !m_strAnchor.isEmpty() )
setCursor( KCursor::handCursor() );
else
setCursor( arrowCursor );
}
if ( m_eMouseAction == NoAction )
return;
if ( col < m_iMouseStartColumn )
col = m_iMouseStartColumn;
if ( row < m_iMouseStartRow )
row = m_iMouseStartRow;
if ( row == selection.bottom() && col == selection.right() )
return;
hideMarker();
// Set the new lower right corner of the selection
selection.setRight( col );
selection.setBottom( row );
table->setSelection( selection, this );
// Scroll the table if necessary
if ( _ev->pos().x() < 0 )
horzScrollBar()->setValue( xOffset() + xpos );
else if ( _ev->pos().x() > width() )
{
ColumnLayout *cl = table->columnLayout( col + 1 );
xpos = table->columnPos( col + 1, this );
horzScrollBar()->setValue( xOffset() + ( xpos + cl->width( this ) - width() ) );
}
if ( _ev->pos().y() < 0 )
vertScrollBar()->setValue( yOffset() + ypos );
else if ( _ev->pos().y() > height() )
{
RowLayout *rl = table->rowLayout( row + 1 );
ypos = table->rowPos( row + 1, this );
vertScrollBar()->setValue( yOffset() + ( ypos + rl->height( this ) - height() ) );
}
showMarker();
m_bMouseMadeSelection = true;
}
kspread'KSpreadCanvas::mouseReleaseEvent() (./koffice/kspread/kspread_canvas.cc:598)
void KSpreadCanvas::mouseReleaseEvent( QMouseEvent* _ev )
{
if( m_bChoose )
{
chooseMouseReleaseEvent( _ev );
return;
}
m_bMousePressed = false;
KSpreadTable *table = activeTable();
if ( !table )
return;
hideMarker();
QRect selection( table->selectionRect() );
// The user started the drag in the lower right corner of the marker ?
if ( m_eMouseAction == ResizeCell )
{
KSpreadCell *cell = table->nonDefaultCell( m_iMouseStartColumn, m_iMouseStartRow );
cell->forceExtraCells( m_iMouseStartColumn, m_iMouseStartRow,
selection.right() - selection.left(),
selection.bottom() - selection.top() );
selection.setCoords( 0, 0, 0, 0 );
table->setSelection( selection, this );
// m_pView->doc()->setModified( TRUE );
}
else if ( m_eMouseAction == AutoFill )
{
QRect dest = table->selectionRect();
table->autofill( m_rctAutoFillSrc, dest );
// m_pView->doc()->setModified( TRUE );
selection.setCoords( 0, 0, 0, 0 );
table->setSelection( selection, this );
}
// The user started the drag in the middle of a cell ?
else if ( m_eMouseAction == Mark )
{
// Get the object in the lower right corner
KSpreadCell *cell = table->cellAt( m_iMouseStartColumn, m_iMouseStartRow );
// Did we mark only a single cell ?
// Take care: One cell may obscure other cells ( extra size! ).
if ( selection.left() + cell->extraXCells() == selection.right() &&
selection.top() + cell->extraYCells() == selection.bottom() )
{
// Delete the selection
selection.setCoords( 0, 0, 0, 0 );
table->setSelection( selection, this );
}
}
m_eMouseAction = NoAction;
// if ( m_bMouseMadeSelection )
// drawVisibleCells();
m_bMouseMadeSelection = FALSE;
showMarker();
}
kspread'KSpreadCanvas::mousePressEvent() (./koffice/kspread/kspread_canvas.cc:661)
void KSpreadCanvas::mousePressEvent( QMouseEvent * _ev )
{
if( m_bChoose )
{
chooseMousePressEvent( _ev );
return;
}
KSpreadTable *table = activeTable();
m_bMousePressed = true;
if ( !table )
return;
// We were editing a cell -> save value and get out of editing mode
if ( m_pEditor )
{
deleteEditor( true ); //save changes
}
QRect selection( table->selectionRect() );
int old_column = markerColumn();
int old_row = markerRow();
// Check whether we clicked in the little marker in the lower right
// corner of a cell or a marked area.
{
// Get the position and size of the marker/marked-area
int xpos;
int ypos;
int w, h;
// No selection or complete rows/columns are selected
if ( selection.left() == 0 ||
selection.right() == 0x7fff || selection.bottom() == 0x7fff )
{
xpos = table->columnPos( markerColumn(), this );
ypos = table->rowPos( markerRow(), this );
KSpreadCell *cell = table->cellAt( markerColumn(), markerRow() );
w = cell->width( markerColumn() );
h = cell->height( markerRow() );
}
else // if we have a rectangular selection ( not complete rows or columns )
{
xpos = table->columnPos( selection.left(), this );
ypos = table->rowPos( selection.top(), this );
int x = table->columnPos( selection.right(), this );
KSpreadCell *cell = table->cellAt( selection.right(), selection.top() );
int tw = cell->width( selection.right(), this );
w = ( x - xpos ) + tw;
cell = table->cellAt( selection.left(), selection.bottom() );
int y = table->rowPos( selection.bottom(), this );
int th = cell->height( selection.bottom(), this );
h = ( y - ypos ) + th;
}
// Did we click in the lower right corner of the marker/marked-area ?
if ( _ev->pos().x() >= xpos + w - 2 && _ev->pos().x() <= xpos + w + 3 &&
_ev->pos().y() >= ypos + h - 1 && _ev->pos().y() <= ypos + h + 4 )
{
// Auto fill ?
if ( _ev->button() == LeftButton )
{
m_eMouseAction = AutoFill;
// Do we have a selection already ?
if ( selection.left() != 0 && selection.right() != 0x7fff && selection.bottom() != 0x7fff )
{ /* Selection is ok */
m_rctAutoFillSrc = selection;
}
else // Select the current cell
{
KSpreadCell *cell = table->cellAt( markerColumn(), markerRow() );
selection.setCoords( markerColumn(), markerRow(),
markerColumn() + cell->extraXCells(),
markerRow() + cell->extraYCells() );
m_rctAutoFillSrc.setCoords( markerColumn(), markerRow(),
markerColumn(), markerRow() );
}
m_iMouseStartColumn = markerColumn();
m_iMouseStartRow = markerRow();
}
// Resize a cell ?
else if ( _ev->button() == MidButton && selection.left() == 0 )
{
m_eMouseAction = ResizeCell;
KSpreadCell *cell = table->cellAt( markerColumn(), markerRow() );
selection.setCoords( markerColumn(), markerRow(),
markerColumn() + cell->extraXCells(),
markerRow() + cell->extraYCells() );
m_iMouseStartColumn = markerColumn();
m_iMouseStartRow = markerRow();
}
table->setSelection( selection, this );
return;
}
}
hideMarker();
int xpos, ypos;
int row = table->topRow( _ev->pos().y(), ypos, this );
int col = table->leftColumn( _ev->pos().x(), xpos, this );
if ( _ev->button() == LeftButton || !selection.contains( QPoint( col, row ) ) )
table->unselect();
if ((selection.right() != 0x7fff && selection.bottom() != 0x7fff)&& m_bMousePressed && ( _ev->state() & ControlButton ))
{
if( (col!=old_column)||(row!=old_row))
{
if(old_column>col)
{
int tmp=col;
col=old_column;
old_column=tmp;
}
if(old_row>row)
{
int tmp=row;
row=old_row;
old_row=tmp;
}
if( selection.left()!=0&&selection.right()!=0
&&selection.top()!=0&&selection.bottom()!=0)
{
//if you have a selection and you go up in the table
//so bottom is the bottom of the selection
//not the markercolumn
if(selection.bottom()>row)
row=selection.bottom();
if(selection.right()>col)
col=selection.right();
}
selection.setLeft(old_column);
selection.setRight( col );
selection.setTop(old_row);
selection.setBottom( row );
table->setSelection( selection, this );
//always put Marker in top and left
//otherwise all functions don't work
setMarkerColumn( old_column );
setMarkerRow( old_row );
showMarker();
return;
}
}
setMarkerColumn( col );
setMarkerRow( row );
KSpreadCell *cell = table->cellAt( markerColumn(), markerRow() );
// Go to the upper left corner of the obscuring object
if ( cell->isObscured() )
{
setMarkerRow( cell->obscuringCellsRow() );
setMarkerColumn( cell->obscuringCellsColumn() );
cell = table->cellAt( markerColumn(), markerRow() );
}
// Test whether the mouse is over some anchor
{
KSpreadCell *cell = table->visibleCellAt( markerColumn(), markerRow() );
QString anchor = cell->testAnchor( _ev->pos().x() - xpos,
_ev->pos().y() - ypos, this );
if ( !anchor.isEmpty() && anchor != m_strAnchor )
setCursor( KCursor::handCursor() );
m_strAnchor = anchor;
}
// Start a marking action ?
if ( m_strAnchor.isEmpty() && _ev->button() == LeftButton )
{
m_eMouseAction = Mark;
selection.setCoords( markerColumn(), markerRow(),
markerColumn() + cell->extraXCells(),
markerRow() + cell->extraYCells() );
// if ( old_selection.left() != 0 || cell->extraXCells() != 0 || cell->extraYCells() != 0 )
table->setSelection( selection, this );
m_iMouseStartColumn = markerColumn();
m_iMouseStartRow = markerRow();
}
// Update the edit box
m_pView->updateEditWidget();
if ( !m_strAnchor.isEmpty() )
{
gotoLocation( KSpreadPoint( m_strAnchor, m_pDoc->map() ) );
}
showMarker();
// Context menu ?
if ( _ev->button() == RightButton )
{
// TODO: Handle anchor
QPoint p = mapToGlobal( _ev->pos() );
m_pView->openPopupMenu( p );
}
}
kspread'KSpreadCanvas::chooseMouseMoveEvent() (./koffice/kspread/kspread_canvas.cc:864)
void KSpreadCanvas::chooseMouseMoveEvent( QMouseEvent * _ev )
{
if ( !m_bMousePressed )
return;
KSpreadTable *table = activeTable();
if ( !table )
return;
int ypos, xpos;
int row = table->topRow( _ev->pos().y(), ypos, this );
int col = table->leftColumn( _ev->pos().x(), xpos, this );
if ( col < m_iMouseStartColumn )
col = m_iMouseStartColumn;
if ( row < m_iMouseStartRow )
row = m_iMouseStartRow;
// Noting changed ?
QRect selection( table->chooseRect() );
if ( row == selection.bottom() && col == selection.right() )
return;
// Set the new lower right corner of the selection
selection.setRight( col );
selection.setBottom( row );
table->setChooseRect( selection );
// Scroll the table if neccessary
if ( _ev->pos().x() < 0 )
horzScrollBar()->setValue( xOffset() + xpos );
else if ( _ev->pos().x() > width() )
{
ColumnLayout *cl = table->columnLayout( col + 1 );
xpos = table->columnPos( col + 1, this );
horzScrollBar()->setValue( xOffset() + ( xpos + cl->width( this ) - width() ) );
}
if ( _ev->pos().y() < 0 )
vertScrollBar()->setValue( yOffset() + ypos );
else if ( _ev->pos().y() > height() )
{
RowLayout *rl = table->rowLayout( row + 1 );
ypos = table->rowPos( row + 1, this );
vertScrollBar()->setValue( yOffset() + ( ypos + rl->height( this ) - height() ) );
}
}
kspread'KSpreadCanvas::chooseMouseReleaseEvent() (./koffice/kspread/kspread_canvas.cc:912)
void KSpreadCanvas::chooseMouseReleaseEvent( QMouseEvent* )
{
m_bMousePressed = FALSE;
}
kspread'KSpreadCanvas::chooseMousePressEvent() (./koffice/kspread/kspread_canvas.cc:917)
void KSpreadCanvas::chooseMousePressEvent( QMouseEvent * _ev )
{
m_bMousePressed = TRUE;
KSpreadTable *table = activeTable();
if ( !table )
return;
QRect selection(table->chooseRect());
int ypos, xpos;
int row = table->topRow( _ev->pos().y(), ypos, this );
int col = table->leftColumn( _ev->pos().x(), xpos, this );
if ((selection.right() != 0x7fff && selection.bottom() != 0x7fff)&& ( _ev->state() & ControlButton ))
{
if( (col!=m_iMouseStartColumn)||(row!=m_iMouseStartRow))
{
if( selection.left()!=0&&selection.right()!=0
&&selection.top()!=0&&selection.bottom()!=0)
{
if ( col < m_iMouseStartColumn )
col = m_iMouseStartColumn;
if ( row < m_iMouseStartRow )
row = m_iMouseStartRow;
if ( row == selection.bottom() && col == selection.right() )
return;
}
selection.setLeft(m_iMouseStartColumn);
selection.setRight( col );
selection.setTop(m_iMouseStartRow);
selection.setBottom( row );
table->setChooseRect( selection );
return;
}
}
setChooseMarkerColumn( col );
setChooseMarkerRow( row );
KSpreadCell *cell = table->cellAt( chooseMarkerColumn(), chooseMarkerRow() );
// Go to the upper left corner of the obscuring object
if ( cell->isObscured() )
{
setChooseMarkerRow( cell->obscuringCellsRow() );
setChooseMarkerColumn( cell->obscuringCellsColumn() );
cell = table->cellAt( chooseMarkerColumn(), chooseMarkerRow() );
}
selection.setCoords( chooseMarkerColumn(), chooseMarkerRow(),
chooseMarkerColumn() + cell->extraXCells(),
chooseMarkerRow() + cell->extraYCells() );
table->setChooseRect( selection );
m_iMouseStartColumn = chooseMarkerColumn();
m_iMouseStartRow = chooseMarkerRow();
}
kspread'KSpreadCanvas::mouseDoubleClickEvent() (./koffice/kspread/kspread_canvas.cc:975)
void KSpreadCanvas::mouseDoubleClickEvent( QMouseEvent* )
{
if ( m_pView->koDocument()->isReadWrite() )
createEditor();
}
kspread'KSpreadCanvas::paintEvent() (./koffice/kspread/kspread_canvas.cc:981)
void KSpreadCanvas::paintEvent( QPaintEvent* _ev )
{
if ( m_pDoc->isLoading() )
return;
if ( !activeTable() )
return;
qDebug("------------PAINT EVENT %i,%i %i|%i widget %i:%i", _ev->rect().x(), _ev->rect().y(),
_ev->rect().width(), _ev->rect().height(), width(), height() );
hideMarker();
QPainter painter;
painter.begin( this );
QWMatrix m = m_pView->matrix();
painter.setWorldMatrix( m );
m = m.invert();
QPoint tl = m.map( _ev->rect().topLeft() );
QPoint br = m.map( _ev->rect().bottomRight() );
qDebug("Mapped topleft to %i:%i", tl.x(), tl.y() );
painter.save();
// Clip away children
QRegion rgn = painter.clipRegion();
if ( rgn.isEmpty() )
rgn = QRegion( _ev->rect() );
QListIterator<KoDocumentChild> it( m_pDoc->children() );
for( ; it.current(); ++it )
{
if ( ((KSpreadChild*)it.current())->table() == activeTable() &&
!m_pView->hasDocumentInWindow( it.current()->document() ) )
{
rgn -= it.current()->region( painter.worldMatrix() );
}
}
painter.setClipRegion( rgn );
// Draw content
m_pDoc->paintContent( painter, QRect( tl, br ), FALSE, activeTable() );
painter.restore();
// Draw children
// QListIterator<PartChild> it( m_pDoc->children() );
it.toFirst();
for( ; it.current(); ++it )
{
if ( ((KSpreadChild*)it.current())->table() == activeTable() &&
!m_pView->hasDocumentInWindow( it.current()->document() ) )
{
// #### todo: paint only if child is visible inside rect
painter.save();
m_pDoc->paintChild( it.current(), painter, m_pView );
painter.restore();
}
}
painter.end();
showMarker();
if( choose_visible )
drawChooseMarker( );
}
kspread'KSpreadCanvas::focusInEvent() (./koffice/kspread/kspread_canvas.cc:1050)
void KSpreadCanvas::focusInEvent( QFocusEvent* )
{
if ( !m_pEditor )
return;
kdDebug() << "m_bChoose : " << ( m_bChoose ? "true" : "false" ) << endl;
// If we are in editing mode, we redirect the
// focus to the CellEditor or EditWidget
// And we know which, using lastEditorWithFocus.
// This screws up <Tab> though (David)
if ( lastEditorWithFocus() == EditWidget )
{
m_pView->editWidget()->setFocus();
kdDebug() << "Focus to EditWidget" << endl;
return;
}
kdDebug() << "Redirecting focus to editor" << endl;
m_pEditor->setFocus();
}
kspread'KSpreadCanvas::focusOutEvent() (./koffice/kspread/kspread_canvas.cc:1071)
void KSpreadCanvas::focusOutEvent( QFocusEvent* )
{
}
kspread'KSpreadCanvas::keyPressEvent() (./koffice/kspread/kspread_canvas.cc:1075)
void KSpreadCanvas::keyPressEvent ( QKeyEvent * _ev )
{
KSpreadTable *table = activeTable();
QString tmp;
if ( !table )
return;
// Dont handle accelerators
if ( _ev->state() & ( Qt::AltButton | Qt::ControlButton ) )
{
QWidget::keyPressEvent( _ev );
return;
}
_ev->accept();
// Find out about the current selection
QRect selection;
if ( m_bChoose )
selection = activeTable()->chooseRect();
else
selection = activeTable()->selectionRect();
// Is this a key that involves goint to another cell ? If yes, do the
// "end of editing" stuff here, instead of for each case - this bool is
// also used for make_select (extending selection), so it doesn't include Return
bool bChangingCells = ( _ev->key() == Key_Down || _ev->key() == Key_Up ||
_ev->key() == Key_Left || _ev->key() == Key_Right ||
_ev->key() == Key_Prior || _ev->key() == Key_Next );
// End of editing a cell
if ( ( bChangingCells || _ev->key() == Key_Return || _ev->key() == Key_Enter )
&& m_pEditor && !m_bChoose )
{
deleteEditor( true /*save changes*/ );
}
// Are we making a selection right now ? Go thru this only if no selection is made
// or if we neither selected complete rows nor columns.
bool make_select = ( _ev->state() & ShiftButton ) == ShiftButton &&
( bChangingCells || _ev->key() == Key_Home || _ev->key() == Key_End );
switch( _ev->key() )
{
case Key_Return:
case Key_Enter:
case Key_Down:
if ( !m_bChoose && markerRow() == 0xFFFF )
return;
if ( m_bChoose && chooseMarkerRow() == 0xFFFF )
return;
if ( m_bChoose )
chooseGotoLocation( chooseMarkerColumn(), QMIN( 0x7FFF, chooseMarkerRow() + 1 ), 0, make_select );
else
gotoLocation( markerColumn(), QMIN( 0x7FFF, markerRow() + 1 ), 0, make_select );
return;
case Key_Up:
if ( !m_bChoose && markerRow() == 1 )
return;
if ( m_bChoose && chooseMarkerRow() == 1 )
return;
if ( m_bChoose )
chooseGotoLocation( chooseMarkerColumn(), QMAX( 1, chooseMarkerRow() - 1 ), 0, make_select );
else
gotoLocation( markerColumn(), QMAX( 1, markerRow() - 1 ), 0, make_select );
return;
case Key_Right:
if ( !m_bChoose && markerColumn() == 0xFFFF )
return;
if ( m_bChoose && chooseMarkerColumn() == 0xFFFF )
return;
if ( m_bChoose )
chooseGotoLocation( QMIN( 0x7FFF, chooseMarkerColumn() + 1 ), chooseMarkerRow(), 0, make_select );
else
gotoLocation( QMIN( 0x7FFF, markerColumn() + 1 ), markerRow(), 0, make_select );
return;
case Key_Left:
if ( !m_bChoose && markerColumn() == 1 )
return;
if ( m_bChoose && chooseMarkerColumn() == 1 )
return;
if ( m_bChoose )
chooseGotoLocation( QMAX( 1, chooseMarkerColumn() - 1 ), chooseMarkerRow(), 0, make_select );
else
gotoLocation( QMAX( 1, markerColumn() - 1 ), markerRow(), 0, make_select );
return;
case Key_Escape:
if ( m_pEditor )
deleteEditor( false );
_ev->accept(); // ?
return;
case Key_Home:
// We are in edit mode -> go beginning of line
if ( m_pEditor )
{
// (David) Do this for text editor only, not formula editor...
// Don't know how to avoid this hack (member var for editor type ?)
if ( m_pEditor->inherits("KSpreadTextEditor") )
QApplication::sendEvent( m_pEditWidget, _ev );
// What to do for a formula editor ?
}
else
{
if ( m_bChoose )
chooseGotoLocation( 1, 1, 0, make_select );
else
gotoLocation( 1, 1, 0, make_select );
}
return;
case Key_Prior:
if( !m_bChoose && markerRow() == 1 )
return;
if( m_bChoose && chooseMarkerRow() == 1 )
return;
if ( m_bChoose )
chooseGotoLocation( chooseMarkerColumn(), QMAX( 1, chooseMarkerRow() - 10 ), 0, make_select );
else
gotoLocation( markerColumn(), QMAX( 1, markerRow() - 10 ), 0, make_select );
return;
case Key_Next:
if( !m_bChoose && markerRow() == 0x7FFF )
return;
if( m_bChoose && chooseMarkerRow() == 0x7FFF )
return;
if ( m_bChoose )
chooseGotoLocation( chooseMarkerColumn(), QMIN( 0x7FFF, chooseMarkerRow() + 10 ), 0, make_select );
else
gotoLocation( markerColumn(), QMIN( 0x7FFF, markerRow() + 10 ), 0, make_select );
return;
case Key_Delete:
activeTable()->clearSelection( QPoint( markerColumn(), markerRow() ) );
return;
default:
// No null character ...
if ( _ev->ascii() == 0 || !m_pView->koDocument()->isReadWrite() )
{
_ev->accept();
return;
}
if ( !m_pEditor && !m_bChoose )
{
if ( _ev->ascii() == '*' )
createEditor( FormulaEditor );
else
{
// Switch to editing mode
createEditor( CellEditor );
m_pEditor->handleKeyPressEvent( _ev );
}
}
else if ( m_pEditor )
m_pEditor->handleKeyPressEvent( _ev );
return;
}
/**
* Tell the KSpreadView event handler and enable
* makro recording by the way.
*/
// _ev->accept();
// m_pView->eventKeyPressed( _ev, m_bChoose );
}
kspread'KSpreadCanvas::deleteEditor() (./koffice/kspread/kspread_canvas.cc:1274)
void KSpreadCanvas::deleteEditor( bool saveChanges )
{
if( !m_pEditor )
return;
// We need to set the line-edit out of edit mode,
// but only if we are using it (text editor)
// A bit of a hack - perhaps we should store the editor mode ?
if ( m_pEditor->inherits("KSpreadTextEditor") )
m_pEditWidget->setEditMode( false );
QString t = m_pEditor->text();
// Delete the cell editor first and after that update the document.
// That means we get a synchronous repaint after the cell editor
// widget is gone. Otherwise we may get painting errors.
delete m_pEditor;
m_pEditor = 0;
if (saveChanges)
m_pView->setText( t );
else
m_pView->updateEditWidget();
setFocus();
m_pView->enableFormulaToolBar( TRUE );
}
kspread'KSpreadCanvas::createEditor() (./koffice/kspread/kspread_canvas.cc:1301)
void KSpreadCanvas::createEditor()
{
KSpreadCell* cell = activeTable()->cellAt( markerColumn(), markerRow() );
if ( cell && cell->content() == KSpreadCell::VisualFormula )
{
QString tmp = cell->text();
createEditor( FormulaEditor );
m_pEditor->setText( tmp.right( tmp.length() - 1 ) );
}
else
{
createEditor( CellEditor );
if ( cell )
m_pEditor->setText(cell->text());
}
}
kspread'KSpreadCanvas::createEditor() (./koffice/kspread/kspread_canvas.cc:1319)
void KSpreadCanvas::createEditor( EditorType ed )
{
KSpreadTable *table = activeTable();
if ( !m_pEditor )
{
KSpreadCell* cell = activeTable()->cellAt( marker() );
if ( ed == CellEditor )
{
m_pView->enableFormulaToolBar( FALSE );
m_pEditWidget->setEditMode( true );
m_pEditor = new KSpreadTextEditor( cell, this );
}
else if( ed == FormulaEditor )
{
m_pView->enableFormulaToolBar( TRUE );
m_pEditor = new KSpreadFormulaEditor( cell, this );
}
int w, h;
int min_w = cell->width( m_iMarkerColumn, this );
int min_h = cell->height( m_iMarkerRow, this );
if ( cell->isDefault() )
{
w = min_w;
h = min_h;
qDebug("DEFAULT");
}
else
{
w = cell->extraWidth() + 1;
h = cell->extraHeight() + 1;
qDebug("HEIGHT=%i EXTRA=%i", min_h, h );
}
int xpos = table->columnPos( markerColumn(), this );
int ypos = table->rowPos( markerRow(), this );
QPalette p = m_pEditor->palette();
QColorGroup g( p.normal() );
g.setColor( QColorGroup::Text, cell->textPen().color() );
g.setColor( QColorGroup::Background, cell->KSpreadLayout::bgColor() );
m_pEditor->setPalette( QPalette( g, p.disabled(), g ) );
m_pEditor->setFont( cell->textFont() );
m_pEditor->setGeometry( xpos, ypos, w, h );
m_pEditor->setMinimumSize( QSize( min_w, min_h ) );
m_pEditor->show();
qDebug("FOCUS1");
m_pEditor->setFocus();
qDebug("FOCUS2");
}
}
//---------------------------------------------
//
// Drawing Engine
//
//---------------------------------------------
kspread'KSpreadCanvas::updateCellRect() (./koffice/kspread/kspread_canvas.cc:1377)
void KSpreadCanvas::updateCellRect( const QRect &_rect )
{
qDebug("======================= UPDATE RECT %i,%i %i,%i==================",
_rect.x(), _rect.y(), _rect.width(), _rect.height() );
KSpreadTable *table = activeTable();
if ( !table )
return;
QRect param( _rect );
if ( param.left() <= 0 && param.top() <= 0 && param.right() <= 0 && param.bottom() <= 0 )
return;
// We want to repaint the border too => enlarge the rect
if ( param.left() > 1 )
param.setLeft( param.left() - 1 );
if ( param.right() < 0x7fff )
param.setRight( param.right() + 1 );
if ( param.top() > 1 )
param.setTop( param.top() - 1 );
if ( param.bottom() < 0x7fff )
param.setBottom( param.bottom() + 1 );
if ( param.left() <= 0 )
param.setLeft( 1 );
if ( param.top() <= 0 )
param.setTop( 1 );
if ( param.right() < param.left() )
return;
if ( param.bottom() < param.top() )
return;
int bottom, right;
int left = table->columnPos( param.left() );
int top = table->rowPos( param.top() );
if ( param.right() < 0x7fff )
right = table->columnPos( param.right() + 1 );
else
right = int( (double)width() / m_pView->xScaling() );
if ( param.bottom() < 0x7fff )
bottom = table->rowPos( param.bottom() + 1 );
else
bottom = int( (double)height() / m_pView->yScaling() );
QPoint tl( left, top );
QPoint br( right, bottom );
QWMatrix m = m_pView->matrix();
tl = m.map( tl );
br = m.map( br );
QPaintEvent event( QRect( tl, br ) );
paintEvent( &event );
}
kspread'KSpreadCanvas::drawMarker() (./koffice/kspread/kspread_canvas.cc:1431)
void KSpreadCanvas::drawMarker( QPainter * _painter )
{
bool own_painter = FALSE;
if ( _painter == 0L )
{
_painter = new QPainter();
_painter->begin( this );
own_painter = TRUE;
}
int xpos;
int ypos;
int w, h;
QRect selection( activeTable()->selectionRect() );
// printf("selection: %i %i %i\n",selection.left(), selection.right(), selection.bottom() );
if ( selection.left() == 0 || selection.right() == 0x7fff || selection.bottom() == 0x7fff )
{
xpos = activeTable()->columnPos( m_iMarkerColumn, this );
ypos = activeTable()->rowPos( m_iMarkerRow, this );
KSpreadCell *cell = activeTable()->cellAt( m_iMarkerColumn, m_iMarkerRow );
w = cell->width( m_iMarkerColumn, this );
h = cell->height( m_iMarkerRow, this );
}
else
{
xpos = activeTable()->columnPos( selection.left(), this );
ypos = activeTable()->rowPos( selection.top(), this );
int x = activeTable()->columnPos( selection.right(), this );
KSpreadCell *cell = activeTable()->cellAt( selection.right(), selection.top() );
int tw = cell->width( selection.right(), this );
w = ( x - xpos ) + tw;
cell = activeTable()->cellAt( selection.left(), selection.bottom() );
int y = activeTable()->rowPos( selection.bottom(), this );
int th = cell->height( selection.bottom(), this );
h = ( y - ypos ) + th;
}
RasterOp rop = _painter->rasterOp();
_painter->setRasterOp( NotROP );
QPen pen;
pen.setWidth( 3 );
_painter->setPen( pen );
// _painter->drawRect( xpos - 1, ypos - 1, w + 2, h + 2 );
_painter->drawLine( xpos - 2, ypos - 1, xpos + w + 2, ypos - 1 );
_painter->drawLine( xpos - 1, ypos + 1, xpos - 1, ypos + h + 3 );
_painter->drawLine( xpos + 1, ypos + h + 1, xpos + w - 3, ypos + h + 1 );
_painter->drawLine( xpos + w, ypos + 1, xpos + w, ypos + h - 2 );
_painter->fillRect( xpos + w - 2, ypos + h - 1, 5, 5, black );
_painter->setRasterOp( rop );
if ( own_painter )
{
_painter->end();
delete _painter;
}
char buffer[ 20 ];
sprintf( buffer, "%s%d", activeTable()->columnLabel( m_iMarkerColumn ), m_iMarkerRow );
m_pPosWidget->setText(buffer);
}
kspread'KSpreadCanvas::updateChooseMarker() (./koffice/kspread/kspread_canvas.cc:1497)
void KSpreadCanvas::updateChooseMarker( const QRect& _old, const QRect& _new )
{
if ( isChooseMarkerVisible() )
{
drawChooseMarker( _old );
drawChooseMarker( _new );
}
else
{
choose_visible = TRUE;
drawChooseMarker( _new );
}
if ( _new.left() == 0 || !m_bChoose || !m_pEditor )
{
qDebug("updateChooseMarker len=0");
length_namecell = 0;
return;
}
KSpreadTable* table = activeTable();
// ##### Torben: Clean up here!
QString name_cell;
kDebugInfo( "%s,%s", m_chooseStartTable->tableName().ascii(), table->tableName().ascii());
if( m_chooseStartTable != table )
{
if ( _new.left() >= _new.right() && _new.top() >= _new.bottom() )
name_cell = util_cellName( table, _new.left(), _new.top() );
else
name_cell = util_rangeName( table, _new );
}
else
{
if ( _new.left() >= _new.right() && _new.top() >= _new.bottom() )
name_cell = util_cellName( _new.left(), _new.top() );
else
name_cell = util_rangeName( _new );
}
int old = length_namecell;
length_namecell= name_cell.length();
length_text = m_pEditor->text().length();
qDebug("updateChooseMarker2 len=%i", length_namecell);
QString text = m_pEditor->text();
QString res = text.left( m_pEditor->cursorPosition() - old ) + name_cell + text.right( text.length() - m_pEditor->cursorPosition() );
int pos = m_pEditor->cursorPosition() - old;
((KSpreadTextEditor*)m_pEditor)->blockCheckChoose( TRUE );
m_pEditor->setText( res );
((KSpreadTextEditor*)m_pEditor)->blockCheckChoose( FALSE );
m_pEditor->setCursorPosition( pos + length_namecell );
qDebug("old=%i len=%i pos=%i", old, length_namecell, pos );
// m_pEditor->setText(m_pEditor->text().left(length_text-old)+ name_cell);
/*
//####### Torben: That looks too hacky
if( m_pEditor->text().right(1)=="=")
{
m_pEditor->setText(m_pEditor->text()+ name_cell);
}
else
{
//######### TODO: TORBEN: There are more operators!!!
if( (m_pEditor->text().right(1)!="+") && (m_pEditor->text().right(1)!="-") &&
(m_pEditor->text().right(1)!="*") &&(m_pEditor->text().right(1)!="/"))
{
m_pEditor->setText(m_pEditor->text().left(length_text-old)+ name_cell);
}
else
{
m_pEditor->setText(m_pEditor->text()+ name_cell);
}
}
*/
// m_pEditor->setFocus();
}
kspread'KSpreadCanvas::drawChooseMarker() (./koffice/kspread/kspread_canvas.cc:1577)
void KSpreadCanvas::drawChooseMarker()
{
drawChooseMarker( activeTable()->chooseRect() );
}
kspread'KSpreadCanvas::drawChooseMarker() (./koffice/kspread/kspread_canvas.cc:1582)
void KSpreadCanvas::drawChooseMarker( const QRect& selection )
{
// Draw nothing if the selection is empty
if ( selection.left() == 0 )
return;
QPainter painter;
painter.begin( this );
int xpos;
int ypos;
int w, h;
if ( selection.left() == 0 || selection.right() == 0x7fff || selection.bottom() == 0x7fff )
{
xpos = activeTable()->columnPos( chooseMarkerColumn(), this );
ypos = activeTable()->rowPos( chooseMarkerRow(), this );
KSpreadCell *cell = activeTable()->cellAt( chooseMarkerColumn(), chooseMarkerRow() );
w = cell->width( chooseMarkerColumn(), this );
h = cell->height( chooseMarkerRow(), this );
}
else
{
xpos = activeTable()->columnPos( selection.left(), this );
ypos = activeTable()->rowPos( selection.top(), this );
int x = activeTable()->columnPos( selection.right(), this );
KSpreadCell *cell = activeTable()->cellAt( selection.right(), selection.top() );
int tw = cell->width( selection.right(), this );
w = ( x - xpos ) + tw;
cell = activeTable()->cellAt( selection.left(), selection.bottom() );
int y = activeTable()->rowPos( selection.bottom(), this );
int th = cell->height( selection.bottom(), this );
h = ( y - ypos ) + th;
}
RasterOp rop = painter.rasterOp();
painter.setRasterOp( NotROP );
QPen pen;
pen.setWidth( 2 );
pen.setStyle(DashLine);
painter.setPen( pen );
painter.drawLine( xpos - 2, ypos - 1, xpos + w + 2, ypos - 1 );
painter.drawLine( xpos - 1, ypos + 1, xpos - 1, ypos + h + 3 );
painter.drawLine( xpos + 1, ypos + h + 1, xpos + w - 3, ypos + h + 1 );
painter.drawLine( xpos + w, ypos + 1, xpos + w, ypos + h - 2 );
// painter.fillRect( xpos + w - 2, ypos + h - 1, 5, 5, black );
painter.setRasterOp( rop );
painter.end();
}
kspread'KSpreadCanvas::setChooseMarker() (./koffice/kspread/kspread_canvas.cc:1635)
void KSpreadCanvas::setChooseMarker( const QPoint& p )
{
if ( p.x() == m_i_chooseMarkerColumn && p.y() == m_i_chooseMarkerRow )
return;
m_i_chooseMarkerRow = p.y();
m_i_chooseMarkerColumn = p.x();
// This will trigger a redraw
activeTable()->setChooseRect( QRect( p.x(), p.y(), 1, 1 ) );
}
kspread'KSpreadCanvas::setMarker() (./koffice/kspread/kspread_canvas.cc:1646)
void KSpreadCanvas::setMarker( const QPoint& p )
{
if ( p.x() == m_iMarkerColumn && p.y() == m_iMarkerRow )
return;
if ( m_iMarkerVisible < 1 )
{
m_iMarkerRow = p.y();
m_iMarkerColumn = p.x();
return;
}
hideMarker();
m_iMarkerRow = p.y();
m_iMarkerColumn = p.x();
showMarker();
}
kspread'KSpreadCanvas::setMarkerColumn() (./koffice/kspread/kspread_canvas.cc:1664)
void KSpreadCanvas::setMarkerColumn( int _c )
{
if ( !m_iMarkerVisible < 1 )
{
m_iMarkerColumn = _c;
return;
}
hideMarker();
m_iMarkerColumn = _c;
showMarker();
}
kspread'KSpreadCanvas::setMarkerRow() (./koffice/kspread/kspread_canvas.cc:1677)
void KSpreadCanvas::setMarkerRow( int _r )
{
if ( !m_iMarkerVisible < 1 )
{
m_iMarkerRow = _r;
return;
}
hideMarker();
m_iMarkerRow = _r;
showMarker();
}
kspread'KSpreadCanvas::hideMarker() (./koffice/kspread/kspread_canvas.cc:1690)
void KSpreadCanvas::hideMarker( QPainter& _painter )
{
if ( m_iMarkerVisible == 1 )
drawMarker( &_painter );
m_iMarkerVisible--;
}
kspread'KSpreadCanvas::showMarker() (./koffice/kspread/kspread_canvas.cc:1697)
void KSpreadCanvas::showMarker( QPainter& _painter)
{
if ( m_iMarkerVisible == 1 )
return;
m_iMarkerVisible++;
if ( m_iMarkerVisible == 1 )
drawMarker( &_painter );
}
// Torben: ########### Not needed any more
kspread'KSpreadCanvas::drawCell() (./koffice/kspread/kspread_canvas.cc:1708)
void KSpreadCanvas::drawCell( KSpreadCell *_cell, int _col, int _row )
{
int left = activeTable()->columnPos( _col ) - m_iXOffset;
int top = activeTable()->rowPos( _row ) - m_iYOffset;
int right = left + _cell->extraWidth() - m_iXOffset;
int bottom = top + _cell->extraHeight() - m_iYOffset;
qDebug("left=%i right=%i extra=%i", left, right, _cell->extraWidth() );
QPoint tl( left, top );
QPoint br( right, bottom );
QWMatrix m = m_pView->matrix();
tl = m.map( tl );
br = m.map( br );
QPaintEvent event( QRect( tl, br ) );
paintEvent( &event );
}
kspread'KSpreadCanvas::adjustArea() (./koffice/kspread/kspread_canvas.cc:1727)
void KSpreadCanvas::adjustArea()
{
QRect selection( activeTable()->selectionRect() );
// Columns selected
if( selection.left() != 0 && selection.bottom() == 0x7FFF )
{
for (int x=selection.left(); x <= selection.right(); x++ )
{
hBorderWidget()->adjustColumn(x);
}
}
// Rows selected
else if(selection.left() != 0 && selection.right() == 0x7FFF )
{
for(int y = selection.top(); y <= selection.bottom(); y++ )
{
vBorderWidget()->adjustRow(y);
}
}
// No selection
else if( selection.left() == 0 || selection.top() == 0 ||
selection.bottom() == 0 || selection.right() == 0 )
{
vBorderWidget()->adjustRow(markerRow());
hBorderWidget()->adjustColumn(markerColumn());
}
// Selection of a rectangualar area
else
{
for (int x=selection.left(); x <= selection.right(); x++ )
{
hBorderWidget()->adjustColumn(x);
}
for(int y = selection.top(); y <= selection.bottom(); y++ )
{
vBorderWidget()->adjustRow(y);
}
}
}
/****************************************************************
*
* KSpreadVBorder
*
****************************************************************/