kformuladocument.h
1/* This file is part of the KDE project
2 Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
3 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef KFORMULADOCUMENT_H
22#define KFORMULADOCUMENT_H
23
24#include <tqdom.h>
25#include <tqobject.h>
26#include <tqptrlist.h>
27#include <tqstring.h>
28#include <tqstringlist.h>
29
30#include <tdeaction.h>
31#include <kcommand.h>
32#include <tdeconfig.h>
33#include <KoCommandHistory.h>
34//#include "KoCommandHistory.h"
35#include "kformuladefs.h"
36
37KFORMULA_NAMESPACE_BEGIN
38
39class Container;
40class ContextStyle;
41class SymbolAction;
42class SymbolTable;
43class DocumentWrapper;
45
46
51class FormulaList: public TQPtrList<Container>
52{
53protected:
54 virtual int compareItems( TQPtrCollection::Item a, TQPtrCollection::Item b );
55};
56
57
68class KOFORMULA_EXPORT Document : public TQObject {
69 TQ_OBJECT
70
71
72 friend class DocumentWrapper;
73 friend class Container;
74
75public:
76
80 Document( TQObject *parent=0, const char *name=0,
81 const TQStringList &args=TQStringList() );
82 ~Document();
83
87 virtual Container* createFormula( int pos=-1, bool registerMe=true );
88
93 virtual void registerFormula( Container*, int pos=-1 );
94
99 virtual void unregisterFormula( Container* );
100
105 virtual void evaluateFormulas() {}
106 virtual void enableEvaluation( bool ) {}
107
112 bool loadXML( const TQDomDocument& doc );
113
118 bool loadOasis( const TQDomDocument& doc );
119
123 bool loadDocumentPart( TQDomElement node );
124
128 TQDomDocument saveXML();
129
133 TQDomElement saveDocumentPart( TQDomDocument& doc );
134
135
139 ContextStyle& getContextStyle( bool edit=false );
140
146 void setZoomAndResolution( int zoom, int dpiX, int dpiY );
147
148 void newZoomAndResolution( bool updateViews, bool forPrint );
149
153 void setZoomAndResolution( int zoom, double zoomX, double zoomY,
154 bool updateViews=false, bool forPrint=false );
155
156 double getXResolution() const;
157 double getYResolution() const;
158
162 void activate(Container* formula);
163
167 void setEnabled( bool enabled );
168
172 KoCommandHistory* getHistory() const;
173
177 const SymbolTable& getSymbolTable() const;
178
183 void updateConfig();
184
188 static TQDomDocument createDomDocument();
189
194 TQDomDocument createMathMLDomDocument();
195
202 void setCreationStrategy( TQString strategy );
203
204public:
205
209 TQPtrListIterator<Container> formulas();
210
211 SymbolType leftBracketChar();
212 SymbolType rightBracketChar();
213
214 DocumentWrapper* wrapper() { return m_wrapper; }
215
216protected:
217
222 int formulaPos( Container* formula );
223
227 Container* formulaAt( uint pos );
228
232 int formulaCount();
233
237 void sortFormulaList();
238
239private:
240
245 Container* newFormula( uint number );
246
250 bool hasFormula();
251
255 void recalc();
256
257 void introduceWrapper( DocumentWrapper* wrapper, bool init );
258
262 DocumentWrapper* m_wrapper;
263
267 Container* m_formula;
268
273 ContextStyle* m_contextStyle;
274
278 FormulaList formulae;
279
283 ElementCreationStrategy* creationStrategy;
284};
285
286
287
292class KOFORMULA_EXPORT DocumentWrapper : public TQObject {
293 TQ_OBJECT
294
295
296public:
297
298 DocumentWrapper( TDEConfig* config,
299 TDEActionCollection* collection,
300 KoCommandHistory* history = 0 );
302
303 TDEConfig* config() { return m_config; }
304 KoCommandHistory* history() { return m_history; }
305
309 Document* document() const { return m_document; }
310
314 void setEnabled( bool enabled );
315
320 void document( Document* document, bool init = true );
321
322 TDEAction* getAddNegThinSpaceAction() { return m_addNegThinSpaceAction; }
323 TDEAction* getAddThinSpaceAction() { return m_addThinSpaceAction; }
324 TDEAction* getAddMediumSpaceAction() { return m_addMediumSpaceAction; }
325 TDEAction* getAddThickSpaceAction() { return m_addThickSpaceAction; }
326 TDEAction* getAddQuadSpaceAction() { return m_addQuadSpaceAction; }
327 TDEAction* getAddBracketAction() { return m_addBracketAction; }
328 TDEAction* getAddSBracketAction() { return m_addSBracketAction;}
329 TDEAction* getAddCBracketAction() { return m_addCBracketAction;}
330 TDEAction* getAddAbsAction() { return m_addAbsAction;}
331 TDEAction* getAddFractionAction() { return m_addFractionAction; }
332 TDEAction* getAddRootAction() { return m_addRootAction; }
333 TDEAction* getAddSumAction() { return m_addSumAction; }
334 TDEAction* getAddProductAction() { return m_addProductAction; }
335 TDEAction* getAddIntegralAction() { return m_addIntegralAction; }
336 TDEAction* getAddMatrixAction() { return m_addMatrixAction; }
337 TDEAction* getAddOneByTwoMatrixAction(){ return m_addOneByTwoMatrixAction; }
338 TDEAction* getAddUpperLeftAction() { return m_addUpperLeftAction; }
339 TDEAction* getAddLowerLeftAction() { return m_addLowerLeftAction; }
340 TDEAction* getAddUpperRightAction() { return m_addUpperRightAction; }
341 TDEAction* getAddLowerRightAction() { return m_addLowerRightAction; }
342 TDEAction* getAddGenericUpperAction() { return m_addGenericUpperAction; }
343 TDEAction* getAddGenericLowerAction() { return m_addGenericLowerAction; }
344 TDEAction* getAddOverlineAction() { return m_addOverlineAction; }
345 TDEAction* getAddUnderlineAction() { return m_addUnderlineAction; }
346 TDEAction* getAddMultilineAction() { return m_addMultilineAction; }
347 TDEAction* getRemoveEnclosingAction() { return m_removeEnclosingAction; }
348 TDEAction* getMakeGreekAction() { return m_makeGreekAction; }
349 TDEAction* getInsertSymbolAction() { return m_insertSymbolAction; }
350
351 TDEAction* getAppendColumnAction() { return m_appendColumnAction; }
352 TDEAction* getInsertColumnAction() { return m_insertColumnAction; }
353 TDEAction* getRemoveColumnAction() { return m_removeColumnAction; }
354 TDEAction* getAppendRowAction() { return m_appendRowAction; }
355 TDEAction* getInsertRowAction() { return m_insertRowAction; }
356 TDEAction* getRemoveRowAction() { return m_removeRowAction; }
357
358 void enableMatrixActions(bool);
359 TDESelectAction* getLeftBracketAction() { return m_leftBracket; }
360 TDESelectAction* getRightBracketAction() { return m_rightBracket; }
361 SymbolAction* getSymbolNamesAction() { return m_symbolNamesAction; }
362 TDEToggleAction* getSyntaxHighlightingAction()
363 { return m_syntaxHighlightingAction; }
364 TDEToggleAction* getFormatBoldAction() { return m_formatBoldAction; }
365 TDEToggleAction* getFormatItalicAction() { return m_formatItalicAction; }
366
367 TDESelectAction* getFontFamilyAction() { return m_fontFamily; }
368 TDESelectAction* getTokenElementAction() { return m_tokenElement; }
369
370 SymbolType leftBracketChar() const { return m_leftBracketChar; }
371 SymbolType rightBracketChar() const { return m_rightBracketChar; }
372
373 void updateConfig();
374
375 KoCommandHistory* getHistory() const { return m_history; }
376
377 void undo();
378 void redo();
379
380public slots:
381
382 void paste();
383 void copy();
384 void cut();
385
386 void addNegThinSpace();
387 void addThinSpace();
388 void addMediumSpace();
389 void addThickSpace();
390 void addQuadSpace();
391 void addDefaultBracket();
392 void addBracket( SymbolType left, SymbolType right );
393 void addParenthesis();
394 void addSquareBracket();
395 void addCurlyBracket();
396 void addLineBracket();
397 void addFraction();
398 void addRoot();
399 void addIntegral();
400 void addProduct();
401 void addSum();
402 void addMatrix( uint rows=0, uint columns=0 );
403 void addOneByTwoMatrix();
404 void addNameSequence();
405 void addLowerLeftIndex();
406 void addUpperLeftIndex();
407 void addLowerRightIndex();
408 void addUpperRightIndex();
409 void addGenericLowerIndex();
410 void addGenericUpperIndex();
411 void addOverline();
412 void addUnderline();
413 void addMultiline();
414 void removeEnclosing();
415 void makeGreek();
416 void insertSymbol();
417 void insertSymbol( TQString name );
418
419 void appendColumn();
420 void insertColumn();
421 void removeColumn();
422 void appendRow();
423 void insertRow();
424 void removeRow();
425
426 void toggleSyntaxHighlighting();
427 void textBold();
428 void textItalic();
429 void delimiterLeft();
430 void delimiterRight();
431 void symbolNames();
432
433 void fontFamily();
434 void tokenElement();
435
436private:
437
438 void createActions( TDEActionCollection* collection );
439 void initSymbolNamesAction();
440 void setCommandStack( KoCommandHistory* history );
441
442 bool hasFormula() { return m_document->hasFormula(); }
443 Container* formula() { return m_document->m_formula; }
444
445 Document* m_document;
446
447 TDEAction* m_addNegThinSpaceAction;
448 TDEAction* m_addThinSpaceAction;
449 TDEAction* m_addMediumSpaceAction;
450 TDEAction* m_addThickSpaceAction;
451 TDEAction* m_addQuadSpaceAction;
452 TDEAction* m_addBracketAction;
453 TDEAction* m_addSBracketAction;
454 TDEAction* m_addCBracketAction;
455 TDEAction* m_addAbsAction;
456 TDEAction* m_addFractionAction;
457 TDEAction* m_addRootAction;
458 TDEAction* m_addSumAction;
459 TDEAction* m_addProductAction;
460 TDEAction* m_addIntegralAction;
461 TDEAction* m_addMatrixAction;
462 TDEAction* m_addOneByTwoMatrixAction;
463 TDEAction* m_addUpperLeftAction;
464 TDEAction* m_addLowerLeftAction;
465 TDEAction* m_addUpperRightAction;
466 TDEAction* m_addLowerRightAction;
467 TDEAction* m_addGenericUpperAction;
468 TDEAction* m_addGenericLowerAction;
469 TDEAction* m_addOverlineAction;
470 TDEAction* m_addUnderlineAction;
471 TDEAction* m_addMultilineAction;
472 TDEAction* m_removeEnclosingAction;
473 TDEAction* m_makeGreekAction;
474 TDEAction* m_insertSymbolAction;
475
476 TDEAction* m_appendColumnAction;
477 TDEAction* m_insertColumnAction;
478 TDEAction* m_removeColumnAction;
479 TDEAction* m_appendRowAction;
480 TDEAction* m_insertRowAction;
481 TDEAction* m_removeRowAction;
482
483 TDEToggleAction* m_syntaxHighlightingAction;
484 TDEToggleAction* m_formatBoldAction;
485 TDEToggleAction* m_formatItalicAction;
486
487 TDESelectAction* m_leftBracket;
488 TDESelectAction* m_rightBracket;
489 SymbolAction* m_symbolNamesAction;
490
491 TDESelectAction* m_fontFamily;
492 TDESelectAction* m_tokenElement;
493
494 SymbolType m_leftBracketChar;
495 SymbolType m_rightBracketChar;
496 TQString m_selectedName;
497
498 TDEConfig* m_config;
499 KoCommandHistory* m_history;
500
504 bool m_ownHistory;
505
506 bool m_hasActions;
507};
508
509
510KFORMULA_NAMESPACE_END
511
512#endif // KFORMULADOCUMENT_H
The document.
Contains all the style information for the formela.
A Wrapper that constracts the actions and must be given a real document to work with.
Document * document() const
A document that can contain a lot of formulas (container).
virtual void evaluateFormulas()
Triggers the evaluation of the whole document.
An object of this type needs to be known by the SequenceElement.
small utility class representing a sortable (by x,y position) list of formulas you can use sort() and...
The command history stores a (user) configurable amount of Commands.
The symbol table.
Definition symboltable.h:77
TDEAction * paste(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * undo(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * redo(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * cut(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * copy(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)