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

Class Index

kspread'Calculator (./koffice/kspread/plugins/calculator/main.h:50)

class Calculator : public KParts::Plugin
{
    Q_OBJECT
public:
    Calculator( KSpreadView* parent, const char* name = 0 );
    ~Calculator();

    KSpreadView* view() { return m_view; }

protected slots:
    void showCalculator();

protected:
    bool eventFilter( QObject*, QEvent* );

private:
    QtCalculator* m_calc;
    KSpreadView* m_view;
};

kspread'Calculator::Calculator() (./koffice/kspread/plugins/calculator/main.cpp:89)

Calculator::Calculator( KSpreadView* parent, const char* name )
    : KParts::Plugin( parent, name )
{
    m_calc = 0;
    m_view = parent;

    parent->installEventFilter( this );

    (void)new KAction( i18n("Calculator"), "kspreadcalc", 0, actionCollection(), "kspreadcalc");
}


kspread'Calculator::showCalculator() (./koffice/kspread/plugins/calculator/main.cpp:100)

void Calculator::showCalculator()
{
    if ( m_calc )
    {
	m_calc->show();
	m_calc->raise();
	return;
    }

     m_calc = new QtCalculator( this, (KSpreadView*)parent() );
     m_calc->setFixedSize( 9 + 100 + 9 + 233 + 9, 239);
     m_calc->show();
     m_calc->raise();
}


kspread'Calculator::~Calculator() (./koffice/kspread/plugins/calculator/main.cpp:115)

Calculator::~Calculator()
{
}


kspread'Calculator::eventFilter() (./koffice/kspread/plugins/calculator/main.cpp:119)

bool Calculator::eventFilter( QObject*, QEvent* ev )
{
    if ( !m_calc )
	return FALSE;

    if ( KSpreadSelectionChanged::test( ev ) )
    {
	KSpreadSelectionChanged* event = (KSpreadSelectionChanged*)ev;
	
	// Selection cleared ?
	if ( event->rect().left() == 0 )
	    return FALSE;

	KSpreadTable* table = m_view->doc()->map()->findTable( event->table() );
	if ( !table )
	    return FALSE;

	// A single cell selected ?
	if ( event->rect().left() == event->rect().right() &&
	     event->rect().top() == event->rect().bottom() )
        {
	    KSpreadCell* cell = table->cellAt( event->rect().left(), event->rect().top() );
	    if ( !cell )
		return FALSE;
	
	    double d;
	    if ( cell->isEmpty() )
		d = 0;
	    else
		d = cell->valueDouble();
	    m_calc->setValue( d );

	    return FALSE;
	}

	// Multiple cells selected ?
	m_calc->setData( event->rect(), event->table() );
	QString str = util_rangeName( table, event->rect() );
	m_calc->setLabel( str );
	
	return FALSE;
    }

    return FALSE;
}

/***************************************************
 *
 * QtCalculator
 *
 ***************************************************/

/**
 * This is a hook that makes the calculator to
 * ask KSpread for the values of the selected cells.
 */