00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KFORMULACONTAINER_H
00023 #define KFORMULACONTAINER_H
00024
00025 #include <QObject>
00026 #include <QString>
00027 #include <QTextStream>
00028 #include <QKeyEvent>
00029 #include <QDomElement>
00030 #include "kformuladefs.h"
00031 class QColorGroup;
00032 class QKeyEvent;
00033 class QPainter;
00034
00035
00036 namespace KFormula {
00037
00038 class BasicElement;
00039 class FormulaCursor;
00040 class FormulaElement;
00041 class IndexElement;
00042 class PlainCommand;
00043 class SymbolTable;
00044
00045
00053 class FormulaDocument {
00054
00055 FormulaDocument( const FormulaDocument& ) {}
00056 FormulaDocument& operator=( const FormulaDocument& ) { return *this; }
00057 public:
00058
00059 FormulaDocument() {}
00060 virtual ~FormulaDocument() {}
00061
00062 virtual void elementRemoval(BasicElement* ) {}
00063 virtual void changed() {}
00064 virtual void cursorHasMoved( FormulaCursor* ) {}
00065 virtual void moveOutLeft( FormulaCursor* ) {}
00066 virtual void moveOutRight( FormulaCursor* ) {}
00067 virtual void moveOutAbove( FormulaCursor* ) {}
00068 virtual void moveOutBelow( FormulaCursor* ) {}
00069 virtual void tell( const QString& ) {}
00070 virtual void insertFormula( FormulaCursor* ) {}
00071 virtual void removeFormula( FormulaCursor* ) {}
00072 virtual void baseSizeChanged( int, bool ) {}
00073 virtual const SymbolTable& getSymbolTable() const = 0;
00074 };
00075
00076
00081 class KOFORMULA_EXPORT Container : public QObject, public FormulaDocument {
00082 Q_OBJECT
00083
00084
00085 Container( const Container& );
00086 Container& operator= ( const Container& );
00087
00088 public:
00089
00090 enum ViewActions { EXIT_LEFT, EXIT_RIGHT,
00091 EXIT_ABOVE, EXIT_BELOW,
00092 INSERT_FORMULA, REMOVE_FORMULA };
00093
00102 Container( int pos, bool registerMe=true );
00103
00105 ~Container();
00106
00108 void recalcLayout();
00109
00110
00111
00112
00118 void initialize();
00119
00125 FormulaCursor* createCursor();
00126
00131 void elementRemoval(BasicElement* child);
00132
00137 void changed();
00138
00144 void cursorHasMoved( FormulaCursor* );
00145
00150 void moveOutLeft( FormulaCursor* );
00151 void moveOutRight( FormulaCursor* );
00152 void moveOutAbove( FormulaCursor* );
00153 void moveOutBelow( FormulaCursor* );
00154 void tell( const QString& msg );
00155 void removeFormula( FormulaCursor* );
00156
00160 void registerFormula( int pos=-1 );
00161 void unregisterFormula();
00162
00166 void baseSizeChanged( int size, bool owned );
00167
00171 void draw( QPainter& painter, const QRectF& r,
00172 const QPalette& palette, bool edit=false );
00173
00177 void draw( QPainter& painter, const QRectF& r, bool edit=false );
00178
00182 void save( QDomElement &root );
00183
00187 void saveMathML( QTextStream& stream, bool oasisFormat = false );
00188
00193 bool loadMathML( const QDomDocument &doc, bool oasisFormat = false );
00194
00199 bool loadMathML( const QDomElement &element, bool oasisFormat = false );
00200
00204 bool load( const QDomElement &fe );
00205
00209 FormulaCursor* activeCursor();
00210 const FormulaCursor* activeCursor() const;
00211
00218 void setActiveCursor(FormulaCursor* cursor);
00219
00223 const QRectF& boundingRect() const;
00224
00228 const QRectF& coveredRect() const;
00229
00230
00231
00232
00237 double baseline() const;
00238
00243 void moveTo( int x, int y );
00244
00251 virtual double getDocumentX() const { return -1; }
00252 virtual double getDocumentY() const { return -1; }
00253 virtual void setDocumentPosition( double , double ) {}
00254
00258 void testDirty();
00259
00260
00261
00265 bool isEmpty();
00266
00270
00271
00272 virtual const SymbolTable& getSymbolTable() const;
00273
00274 int fontSize() const;
00275
00279 void setFontSize( int pointSize, bool forPrint = false );
00280
00281 void setFontSizeDirect( int pointSize );
00282
00286 void updateMatrixActions();
00287
00288 signals:
00289
00294 void cursorMoved(FormulaCursor* cursor);
00295
00299 void leaveFormula( Container* formula, FormulaCursor* cursor, int cmd );
00300
00304 void formulaChanged( int width, int height );
00305 void formulaChanged( double width, double height );
00306
00310 void statusMsg( const QString& msg );
00311
00315 void errorMsg( const QString& );
00316
00320 void elementWillVanish(BasicElement* element);
00321
00325 void formulaLoaded(FormulaElement*);
00326
00330 void baseSizeChanged( int );
00331
00332 public:
00333
00337 void input( QKeyEvent* event );
00338
00339 void performRequest( Request* request );
00340
00341
00342
00346 void paste();
00347
00351 void paste( const QDomDocument& document, const QString& desc );
00352
00356 void copy();
00357
00361 void cut();
00362
00363 protected:
00364 void emitErrorMsg( const QString& );
00365
00366 private:
00368 QList<BasicElement> m_elements;
00369
00371 FormulaElement* m_formulaElement;
00372
00374 void checkCursor();
00375
00377 bool hasValidCursor() const;
00378
00379 struct Container_Impl;
00380 Container_Impl* impl;
00381 };
00382
00383 }
00384
00385 #endif // KFORMULACONTAINER_H