Source Code (Use browser search to find items of interest.)

Class Index

kspread'KSpreadTextEditor (./koffice/kspread/kspread_editors.h:40)

class KSpreadTextEditor : public KSpreadCellEditor
{
    Q_OBJECT
public:
    KSpreadTextEditor( KSpreadCell*, KSpreadCanvas* _parent = 0, const char* _name = 0 );
    ~KSpreadTextEditor();

    virtual void handleKeyPressEvent( QKeyEvent* _ev );
    virtual QString text() const;
    virtual void setText(QString text);
    virtual int cursorPosition() const;
    virtual void setCursorPosition(int pos);
    // virtual void setFocus();
    virtual void insertFormulaChar(int c);

    void checkChoose();
    void blockCheckChoose( bool b ) { m_blockCheck = b; }
    
private slots:
    void slotTextChanged( const QString& text );

protected:
    void resizeEvent( QResizeEvent* );
    /**
     * Steals some key events from the QLineEdit and sends
     * it to the @ref KSpreadCancvas ( its parent ) instead.
     */
    bool eventFilter( QObject* o, QEvent* e );

private:
    QLineEdit* m_pEdit;
    bool m_blockCheck;
};


kspread'KSpreadTextEditor::KSpreadTextEditor() (./koffice/kspread/kspread_editors.cc:34)

KSpreadTextEditor::KSpreadTextEditor( KSpreadCell* _cell, KSpreadCanvas* _parent, const char* _name )
  : KSpreadCellEditor( _cell, _parent, _name )
{
  m_pEdit = new QLineEdit( this );
  m_pEdit->installEventFilter( this );
  m_pEdit->setFrame( FALSE );

  setFocusProxy( m_pEdit );
  setFontPropagation( AllChildren );
  setPalettePropagation( AllChildren );

  connect( m_pEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( slotTextChanged( const QString& ) ) );

  // A choose should always start at the edited cell
  canvas()->setChooseMarkerRow( canvas()->markerRow() );
  canvas()->setChooseMarkerColumn( canvas()->markerColumn() );

  m_blockCheck = FALSE;
}


kspread'KSpreadTextEditor::~KSpreadTextEditor() (./koffice/kspread/kspread_editors.cc:54)

KSpreadTextEditor::~KSpreadTextEditor()
{
    canvas()->endChoose();
}


kspread'KSpreadTextEditor::slotTextChanged() (./koffice/kspread/kspread_editors.cc:59)

void KSpreadTextEditor::slotTextChanged( const QString& t )
{
    // if ( canvas->chooseCursorPosition() >= 0 )
    // m_pEdit->setCursorPosition( canvas->chooseCursorPosition() );
    checkChoose();

    canvas()->view()->editWidget()->setText( t );
    // canvas()->view()->editWidget()->setCursorPosition( m_pEdit->cursorPosition() );
}


kspread'KSpreadTextEditor::checkChoose() (./koffice/kspread/kspread_editors.cc:69)

void KSpreadTextEditor::checkChoose()
{
    if ( m_blockCheck )
	return;

    QString t = m_pEdit->text();
    // QString r = t.mid( t.length() - 1 - canvas()->chooseTextLen(), 1 );
    QString r = t.mid( m_pEdit->cursorPosition() - 1 - canvas()->chooseTextLen(), 1 );
    kdDebug() << "r='" << r << "'" << endl;
    if ( t.left(1) == "=" && ( r == "*" || r == "|" || r == "&" || r == "-" ||
			       r == "+" || r == "/" || r == "!" || r == "(" ||
			       r == "^" || r == "," || r == "%" || r == "[" ||
			       r == "{" || r == "~" || r == "=" ) )
    {
	kdDebug() << "Start CHOOSE" << endl;
	canvas()->startChoose();
    }
    else
    {
	kdDebug() << "End CHOOSE" << endl;
	canvas()->endChoose();
    }
}


kspread'KSpreadTextEditor::resizeEvent() (./koffice/kspread/kspread_editors.cc:93)

void KSpreadTextEditor::resizeEvent( QResizeEvent* )
{
    m_pEdit->setGeometry( 0, 0, width(), height() );
}


kspread'KSpreadTextEditor::handleKeyPressEvent() (./koffice/kspread/kspread_editors.cc:98)

void KSpreadTextEditor::handleKeyPressEvent( QKeyEvent* _ev )
{
    // Send the key event to the QLineEdit
    QApplication::sendEvent( m_pEdit, _ev );
}


kspread'KSpreadTextEditor::text() (./koffice/kspread/kspread_editors.cc:104)

QString KSpreadTextEditor::text() const
{
    return m_pEdit->text();
}


kspread'KSpreadTextEditor::setText() (./koffice/kspread/kspread_editors.cc:109)

void KSpreadTextEditor::setText(QString text)
{
    if(m_pEdit !=0)
	m_pEdit->setText(text);
}	


kspread'KSpreadTextEditor::cursorPosition() (./koffice/kspread/kspread_editors.cc:115)

int KSpreadTextEditor::cursorPosition() const
{
    return m_pEdit->cursorPosition();
}


kspread'KSpreadTextEditor::setCursorPosition() (./koffice/kspread/kspread_editors.cc:120)

void KSpreadTextEditor::setCursorPosition( int pos )
{
    m_pEdit->setCursorPosition(pos);
    canvas()->view()->editWidget()->setCursorPosition( pos );
    checkChoose();
}


kspread'KSpreadTextEditor::insertFormulaChar() (./koffice/kspread/kspread_editors.cc:127)

void KSpreadTextEditor::insertFormulaChar(int c)
{
}


kspread'KSpreadTextEditor::eventFilter() (./koffice/kspread/kspread_editors.cc:131)

bool KSpreadTextEditor::eventFilter( QObject* o, QEvent* e )
{
    // Only interested in QLineEdit
    if ( o != m_pEdit )
	return FALSE;

    if ( e->type() == QEvent::FocusOut )
    {
	canvas()->setLastEditorWithFocus( KSpreadCanvas::CellEditor );
	return FALSE;
    }

    if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease )
    {
	QKeyEvent* k = (QKeyEvent*)e;
	if ( k->key() == Key_Right || k->key() == Key_Left || k->key() == Key_Up ||
	     k->key() == Key_Down || k->key() == Key_Next || k->key() == Key_Prior ||
	     k->key() == Key_Escape )
        {
	    // Send directly to canvas
	    QApplication::sendEvent( parent(), e );
	    return TRUE;	
	}
	
	// End choosing. May be restarted by KSpreadTextEditor::slotTextChanged
	if ( e->type() == QEvent::KeyPress && !k->ascii() == 0 )
        {
	    kdDebug() << "eventFilter End Choose" << endl;
	    canvas()->endChoose();
	    kdDebug() << "Cont" << endl;
	}
    }

    return FALSE;
}


/*********************************************************
 *
 * KSpreadFormulaEditor
 *
 *********************************************************/