lib

kformulacontainer.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 KFORMULACONTAINER_H
00022 #define KFORMULACONTAINER_H
00023 
00024 #include <qclipboard.h>
00025 #include <qdom.h>
00026 #include <qimage.h>
00027 #include <qptrlist.h>
00028 #include <qobject.h>
00029 #include <qptrstack.h>
00030 #include <qstring.h>
00031 
00032 #include <kcommand.h>
00033 //#include <KoCommandHistory.h>
00034 #include "KoCommandHistory.h"
00035 #include "kformuladefs.h"
00036 
00037 class QColorGroup;
00038 class QKeyEvent;
00039 class QPainter;
00040 
00041 class KCommand;
00042 class KPrinter;
00043 
00044 KFORMULA_NAMESPACE_BEGIN
00045 
00046 class BasicElement;
00047 class Document;
00048 class FormulaCursor;
00049 class FormulaElement;
00050 class IndexElement;
00051 class PlainCommand;
00052 class SymbolTable;
00053 
00054 
00062 class FormulaDocument {
00063     // not allowed
00064     FormulaDocument( const FormulaDocument& ) {}
00065     FormulaDocument& operator=( const FormulaDocument& ) { return *this; }
00066 public:
00067 
00068     FormulaDocument() {}
00069     virtual ~FormulaDocument() {}
00070 
00071     virtual void elementRemoval(BasicElement* /*child*/) {}
00072     virtual void changed() {}
00073     virtual void cursorHasMoved( FormulaCursor* ) {}
00074     virtual void moveOutLeft( FormulaCursor* ) {}
00075     virtual void moveOutRight( FormulaCursor* ) {}
00076     virtual void moveOutAbove( FormulaCursor* ) {}
00077     virtual void moveOutBelow( FormulaCursor* ) {}
00078     virtual void tell( const QString& /*msg*/ ) {}
00079     virtual void insertFormula( FormulaCursor* ) {}
00080     virtual void removeFormula( FormulaCursor* ) {}
00081     virtual void baseSizeChanged( int, bool ) {}
00082     virtual const SymbolTable& getSymbolTable() const = 0;
00083 };
00084 
00085 
00090 class KOFORMULA_EXPORT Container : public QObject, public FormulaDocument {
00091     friend class MimeSource;
00092     Q_OBJECT
00093 
00094     // no copying
00095     Container( const Container& );
00096     Container& operator= ( const Container& );
00097 
00098 public:
00099 
00100     enum ViewActions { EXIT_LEFT, EXIT_RIGHT,
00101                        EXIT_ABOVE, EXIT_BELOW,
00102                        INSERT_FORMULA, REMOVE_FORMULA };
00103 
00112     Container( Document* doc, int pos, bool registerMe=true );
00113     ~Container();
00114 
00120     void initialize();
00121 
00127     FormulaCursor* createCursor();
00128 
00133     void elementRemoval(BasicElement* child);
00134 
00139     void changed();
00140 
00146     void cursorHasMoved( FormulaCursor* );
00147 
00152     void moveOutLeft( FormulaCursor* );
00153     void moveOutRight( FormulaCursor* );
00154     void moveOutAbove( FormulaCursor* );
00155     void moveOutBelow( FormulaCursor* );
00156     void tell( const QString& msg );
00157     void removeFormula( FormulaCursor* );
00158 
00162     void registerFormula( int pos=-1 );
00163     void unregisterFormula();
00164 
00168     void baseSizeChanged( int size, bool owned );
00169 
00173     void draw( QPainter& painter, const QRect& r,
00174                const QColorGroup& cg, bool edit=false );
00175 
00179     void draw( QPainter& painter, const QRect& r, bool edit=false );
00180 
00184     void save( QDomElement &root );
00185 
00189     void saveMathML( QTextStream& stream, bool oasisFormat = false );
00190 
00195     bool loadMathML( const QDomDocument &doc, bool oasisFormat = false );
00196 
00200     bool load( const QDomElement &fe );
00201 
00205     QString texString();
00206 
00207     QString formulaString();
00208 
00212     void print(KPrinter& printer);
00213 
00217     QImage drawImage( int width, int height );
00218 
00222     FormulaCursor* activeCursor();
00223     const FormulaCursor* activeCursor() const;
00224 
00231     void setActiveCursor(FormulaCursor* cursor);
00232 
00236     QRect boundingRect() const;
00237 
00241     QRect coveredRect();
00242 
00243     double width() const;
00244     double height() const;
00245 
00250     double baseline() const;
00251 
00256     void moveTo( int x, int y );
00257 
00264     virtual double getDocumentX() const { return -1; }
00265     virtual double getDocumentY() const { return -1; }
00266     virtual void setDocumentPosition( double /*x*/, double /*y*/ ) {}
00267 
00275     virtual void startEvaluation() {}
00276 
00280     void testDirty();
00281 
00285     virtual void recalc();
00286 
00290     bool isEmpty();
00291 
00295     virtual Document* document() const;
00296 
00297     virtual const SymbolTable& getSymbolTable() const;
00298 
00299     int fontSize() const;
00300 
00304     void setFontSize( int pointSize, bool forPrint = false );
00305 
00306     void setFontSizeDirect( int pointSize );
00307 
00311     void updateMatrixActions();
00312 
00313 signals:
00314 
00319     void cursorMoved(FormulaCursor* cursor);
00320 
00324     void leaveFormula( Container* formula, FormulaCursor* cursor, int cmd );
00325 
00329     void formulaChanged( int width, int height );
00330     void formulaChanged( double width, double height );
00331 
00335     void statusMsg( const QString& msg );
00336 
00340     void errorMsg( const QString& );
00341 
00345     void elementWillVanish(BasicElement* element);
00346 
00350     void formulaLoaded(FormulaElement*);
00351 
00355     void baseSizeChanged( int );
00356 
00357 public:
00358 
00362     void input( QKeyEvent* event );
00363 
00364     void performRequest( Request* request );
00365 
00366     // There are a lot of thing we can do with the formula.
00367 
00371     void paste();
00372 
00376     void paste( const QDomDocument& document, QString desc );
00377 
00381     void copy();
00382 
00386     void cut();
00387 
00388 protected:
00389 
00390     KoCommandHistory* getHistory() const;
00391 
00395     FormulaElement* rootElement() const;
00396 
00400     virtual FormulaElement* createMainSequence();
00401 
00402     void emitErrorMsg( const QString& );
00403 
00404 private:
00405 
00409     void execute(KCommand *command);
00410 
00414     void checkCursor();
00415 
00419     bool hasValidCursor() const;
00420 
00421     struct Container_Impl;
00422     Container_Impl* impl;
00423 
00424     // debug
00425     friend class TestFormulaCursor;
00426     friend class TestFormulaElement;
00427     friend class TestIndexElement;
00428     friend class TestCommands;
00429 };
00430 
00431 KFORMULA_NAMESPACE_END
00432 
00433 #endif // KFORMULACONTAINER_H
KDE Home | KDE Accessibility Home | Description of Access Keys