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 
00045 
00050 class FormulaList: public QPtrList<Container>
00051 {
00052 protected:
00053     virtual int compareItems( QPtrCollection::Item a, QPtrCollection::Item b );
00054 };
00055 
00056 
00067 class KOFORMULA_EXPORT Document : public QObject {
00068     Q_OBJECT
00069 
00070     friend class DocumentWrapper;
00071     friend class Container;
00072 
00073 public:
00074 
00078     Document( QObject *parent=0, const char *name=0,
00079               const QStringList &args=QStringList() );
00080     ~Document();
00081 
00085     virtual Container* createFormula( int pos=-1, bool registerMe=true );
00086 
00091     virtual void registerFormula( Container*, int pos=-1 );
00092 
00097     virtual void unregisterFormula( Container* );
00098 
00103     virtual void evaluateFormulas() {}
00104     virtual void enableEvaluation( bool ) {}
00105 
00110     bool loadXML( const QDomDocument& doc );
00111 
00116     bool loadOasis( const QDomDocument& doc );
00117     
00121     bool loadDocumentPart( QDomElement node );
00122 
00126     QDomDocument saveXML();
00127 
00131     QDomElement saveDocumentPart( QDomDocument& doc );
00132 
00133 
00137     ContextStyle& getContextStyle( bool edit=false );
00138 
00144     void setZoomAndResolution( int zoom, int dpiX, int dpiY );
00145 
00146     void newZoomAndResolution( bool updateViews, bool forPrint );
00147 
00151     void setZoomAndResolution( int zoom, double zoomX, double zoomY,
00152                                bool updateViews=false, bool forPrint=false );
00153 
00154     double getXResolution() const;
00155     double getYResolution() const;
00156 
00160     void activate(Container* formula);
00161 
00165     void setEnabled( bool enabled );
00166 
00170     KoCommandHistory* getHistory() const;
00171 
00175     const SymbolTable& getSymbolTable() const;
00176 
00181     void updateConfig();
00182 
00186     static QDomDocument createDomDocument();
00187 
00188 public:
00189 
00193     QPtrListIterator<Container> formulas();
00194 
00195     SymbolType leftBracketChar();
00196     SymbolType rightBracketChar();
00197 
00198     DocumentWrapper* wrapper() { return m_wrapper; }
00199 
00200 protected:
00201 
00206     int formulaPos( Container* formula );
00207 
00211     Container* formulaAt( uint pos );
00212 
00216     int formulaCount();
00217 
00221     void sortFormulaList();
00222 
00223 private:
00224 
00229     Container* newFormula( uint number );
00230 
00234     bool hasFormula();
00235 
00239     void recalc();
00240 
00241     void introduceWrapper( DocumentWrapper* wrapper, bool init );
00242 
00246     DocumentWrapper* m_wrapper;
00247 
00251     Container* m_formula;
00252 
00257     ContextStyle* m_contextStyle;
00258 
00262     FormulaList formulae;
00263 };
00264 
00265 
00266 
00271 class KOFORMULA_EXPORT DocumentWrapper : public QObject {
00272     Q_OBJECT
00273 
00274 public:
00275 
00276     DocumentWrapper( KConfig* config,
00277                      KActionCollection* collection,
00278                      KoCommandHistory* history = 0 );
00279     ~DocumentWrapper();
00280 
00281     KConfig* config() { return m_config; }
00282     KoCommandHistory* history() { return m_history; }
00283 
00287     Document* document() const { return m_document; }
00288 
00292     void setEnabled( bool enabled );
00293 
00298     void document( Document* document, bool init = true );
00299 
00300     KAction* getAddNegThinSpaceAction()  { return m_addNegThinSpaceAction; }
00301     KAction* getAddThinSpaceAction()     { return m_addThinSpaceAction; }
00302     KAction* getAddMediumSpaceAction()   { return m_addMediumSpaceAction; }
00303     KAction* getAddThickSpaceAction()    { return m_addThickSpaceAction; }
00304     KAction* getAddQuadSpaceAction()     { return m_addQuadSpaceAction; }
00305     KAction* getAddBracketAction()       { return m_addBracketAction; }
00306     KAction* getAddSBracketAction()      { return m_addSBracketAction;}
00307     KAction* getAddCBracketAction()      { return m_addCBracketAction;}
00308     KAction* getAddAbsAction()           { return m_addAbsAction;}
00309     KAction* getAddFractionAction()      { return m_addFractionAction; }
00310     KAction* getAddRootAction()          { return m_addRootAction; }
00311     KAction* getAddSumAction()           { return m_addSumAction; }
00312     KAction* getAddProductAction()       { return m_addProductAction; }
00313     KAction* getAddIntegralAction()      { return m_addIntegralAction; }
00314     KAction* getAddMatrixAction()        { return m_addMatrixAction; }
00315     KAction* getAddOneByTwoMatrixAction(){ return m_addOneByTwoMatrixAction; }
00316     KAction* getAddUpperLeftAction()     { return m_addUpperLeftAction; }
00317     KAction* getAddLowerLeftAction()     { return m_addLowerLeftAction; }
00318     KAction* getAddUpperRightAction()    { return m_addUpperRightAction; }
00319     KAction* getAddLowerRightAction()    { return m_addLowerRightAction; }
00320     KAction* getAddGenericUpperAction()  { return m_addGenericUpperAction; }
00321     KAction* getAddGenericLowerAction()  { return m_addGenericLowerAction; }
00322     KAction* getAddOverlineAction()      { return m_addOverlineAction; }
00323     KAction* getAddUnderlineAction()     { return m_addUnderlineAction; }
00324     KAction* getAddMultilineAction()     { return m_addMultilineAction; }
00325     KAction* getRemoveEnclosingAction()  { return m_removeEnclosingAction; }
00326     KAction* getMakeGreekAction()        { return m_makeGreekAction; }
00327     KAction* getInsertSymbolAction()     { return m_insertSymbolAction; }
00328 
00329     KAction* getAppendColumnAction()     { return m_appendColumnAction; }
00330     KAction* getInsertColumnAction()     { return m_insertColumnAction; }
00331     KAction* getRemoveColumnAction()     { return m_removeColumnAction; }
00332     KAction* getAppendRowAction()        { return m_appendRowAction; }
00333     KAction* getInsertRowAction()        { return m_insertRowAction; }
00334     KAction* getRemoveRowAction()        { return m_removeRowAction; }
00335 
00336     void enableMatrixActions(bool);
00337     KSelectAction* getLeftBracketAction()  { return m_leftBracket; }
00338     KSelectAction* getRightBracketAction() { return m_rightBracket; }
00339     SymbolAction* getSymbolNamesAction()  { return m_symbolNamesAction; }
00340     KToggleAction* getSyntaxHighlightingAction()
00341         { return m_syntaxHighlightingAction; }
00342     KToggleAction* getFormatBoldAction()   { return m_formatBoldAction; }
00343     KToggleAction* getFormatItalicAction() { return m_formatItalicAction; }
00344 
00345     KSelectAction* getFontFamilyAction() { return m_fontFamily; }
00346 
00347     SymbolType leftBracketChar() const  { return m_leftBracketChar; }
00348     SymbolType rightBracketChar() const { return m_rightBracketChar; }
00349 
00350     void updateConfig();
00351 
00352     KoCommandHistory* getHistory() const { return m_history; }
00353 
00354     void undo();
00355     void redo();
00356 
00357 public slots:
00358 
00359     void paste();
00360     void copy();
00361     void cut();
00362 
00363     void addNegThinSpace();
00364     void addThinSpace();
00365     void addMediumSpace();
00366     void addThickSpace();
00367     void addQuadSpace();
00368     void addDefaultBracket();
00369     void addBracket( SymbolType left, SymbolType right );
00370     void addParenthesis();
00371     void addSquareBracket();
00372     void addCurlyBracket();
00373     void addLineBracket();
00374     void addFraction();
00375     void addRoot();
00376     void addIntegral();
00377     void addProduct();
00378     void addSum();
00379     void addMatrix( uint rows=0, uint columns=0 );
00380     void addOneByTwoMatrix();
00381     void addNameSequence();
00382     void addLowerLeftIndex();
00383     void addUpperLeftIndex();
00384     void addLowerRightIndex();
00385     void addUpperRightIndex();
00386     void addGenericLowerIndex();
00387     void addGenericUpperIndex();
00388     void addOverline();
00389     void addUnderline();
00390     void addMultiline();
00391     void removeEnclosing();
00392     void makeGreek();
00393     void insertSymbol();
00394     void insertSymbol( QString name );
00395 
00396     void appendColumn();
00397     void insertColumn();
00398     void removeColumn();
00399     void appendRow();
00400     void insertRow();
00401     void removeRow();
00402 
00403     void toggleSyntaxHighlighting();
00404     void textBold();
00405     void textItalic();
00406     void delimiterLeft();
00407     void delimiterRight();
00408     void symbolNames();
00409 
00410     void fontFamily();
00411 
00412 private:
00413 
00414     void createActions( KActionCollection* collection );
00415     void initSymbolNamesAction();
00416     void setCommandStack( KoCommandHistory* history );
00417 
00418     bool hasFormula() { return m_document->hasFormula(); }
00419     Container* formula() { return m_document->m_formula; }
00420 
00421     Document* m_document;
00422 
00423     KAction* m_addNegThinSpaceAction;
00424     KAction* m_addThinSpaceAction;
00425     KAction* m_addMediumSpaceAction;
00426     KAction* m_addThickSpaceAction;
00427     KAction* m_addQuadSpaceAction;
00428     KAction* m_addBracketAction;
00429     KAction* m_addSBracketAction;
00430     KAction* m_addCBracketAction;
00431     KAction* m_addAbsAction;
00432     KAction* m_addFractionAction;
00433     KAction* m_addRootAction;
00434     KAction* m_addSumAction;
00435     KAction* m_addProductAction;
00436     KAction* m_addIntegralAction;
00437     KAction* m_addMatrixAction;
00438     KAction* m_addOneByTwoMatrixAction;
00439     KAction* m_addUpperLeftAction;
00440     KAction* m_addLowerLeftAction;
00441     KAction* m_addUpperRightAction;
00442     KAction* m_addLowerRightAction;
00443     KAction* m_addGenericUpperAction;
00444     KAction* m_addGenericLowerAction;
00445     KAction* m_addOverlineAction;
00446     KAction* m_addUnderlineAction;
00447     KAction* m_addMultilineAction;
00448     KAction* m_removeEnclosingAction;
00449     KAction* m_makeGreekAction;
00450     KAction* m_insertSymbolAction;
00451 
00452     KAction* m_appendColumnAction;
00453     KAction* m_insertColumnAction;
00454     KAction* m_removeColumnAction;
00455     KAction* m_appendRowAction;
00456     KAction* m_insertRowAction;
00457     KAction* m_removeRowAction;
00458 
00459     KToggleAction* m_syntaxHighlightingAction;
00460     KToggleAction* m_formatBoldAction;
00461     KToggleAction* m_formatItalicAction;
00462 
00463     KSelectAction* m_leftBracket;
00464     KSelectAction* m_rightBracket;
00465     SymbolAction* m_symbolNamesAction;
00466 
00467     KSelectAction* m_fontFamily;
00468 
00469     SymbolType m_leftBracketChar;
00470     SymbolType m_rightBracketChar;
00471     QString m_selectedName;
00472 
00473     KConfig* m_config;
00474     KoCommandHistory* m_history;
00475 
00479     bool m_ownHistory;
00480 
00481     bool m_hasActions;
00482 };
00483 
00484 
00485 KFORMULA_NAMESPACE_END
00486 
00487 #endif // KFORMULADOCUMENT_H
KDE Home | KDE Accessibility Home | Description of Access Keys