lib Library API Documentation

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., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, 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 
00044 
00049 class FormulaList: public QPtrList<Container>
00050 {
00051 protected:
00052     virtual int compareItems( QPtrCollection::Item a, QPtrCollection::Item b );
00053 };
00054 
00055 
00066 class Document : public QObject {
00067     Q_OBJECT
00068 
00069     friend class DocumentWrapper;
00070     friend class Container;
00071 
00072 public:
00073 
00077     Document( QObject *parent=0, const char *name=0,
00078               const QStringList &args=QStringList() );
00079     ~Document();
00080 
00084     virtual Container* createFormula( int pos=-1, bool registerMe=true );
00085 
00090     virtual void registerFormula( Container*, int pos=-1 );
00091 
00096     virtual void unregisterFormula( Container* );
00097 
00102     virtual void evaluateFormulas() {}
00103     virtual void enableEvaluation( bool ) {}
00104 
00109     bool loadXML( QDomDocument doc );
00110 
00114     bool loadDocumentPart( QDomElement node );
00115 
00119     QDomDocument saveXML();
00120 
00124     QDomElement saveDocumentPart( QDomDocument doc );
00125 
00126 
00130     ContextStyle& getContextStyle( bool edit=false );
00131 
00137     void setZoomAndResolution( int zoom, int dpiX, int dpiY );
00138 
00139     void newZoomAndResolution( bool updateViews, bool forPrint );
00140 
00144     void setZoomAndResolution( int zoom, double zoomX, double zoomY,
00145                                bool updateViews=false, bool forPrint=false );
00146 
00147     double getXResolution() const;
00148     double getYResolution() const;
00149 
00153     void activate(Container* formula);
00154 
00158     void setEnabled( bool enabled );
00159 
00163     KoCommandHistory* getHistory() const;
00164 
00168     const SymbolTable& getSymbolTable() const;
00169 
00174     void updateConfig();
00175 
00179     static QDomDocument createDomDocument();
00180 
00181 public:
00182 
00186     QPtrListIterator<Container> formulas();
00187 
00188     SymbolType leftBracketChar();
00189     SymbolType rightBracketChar();
00190 
00191     DocumentWrapper* wrapper() { return m_wrapper; }
00192 
00193 protected:
00194 
00199     int formulaPos( Container* formula );
00200 
00204     Container* formulaAt( uint pos );
00205 
00209     int formulaCount();
00210 
00214     void sortFormulaList();
00215 
00216 private:
00217 
00222     Container* newFormula( uint number );
00223 
00227     bool hasFormula();
00228 
00232     void recalc();
00233 
00234     void introduceWrapper( DocumentWrapper* wrapper );
00235 
00239     DocumentWrapper* m_wrapper;
00240 
00244     Container* m_formula;
00245 
00250     ContextStyle* m_contextStyle;
00251 
00255     FormulaList formulae;
00256 };
00257 
00258 
00259 
00264 class DocumentWrapper : public QObject {
00265     Q_OBJECT
00266 
00267 public:
00268 
00269     DocumentWrapper( KConfig* config,
00270                      KActionCollection* collection,
00271                      KoCommandHistory* history = 0 );
00272     ~DocumentWrapper();
00273 
00274     KConfig* config() { return m_config; }
00275     KoCommandHistory* history() { return m_history; }
00276 
00280     Document* document() const { return m_document; }
00281 
00286     void document( Document* document );
00287 
00288     KAction* getAddNegThinSpaceAction()  { return m_addNegThinSpaceAction; }
00289     KAction* getAddThinSpaceAction()     { return m_addThinSpaceAction; }
00290     KAction* getAddMediumSpaceAction()   { return m_addMediumSpaceAction; }
00291     KAction* getAddThickSpaceAction()    { return m_addThickSpaceAction; }
00292     KAction* getAddQuadSpaceAction()     { return m_addQuadSpaceAction; }
00293     KAction* getAddBracketAction()       { return m_addBracketAction; }
00294     KAction* getAddSBracketAction()      { return m_addSBracketAction;}
00295     KAction* getAddCBracketAction()      { return m_addCBracketAction;}
00296     KAction* getAddAbsAction()           { return m_addAbsAction;}
00297     KAction* getAddFractionAction()      { return m_addFractionAction; }
00298     KAction* getAddRootAction()          { return m_addRootAction; }
00299     KAction* getAddSumAction()           { return m_addSumAction; }
00300     KAction* getAddProductAction()       { return m_addProductAction; }
00301     KAction* getAddIntegralAction()      { return m_addIntegralAction; }
00302     KAction* getAddMatrixAction()        { return m_addMatrixAction; }
00303     KAction* getAddOneByTwoMatrixAction(){ return m_addOneByTwoMatrixAction; }
00304     KAction* getAddUpperLeftAction()     { return m_addUpperLeftAction; }
00305     KAction* getAddLowerLeftAction()     { return m_addLowerLeftAction; }
00306     KAction* getAddUpperRightAction()    { return m_addUpperRightAction; }
00307     KAction* getAddLowerRightAction()    { return m_addLowerRightAction; }
00308     KAction* getAddGenericUpperAction()  { return m_addGenericUpperAction; }
00309     KAction* getAddGenericLowerAction()  { return m_addGenericLowerAction; }
00310     KAction* getAddOverlineAction()      { return m_addOverlineAction; }
00311     KAction* getAddUnderlineAction()     { return m_addUnderlineAction; }
00312     KAction* getAddMultilineAction()     { return m_addMultilineAction; }
00313     KAction* getRemoveEnclosingAction()  { return m_removeEnclosingAction; }
00314     KAction* getMakeGreekAction()        { return m_makeGreekAction; }
00315     KAction* getInsertSymbolAction()     { return m_insertSymbolAction; }
00316 
00317     KAction* getAppendColumnAction()     { return m_appendColumnAction; }
00318     KAction* getInsertColumnAction()     { return m_insertColumnAction; }
00319     KAction* getRemoveColumnAction()     { return m_removeColumnAction; }
00320     KAction* getAppendRowAction()        { return m_appendRowAction; }
00321     KAction* getInsertRowAction()        { return m_insertRowAction; }
00322     KAction* getRemoveRowAction()        { return m_removeRowAction; }
00323 
00324     KSelectAction* getLeftBracketAction()  { return m_leftBracket; }
00325     KSelectAction* getRightBracketAction() { return m_rightBracket; }
00326     SymbolAction* getSymbolNamesAction()  { return m_symbolNamesAction; }
00327     KToggleAction* getSyntaxHighlightingAction()
00328         { return m_syntaxHighlightingAction; }
00329     KToggleAction* getFormatBoldAction()   { return m_formatBoldAction; }
00330     KToggleAction* getFormatItalicAction() { return m_formatItalicAction; }
00331 
00332     KSelectAction* getFontFamilyAction() { return m_fontFamily; }
00333 
00334     SymbolType leftBracketChar() const  { return m_leftBracketChar; }
00335     SymbolType rightBracketChar() const { return m_rightBracketChar; }
00336 
00337     void updateConfig();
00338 
00339     KoCommandHistory* getHistory() const { return m_history; }
00340 
00341     void undo();
00342     void redo();
00343 
00344 public slots:
00345 
00346     void paste();
00347     void copy();
00348     void cut();
00349 
00350     void addNegThinSpace();
00351     void addThinSpace();
00352     void addMediumSpace();
00353     void addThickSpace();
00354     void addQuadSpace();
00355     void addDefaultBracket();
00356     void addBracket( SymbolType left, SymbolType right );
00357     void addParenthesis();
00358     void addSquareBracket();
00359     void addCurlyBracket();
00360     void addLineBracket();
00361     void addFraction();
00362     void addRoot();
00363     void addIntegral();
00364     void addProduct();
00365     void addSum();
00366     void addMatrix( uint rows=0, uint columns=0 );
00367     void addOneByTwoMatrix();
00368     void addNameSequence();
00369     void addLowerLeftIndex();
00370     void addUpperLeftIndex();
00371     void addLowerRightIndex();
00372     void addUpperRightIndex();
00373     void addGenericLowerIndex();
00374     void addGenericUpperIndex();
00375     void addOverline();
00376     void addUnderline();
00377     void addMultiline();
00378     void removeEnclosing();
00379     void makeGreek();
00380     void insertSymbol();
00381     void insertSymbol( QString name );
00382 
00383     void appendColumn();
00384     void insertColumn();
00385     void removeColumn();
00386     void appendRow();
00387     void insertRow();
00388     void removeRow();
00389 
00390     void toggleSyntaxHighlighting();
00391     void textBold();
00392     void textItalic();
00393     void delimiterLeft();
00394     void delimiterRight();
00395     void symbolNames();
00396 
00397     void fontFamily();
00398 
00399 private:
00400 
00401     void createActions( KActionCollection* collection );
00402     void initSymbolNamesAction();
00403     void setCommandStack( KoCommandHistory* history );
00404 
00405     bool hasFormula() { return m_document->hasFormula(); }
00406     Container* formula() { return m_document->m_formula; }
00407 
00408     Document* m_document;
00409 
00410     KAction* m_addNegThinSpaceAction;
00411     KAction* m_addThinSpaceAction;
00412     KAction* m_addMediumSpaceAction;
00413     KAction* m_addThickSpaceAction;
00414     KAction* m_addQuadSpaceAction;
00415     KAction* m_addBracketAction;
00416     KAction* m_addSBracketAction;
00417     KAction* m_addCBracketAction;
00418     KAction* m_addAbsAction;
00419     KAction* m_addFractionAction;
00420     KAction* m_addRootAction;
00421     KAction* m_addSumAction;
00422     KAction* m_addProductAction;
00423     KAction* m_addIntegralAction;
00424     KAction* m_addMatrixAction;
00425     KAction* m_addOneByTwoMatrixAction;
00426     KAction* m_addUpperLeftAction;
00427     KAction* m_addLowerLeftAction;
00428     KAction* m_addUpperRightAction;
00429     KAction* m_addLowerRightAction;
00430     KAction* m_addGenericUpperAction;
00431     KAction* m_addGenericLowerAction;
00432     KAction* m_addOverlineAction;
00433     KAction* m_addUnderlineAction;
00434     KAction* m_addMultilineAction;
00435     KAction* m_removeEnclosingAction;
00436     KAction* m_makeGreekAction;
00437     KAction* m_insertSymbolAction;
00438 
00439     KAction* m_appendColumnAction;
00440     KAction* m_insertColumnAction;
00441     KAction* m_removeColumnAction;
00442     KAction* m_appendRowAction;
00443     KAction* m_insertRowAction;
00444     KAction* m_removeRowAction;
00445 
00446     KToggleAction* m_syntaxHighlightingAction;
00447     KToggleAction* m_formatBoldAction;
00448     KToggleAction* m_formatItalicAction;
00449 
00450     KSelectAction* m_leftBracket;
00451     KSelectAction* m_rightBracket;
00452     SymbolAction* m_symbolNamesAction;
00453 
00454     KSelectAction* m_fontFamily;
00455 
00456     SymbolType m_leftBracketChar;
00457     SymbolType m_rightBracketChar;
00458     QString m_selectedName;
00459 
00460     KConfig* m_config;
00461     KoCommandHistory* m_history;
00462 
00466     bool m_ownHistory;
00467 
00468     bool m_hasActions;
00469 };
00470 
00471 
00472 KFORMULA_NAMESPACE_END
00473 
00474 #endif // KFORMULADOCUMENT_H
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 Wed Nov 17 13:19:22 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2003