kspread

kspread_dlg_formula.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002-2003 Ariya Hidayat <ariya@kde.org>
00003              (C) 2002-2003 Norbert Andres <nandres@web.de>
00004              (C) 1999-2003 Laurent Montel <montel@kde.org>
00005              (C) 2002 Philipp Mueller <philipp.mueller@gmx.de>
00006              (C) 2002 John Dailey <dailey@vt.edu>
00007              (C) 2002 Daniel Herring <herring@eecs.ku.edu>
00008              (C) 2000-2001 Werner Trobin <trobin@kde.org>
00009              (C) 1998-2000 Torben Weis <weis@kde.org>
00010 
00011    This library is free software; you can redistribute it and/or
00012    modify it under the terms of the GNU Library General Public
00013    License as published by the Free Software Foundation; either
00014    version 2 of the License, or (at your option) any later version.
00015 
00016    This library is distributed in the hope that it will be useful,
00017    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019    Library General Public License for more details.
00020 
00021    You should have received a copy of the GNU Library General Public License
00022    along with this library; see the file COPYING.LIB.  If not, write to
00023    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00024  * Boston, MA 02110-1301, USA.
00025 */
00026 
00027 #include <qtextbrowser.h>
00028 #include <qtabwidget.h>
00029 
00030 #include "kspread_dlg_formula.h"
00031 #include "kspread_canvas.h"
00032 #include "kspread_util.h"
00033 #include "kspread_editors.h"
00034 #include "kspread_doc.h"
00035 #include "kspread_locale.h"
00036 #include "kspread_map.h"
00037 #include "selection.h"
00038 #include "kspread_sheet.h"
00039 #include "kspread_view.h"
00040 #include "functions.h"
00041 
00042 #include <kapplication.h>
00043 #include <kdebug.h>
00044 #include <kbuttonbox.h>
00045 #include <knumvalidator.h>
00046 #include <qcombobox.h>
00047 #include <qevent.h>
00048 #include <qlistbox.h>
00049 #include <qlabel.h>
00050 #include <qpushbutton.h>
00051 #include <klineedit.h>
00052 #include <qlayout.h>
00053 
00054 using namespace KSpread;
00055 
00056 FormulaDialog::FormulaDialog( View* parent, const char* name,const QString& formulaName)
00057     : KDialogBase( parent, name,false,i18n("Function"), Ok|Cancel )
00058 {
00059   setWFlags( Qt::WDestructiveClose );
00060 
00061     m_pView = parent;
00062     m_focus = 0;
00063     m_desc = 0;
00064 
00065     Cell* cell = m_pView->activeSheet()->cellAt( m_pView->canvasWidget()->markerColumn(),
00066                             m_pView->canvasWidget()->markerRow() );
00067      m_oldText=cell->text();
00068     // Make sure that there is a cell editor running.
00069     if ( !m_pView->canvasWidget()->editor() )
00070     {
00071         m_pView->canvasWidget()->createEditor( Canvas::CellEditor );
00072         if(cell->text().isEmpty())
00073           m_pView->canvasWidget()->editor()->setText( "=" );
00074         else
00075           if(cell->text().at(0)!='=')
00076             m_pView->canvasWidget()->editor()->setText( "="+cell->text() );
00077           else
00078             m_pView->canvasWidget()->editor()->setText( cell->text() );
00079     }
00080 
00081     Q_ASSERT( m_pView->canvasWidget()->editor() );
00082 
00083     QWidget *page = new QWidget( this );
00084     setMainWidget(page);
00085 
00086     QGridLayout *grid1 = new QGridLayout(page,11,2,KDialog::marginHint(), KDialog::spacingHint());
00087 
00088     searchFunct = new KLineEdit(page);
00089     QSizePolicy sp3( QSizePolicy::Preferred, QSizePolicy::Fixed );
00090     searchFunct->setSizePolicy( sp3 );
00091 
00092     grid1->addWidget( searchFunct, 0, 0 );
00093 
00094     typeFunction = new QComboBox(page);
00095     QStringList cats = FunctionRepository::self()->groups();
00096     cats.prepend( i18n("All") );
00097     typeFunction->insertStringList( cats  );
00098     grid1->addWidget( typeFunction, 1, 0 );
00099 
00100     functions = new QListBox(page);
00101     QSizePolicy sp1( QSizePolicy::Preferred, QSizePolicy::Expanding );
00102     functions->setSizePolicy( sp1 );
00103     grid1->addWidget( functions, 2, 0 );
00104 
00105     selectFunction = new QPushButton( page );
00106     QToolTip::add(selectFunction, i18n("Insert function") );
00107     selectFunction->setPixmap( BarIcon( "down", KIcon::SizeSmall ) );
00108     grid1->addWidget( selectFunction, 3, 0 );
00109 
00110     result = new QLineEdit( page );
00111     grid1->addMultiCellWidget( result, 4, 4, 0, 1 );
00112 
00113     m_tabwidget = new QTabWidget( page );
00114     QSizePolicy sp2( QSizePolicy::Expanding, QSizePolicy::Expanding );
00115     m_tabwidget->setSizePolicy( sp2 );
00116     grid1->addMultiCellWidget( m_tabwidget, 0, 2, 1, 1 );
00117 
00118     m_browser = new QTextBrowser( m_tabwidget );
00119     m_browser->setMinimumWidth( 300 );
00120 
00121     m_tabwidget->addTab( m_browser, i18n("&Help") );
00122     int index = m_tabwidget->currentPageIndex();
00123 
00124     m_input = new QWidget( m_tabwidget );
00125     QVBoxLayout *grid2 = new QVBoxLayout( m_input, KDialog::marginHint(), KDialog::spacingHint() );
00126 
00127     // grid2->setResizeMode (QLayout::Minimum);
00128 
00129     label1 = new QLabel(m_input);
00130     grid2->addWidget( label1 );
00131 
00132     firstElement=new QLineEdit(m_input);
00133     grid2->addWidget( firstElement );
00134 
00135     label2=new QLabel(m_input);
00136     grid2->addWidget( label2 );
00137 
00138     secondElement=new QLineEdit(m_input);
00139     grid2->addWidget( secondElement );
00140 
00141     label3=new QLabel(m_input);
00142     grid2->addWidget( label3 );
00143 
00144     thirdElement=new QLineEdit(m_input);
00145     grid2->addWidget( thirdElement );
00146 
00147     label4=new QLabel(m_input);
00148     grid2->addWidget( label4 );
00149 
00150     fourElement=new QLineEdit(m_input);
00151     grid2->addWidget( fourElement );
00152 
00153     label5=new QLabel(m_input);
00154     grid2->addWidget( label5 );
00155 
00156     fiveElement=new QLineEdit(m_input);
00157     grid2->addWidget( fiveElement );
00158 
00159     grid2->addStretch( 10 );
00160 
00161     m_tabwidget->addTab( m_input, i18n("&Parameters") );
00162     m_tabwidget->setTabEnabled( m_input, FALSE );
00163 
00164     m_tabwidget->setCurrentPage( index );
00165 
00166     refresh_result = true;
00167 
00168     connect( this, SIGNAL( cancelClicked() ), this, SLOT( slotClose() ) );
00169     connect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
00170     connect( typeFunction, SIGNAL( activated(const QString &) ),
00171              this, SLOT( slotActivated(const QString &) ) );
00172     connect( functions, SIGNAL( highlighted(const QString &) ),
00173              this, SLOT( slotSelected(const QString &) ) );
00174     connect( functions, SIGNAL( selected(const QString &) ),
00175              this, SLOT( slotSelected(const QString &) ) );
00176     connect( functions, SIGNAL( doubleClicked(QListBoxItem * ) ),
00177              this ,SLOT( slotDoubleClicked(QListBoxItem *) ) );
00178 
00179     slotActivated(i18n("All"));
00180 
00181     connect( selectFunction, SIGNAL(clicked()),
00182          this,SLOT(slotSelectButton()));
00183 
00184     connect( firstElement,SIGNAL(textChanged ( const QString & )),
00185          this,SLOT(slotChangeText(const QString &)));
00186     connect( secondElement,SIGNAL(textChanged ( const QString & )),
00187          this,SLOT(slotChangeText(const QString &)));
00188     connect( thirdElement,SIGNAL(textChanged ( const QString & )),
00189          this,SLOT(slotChangeText(const QString &)));
00190     connect( fourElement,SIGNAL(textChanged ( const QString & )),
00191          this,SLOT(slotChangeText(const QString &)));
00192     connect( fiveElement,SIGNAL(textChanged ( const QString & )),
00193          this,SLOT(slotChangeText(const QString &)));
00194 
00195     connect( m_pView->choice(), SIGNAL(changed(const Region&)),
00196              this, SLOT(slotSelectionChanged()));
00197 
00198     connect( m_browser, SIGNAL( linkClicked( const QString& ) ),
00199              this, SLOT( slotShowFunction( const QString& ) ) );
00200 
00201     // Save the name of the active sheet.
00202     m_sheetName = m_pView->activeSheet()->sheetName();
00203     // Save the cells current text.
00204     QString tmp_oldText = m_pView->canvasWidget()->editor()->text();
00205     // Position of the cell.
00206     m_column = m_pView->canvasWidget()->markerColumn();
00207     m_row = m_pView->canvasWidget()->markerRow();
00208 
00209     if( tmp_oldText.isEmpty() )
00210         result->setText("=");
00211     else
00212     {
00213         if( tmp_oldText.at(0)!='=')
00214         result->setText( "=" + tmp_oldText );
00215         else
00216         result->setText( tmp_oldText );
00217     }
00218 
00219     // Allow the user to select cells on the spreadsheet.
00220     m_pView->canvasWidget()->startChoose();
00221 
00222     qApp->installEventFilter( this );
00223 
00224     // Was a function name passed along with the constructor ? Then activate it.
00225     if( !formulaName.isEmpty() )
00226     {
00227         functions->setCurrentItem( functions->index( functions->findItem( formulaName ) ) );
00228         slotDoubleClicked( functions->findItem( formulaName ) );
00229     }
00230     else
00231     {
00232     // Set keyboard focus to allow selection of a formula.
00233         searchFunct->setFocus();
00234     }
00235 
00236     // Add auto completion.
00237     searchFunct->setCompletionMode( KGlobalSettings::CompletionAuto );
00238     searchFunct->setCompletionObject( &listFunct, true );
00239 
00240     if( functions->currentItem() == -1 )
00241         selectFunction->setEnabled( false );
00242 
00243     connect( searchFunct, SIGNAL( textChanged( const QString & ) ),
00244          this, SLOT( slotSearchText(const QString &) ) );
00245     connect( searchFunct, SIGNAL( returnPressed() ),
00246          this, SLOT( slotPressReturn() ) );
00247 }
00248 
00249 FormulaDialog::~FormulaDialog()
00250 {
00251     kdDebug(36001)<<"FormulaDialog::~FormulaDialog() \n";
00252 }
00253 
00254 void FormulaDialog::slotPressReturn()
00255 {
00256     //laurent 2001-07-07 desactivate this code
00257     //because kspread crash.
00258     //TODO fix it
00259     /*
00260     if( !functions->currentText().isEmpty() )
00261         slotDoubleClicked( functions->findItem( functions->currentText() ) );
00262     */
00263 }
00264 
00265 void FormulaDialog::slotSearchText(const QString &_text)
00266 {
00267     QString result = listFunct.makeCompletion( _text.upper() );
00268     if( !result.isNull() )
00269         functions->setCurrentItem( functions->index( functions->findItem( result ) ) );
00270 }
00271 
00272 bool FormulaDialog::eventFilter( QObject* obj, QEvent* ev )
00273 {
00274     if ( obj == firstElement && ev->type() == QEvent::FocusIn )
00275         m_focus = firstElement;
00276     else if ( obj == secondElement && ev->type() == QEvent::FocusIn )
00277         m_focus = secondElement;
00278     else if ( obj == thirdElement && ev->type() == QEvent::FocusIn )
00279         m_focus = thirdElement;
00280     else if ( obj == fourElement && ev->type() == QEvent::FocusIn )
00281         m_focus = fourElement;
00282     else if ( obj == fiveElement && ev->type() == QEvent::FocusIn )
00283         m_focus = fiveElement;
00284     else
00285         return FALSE;
00286 
00287     if ( m_focus )
00288         m_pView->canvasWidget()->startChoose();
00289 
00290     return FALSE;
00291 }
00292 
00293 void FormulaDialog::slotOk()
00294 {
00295     m_pView->doc()->emitBeginOperation( false );
00296 
00297     m_pView->canvasWidget()->endChoose();
00298     // Switch back to the old sheet
00299     if( m_pView->activeSheet()->sheetName() !=  m_sheetName )
00300     {
00301         Sheet *sheet=m_pView->doc()->map()->findSheet(m_sheetName);
00302         if( sheet)
00303         m_pView->setActiveSheet(sheet);
00304     }
00305 
00306     // Revert the marker to its original position
00307     m_pView->selectionInfo()->initialize( QPoint( m_column, m_row ) );
00308 
00309     // If there is still an editor then set the text.
00310     // Usually the editor is always in place.
00311     if( m_pView->canvasWidget()->editor() != 0 )
00312     {
00313         Q_ASSERT( m_pView->canvasWidget()->editor() );
00314         QString tmp = result->text();
00315         if( tmp.at(0) != '=')
00316         tmp = "=" + tmp;
00317         int pos = m_pView->canvasWidget()->editor()->cursorPosition()+ tmp.length();
00318         m_pView->canvasWidget()->editor()->setText( tmp );
00319         m_pView->canvasWidget()->editor()->setFocus();
00320         m_pView->canvasWidget()->editor()->setCursorPosition( pos );
00321     }
00322 
00323     m_pView->slotUpdateView( m_pView->activeSheet() );
00324     accept();
00325     //  delete this;
00326 }
00327 
00328 void FormulaDialog::slotClose()
00329 {
00330     m_pView->doc()->emitBeginOperation( false );
00331 
00332     m_pView->canvasWidget()->endChoose();
00333 
00334     // Switch back to the old sheet
00335     if(m_pView->activeSheet()->sheetName() !=  m_sheetName )
00336     {
00337         Sheet *sheet=m_pView->doc()->map()->findSheet(m_sheetName);
00338         if( !sheet )
00339         return;
00340     m_pView->setActiveSheet(sheet);
00341     }
00342 
00343 
00344     // Revert the marker to its original position
00345     m_pView->selectionInfo()->initialize( QPoint( m_column, m_row ) );
00346 
00347     // If there is still an editor then reset the text.
00348     // Usually the editor is always in place.
00349     if( m_pView->canvasWidget()->editor() != 0 )
00350     {
00351         Q_ASSERT( m_pView->canvasWidget()->editor() );
00352         m_pView->canvasWidget()->editor()->setText( m_oldText );
00353         m_pView->canvasWidget()->editor()->setFocus();
00354     }
00355 
00356     m_pView->slotUpdateView( m_pView->activeSheet() );
00357     reject();
00358     //laurent 2002-01-03 comment this line otherwise kspread crash
00359     //but dialog box is not deleted => not good
00360     //delete this;
00361 }
00362 
00363 void FormulaDialog::slotSelectButton()
00364 {
00365     if( functions->currentItem() != -1 )
00366     {
00367         slotDoubleClicked(functions->findItem(functions->text(functions->currentItem())));
00368     }
00369 }
00370 
00371 void FormulaDialog::slotChangeText( const QString& )
00372 {
00373     // Test the lock
00374     if( !refresh_result )
00375     return;
00376 
00377     if ( m_focus == 0 )
00378     return;
00379 
00380     QString tmp = m_leftText+m_funcName+"(";
00381     tmp += createFormula();
00382     tmp = tmp+ ")" + m_rightText;
00383 
00384     result->setText( tmp );
00385 }
00386 
00387 QString FormulaDialog::createFormula()
00388 {
00389     QString tmp( "" );
00390 
00391     if ( !m_desc )
00392     return QString::null;
00393 
00394     bool first = TRUE;
00395 
00396     int count = m_desc->params();
00397 
00398     if(!firstElement->text().isEmpty() && count >= 1 )
00399     {
00400         tmp=tmp+createParameter(firstElement->text(), 0 );
00401     first = FALSE;
00402     }
00403 
00404     if(!secondElement->text().isEmpty() && count >= 2 )
00405     {
00406     first = FALSE;
00407     if ( !first )
00408         tmp=tmp+";"+createParameter(secondElement->text(), 1 );
00409     else
00410         tmp=tmp+createParameter(secondElement->text(), 1 );
00411     }
00412     if(!thirdElement->text().isEmpty() && count >= 3 )
00413     {
00414     first = FALSE;
00415     if ( !first )
00416         tmp=tmp+";"+createParameter(thirdElement->text(), 2 );
00417         else
00418         tmp=tmp+createParameter(thirdElement->text(), 2 );
00419     }
00420     if(!fourElement->text().isEmpty() && count >= 4 )
00421     {
00422     first = FALSE;
00423     if ( !first )
00424         tmp=tmp+";"+createParameter(fourElement->text(), 3 );
00425         else
00426         tmp=tmp+createParameter(fourElement->text(), 3 );
00427     }
00428     if(!fiveElement->text().isEmpty() && count >= 5 )
00429     {
00430     first = FALSE;
00431     if ( !first )
00432         tmp=tmp+";"+createParameter(fiveElement->text(), 4 );
00433         else
00434         tmp=tmp+createParameter(fiveElement->text(), 4 );
00435     }
00436 
00437     return(tmp);
00438 }
00439 
00440 QString FormulaDialog::createParameter( const QString& _text, int param )
00441 {
00442     if ( _text.isEmpty() )
00443     return QString( "" );
00444 
00445     if ( !m_desc )
00446     return QString( "" );
00447 
00448     QString text;
00449 
00450     ParameterType elementType = m_desc->param( param ).type();
00451 
00452     switch( elementType )
00453     {
00454     case KSpread_Any:
00455     {
00456         bool isNumber;
00457         double tmp = m_pView->doc()->locale()->readNumber( _text, &isNumber );
00458         Q_UNUSED( tmp );
00459 
00460         //In case of number or boolean return _text, else return value as KSpread_String
00461         if ( isNumber || _text.upper() =="FALSE" || _text.upper() == "TRUE" )
00462             return _text;
00463     }
00464         // fall through
00465     case KSpread_String:
00466     {
00467         // Does the text start with quotes?
00468         if ( _text[0] == '"' )
00469         {
00470             text = "\\"; // changed: was "\""
00471 
00472         // Escape quotes
00473         QString tmp = _text;
00474         int pos;
00475         int start = 1;
00476         while( ( pos = tmp.find( '"', start ) ) != -1 )
00477         {
00478           if (tmp[pos - 1] != '\\')
00479             tmp.replace( pos, 1, "\\\"" );
00480           else
00481             start = pos + 1;
00482         }
00483 
00484         text += tmp;
00485         text += "\"";
00486         }
00487         else
00488         {
00489         Point p = Point( _text, m_pView->doc()->map() );
00490         Range r = Range( _text, m_pView->doc()->map() );
00491 
00492         if( !p.isValid() && !r.isValid() )
00493         {
00494             text = "\"";
00495 
00496             // Escape quotes
00497             QString tmp = _text;
00498             int pos;
00499             int start = 1;
00500             while( ( pos = tmp.find( '"', start ) ) != -1 )
00501             {
00502                 if (tmp[pos - 1] != '\\')
00503               tmp.replace( pos, 1, "\\\"" );
00504             else
00505               start = pos + 1;
00506             }
00507 
00508             text += tmp;
00509             text += "\"";
00510         }
00511         else
00512             text = _text;
00513             }
00514         }
00515     return text;
00516     case KSpread_Float:
00517     return _text;
00518     case KSpread_Boolean:
00519     return _text;
00520     case KSpread_Int:
00521     return _text;
00522     }
00523 
00524     // Never reached
00525     return text;
00526 }
00527 
00528 static void showEntry( QLineEdit* edit, QLabel* label,
00529     FunctionDescription* desc, int param )
00530 {
00531     edit->show();
00532     label->setText( desc->param( param ).helpText()+":" );
00533     label->show();
00534     ParameterType elementType = desc->param( param ).type();
00535     KFloatValidator *validate=0L;
00536     switch( elementType )
00537     {
00538     case KSpread_String:
00539     case KSpread_Boolean:
00540     case KSpread_Any:
00541       edit->clearValidator ();
00542       break;
00543     case KSpread_Float:
00544         validate=new KFloatValidator (edit);
00545         validate->setAcceptLocalizedNumbers(true);
00546         edit->setValidator(validate);
00547         edit->setText( "0" );
00548       break;
00549     case KSpread_Int:
00550       edit->setValidator(new QIntValidator (edit));
00551       edit->setText( "0" );
00552       break;
00553       }
00554 
00555 }
00556 
00557 void FormulaDialog::slotDoubleClicked( QListBoxItem* item )
00558 {
00559     if ( !item )
00560     return;
00561     refresh_result = false;
00562     if ( !m_desc )
00563     {
00564     m_browser->setText( "" );
00565     return;
00566     }
00567 
00568     m_focus = 0;
00569     int old_length = result->text().length();
00570 
00571     // Dont change order of these function calls due to a bug in Qt 2.2
00572     m_browser->setText( m_desc->toQML() );
00573     m_tabwidget->setTabEnabled( m_input, TRUE );
00574     m_tabwidget->setCurrentPage( 1 );
00575 
00576     //
00577     // Show as many QLineEdits as needed.
00578     //
00579     if( m_desc->params() > 0 )
00580     {
00581         m_focus = firstElement;
00582         firstElement->setFocus();
00583 
00584     showEntry( firstElement, label1, m_desc, 0 );
00585     }
00586     else
00587     {
00588     label1->hide();
00589     firstElement->hide();
00590     }
00591 
00592     if( m_desc->params() > 1 )
00593     {
00594     showEntry( secondElement, label2, m_desc, 1 );
00595     }
00596     else
00597     {
00598     label2->hide();
00599     secondElement->hide();
00600     }
00601 
00602     if( m_desc->params() > 2 )
00603     {
00604     showEntry( thirdElement, label3, m_desc, 2 );
00605     }
00606     else
00607     {
00608     label3->hide();
00609     thirdElement->hide();
00610     }
00611 
00612     if( m_desc->params() > 3 )
00613     {
00614     showEntry( fourElement, label4, m_desc, 3 );
00615     }
00616     else
00617     {
00618     label4->hide();
00619     fourElement->hide();
00620     }
00621 
00622     if( m_desc->params() > 4 )
00623     {
00624     showEntry( fiveElement, label5, m_desc, 4 );
00625     }
00626     else
00627     {
00628     label5->hide();
00629     fiveElement->hide();
00630     }
00631 
00632     if( m_desc->params() > 5 )
00633     {
00634         kdDebug(36001) << "Error in param->nb_param" << endl;
00635     }
00636     refresh_result= true;
00637     //
00638     // Put the new function call in the result.
00639     //
00640     if( result->cursorPosition() < old_length )
00641     {
00642         m_rightText=result->text().right(old_length-result->cursorPosition());
00643         m_leftText=result->text().left(result->cursorPosition());
00644     }
00645     else
00646     {
00647         m_rightText="";
00648         m_leftText=result->text();
00649     }
00650     int pos = result->cursorPosition();
00651     result->setText( m_leftText+functions->text( functions->currentItem() ) + "()" + m_rightText);
00652 
00653     if (result->text()[0] != '=')
00654       result->setText("=" + result->text());
00655 
00656     //
00657     // Put focus somewhere is there are no QLineEdits visible
00658     //
00659     if( m_desc->params() == 0 )
00660     {
00661     label1->show();
00662     label1->setText( i18n("This function has no parameters.") );
00663 
00664         result->setFocus();
00665         result->setCursorPosition(pos+functions->text(functions->currentItem()).length()+2);
00666     }
00667     slotChangeText( "" );
00668 }
00669 
00670 void FormulaDialog::slotSelected( const QString& function )
00671 {
00672     FunctionDescription* desc =
00673         FunctionRepository::self()->functionInfo (function);
00674     if ( !desc )
00675     {
00676       m_browser->setText (i18n ("Description is not available."));
00677       return;
00678     }
00679 
00680     if( functions->currentItem() !=- 1 )
00681         selectFunction->setEnabled( TRUE );
00682 
00683     // Lock
00684     refresh_result = false;
00685 
00686     m_funcName = function;
00687     m_desc = desc;
00688 
00689     // Set the help text
00690     m_browser->setText( m_desc->toQML() );
00691     m_browser->setContentsPos( 0, 0 );
00692 
00693     m_focus=0;
00694 
00695     m_tabwidget->setCurrentPage( 0 );
00696     m_tabwidget->setTabEnabled( m_input, FALSE );
00697 
00698     // Unlock
00699     refresh_result=true;
00700 }
00701 
00702 // from hyperlink in the "Related Function"
00703 void FormulaDialog::slotShowFunction( const QString& function )
00704 {
00705     FunctionDescription* desc =
00706        FunctionRepository::self()->functionInfo( function );
00707     if ( !desc ) return;
00708 
00709     // select the category
00710     QString category = desc->group();
00711     typeFunction->setCurrentText( category );
00712     slotActivated( category );
00713 
00714     // select the function
00715     QListBoxItem* item = functions->findItem( function,
00716       Qt::ExactMatch | Qt::CaseSensitive );
00717     if( item ) functions->setCurrentItem( item );
00718 
00719     slotSelected( function );
00720 }
00721 
00722 void FormulaDialog::slotSelectionChanged()
00723 {
00724     if ( !m_focus )
00725         return;
00726 
00727     if (m_pView->choice()->isValid())
00728     {
00729       QString area = m_pView->choice()->name();
00730       m_focus->setText( area );
00731     }
00732 }
00733 
00734 void FormulaDialog::slotActivated( const QString& category )
00735 {
00736     QStringList lst;
00737     if ( category == i18n("All") )
00738       lst = FunctionRepository::self()->functionNames();
00739     else
00740       lst = FunctionRepository::self()->functionNames( category );
00741 
00742     kdDebug(36001)<<"category: "<<category<<" ("<<lst.count()<<"functions)" << endl;
00743 
00744     functions->clear();
00745     functions->insertStringList( lst );
00746 
00747     QStringList upperList;
00748     for ( QStringList::Iterator it = lst.begin(); it != lst.end();++it )
00749       upperList.append((*it).upper());
00750 
00751     listFunct.setItems( upperList );
00752 
00753     // Go to the first function in the list.
00754     functions->setCurrentItem(0);
00755     slotSelected( functions->text(0) );
00756 }
00757 
00758 void FormulaDialog::closeEvent ( QCloseEvent * e )
00759 {
00760   e->accept();
00761 }
00762 
00763 #include "kspread_dlg_formula.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys