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 
00201     bool loadMathML( const QDomElement &doc, bool oasisFormat = false );
00202 
00206     bool load( const QDomElement &fe );
00207 
00211     QString texString();
00212 
00213     QString formulaString();
00214 
00218     void print(KPrinter& printer);
00219 
00223     QImage drawImage( int width, int height );
00224 
00228     FormulaCursor* activeCursor();
00229     const FormulaCursor* activeCursor() const;
00230 
00237     void setActiveCursor(FormulaCursor* cursor);
00238 
00242     QRect boundingRect() const;
00243 
00247     QRect coveredRect();
00248 
00249     double width() const;
00250     double height() const;
00251 
00256     double baseline() const;
00257 
00262     void moveTo( int x, int y );
00263 
00270     virtual double getDocumentX() const { return -1; }
00271     virtual double getDocumentY() const { return -1; }
00272     virtual void setDocumentPosition( double /*x*/, double /*y*/ ) {}
00273 
00281     virtual void startEvaluation() {}
00282 
00286     void testDirty();
00287 
00291     virtual void recalc();
00292 
00296     bool isEmpty();
00297 
00301     virtual Document* document() const;
00302 
00303     virtual const SymbolTable& getSymbolTable() const;
00304 
00305     int fontSize() const;
00306 
00310     void setFontSize( int pointSize, bool forPrint = false );
00311 
00312     void setFontSizeDirect( int pointSize );
00313 
00317     void updateMatrixActions();
00318 
00319 signals:
00320 
00325     void cursorMoved(FormulaCursor* cursor);
00326 
00330     void leaveFormula( Container* formula, FormulaCursor* cursor, int cmd );
00331 
00335     void formulaChanged( int width, int height );
00336     void formulaChanged( double width, double height );
00337 
00341     void statusMsg( const QString& msg );
00342 
00346     void errorMsg( const QString& );
00347 
00351     void elementWillVanish(BasicElement* element);
00352 
00356     void formulaLoaded(FormulaElement*);
00357 
00361     void baseSizeChanged( int );
00362 
00363 public:
00364 
00368     void input( QKeyEvent* event );
00369 
00370     void performRequest( Request* request );
00371 
00372     // There are a lot of thing we can do with the formula.
00373 
00377     void paste();
00378 
00382     void paste( const QDomDocument& document, QString desc );
00383 
00387     void copy();
00388 
00392     void cut();
00393 
00394 protected:
00395 
00396     KoCommandHistory* getHistory() const;
00397 
00401     FormulaElement* rootElement() const;
00402 
00406     virtual FormulaElement* createMainSequence();
00407 
00408     void emitErrorMsg( const QString& );
00409 
00410 private:
00411 
00415     void execute(KCommand *command);
00416 
00420     void checkCursor();
00421 
00425     bool hasValidCursor() const;
00426 
00427     struct Container_Impl;
00428     Container_Impl* impl;
00429 
00430     // debug
00431     friend class TestFormulaCursor;
00432     friend class TestFormulaElement;
00433     friend class TestIndexElement;
00434     friend class TestCommands;
00435 };
00436 
00437 KFORMULA_NAMESPACE_END
00438 
00439 #endif // KFORMULACONTAINER_H
KDE Home | KDE Accessibility Home | Description of Access Keys