main.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "main.h"
00021 #include "kcalc.h"
00022 #include "kspread_view.h"
00023 #include "kspread_events.h"
00024 #include "kspread_doc.h"
00025 #include "kspread_locale.h"
00026 #include "kspread_util.h"
00027 #include "kspread_map.h"
00028
00029
00030 #include <kdebug.h>
00031
00032 #include <stdio.h>
00033
00034
00035
00036
00037
00038
00039
00040 K_EXPORT_COMPONENT_FACTORY( libkspreadcalc, CalcFactory )
00041
00042 KInstance* CalcFactory::s_global = 0;
00043
00044 CalcFactory::CalcFactory( QObject* parent, const char* name )
00045 : KLibFactory( parent, name )
00046 {
00047 s_global = new KInstance( "kspreadcalc" );
00048 }
00049
00050 CalcFactory::~CalcFactory()
00051 {
00052 delete s_global;
00053 }
00054
00055 QObject* CalcFactory::createObject( QObject* parent, const char* name, const char* , const QStringList & )
00056 {
00057 if ( !parent->inherits("KSpreadView") )
00058 {
00059 kdError() << "CalcFactory: KSpreadView expected. Parent is " << parent->className() << endl;
00060 return 0;
00061 }
00062
00063 QObject *obj = new Calculator( (KSpreadView*)parent, name );
00064 return obj;
00065 }
00066
00067 KInstance* CalcFactory::global()
00068 {
00069 return s_global;
00070 }
00071
00072
00073
00074
00075
00076
00077
00078 Calculator::Calculator( KSpreadView* parent, const char* name )
00079 : KParts::Plugin( parent, name )
00080 {
00081 m_calc = 0;
00082 m_view = parent;
00083
00084 KGlobal::locale()->insertCatalogue("kspreadcalc_calc");
00085 parent->installEventFilter( this );
00086
00087 (void)new KAction( i18n("Calculator"), SmallIcon("kcalc", CalcFactory::global()),
00088 0, this, SLOT( showCalculator() ), actionCollection(), "kspreadcalc");
00089 }
00090
00091 void Calculator::showCalculator()
00092 {
00093 if ( m_calc )
00094 {
00095 m_calc->show();
00096 m_calc->raise();
00097 return;
00098 }
00099
00100 m_calc = new QtCalculator( this, (KSpreadView*)parent() );
00101 m_calc->setFixedSize( 9 + 100 + 9 + 233 + 9, 239);
00102 m_calc->show();
00103 m_calc->raise();
00104 }
00105
00106 Calculator::~Calculator()
00107 {
00108 }
00109
00110 bool Calculator::eventFilter( QObject*, QEvent* ev )
00111 {
00112 if ( !m_calc )
00113 return FALSE;
00114
00115 if ( KSpreadSelectionChanged::test( ev ) )
00116 {
00117 KSpreadSelectionChanged* event = (KSpreadSelectionChanged*)ev;
00118
00119
00120 if ( event->rect().left() == 0 )
00121 return FALSE;
00122
00123 KSpreadSheet* sheet = m_view->doc()->map()->findSheet( event->sheet() );
00124 if ( !sheet )
00125 return FALSE;
00126
00127
00128 if ( event->rect().left() == event->rect().right() &&
00129 event->rect().top() == event->rect().bottom() )
00130 {
00131 KSpreadCell* cell = sheet->cellAt( event->rect().left(), event->rect().top(), false );
00132 if ( !cell )
00133 return FALSE;
00134
00135 double d;
00136 if ( cell->isEmpty() )
00137 d = 0;
00138 else
00139 d = cell->value().asFloat();
00140 m_calc->setValue( d );
00141
00142 return FALSE;
00143 }
00144
00145
00146 m_calc->setData( event->rect(), event->sheet().latin1() );
00147 QString str = util_rangeName( sheet, event->rect() );
00148 m_calc->setLabel( str.latin1() );
00149
00150 return FALSE;
00151 }
00152
00153 return FALSE;
00154 }
00155
00156
00157
00158
00159
00160
00161
00166 void QtCalculator::useData()
00167 {
00168 stats.clearAll();
00169
00170
00171 int len = ( sheet_range.right() - sheet_range.left() + 1 ) *
00172 ( sheet_range.bottom() - sheet_range.top() + 1 );
00173
00174 double *v = new double[ len ];
00175 int n = 0;
00176 for( int x = sheet_range.left(); x <= sheet_range.right(); x++ )
00177 for( int y = sheet_range.top(); y <= sheet_range.bottom(); y++ )
00178 {
00179 KSpreadView* view = corba->view();
00180 KSpreadSheet* sheet = view->doc()->map()->findSheet( sheet_name );
00181 if ( !sheet )
00182 return;
00183 KSpreadCell* cell = sheet->cellAt( x, y, false );
00184 if ( !cell )
00185 return;
00186
00187 v[n++] = cell->value().asFloat();
00188 }
00189
00190 for( int i = 0; i < n; i++ )
00191 stats.enterData( v[i] );
00192
00193 delete []v;
00194
00195 sheet_name = QString::null;
00196 }
00197
00198 #include "main.moc"
This file is part of the documentation for kspread Library Version 1.4.2.