lib Library API Documentation

kformuladocument.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
00003                   Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include <qptrlist.h>
00022 #include <qstringlist.h>
00023 
00024 #include <kdebug.h>
00025 #include <kglobal.h>
00026 #include <kiconloader.h>
00027 #include <klocale.h>
00028 #include <kstandarddirs.h>
00029 
00030 #include <koDocument.h>
00031 
00032 #include "contextstyle.h"
00033 #include "creationstrategy.h"
00034 #include "kformulacontainer.h"
00035 #include "kformuladocument.h"
00036 #include "sequenceelement.h"
00037 #include "symboltable.h"
00038 #include "symbolaction.h"
00039 
00040 KFORMULA_NAMESPACE_BEGIN
00041 
00042 
00043 static const int CURRENT_SYNTAX_VERSION = 1;
00044 // Make sure an appropriate DTD is available in www/koffice/DTD if changing this value
00045 static const char * CURRENT_DTD_VERSION = "1.3";
00046 
00050 static OrdinaryCreationStrategy creationStrategy;
00051 
00052 
00053 int FormulaList::compareItems( QPtrCollection::Item a, QPtrCollection::Item b )
00054 {
00055     double ya = static_cast<Container*>( a )->getDocumentY();
00056     double yb = static_cast<Container*>( b )->getDocumentY();
00057     if ( fabs( ya-yb ) < 1e-4 ) {
00058         double xa = static_cast<Container*>( a )->getDocumentX();
00059         double xb = static_cast<Container*>( b )->getDocumentX();
00060         if ( xa < xb ) return -1;
00061         if ( xa > xb ) return 1;
00062         return 0;
00063     }
00064     if ( ya < yb ) return -1;
00065     return 1;
00066 }
00067 
00068 
00069 Document::Document( QObject *parent, const char *name,
00070                     const QStringList &/*args*/ )
00071     : QObject( parent, name ), m_wrapper( 0 ), m_formula( 0 )
00072 {
00073     m_contextStyle = new ContextStyle;
00074     SequenceElement::setCreationStrategy( &creationStrategy );
00075     formulae.setAutoDelete( false );
00076 }
00077 
00078 
00079 Document::~Document()
00080 {
00081     // Destroy remaining formulae. We do it backward because
00082     // the formulae remove themselves from this document upon
00083     // destruction.
00084     int count = formulae.count();
00085     for ( int i=count-1; i>=0; --i ) {
00086         delete formulae.at( i );
00087     }
00088     delete m_contextStyle;
00089 }
00090 
00091 
00092 bool Document::hasFormula()
00093 {
00094     return ( m_formula != 0 ) && ( m_formula->activeCursor() != 0 );
00095 }
00096 
00097 
00098 Container* Document::createFormula( int pos, bool registerMe )
00099 {
00100     Container* formula = new Container( this, pos, registerMe );
00101     formula->initialize();
00102     return formula;
00103 }
00104 
00105 
00106 QPtrListIterator<Container> Document::formulas()
00107 {
00108     return QPtrListIterator<Container>( formulae );
00109 }
00110 
00111 
00112 int Document::formulaPos( Container* formula )
00113 {
00114     return formulae.find( formula );
00115 }
00116 
00117 
00118 Container* Document::formulaAt( uint pos )
00119 {
00120     return formulae.at( pos );
00121 }
00122 
00123 
00124 int Document::formulaCount()
00125 {
00126     return formulae.count();
00127 }
00128 
00129 
00130 bool Document::loadXML( QDomDocument doc )
00131 {
00132     //clear();
00133     QDomElement root = doc.documentElement();
00134 
00135     // backward compatibility
00136     if ( root.tagName() == "FORMULA" ) {
00137         Container* formula = newFormula( 0 );
00138         return formula->load( root );
00139     }
00140 
00141     QDomNode node = root.firstChild();
00142     if ( node.isElement() ) {
00143         QDomElement element = node.toElement();
00144         if ( element.tagName() == "FORMULASETTINGS" ) {
00145             if ( !loadDocumentPart( element ) ) {
00146                 return false;
00147             }
00148         }
00149         node = node.nextSibling();
00150     }
00151     uint number = 0;
00152     while ( !node.isNull() ) {
00153         if ( node.isElement() ) {
00154             QDomElement element = node.toElement();
00155             Container* formula = newFormula( number );
00156             if ( !formula->load( element ) ) {
00157                 return false;
00158             }
00159             number += 1;
00160         }
00161         node = node.nextSibling();
00162     }
00163     return formulae.count() > 0;
00164 }
00165 
00166 bool Document::loadDocumentPart( QDomElement /*node*/ )
00167 {
00168     return true;
00169 }
00170 
00171 QDomDocument Document::saveXML()
00172 {
00173     QDomDocument doc = createDomDocument();
00174     QDomElement root = doc.documentElement();
00175     root.appendChild( saveDocumentPart( doc ) );
00176     uint count = formulae.count();
00177     for ( uint i=0; i<count; ++i ) {
00178         formulae.at( i )->save( root );
00179     }
00180     return doc;
00181 }
00182 
00183 
00184 QDomElement Document::saveDocumentPart( QDomDocument doc )
00185 {
00186     QDomElement settings = doc.createElement( "FORMULASETTINGS" );
00187     return settings;
00188 }
00189 
00190 
00191 QDomDocument Document::createDomDocument()
00192 {
00193     return KoDocument::createDomDocument( "kformula", "KFORMULA",
00194                                           CURRENT_DTD_VERSION );
00195 }
00196 
00197 void Document::registerFormula( Container* f, int pos )
00198 {
00199     if ( ( pos > -1 ) &&
00200          ( static_cast<uint>( pos ) < formulae.count() ) ) {
00201         formulae.insert( pos, f );
00202         //emit sigInsertFormula( f, pos );
00203     }
00204     else {
00205         formulae.append( f );
00206         //emit sigInsertFormula( f, formulae.count()-1 );
00207     }
00208 }
00209 
00210 void Document::unregisterFormula( Container* f )
00211 {
00212     if ( m_formula == f ) {
00213         m_formula = 0;
00214     }
00215     formulae.removeRef( f );
00216 }
00217 
00218 void Document::activate(Container* f)
00219 {
00220     m_formula = f;
00221 }
00222 
00223 
00224 void Document::sortFormulaList()
00225 {
00226     formulae.sort();
00227 }
00228 
00229 
00230 Container* Document::newFormula( uint number )
00231 {
00232     if ( number < formulae.count() ) {
00233         return formulae.at( number );
00234     }
00235     return createFormula();
00236 }
00237 
00238 
00239 double Document::getXResolution() const
00240 {
00241     return m_contextStyle->zoomedResolutionX();
00242 }
00243 double Document::getYResolution() const
00244 {
00245     return m_contextStyle->zoomedResolutionY();
00246 }
00247 
00248 const SymbolTable& Document::getSymbolTable() const
00249 {
00250     return m_contextStyle->symbolTable();
00251 }
00252 
00253 ContextStyle& Document::getContextStyle( bool edit )
00254 {
00255     m_contextStyle->setEdit( edit );
00256     return *m_contextStyle;
00257 }
00258 
00259 void Document::setZoomAndResolution( int zoom, int dpiX, int dpiY )
00260 {
00261     m_contextStyle->setZoomAndResolution( zoom, dpiX, dpiY );
00262 }
00263 
00264 void Document::newZoomAndResolution( bool updateViews, bool /*forPrint*/ )
00265 {
00266     if ( updateViews ) {
00267         recalc();
00268     }
00269 }
00270 
00271 void Document::setZoomAndResolution( int zoom,
00272                                      double zoomX, double zoomY,
00273                                      bool updateViews, bool forPrint )
00274 {
00275     if ( getContextStyle( !forPrint ).setZoomAndResolution( zoom, zoomX, zoomY, updateViews, forPrint ) && updateViews ) {
00276         recalc();
00277     }
00278 }
00279 
00280 
00281 SymbolType Document::leftBracketChar()
00282 {
00283     return m_wrapper->leftBracketChar();
00284 }
00285 
00286 SymbolType Document::rightBracketChar()
00287 {
00288     return m_wrapper->rightBracketChar();
00289 }
00290 
00291 
00292 void Document::setEnabled( bool enabled )
00293 {
00294     //kdDebug( DEBUGID ) << "Document::setEnabled " << enabled << endl;
00295     m_wrapper->getAddNegThinSpaceAction()->setEnabled( enabled );
00296     m_wrapper->getMakeGreekAction()->setEnabled( enabled );
00297     m_wrapper->getAddGenericUpperAction()->setEnabled( enabled );
00298     m_wrapper->getAddGenericLowerAction()->setEnabled( enabled );
00299     m_wrapper->getAddOverlineAction()->setEnabled( enabled );
00300     m_wrapper->getAddUnderlineAction()->setEnabled( enabled );
00301     m_wrapper->getRemoveEnclosingAction()->setEnabled( enabled );
00302     m_wrapper->getInsertSymbolAction()->setEnabled( enabled );
00303     m_wrapper->getAddThinSpaceAction()->setEnabled( enabled );
00304     m_wrapper->getAddMediumSpaceAction()->setEnabled( enabled );
00305     m_wrapper->getAddThickSpaceAction()->setEnabled( enabled );
00306     m_wrapper->getAddQuadSpaceAction()->setEnabled( enabled );
00307     m_wrapper->getAddBracketAction()->setEnabled( enabled );
00308     m_wrapper->getAddSBracketAction()->setEnabled( enabled );
00309     m_wrapper->getAddCBracketAction()->setEnabled( enabled );
00310     m_wrapper->getAddAbsAction()->setEnabled(enabled);
00311     m_wrapper->getAddFractionAction()->setEnabled( enabled );
00312     m_wrapper->getAddRootAction()->setEnabled( enabled );
00313     m_wrapper->getAddSumAction()->setEnabled( enabled );
00314     m_wrapper->getAddProductAction()->setEnabled( enabled );
00315     m_wrapper->getAddIntegralAction()->setEnabled( enabled );
00316     m_wrapper->getAddMatrixAction()->setEnabled( enabled );
00317     m_wrapper->getAddOneByTwoMatrixAction()->setEnabled( enabled );
00318     m_wrapper->getAddUpperLeftAction()->setEnabled( enabled );
00319     m_wrapper->getAddLowerLeftAction()->setEnabled( enabled );
00320     m_wrapper->getAddUpperRightAction()->setEnabled( enabled );
00321     m_wrapper->getAddLowerRightAction()->setEnabled( enabled );
00322     m_wrapper->getAppendColumnAction()->setEnabled( enabled );
00323     m_wrapper->getInsertColumnAction()->setEnabled( enabled );
00324     m_wrapper->getRemoveColumnAction()->setEnabled( enabled );
00325     m_wrapper->getAppendRowAction()->setEnabled( enabled );
00326     m_wrapper->getInsertRowAction()->setEnabled( enabled );
00327     m_wrapper->getRemoveRowAction()->setEnabled( enabled );
00328 
00329     if ( enabled ) {
00330         m_wrapper->getAddGenericUpperAction()->
00331             setShortcut( KShortcut( CTRL + Key_U ) );
00332         m_wrapper->getAddGenericLowerAction()->
00333             setShortcut( KShortcut( CTRL + Key_L ) );
00334         m_wrapper->getRemoveEnclosingAction()->
00335             setShortcut( KShortcut( CTRL + Key_R ) );
00336         m_wrapper->getMakeGreekAction()->
00337             setShortcut( KShortcut( CTRL + Key_G ) );
00338         m_wrapper->getInsertSymbolAction()->
00339             setShortcut( KShortcut( CTRL + Key_I ) );
00340     }
00341     else {
00342         m_wrapper->getAddGenericUpperAction()->setShortcut( KShortcut() );
00343         m_wrapper->getAddGenericLowerAction()->setShortcut( KShortcut() );
00344         m_wrapper->getRemoveEnclosingAction()->setShortcut( KShortcut() );
00345         m_wrapper->getMakeGreekAction()->setShortcut( KShortcut() );
00346         m_wrapper->getInsertSymbolAction()->setShortcut( KShortcut() );
00347     }
00348 }
00349 
00350 
00351 KoCommandHistory* Document::getHistory() const
00352 {
00353     return m_wrapper->getHistory();
00354 }
00355 
00356 
00357 void Document::recalc()
00358 {
00359     for ( Container* f = formulae.first();
00360           f != 0;
00361           f=formulae.next() ) {
00362         f->recalc();
00363     }
00364 }
00365 
00366 
00367 void Document::updateConfig()
00368 {
00369     m_wrapper->updateConfig();
00370     recalc();
00371 }
00372 
00373 
00374 void Document::introduceWrapper( DocumentWrapper* wrapper )
00375 {
00376     m_wrapper = wrapper;
00377     m_contextStyle->readConfig( wrapper->config() );
00378     m_contextStyle->init();
00379 }
00380 
00381 
00383 
00384 DocumentWrapper::DocumentWrapper( KConfig* config,
00385                                   KActionCollection* collection,
00386                                   KoCommandHistory* history )
00387     : m_document( 0 ),
00388       m_leftBracketChar( LeftRoundBracket ),
00389       m_rightBracketChar( RightRoundBracket ),
00390       m_config( config ),
00391       m_hasActions( collection != 0 )
00392 {
00393     if ( m_hasActions ) {
00394         createActions( collection );
00395     }
00396     setCommandStack( history );
00397 }
00398 
00399 
00400 DocumentWrapper::~DocumentWrapper()
00401 {
00402     delete m_document;
00403     if ( m_ownHistory ) {
00404         delete m_history;
00405     }
00406 }
00407 
00408 
00409 void DocumentWrapper::document( Document* document )
00410 {
00411     m_document = document;
00412     m_document->introduceWrapper( this );
00413     initSymbolNamesAction();
00414 }
00415 
00416 
00417 void DocumentWrapper::setCommandStack( KoCommandHistory* history )
00418 {
00419     if ( history == 0 ) {
00420         m_history = new KoCommandHistory;
00421         m_ownHistory = true;
00422     }
00423     else {
00424         m_history = history;
00425         m_ownHistory = false;
00426     }
00427 }
00428 
00429 
00430 void DocumentWrapper::createActions( KActionCollection* collection )
00431 {
00432     KGlobal::dirs()->addResourceType( "toolbar",
00433                                       KStandardDirs::kde_default("data") +
00434                                       "kformula/pics/" );
00435 
00436     m_addNegThinSpaceAction = new KAction( i18n( "Add Negative Thin Space" ),
00437                                     0,
00438                                     this, SLOT( addNegThinSpace() ),
00439                                     collection, "formula_addnegthinspace") ;
00440     m_addThinSpaceAction = new KAction( i18n( "Add Thin Space" ),
00441                                     0,
00442                                     this, SLOT( addThinSpace() ),
00443                                     collection, "formula_addthinspace") ;
00444     m_addMediumSpaceAction = new KAction( i18n( "Add Medium Space" ),
00445                                     0,
00446                                     this, SLOT( addMediumSpace() ),
00447                                     collection, "formula_addmediumspace" );
00448     m_addThickSpaceAction = new KAction( i18n( "Add Thick Space" ),
00449                                     0,
00450                                     this, SLOT( addThickSpace() ),
00451                                     collection, "formula_addthickspace" );
00452     m_addQuadSpaceAction = new KAction( i18n( "Add Quad Space" ),
00453                                     0,
00454                                     this, SLOT( addQuadSpace() ),
00455                                     collection, "formula_addquadspace" );
00456 
00457     m_addIntegralAction = new KAction(i18n("Add Integral"),
00458                                     "int",
00459                                     0,
00460                                     this, SLOT(addIntegral()),
00461                                     collection, "formula_addintegral");
00462     m_addSumAction      = new KAction(i18n("Add Sum"),
00463                                     "sum",
00464                                     0,
00465                                     this, SLOT(addSum()),
00466                                     collection, "formula_addsum");
00467     m_addProductAction  = new KAction(i18n("Add Product"),
00468                                     "prod",
00469                                     0,
00470                                     this, SLOT(addProduct()),
00471                                     collection, "formula_addproduct");
00472     m_addRootAction     = new KAction(i18n("Add Root"),
00473                                     "sqrt",
00474                                     0,
00475                                     this, SLOT(addRoot()),
00476                                     collection, "formula_addroot");
00477     m_addFractionAction = new KAction(i18n("Add Fraction"),
00478                                     "frac",
00479                                     0,
00480                                     this, SLOT(addFraction()),
00481                                     collection, "formula_addfrac");
00482     m_addBracketAction  = new KAction(i18n("Add Bracket"),
00483                                     "paren",
00484                                     0,
00485                                     this, SLOT(addDefaultBracket()),
00486                                     collection,"formula_addbra");
00487     m_addSBracketAction = new KAction(i18n("Add Square Bracket"),
00488                                     "brackets",
00489                                     0,
00490                                     this, SLOT(addSquareBracket()),
00491                                     collection,"formula_addsqrbra");
00492     m_addCBracketAction = new KAction(i18n("Add Curly Bracket"),
00493                                     "math_brace",
00494                                     0,
00495                                     this, SLOT(addCurlyBracket()),
00496                                     collection,"formula_addcurbra");
00497     m_addAbsAction      = new KAction(i18n("Add Abs"),
00498                                     "abs",
00499                                     0,
00500                                     this, SLOT(addLineBracket()),
00501                                     collection,"formula_addabsbra");
00502 
00503     m_addMatrixAction   = new KAction(i18n("Add Matrix..."),
00504                                     "matrix",
00505                                     0,
00506                                     this, SLOT(addMatrix()),
00507                                     collection, "formula_addmatrix");
00508 
00509     m_addOneByTwoMatrixAction   = new KAction(i18n("Add 1x2 Matrix"),
00510                                     "onetwomatrix",
00511                                     0,
00512                                     this, SLOT(addOneByTwoMatrix()),
00513                                     collection, "formula_add_one_by_two_matrix");
00514 
00515 
00516     m_addUpperLeftAction  = new KAction(i18n("Add Upper Left Index"),
00517                                       "lsup",
00518                                       0,
00519                                       this, SLOT(addUpperLeftIndex()),
00520                                       collection, "formula_addupperleft");
00521     m_addLowerLeftAction  = new KAction(i18n("Add Lower Left Index"),
00522                                       "lsub",
00523                                       0,
00524                                       this, SLOT(addLowerLeftIndex()),
00525                                       collection, "formula_addlowerleft");
00526     m_addUpperRightAction = new KAction(i18n("Add Upper Right Index"),
00527                                       "rsup",
00528                                       0,
00529                                       this, SLOT(addUpperRightIndex()),
00530                                       collection, "formula_addupperright");
00531     m_addLowerRightAction = new KAction(i18n("Add Lower Right Index"),
00532                                       "rsub",
00533                                       0,
00534                                       this, SLOT(addLowerRightIndex()),
00535                                       collection, "formula_addlowerright");
00536 
00537     m_addGenericUpperAction = new KAction(i18n("Add Upper Index"),
00538                                               /*CTRL + Key_U*/0,
00539                                       this, SLOT(addGenericUpperIndex()),
00540                                       collection, "formula_addupperindex");
00541     m_addGenericLowerAction = new KAction(i18n("Add Lower Index"),
00542                                       0,
00543                                       this, SLOT(addGenericLowerIndex()),
00544                                       collection, "formula_addlowerindex");
00545 
00546     m_addOverlineAction = new KAction(i18n("Add Overline"),
00547                                           "over",
00548                                           0,
00549                                           this, SLOT(addOverline()),
00550                                           collection, "formula_addoverline");
00551     m_addUnderlineAction = new KAction(i18n("Add Underline"),
00552                                            "under",
00553                                            0,
00554                                            this, SLOT(addUnderline()),
00555                                            collection, "formula_addunderline");
00556 
00557     m_addMultilineAction = new KAction(i18n("Add Multiline"),
00558                                            "multiline",
00559                                            0,
00560                                            this, SLOT(addMultiline()),
00561                                            collection, "formula_addmultiline");
00562 
00563     m_removeEnclosingAction = new KAction(i18n("Remove Enclosing Element"),
00564                                         0,
00565                                         this, SLOT(removeEnclosing()),
00566                                         collection, "formula_removeenclosing");
00567 
00568     m_makeGreekAction = new KAction(i18n("Convert to Greek"),
00569                                   0,
00570                                   this, SLOT(makeGreek()),
00571                                   collection, "formula_makegreek");
00572 
00573     m_appendColumnAction = new KAction( i18n( "Append Column" ),
00574                                             "inscol",
00575                                             0,
00576                                             this, SLOT( appendColumn() ),
00577                                             collection, "formula_appendcolumn" );
00578     m_insertColumnAction = new KAction( i18n( "Insert Column" ),
00579                                             "inscol",
00580                                             0,
00581                                             this, SLOT( insertColumn() ),
00582                                             collection, "formula_insertcolumn" );
00583     m_removeColumnAction = new KAction( i18n( "Remove Column" ),
00584                                             "remcol",
00585                                             0,
00586                                             this, SLOT( removeColumn() ),
00587                                             collection, "formula_removecolumn" );
00588     m_appendRowAction = new KAction( i18n( "Append Row" ),
00589                                          "insrow",
00590                                          0,
00591                                          this, SLOT( appendRow() ),
00592                                          collection, "formula_appendrow" );
00593     m_insertRowAction = new KAction( i18n( "Insert Row" ),
00594                                          "insrow",
00595                                          0,
00596                                          this, SLOT( insertRow() ),
00597                                          collection, "formula_insertrow" );
00598     m_removeRowAction = new KAction( i18n( "Remove Row" ),
00599                                          "remrow",
00600                                          0,
00601                                          this, SLOT( removeRow() ),
00602                                          collection, "formula_removerow" );
00603 
00604     m_syntaxHighlightingAction = new KToggleAction(i18n("Syntax Highlighting"),
00605                                                  0,
00606                                                  this, SLOT(toggleSyntaxHighlighting()),
00607                                                  collection, "formula_syntaxhighlighting");
00608     //m_syntaxHighlightingAction->setChecked( m_contextStyle->syntaxHighlighting() );
00609 
00610     m_formatBoldAction = new KToggleAction( i18n( "&Bold" ), "text_bold",
00611                                                 0, //CTRL + Key_B,
00612                                                 this, SLOT( textBold() ),
00613                                                 collection, "formula_format_bold" );
00614     m_formatItalicAction = new KToggleAction( i18n( "&Italic" ), "text_italic",
00615                                                   0, //CTRL + Key_I,
00616                                                   this, SLOT( textItalic() ),
00617                                                   collection, "formula_format_italic" );
00618     m_formatBoldAction->setEnabled( false );
00619     m_formatItalicAction->setEnabled( false );
00620 
00621     QStringList delimiter;
00622     delimiter.append(QString("("));
00623     delimiter.append(QString("["));
00624     delimiter.append(QString("{"));
00625     delimiter.append(QString("<"));
00626     delimiter.append(QString("/"));
00627     delimiter.append(QString("\\"));
00628     delimiter.append(QString("|"));
00629     delimiter.append(QString(" "));
00630     delimiter.append(QString(")"));
00631     delimiter.append(QString("]"));
00632     delimiter.append(QString("}"));
00633     delimiter.append(QString(">"));
00634     m_leftBracket = new KSelectAction(i18n("Left Delimiter"),
00635                                     0, this, SLOT(delimiterLeft()),
00636                                     collection, "formula_typeleft");
00637     m_leftBracket->setItems(delimiter);
00638     //leftBracket->setCurrentItem(0);
00639 
00640     delimiter.clear();
00641     delimiter.append(QString(")"));
00642     delimiter.append(QString("]"));
00643     delimiter.append(QString("}"));
00644     delimiter.append(QString(">"));
00645     delimiter.append(QString("/"));
00646     delimiter.append(QString("\\"));
00647     delimiter.append(QString("|"));
00648     delimiter.append(QString(" "));
00649     delimiter.append(QString("("));
00650     delimiter.append(QString("["));
00651     delimiter.append(QString("{"));
00652     delimiter.append(QString("<"));
00653     m_rightBracket = new KSelectAction(i18n("Right Delimiter"),
00654                                      0, this, SLOT(delimiterRight()),
00655                                      collection, "formula_typeright");
00656     m_rightBracket->setItems(delimiter);
00657     //rightBracket->setCurrentItem(0);
00658 
00659     m_insertSymbolAction = new KAction(i18n("Insert Symbol"),
00660                                            "key_enter",
00661                                            /*CTRL + Key_I*/0,
00662                                            this, SLOT(insertSymbol()),
00663                                            collection, "formula_insertsymbol");
00664     m_symbolNamesAction = new SymbolAction(i18n("Symbol Names"),
00665                                                0, this, SLOT(symbolNames()),
00666                                                collection, "formula_symbolnames");
00667 
00668     QStringList ff;
00669     ff.append( i18n( "Normal" ) );
00670     ff.append( i18n( "Script" ) );
00671     ff.append( i18n( "Fraktur" ) );
00672     ff.append( i18n( "Double Struck" ) );
00673     m_fontFamily = new KSelectAction(i18n("Font Family"),
00674                                          0, this, SLOT(fontFamily()),
00675                                          collection, "formula_fontfamily");
00676     m_fontFamily->setItems( ff );
00677     m_fontFamily->setEnabled( false );
00678 }
00679 
00680 
00681 void DocumentWrapper::paste()
00682 {
00683     if (hasFormula()) {
00684         formula()->paste();
00685     }
00686 }
00687 
00688 void DocumentWrapper::copy()
00689 {
00690     if (hasFormula()) {
00691         formula()->copy();
00692     }
00693 }
00694 
00695 void DocumentWrapper::cut()
00696 {
00697     if (hasFormula()) {
00698         formula()->cut();
00699     }
00700 }
00701 
00702 void DocumentWrapper::undo()
00703 {
00704     m_history->undo();
00705 }
00706 
00707 void DocumentWrapper::redo()
00708 {
00709     m_history->redo();
00710 }
00711 
00712 void DocumentWrapper::addNegThinSpace()
00713 {
00714     if (hasFormula()) {
00715         SpaceRequest r( NEGTHIN );
00716         formula()->performRequest( &r );
00717     }
00718 }
00719 void DocumentWrapper::addThinSpace()
00720 {
00721     if (hasFormula()) {
00722         SpaceRequest r( THIN );
00723         formula()->performRequest( &r );
00724     }
00725 }
00726 void DocumentWrapper::addMediumSpace()
00727 {
00728     if (hasFormula()) {
00729         SpaceRequest r( MEDIUM );
00730         formula()->performRequest( &r );
00731     }
00732 }
00733 void DocumentWrapper::addThickSpace()
00734 {
00735     if (hasFormula()) {
00736         SpaceRequest r( THICK );
00737         formula()->performRequest( &r );
00738     }
00739 }
00740 void DocumentWrapper::addQuadSpace()
00741 {
00742     if (hasFormula()) {
00743         SpaceRequest r( QUAD );
00744         formula()->performRequest( &r );
00745     }
00746 }
00747 
00748 void DocumentWrapper::addDefaultBracket()
00749 {
00750     if (hasFormula()) {
00751         BracketRequest r( m_leftBracketChar, m_rightBracketChar );
00752         formula()->performRequest( &r );
00753     }
00754 }
00755 
00756 void DocumentWrapper::addBracket( SymbolType left, SymbolType right )
00757 {
00758     if (hasFormula()) {
00759         BracketRequest r( left, right );
00760         formula()->performRequest( &r );
00761     }
00762 }
00763 
00764 void DocumentWrapper::addParenthesis()
00765 {
00766     if (hasFormula()) {
00767         BracketRequest r( LeftRoundBracket, RightRoundBracket );
00768         formula()->performRequest( &r );
00769     }
00770 }
00771 
00772 void DocumentWrapper::addSquareBracket()
00773 {
00774     if (hasFormula()) {
00775         BracketRequest r( LeftSquareBracket, RightSquareBracket );
00776         formula()->performRequest( &r );
00777     }
00778 }
00779 
00780 void DocumentWrapper::addCurlyBracket()
00781 {
00782     if (hasFormula()) {
00783         BracketRequest r( LeftCurlyBracket, RightCurlyBracket );
00784         formula()->performRequest( &r );
00785     }
00786 }
00787 
00788 void DocumentWrapper::addLineBracket()
00789 {
00790     if (hasFormula()) {
00791         BracketRequest r( LeftLineBracket, RightLineBracket );
00792         formula()->performRequest( &r );
00793     }
00794 }
00795 
00796 void DocumentWrapper::addFraction()
00797 {
00798     if (hasFormula()) {
00799         Request r( req_addFraction );
00800         formula()->performRequest( &r );
00801     }
00802 }
00803 
00804 void DocumentWrapper::addRoot()
00805 {
00806     if (hasFormula()) {
00807         Request r( req_addRoot );
00808         formula()->performRequest( &r );
00809     }
00810 }
00811 
00812 void DocumentWrapper::addIntegral()
00813 {
00814     if (hasFormula()) {
00815         SymbolRequest r( Integral );
00816         formula()->performRequest( &r );
00817     }
00818 }
00819 
00820 void DocumentWrapper::addProduct()
00821 {
00822     if (hasFormula()) {
00823         SymbolRequest r( Product );
00824         formula()->performRequest( &r );
00825     }
00826 }
00827 
00828 void DocumentWrapper::addSum()
00829 {
00830     if (hasFormula()) {
00831         SymbolRequest r( Sum );
00832         formula()->performRequest( &r );
00833     }
00834 }
00835 
00836 void DocumentWrapper::addMatrix( uint rows, uint columns )
00837 {
00838     if (hasFormula()) {
00839         MatrixRequest r( rows, columns );
00840         formula()->performRequest( &r );
00841     }
00842 }
00843 
00844 void DocumentWrapper::addOneByTwoMatrix()
00845 {
00846     if (hasFormula()) {
00847         Request r( req_addOneByTwoMatrix );
00848         formula()->performRequest( &r );
00849     }
00850 }
00851 
00852 void DocumentWrapper::addNameSequence()
00853 {
00854     if (hasFormula()) {
00855         Request r( req_addNameSequence );
00856         formula()->performRequest( &r );
00857     }
00858 }
00859 
00860 void DocumentWrapper::addLowerLeftIndex()
00861 {
00862     if (hasFormula()) {
00863         IndexRequest r( lowerLeftPos );
00864         formula()->performRequest( &r );
00865     }
00866 }
00867 
00868 void DocumentWrapper::addUpperLeftIndex()
00869 {
00870     if (hasFormula()) {
00871         IndexRequest r( upperLeftPos );
00872         formula()->performRequest( &r );
00873     }
00874 }
00875 
00876 void DocumentWrapper::addLowerRightIndex()
00877 {
00878     if (hasFormula()) {
00879         IndexRequest r( lowerRightPos );
00880         formula()->performRequest( &r );
00881     }
00882 }
00883 
00884 void DocumentWrapper::addUpperRightIndex()
00885 {
00886     if (hasFormula()) {
00887         IndexRequest r( upperRightPos );
00888         formula()->performRequest( &r );
00889     }
00890 }
00891 
00892 void DocumentWrapper::addGenericLowerIndex()
00893 {
00894     if (hasFormula()) {
00895         IndexRequest r( lowerMiddlePos );
00896         formula()->performRequest( &r );
00897     }
00898 }
00899 
00900 void DocumentWrapper::addGenericUpperIndex()
00901 {
00902     if (hasFormula()) {
00903         IndexRequest r( upperMiddlePos );
00904         formula()->performRequest( &r );
00905     }
00906 }
00907 
00908 void DocumentWrapper::addOverline()
00909 {
00910     if (hasFormula()) {
00911         Request r( req_addOverline );
00912         formula()->performRequest( &r );
00913     }
00914 }
00915 
00916 void DocumentWrapper::addUnderline()
00917 {
00918     if (hasFormula()) {
00919         Request r( req_addUnderline );
00920         formula()->performRequest( &r );
00921     }
00922 }
00923 
00924 void DocumentWrapper::addMultiline()
00925 {
00926     if (hasFormula()) {
00927         Request r( req_addMultiline );
00928         formula()->performRequest( &r );
00929     }
00930 }
00931 
00932 void DocumentWrapper::removeEnclosing()
00933 {
00934     if (hasFormula()) {
00935         DirectedRemove r( req_removeEnclosing, beforeCursor );
00936         formula()->performRequest( &r );
00937     }
00938 }
00939 
00940 void DocumentWrapper::makeGreek()
00941 {
00942     if (hasFormula()) {
00943         Request r( req_makeGreek );
00944         formula()->performRequest( &r );
00945     }
00946 }
00947 
00948 void DocumentWrapper::insertSymbol()
00949 {
00950     if ( hasFormula() &&
00951          m_document->m_contextStyle->symbolTable().contains( m_selectedName ) ) {
00952         QChar ch = m_document->m_contextStyle->symbolTable().unicode( m_selectedName );
00953         if ( ch != QChar::null ) {
00954             TextCharRequest r( ch, true );
00955             formula()->performRequest( &r );
00956         }
00957         else {
00958             TextRequest r( m_selectedName );
00959             formula()->performRequest( &r );
00960         }
00961     }
00962 }
00963 
00964 void DocumentWrapper::insertSymbol( QString name )
00965 {
00966     if ( hasFormula() ) {
00967         if ( m_document->m_contextStyle->symbolTable().contains( name ) ) {
00968             QChar ch = m_document->m_contextStyle->symbolTable().unicode( name );
00969             if ( ch != QChar::null ) {
00970                 TextCharRequest r( ch, true );
00971                 formula()->performRequest( &r );
00972                 return;
00973             }
00974         }
00975         TextRequest r( name );
00976         formula()->performRequest( &r );
00977     }
00978 }
00979 
00980 void DocumentWrapper::appendColumn()
00981 {
00982     if ( hasFormula() ) {
00983         Request r( req_appendColumn );
00984         formula()->performRequest( &r );
00985     }
00986 }
00987 
00988 void DocumentWrapper::insertColumn()
00989 {
00990     if ( hasFormula() ) {
00991         Request r( req_insertColumn );
00992         formula()->performRequest( &r );
00993     }
00994 }
00995 
00996 void DocumentWrapper::removeColumn()
00997 {
00998     if ( hasFormula() ) {
00999         Request r( req_removeColumn );
01000         formula()->performRequest( &r );
01001     }
01002 }
01003 
01004 void DocumentWrapper::appendRow()
01005 {
01006     if ( hasFormula() ) {
01007         Request r( req_appendRow );
01008         formula()->performRequest( &r );
01009     }
01010 }
01011 
01012 void DocumentWrapper::insertRow()
01013 {
01014     if ( hasFormula() ) {
01015         Request r( req_insertRow );
01016         formula()->performRequest( &r );
01017     }
01018 }
01019 
01020 void DocumentWrapper::removeRow()
01021 {
01022     if ( hasFormula() ) {
01023         Request r( req_removeRow );
01024         formula()->performRequest( &r );
01025     }
01026 }
01027 
01028 void DocumentWrapper::toggleSyntaxHighlighting()
01029 {
01030     m_document->m_contextStyle->setSyntaxHighlighting( m_syntaxHighlightingAction->isChecked() );
01031     // Only to notify all views. We don't expect to get new values.
01032     m_document->recalc();
01033 }
01034 
01035 void DocumentWrapper::textBold()
01036 {
01037     if ( hasFormula() ) {
01038         CharStyleRequest r( req_formatBold,
01039                             getFormatBoldAction()->isChecked(),
01040                             getFormatItalicAction()->isChecked() );
01041         formula()->performRequest( &r );
01042     }
01043 }
01044 
01045 void DocumentWrapper::textItalic()
01046 {
01047     if ( hasFormula() ) {
01048         CharStyleRequest r( req_formatItalic,
01049                             getFormatBoldAction()->isChecked(),
01050                             getFormatItalicAction()->isChecked() );
01051         formula()->performRequest( &r );
01052     }
01053 }
01054 
01055 void DocumentWrapper::delimiterLeft()
01056 {
01057     QString left = m_leftBracket->currentText();
01058     switch ( left.at(0).latin1() ) {
01059     case '[':
01060     case ']':
01061     case '{':
01062     case '}':
01063     case '<':
01064     case '>':
01065     case '(':
01066     case ')':
01067     case '/':
01068     case '\\':
01069         m_leftBracketChar = static_cast<SymbolType>( left.at(0).latin1() );
01070         break;
01071     case '|':
01072         m_leftBracketChar = LeftLineBracket;
01073         break;
01074     case ' ':
01075         m_leftBracketChar = EmptyBracket;
01076         break;
01077     }
01078 }
01079 
01080 void DocumentWrapper::delimiterRight()
01081 {
01082     QString right = m_rightBracket->currentText();
01083     switch ( right.at(0).latin1() ) {
01084     case '[':
01085     case ']':
01086     case '{':
01087     case '}':
01088     case '<':
01089     case '>':
01090     case '(':
01091     case ')':
01092     case '/':
01093     case '\\':
01094         m_rightBracketChar = static_cast<SymbolType>( right.at(0).latin1() );
01095         break;
01096     case '|':
01097         m_rightBracketChar = RightLineBracket;
01098         break;
01099     case ' ':
01100         m_rightBracketChar = EmptyBracket;
01101         break;
01102     }
01103 }
01104 
01105 void DocumentWrapper::symbolNames()
01106 {
01107     m_selectedName = m_symbolNamesAction->currentText();
01108 }
01109 
01110 
01111 void DocumentWrapper::fontFamily()
01112 {
01113     if ( hasFormula() ) {
01114         int i = m_fontFamily->currentItem();
01115         CharFamily cf = anyFamily;
01116         switch( i ) {
01117         case 0: cf = normalFamily; break;
01118         case 1: cf = scriptFamily; break;
01119         case 2: cf = frakturFamily; break;
01120         case 3: cf = doubleStruckFamily; break;
01121         }
01122         CharFamilyRequest r( cf );
01123         formula()->performRequest( &r );
01124     }
01125 }
01126 
01127 
01128 void DocumentWrapper::initSymbolNamesAction()
01129 {
01130     if ( m_hasActions ) {
01131         const SymbolTable& st = m_document->m_contextStyle->symbolTable();
01132 
01133         QStringList names = st.allNames();
01134         //QStringList i18nNames;
01135         QValueList<QFont> fonts;
01136         QMemArray<uchar> chars( names.count() );
01137 
01138         int i = 0;
01139         for ( QStringList::Iterator it = names.begin();
01140               it != names.end();
01141               ++it, ++i ) {
01142             QChar ch = st.unicode( *it );
01143             //i18nNames.push_back( i18n( ( *it ).latin1() ) );
01144 
01145             fonts.append( st.font( ch ) );
01146             chars[ i ] = st.character( ch );
01147         }
01148         m_symbolNamesAction->setSymbols( names, fonts, chars );
01149         m_selectedName = names[0];
01150     }
01151 }
01152 
01153 
01154 void DocumentWrapper::updateConfig()
01155 {
01156     m_syntaxHighlightingAction->
01157         setChecked( m_document->m_contextStyle->syntaxHighlighting() );
01158     initSymbolNamesAction();
01159 }
01160 
01161 
01162 KFORMULA_NAMESPACE_END
01163 
01164 using namespace KFormula;
01165 #include "kformuladocument.moc"
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Mar 20 14:25:24 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003