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