00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <QApplication>
00023 #include <QEvent>
00024 #include <QFile>
00025 #include <QClipboard>
00026 #include <QPainter>
00027 #include <QPixmap>
00028 #include <QString>
00029 #include <QTextStream>
00030 #include <QList>
00031 #include <QKeyEvent>
00032
00033 #include <kdebug.h>
00034 #include <klocale.h>
00035
00036 #include "KoGlobal.h"
00037 #include "BracketElement.h"
00038 #include "contextstyle.h"
00039 #include "FormulaCursor.h"
00040 #include "FormulaElement.h"
00041 #include "FractionElement.h"
00042 #include "kformulacommand.h"
00043 #include "kformulacompatibility.h"
00044 #include "FormulaContainer.h"
00045 #include "MatrixElement.h"
00046 #include "RootElement.h"
00047 #include "SequenceElement.h"
00048 #include "symboltable.h"
00049 #include "SpaceElement.h"
00050 #include "TextElement.h"
00051
00052 #include <assert.h>
00053
00054 KFORMULA_NAMESPACE_BEGIN
00055 using namespace std;
00056
00057
00058 struct Container::Container_Impl {
00059
00060 Container_Impl( )
00061 : dirty( true ), cursorMoved( false )
00062 {
00063 }
00064
00065 ~Container_Impl()
00066 {
00067 delete internCursor;
00068
00069
00070 }
00071
00075 bool dirty;
00076
00080 bool cursorMoved;
00081
00085
00086
00090 FormulaCursor* activeCursor;
00091
00095 FormulaCursor* internCursor;
00096
00100
00101 };
00102
00103
00104
00105 Container::Container( int pos, bool registerMe )
00106 {
00107
00108 m_formulaElement = 0;
00109 if ( registerMe ) {
00110 registerFormula( pos );
00111 }
00112 }
00113
00114 Container::~Container()
00115 {
00116 unregisterFormula();
00117 delete impl;
00118 impl = 0;
00119 }
00120
00121
00122 void Container::initialize()
00123 {
00124 m_formulaElement = new FormulaElement( );
00125 impl->activeCursor = impl->internCursor = createCursor();
00126 recalcLayout();
00127 }
00128
00129
00130 FormulaCursor* Container::createCursor()
00131 {
00132 return new FormulaCursor( m_formulaElement );
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00146 void Container::elementRemoval(BasicElement* child)
00147 {
00148 emit elementWillVanish(child);
00149 }
00150
00155 void Container::changed()
00156 {
00157 impl->dirty = true;
00158 }
00159
00160 void Container::cursorHasMoved( FormulaCursor* )
00161 {
00162 impl->cursorMoved = true;
00163 }
00164
00165 void Container::moveOutLeft( FormulaCursor* cursor )
00166 {
00167 emit leaveFormula( this, cursor, EXIT_LEFT );
00168 }
00169
00170 void Container::moveOutRight( FormulaCursor* cursor )
00171 {
00172 emit leaveFormula( this, cursor, EXIT_RIGHT );
00173 }
00174
00175 void Container::moveOutAbove( FormulaCursor* cursor )
00176 {
00177 emit leaveFormula( this, cursor, EXIT_ABOVE );
00178 }
00179
00180 void Container::moveOutBelow( FormulaCursor* cursor )
00181 {
00182 emit leaveFormula( this, cursor, EXIT_BELOW );
00183 }
00184
00185 void Container::tell( const QString& msg )
00186 {
00187 emit statusMsg( msg );
00188 }
00189
00190 void Container::removeFormula( FormulaCursor* cursor )
00191 {
00192 emit leaveFormula( this, cursor, REMOVE_FORMULA );
00193 }
00194
00195
00196 void Container::registerFormula( int pos )
00197 {
00198
00199 }
00200
00201 void Container::unregisterFormula()
00202 {
00203
00204 }
00205
00206
00207 void Container::baseSizeChanged( int size, bool owned )
00208 {
00209
00210
00211
00212
00213
00214
00215
00216 }
00217
00218 FormulaCursor* Container::activeCursor()
00219 {
00220 return impl->activeCursor;
00221 }
00222
00223 const FormulaCursor* Container::activeCursor() const
00224 {
00225 return impl->activeCursor;
00226 }
00227
00228
00233 void Container::setActiveCursor(FormulaCursor* cursor)
00234 {
00235
00236 if (cursor != 0) {
00237 impl->activeCursor = cursor;
00238 }
00239 else {
00240 *(impl->internCursor) = *(impl->activeCursor);
00241 impl->activeCursor = impl->internCursor;
00242 }
00243 }
00244
00245
00246 bool Container::hasValidCursor() const
00247 {
00248 return (impl->activeCursor != 0) ;
00249 }
00250
00251 void Container::testDirty()
00252 {
00253 if (impl->dirty) {
00254 recalcLayout();
00255 }
00256 }
00257
00258 void Container::recalcLayout()
00259 {
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 }
00271
00272 bool Container::isEmpty()
00273 {
00274 return m_formulaElement->childElements().isEmpty();
00275 }
00276
00277
00278 const SymbolTable& Container::getSymbolTable() const
00279 {
00280 static SymbolTable s;
00281 return s;
00282 }
00283
00284
00285 void Container::draw( QPainter& painter, const QRectF& r, const QPalette& palette, bool edit )
00286 {
00287 painter.fillRect( r, palette.base() );
00288 draw( painter, r, edit );
00289 }
00290
00291
00292 void Container::draw( QPainter& painter, const QRectF& r, bool edit )
00293 {
00294
00295
00296 }
00297
00298
00299 void Container::checkCursor()
00300 {
00301 if ( impl->cursorMoved ) {
00302 impl->cursorMoved = false;
00303 emit cursorMoved( activeCursor() );
00304 }
00305 }
00306
00307 void Container::input( QKeyEvent* event )
00308 {
00309
00310 if ( impl->activeCursor == 0 ) {
00311 return;
00312 }
00313
00314 checkCursor();
00315 }
00316
00317
00318 void Container::performRequest( Request* request )
00319 {
00320 if ( !hasValidCursor() )
00321 return;
00322
00323 checkCursor();
00324 }
00325
00326
00327 void Container::paste()
00328 {
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 }
00341
00342 void Container::paste( const QDomDocument& document, const QString& desc )
00343 {
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 }
00359
00360 void Container::copy()
00361 {
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 }
00374
00375 void Container::cut()
00376 {
00377 if (!hasValidCursor())
00378 return;
00379 FormulaCursor* cursor = activeCursor();
00380 if (cursor->hasSelection()) {
00381 copy();
00382 DirectedRemove r( req_remove, beforeCursor );
00383 performRequest( &r );
00384 }
00385 }
00386
00387 void Container::emitErrorMsg( const QString& msg )
00388 {
00389 emit errorMsg( msg );
00390 }
00391
00392 const QRectF& Container::boundingRect() const
00393 {
00394
00395 static QRectF r;
00396
00397
00398
00399
00400 return r;
00401 }
00402
00403 const QRectF& Container::coveredRect() const
00404 {
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418 return boundingRect();
00419 }
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433 double Container::baseline() const
00434 {
00435
00436
00437
00438 return 0.0;
00439 }
00440
00441 void Container::moveTo( int x, int y )
00442 {
00443
00444
00445
00446 }
00447
00448 int Container::fontSize() const
00449 {
00450 if ( m_formulaElement->hasOwnBaseSize() ) {
00451 return m_formulaElement->getBaseSize();
00452 }
00453 else {
00454
00455
00456 }
00457
00458 return 0;
00459 }
00460
00461 void Container::setFontSize( int pointSize, bool )
00462 {
00463 if ( m_formulaElement->getBaseSize() != pointSize ) {
00465 }
00466 }
00467
00468 void Container::setFontSizeDirect( int pointSize )
00469 {
00470 m_formulaElement->setBaseSize( pointSize );
00471 recalcLayout();
00472 }
00473
00474 void Container::updateMatrixActions()
00475 {
00476
00477
00478
00479
00480
00481 }
00482
00483 void Container::save( QDomElement &root )
00484 {
00485 QDomDocument ownerDoc = root.ownerDocument();
00486 root.appendChild(m_formulaElement->getElementDom(ownerDoc));
00487 }
00488
00489
00493 bool Container::load( const QDomElement &fe )
00494 {
00495 if( fe.isNull() ) {
00496 kWarning( DEBUGID ) << "Empty element." << endl;
00497 return false;
00498 }
00499
00500 FormulaElement* root = new FormulaElement( );
00501 if (root->buildFromDom(fe)) {
00502 delete m_formulaElement;
00503 m_formulaElement = root;
00504 emit formulaLoaded(m_formulaElement);
00505
00506 recalcLayout();
00507 return true;
00508 }
00509
00510 delete root;
00511 kWarning( DEBUGID ) << "Error constructing element tree." << endl;
00512 return false;
00513 }
00514
00515
00516 void Container::saveMathML( QTextStream& stream, bool oasisFormat )
00517 {
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535 }
00536
00537 bool Container::loadMathML( const QDomDocument &doc, bool oasisFormat )
00538 {
00539 return loadMathML( doc.documentElement(), oasisFormat );
00540 }
00541
00542 bool Container::loadMathML( const QDomElement &element, bool oasisFormat )
00543 {
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556 return false;
00557 }
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586 }
00587
00588 using namespace KFormula;
00589 #include "FormulaContainer.moc"