lib

kformuladocument.h

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., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef KFORMULADOCUMENT_H
00022 #define KFORMULADOCUMENT_H
00023 
00024 #include <qdom.h>
00025 #include <qobject.h>
00026 #include <qptrlist.h>
00027 #include <qstring.h>
00028 #include <qstringlist.h>
00029 
00030 #include <kaction.h>
00031 #include <kcommand.h>
00032 #include <kconfig.h>
00033 #include <KoCommandHistory.h>
00034 //#include "KoCommandHistory.h"
00035 #include "kformuladefs.h"
00036 
00037 KFORMULA_NAMESPACE_BEGIN
00038 
00039 class Container;
00040 class ContextStyle;
00041 class SymbolAction;
00042 class SymbolTable;
00043 class DocumentWrapper;
00044 class ElementCreationStrategy;
00045 
00046 
00051 class FormulaList: public QPtrList<Container>
00052 {
00053 protected:
00054     virtual int compareItems( QPtrCollection::Item a, QPtrCollection::Item b );
00055 };
00056 
00057 
00068 class KOFORMULA_EXPORT Document : public QObject {
00069     Q_OBJECT
00070 
00071     friend class DocumentWrapper;
00072     friend class Container;
00073 
00074 public:
00075 
00079     Document( QObject *parent=0, const char *name=0,
00080               const QStringList &args=QStringList() );
00081     ~Document();
00082 
00086     virtual Container* createFormula( int pos=-1, bool registerMe=true );
00087 
00092     virtual void registerFormula( Container*, int pos=-1 );
00093 
00098     virtual void unregisterFormula( Container* );
00099 
00104     virtual void evaluateFormulas() {}
00105     virtual void enableEvaluation( bool ) {}
00106 
00111     bool loadXML( const QDomDocument& doc );
00112 
00117     bool loadOasis( const QDomDocument& doc );
00118     
00122     bool loadDocumentPart( QDomElement node );
00123 
00127     QDomDocument saveXML();
00128 
00132     QDomElement saveDocumentPart( QDomDocument& doc );
00133 
00134 
00138     ContextStyle& getContextStyle( bool edit=false );
00139 
00145     void setZoomAndResolution( int zoom, int dpiX, int dpiY );
00146 
00147     void newZoomAndResolution( bool updateViews, bool forPrint );
00148 
00152     void setZoomAndResolution( int zoom, double zoomX, double zoomY,
00153                                bool updateViews=false, bool forPrint=false );
00154 
00155     double getXResolution() const;
00156     double getYResolution() const;
00157 
00161     void activate(Container* formula);
00162 
00166     void setEnabled( bool enabled );
00167 
00171     KoCommandHistory* getHistory() const;
00172 
00176     const SymbolTable& getSymbolTable() const;
00177 
00182     void updateConfig();
00183 
00187     static QDomDocument createDomDocument();
00188 
00193     QDomDocument createMathMLDomDocument();
00194 
00201     void setCreationStrategy( QString strategy );
00202 
00203 public:
00204 
00208     QPtrListIterator<Container> formulas();
00209 
00210     SymbolType leftBracketChar();
00211     SymbolType rightBracketChar();
00212 
00213     DocumentWrapper* wrapper() { return m_wrapper; }
00214 
00215 protected:
00216 
00221     int formulaPos( Container* formula );
00222 
00226     Container* formulaAt( uint pos );
00227 
00231     int formulaCount();
00232 
00236     void sortFormulaList();
00237 
00238 private:
00239 
00244     Container* newFormula( uint number );
00245 
00249     bool hasFormula();
00250 
00254     void recalc();
00255 
00256     void introduceWrapper( DocumentWrapper* wrapper, bool init );
00257 
00261     DocumentWrapper* m_wrapper;
00262 
00266     Container* m_formula;
00267 
00272     ContextStyle* m_contextStyle;
00273 
00277     FormulaList formulae;
00278 
00282     ElementCreationStrategy* creationStrategy;
00283 };
00284 
00285 
00286 
00291 class KOFORMULA_EXPORT DocumentWrapper : public QObject {
00292     Q_OBJECT
00293 
00294 public:
00295 
00296     DocumentWrapper( KConfig* config,
00297                      KActionCollection* collection,
00298                      KoCommandHistory* history = 0 );
00299     ~DocumentWrapper();
00300 
00301     KConfig* config() { return m_config; }
00302     KoCommandHistory* history() { return m_history; }
00303 
00307     Document* document() const { return m_document; }
00308 
00312     void setEnabled( bool enabled );
00313 
00318     void document( Document* document, bool init = true );
00319 
00320     KAction* getAddNegThinSpaceAction()  { return m_addNegThinSpaceAction; }
00321     KAction* getAddThinSpaceAction()     { return m_addThinSpaceAction; }
00322     KAction* getAddMediumSpaceAction()   { return m_addMediumSpaceAction; }
00323     KAction* getAddThickSpaceAction()    { return m_addThickSpaceAction; }
00324     KAction* getAddQuadSpaceAction()     { return m_addQuadSpaceAction; }
00325     KAction* getAddBracketAction()       { return m_addBracketAction; }
00326     KAction* getAddSBracketAction()      { return m_addSBracketAction;}
00327     KAction* getAddCBracketAction()      { return m_addCBracketAction;}
00328     KAction* getAddAbsAction()           { return m_addAbsAction;}
00329     KAction* getAddFractionAction()      { return m_addFractionAction; }
00330     KAction* getAddRootAction()          { return m_addRootAction; }
00331     KAction* getAddSumAction()           { return m_addSumAction; }
00332     KAction* getAddProductAction()       { return m_addProductAction; }
00333     KAction* getAddIntegralAction()      { return m_addIntegralAction; }
00334     KAction* getAddMatrixAction()        { return m_addMatrixAction; }
00335     KAction* getAddOneByTwoMatrixAction(){ return m_addOneByTwoMatrixAction; }
00336     KAction* getAddUpperLeftAction()     { return m_addUpperLeftAction; }
00337     KAction* getAddLowerLeftAction()     { return m_addLowerLeftAction; }
00338     KAction* getAddUpperRightAction()    { return m_addUpperRightAction; }
00339     KAction* getAddLowerRightAction()    { return m_addLowerRightAction; }
00340     KAction* getAddGenericUpperAction()  { return m_addGenericUpperAction; }
00341     KAction* getAddGenericLowerAction()  { return m_addGenericLowerAction; }
00342     KAction* getAddOverlineAction()      { return m_addOverlineAction; }
00343     KAction* getAddUnderlineAction()     { return m_addUnderlineAction; }
00344     KAction* getAddMultilineAction()     { return m_addMultilineAction; }
00345     KAction* getRemoveEnclosingAction()  { return m_removeEnclosingAction; }
00346     KAction* getMakeGreekAction()        { return m_makeGreekAction; }
00347     KAction* getInsertSymbolAction()     { return m_insertSymbolAction; }
00348 
00349     KAction* getAppendColumnAction()     { return m_appendColumnAction; }
00350     KAction* getInsertColumnAction()     { return m_insertColumnAction; }
00351     KAction* getRemoveColumnAction()     { return m_removeColumnAction; }
00352     KAction* getAppendRowAction()        { return m_appendRowAction; }
00353     KAction* getInsertRowAction()        { return m_insertRowAction; }
00354     KAction* getRemoveRowAction()        { return m_removeRowAction; }
00355 
00356     void enableMatrixActions(bool);
00357     KSelectAction* getLeftBracketAction()  { return m_leftBracket; }
00358     KSelectAction* getRightBracketAction() { return m_rightBracket; }
00359     SymbolAction* getSymbolNamesAction()  { return m_symbolNamesAction; }
00360     KToggleAction* getSyntaxHighlightingAction()
00361         { return m_syntaxHighlightingAction; }
00362     KToggleAction* getFormatBoldAction()   { return m_formatBoldAction; }
00363     KToggleAction* getFormatItalicAction() { return m_formatItalicAction; }
00364 
00365     KSelectAction* getFontFamilyAction() { return m_fontFamily; }
00366     KSelectAction* getTokenElementAction() { return m_tokenElement; }
00367 
00368     SymbolType leftBracketChar() const  { return m_leftBracketChar; }
00369     SymbolType rightBracketChar() const { return m_rightBracketChar; }
00370 
00371     void updateConfig();
00372 
00373     KoCommandHistory* getHistory() const { return m_history; }
00374 
00375     void undo();
00376     void redo();
00377 
00378 public slots:
00379 
00380     void paste();
00381     void copy();
00382     void cut();
00383 
00384     void addNegThinSpace();
00385     void addThinSpace();
00386     void addMediumSpace();
00387     void addThickSpace();
00388     void addQuadSpace();
00389     void addDefaultBracket();
00390     void addBracket( SymbolType left, SymbolType right );
00391     void addParenthesis();
00392     void addSquareBracket();
00393     void addCurlyBracket();
00394     void addLineBracket();
00395     void addFraction();
00396     void addRoot();
00397     void addIntegral();
00398     void addProduct();
00399     void addSum();
00400     void addMatrix( uint rows=0, uint columns=0 );
00401     void addOneByTwoMatrix();
00402     void addNameSequence();
00403     void addLowerLeftIndex();
00404     void addUpperLeftIndex();
00405     void addLowerRightIndex();
00406     void addUpperRightIndex();
00407     void addGenericLowerIndex();
00408     void addGenericUpperIndex();
00409     void addOverline();
00410     void addUnderline();
00411     void addMultiline();
00412     void removeEnclosing();
00413     void makeGreek();
00414     void insertSymbol();
00415     void insertSymbol( QString name );
00416 
00417     void appendColumn();
00418     void insertColumn();
00419     void removeColumn();
00420     void appendRow();
00421     void insertRow();
00422     void removeRow();
00423 
00424     void toggleSyntaxHighlighting();
00425     void textBold();
00426     void textItalic();
00427     void delimiterLeft();
00428     void delimiterRight();
00429     void symbolNames();
00430 
00431     void fontFamily();
00432     void tokenElement();
00433 
00434 private:
00435 
00436     void createActions( KActionCollection* collection );
00437     void initSymbolNamesAction();
00438     void setCommandStack( KoCommandHistory* history );
00439 
00440     bool hasFormula() { return m_document->hasFormula(); }
00441     Container* formula() { return m_document->m_formula; }
00442 
00443     Document* m_document;
00444 
00445     KAction* m_addNegThinSpaceAction;
00446     KAction* m_addThinSpaceAction;
00447     KAction* m_addMediumSpaceAction;
00448     KAction* m_addThickSpaceAction;
00449     KAction* m_addQuadSpaceAction;
00450     KAction* m_addBracketAction;
00451     KAction* m_addSBracketAction;
00452     KAction* m_addCBracketAction;
00453     KAction* m_addAbsAction;
00454     KAction* m_addFractionAction;
00455     KAction* m_addRootAction;
00456     KAction* m_addSumAction;
00457     KAction* m_addProductAction;
00458     KAction* m_addIntegralAction;
00459     KAction* m_addMatrixAction;
00460     KAction* m_addOneByTwoMatrixAction;
00461     KAction* m_addUpperLeftAction;
00462     KAction* m_addLowerLeftAction;
00463     KAction* m_addUpperRightAction;
00464     KAction* m_addLowerRightAction;
00465     KAction* m_addGenericUpperAction;
00466     KAction* m_addGenericLowerAction;
00467     KAction* m_addOverlineAction;
00468     KAction* m_addUnderlineAction;
00469     KAction* m_addMultilineAction;
00470     KAction* m_removeEnclosingAction;
00471     KAction* m_makeGreekAction;
00472     KAction* m_insertSymbolAction;
00473 
00474     KAction* m_appendColumnAction;
00475     KAction* m_insertColumnAction;
00476     KAction* m_removeColumnAction;
00477     KAction* m_appendRowAction;
00478     KAction* m_insertRowAction;
00479     KAction* m_removeRowAction;
00480 
00481     KToggleAction* m_syntaxHighlightingAction;
00482     KToggleAction* m_formatBoldAction;
00483     KToggleAction* m_formatItalicAction;
00484 
00485     KSelectAction* m_leftBracket;
00486     KSelectAction* m_rightBracket;
00487     SymbolAction* m_symbolNamesAction;
00488 
00489     KSelectAction* m_fontFamily;
00490     KSelectAction* m_tokenElement;
00491 
00492     SymbolType m_leftBracketChar;
00493     SymbolType m_rightBracketChar;
00494     QString m_selectedName;
00495 
00496     KConfig* m_config;
00497     KoCommandHistory* m_history;
00498 
00502     bool m_ownHistory;
00503 
00504     bool m_hasActions;
00505 };
00506 
00507 
00508 KFORMULA_NAMESPACE_END
00509 
00510 #endif // KFORMULADOCUMENT_H
KDE Home | KDE Accessibility Home | Description of Access Keys