~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to lib/kformula/matrixelement.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
   This library is free software; you can redistribute it and/or
6
6
   modify it under the terms of the GNU Library General Public
7
7
   License as published by the Free Software Foundation; either
8
 
   version 2.
 
8
   version 2 of the License, or (at your option) any later version.
9
9
 
10
10
   This library is distributed in the hope that it will be useful,
11
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
21
21
#ifndef MATRIXELEMENT_H
22
22
#define MATRIXELEMENT_H
23
23
 
24
 
#include <qlist.h>
 
24
#include <qptrlist.h>
25
25
 
26
26
#include "basicelement.h"
27
27
 
28
28
KFORMULA_NAMESPACE_BEGIN
29
29
 
 
30
 
 
31
class MatrixSequenceElement;
 
32
 
 
33
 
30
34
/**
31
35
 * A matrix.
32
36
 */
33
37
class MatrixElement : public BasicElement {
 
38
    friend class KFCRemoveColumn;
 
39
    friend class KFCRemoveRow;
 
40
    friend class MatrixSequenceElement;
 
41
 
 
42
    MatrixElement& operator=( const MatrixElement& ) { return *this; }
34
43
public:
35
44
    MatrixElement(uint rows = 1, uint columns = 1, BasicElement* parent = 0);
36
45
    ~MatrixElement();
37
46
 
 
47
    MatrixElement( const MatrixElement& );
 
48
 
 
49
    virtual MatrixElement* clone() {
 
50
        return new MatrixElement( *this );
 
51
    }
 
52
 
 
53
    virtual bool accept( ElementVisitor* visitor );
 
54
 
 
55
    /**
 
56
     * The cursor has entered one of our child sequences.
 
57
     * This is a good point to tell the user where he is.
 
58
     */
 
59
    virtual void entered( SequenceElement* child );
 
60
 
38
61
    /**
39
62
     * Sets the cursor and returns the element the point is in.
40
63
     * The handled flag shows whether the cursor has been set.
41
64
     * This is needed because only the innermost matching element
42
65
     * is allowed to set the cursor.
43
66
     */
44
 
    virtual BasicElement* goToPos(FormulaCursor*, bool& handled,
45
 
                                  const KoPoint& point, const KoPoint& parentOrigin);
 
67
    virtual BasicElement* goToPos( FormulaCursor*, bool& handled,
 
68
                                   const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
46
69
 
47
70
    // drawing
48
71
    //
62
85
     * The `parentOrigin' is the point this element's parent starts.
63
86
     * We can use our parentPosition to get our own origin then.
64
87
     */
65
 
    virtual void draw(QPainter& painter, const QRect& r,
66
 
                      const ContextStyle& context,
67
 
                      ContextStyle::TextStyle tstyle,
68
 
                      ContextStyle::IndexStyle istyle,
69
 
                      const KoPoint& parentOrigin);
 
88
    virtual void draw( QPainter& painter, const LuPixelRect& r,
 
89
                       const ContextStyle& context,
 
90
                       ContextStyle::TextStyle tstyle,
 
91
                       ContextStyle::IndexStyle istyle,
 
92
                       const LuPixelPoint& parentOrigin );
70
93
 
 
94
    /**
 
95
     * Dispatch this FontCommand to all our TextElement children.
 
96
     */
 
97
    virtual void dispatchFontCommand( FontCommand* cmd );
71
98
 
72
99
    // navigation
73
100
    //
121
148
     * Inserts all new children at the cursor position. Places the
122
149
     * cursor according to the direction.
123
150
     */
124
 
    //virtual void insert(FormulaCursor*, QList<BasicElement>&, Direction);
 
151
    //virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction);
125
152
 
126
153
    /**
127
154
     * Removes all selected children and returns them. Places the
128
155
     * cursor to where the children have been.
129
156
     */
130
 
    //virtual void remove(FormulaCursor*, QList<BasicElement>&, Direction);
 
157
    //virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction);
131
158
 
132
159
    /**
133
160
     * Moves the cursor to a normal place where new elements
160
187
     */
161
188
    virtual QString toLatex();
162
189
 
 
190
    virtual QString formulaString();
 
191
 
 
192
    uint getRows() const { return content.count(); }
 
193
    uint getColumns() const { return content.getFirst()->count(); }
 
194
 
 
195
    SequenceElement* elementAt(uint row, uint column);
 
196
 
 
197
    virtual void writeMathML( QDomDocument doc, QDomNode parent );
 
198
 
163
199
protected:
164
200
 
165
201
    //Save/load support
172
208
    /**
173
209
     * Appends our attributes to the dom element.
174
210
     */
175
 
    virtual void writeDom(QDomElement& element);
 
211
    virtual void writeDom(QDomElement element);
176
212
 
177
213
    /**
178
214
     * Reads our attributes from the element.
179
215
     * Returns false if it failed.
180
216
     */
181
 
    virtual bool readAttributesFromDom(QDomElement& element);
 
217
    virtual bool readAttributesFromDom(QDomElement element);
182
218
 
183
219
    /**
184
220
     * Reads our content from the node. Sets the node to the next node
189
225
 
190
226
private:
191
227
 
192
 
    uint getRows() { return content.count(); }
193
 
    uint getColumns() { return content.at(0)->count(); }
194
 
 
195
 
    SequenceElement* getElement(uint row, uint column)
 
228
    MatrixSequenceElement* getElement(uint row, uint column)
196
229
        { return content.at(row)->at(column); }
197
230
 
198
231
    /**
199
 
     * Searches throught the matrix for the element. Sets the
 
232
     * Searches through the matrix for the element. Sets the
200
233
     * row and column if found.
201
234
     * Returns true if the element was found. false otherwise.
202
235
     */
205
238
    /**
206
239
     * The elements we contain.
207
240
     */
208
 
    QList<QList<SequenceElement> > content;
209
 
};
 
241
    QPtrList< QPtrList< MatrixSequenceElement > > content;
 
242
};
 
243
 
 
244
 
 
245
 
 
246
class MultilineSequenceElement;
 
247
 
 
248
 
 
249
/**
 
250
 * Any number of lines.
 
251
 */
 
252
class MultilineElement : public BasicElement {
 
253
    friend class KFCNewLine;
 
254
 
 
255
    typedef BasicElement inherited;
 
256
public:
 
257
 
 
258
    /**
 
259
     * The container this FormulaElement belongs to must not be 0,
 
260
     * except you really know what you are doing.
 
261
     */
 
262
    MultilineElement( BasicElement* parent = 0 );
 
263
    ~MultilineElement();
 
264
 
 
265
    MultilineElement( const MultilineElement& );
 
266
 
 
267
    virtual MultilineElement* clone() {
 
268
        return new MultilineElement( *this );
 
269
    }
 
270
 
 
271
    virtual bool accept( ElementVisitor* visitor );
 
272
 
 
273
    /**
 
274
     * The cursor has entered one of our child sequences.
 
275
     * This is a good point to tell the user where he is.
 
276
     */
 
277
    virtual void entered( SequenceElement* child );
 
278
 
 
279
    /**
 
280
     * Returns the element the point is in.
 
281
     */
 
282
    BasicElement* goToPos( FormulaCursor* cursor, bool& handled,
 
283
                           const LuPixelPoint& point, const LuPixelPoint& parentOrigin );
 
284
 
 
285
    /**
 
286
     * Sets the cursor inside this element to its start position.
 
287
     * For most elements that is the main child.
 
288
     */
 
289
    virtual void goInside(FormulaCursor* cursor);
 
290
 
 
291
    /**
 
292
     * Enters this element while moving to the left starting inside
 
293
     * the element `from'. Searches for a cursor position inside
 
294
     * this element or to the left of it.
 
295
     */
 
296
    virtual void moveLeft( FormulaCursor* cursor, BasicElement* from );
 
297
 
 
298
    /**
 
299
     * Enters this element while moving to the right starting inside
 
300
     * the element `from'. Searches for a cursor position inside
 
301
     * this element or to the right of it.
 
302
     */
 
303
    virtual void moveRight( FormulaCursor* cursor, BasicElement* from );
 
304
 
 
305
    /**
 
306
     * Enters this element while moving up starting inside
 
307
     * the element `from'. Searches for a cursor position inside
 
308
     * this element or above it.
 
309
     */
 
310
    virtual void moveUp( FormulaCursor* cursor, BasicElement* from );
 
311
 
 
312
    /**
 
313
     * Enters this element while moving down starting inside
 
314
     * the element `from'. Searches for a cursor position inside
 
315
     * this element or below it.
 
316
     */
 
317
    virtual void moveDown( FormulaCursor* cursor, BasicElement* from );
 
318
 
 
319
    /**
 
320
     * Calculates our width and height and
 
321
     * our children's parentPosition.
 
322
     */
 
323
    virtual void calcSizes(const ContextStyle& context, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle);
 
324
 
 
325
    /**
 
326
     * Draws the whole element including its children.
 
327
     * The `parentOrigin' is the point this element's parent starts.
 
328
     * We can use our parentPosition to get our own origin then.
 
329
     */
 
330
    virtual void draw( QPainter& painter, const LuPixelRect& r,
 
331
                       const ContextStyle& context,
 
332
                       ContextStyle::TextStyle tstyle,
 
333
                       ContextStyle::IndexStyle istyle,
 
334
                       const LuPixelPoint& parentOrigin );
 
335
 
 
336
    /**
 
337
     * Dispatch this FontCommand to all our TextElement children.
 
338
     */
 
339
    virtual void dispatchFontCommand( FontCommand* cmd );
 
340
 
 
341
    virtual void insert(FormulaCursor*, QPtrList<BasicElement>&, Direction);
 
342
    virtual void remove(FormulaCursor*, QPtrList<BasicElement>&, Direction);
 
343
 
 
344
    virtual void normalize(FormulaCursor*, Direction);
 
345
 
 
346
    virtual SequenceElement* getMainChild();
 
347
 
 
348
    /**
 
349
     * Sets the cursor to select the child. The mark is placed before,
 
350
     * the position behind it.
 
351
     */
 
352
    virtual void selectChild(FormulaCursor* cursor, BasicElement* child);
 
353
 
 
354
    /**
 
355
     * @returns the latex representation of the element and
 
356
     * of the element's children
 
357
     */
 
358
    virtual QString toLatex();
 
359
 
 
360
    virtual QString formulaString();
 
361
 
 
362
    virtual void writeMathML( QDomDocument doc, QDomNode parent );
 
363
 
 
364
protected:
 
365
 
 
366
    //Save/load support
 
367
 
 
368
    /**
 
369
     * Returns the tag name of this element type.
 
370
     */
 
371
    virtual QString getTagName() const { return "MULTILINE"; }
 
372
 
 
373
    /**
 
374
     * Appends our attributes to the dom element.
 
375
     */
 
376
    virtual void writeDom(QDomElement element);
 
377
 
 
378
    /**
 
379
     * Reads our attributes from the element.
 
380
     * Returns false if it failed.
 
381
     */
 
382
    virtual bool readAttributesFromDom(QDomElement element);
 
383
 
 
384
    /**
 
385
     * Reads our content from the node. Sets the node to the next node
 
386
     * that needs to be read.
 
387
     * Returns false if it failed.
 
388
     */
 
389
    virtual bool readContentFromDom(QDomNode& node);
 
390
 
 
391
 
 
392
private:
 
393
 
 
394
    /**
 
395
     * The list of sequences. Each one is a line.
 
396
     */
 
397
    QPtrList< MultilineSequenceElement > content;
 
398
};
 
399
 
210
400
 
211
401
KFORMULA_NAMESPACE_END
212
402