summaryrefslogtreecommitdiffstats
path: root/lib/kofficecore/KoChild.h
blob: 4734bbd4596f74c959e3f3388babb95d162c870b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/
#ifndef __koChild_h__
#define __koChild_h__

#include <tqobject.h>
#include <tqwmatrix.h>
#include <koffice_export.h>

/**
 * KoChild is an abstract base class that represents the tqgeometry
 * associated with an embedded document. In general it handles its position
 * relative to the embedded document's tqparent.
 *
 * In detail it handles size, matrix operations and can give you
 * a clip region. It can deal with scaling, rotation etc. because it
 * makes heavy usage of TQWMatrix.
 *
 * After applying the matrix, viewGeometry() applies zooming, but can be
 * reimplemented to also apply e.g. some translation by the application
 * (e.g. for centering the page).
 *
 * @see KoDocumentChild KoViewChild
 */
class KOFFICECORE_EXPORT KoChild : public TQObject
{
  Q_OBJECT
  TQ_OBJECT
public:

  /**
   * The gadget generally identifies where a child has been hit (generally
   * by the mouse pointer).
   * Based on this information different actions can be taken, for example
   * moving the child or opening a context menu. NoGadget means that
   * this child has not been hit.
   *
   * @see #gadgetHitTest
   */
  enum Gadget { NoGadget, TopLeft, TopMid, TopRight, MidLeft, MidRight,
		BottomLeft, BottomMid, BottomRight, Move };

  KoChild( TQObject *tqparent = 0, const char *name = 0 );
  virtual ~KoChild();

  /**
   *  Sets a new tqgeometry for this child document.
   *  Use noEmit = true if you do not want the 'changed'-signal to be emitted
   */
  void setGeometry( const TQRect &rect, bool noEmit = false );

  /**
   * @return the rectangle that would be used to display this
   *         child document if the child is not rotated or
   *         subject to some other geometric transformation.
   *         The rectangle is in the coordinate system of the tqparent,
   *         using unzoomed coordinates in points.
   *
   * @see #setGeometry
   */
  TQRect tqgeometry() const;

  /**
   * @return the region of this child part relative to the
   *         coordinate system of the tqparent.
   *         The region is transformed with the passed
   *         matrix.
   */
  virtual TQRegion region( const TQWMatrix& = TQWMatrix() ) const;

  /**
   * @return the polygon which surrounds the child part. The points
   *         are in coordinates of the tqparent.
   *         The points are transformed with the
   *         passed matrix.
   */
  virtual TQPointArray pointArray( const TQWMatrix &matrix = TQWMatrix() ) const;

  /**
   * Tests whether the part contains a certain point. The point is
   * in the coordinate system of the tqparent.
   */
  //virtual bool tqcontains( const TQPoint& ) const;

  /**
   * @return the effective bounding rect after all transformations.
   *         The coordinates of the rectangle are in the coordinate system
   *         of the tqparent.
   */
  TQRect boundingRect() const;

  /**
   * Scales the content of the child part. However, that does not
   * affect the size of the child part.
   */
  virtual void setScaling( double x, double y );

  /**
   * @return the x axis scaling of the child part
   */
  virtual double xScaling() const;

  /**
   * @return the y axis scaling of the child part
   */
  virtual double yScaling() const;

  /**
   * Shears the content of the child part.
   */
  virtual void setShearing( double x, double y );

  /**
   * @return the x axis shearing of the child part
   */
  virtual double xShearing() const;

  /**
   * @return the y axis shearing of the child part
   */
  virtual double yShearing() const;

  /**
   * Sets the angle of rotation.
   */
  virtual void setRotation( double );

  /**
   * @return the angle of rotation
   */
  virtual double rotation() const;

  /**
   * Sets the center of the rotation to the point @p pos.
   */
  virtual void setRotationPoint( const TQPoint& pos );

  /**
   * @return the center of the rotation
   */
  virtual TQPoint rotationPoint() const;

  /**
   * @return true if the child part is an orthogonal rectangle relative
   *         to its parents coordinate system.
   */
  bool isRectangle() const;

  /**
   * Sets the clip region of the painter, so that only pixels of the
   * child part can be drawn.
   *
   * @param painter the painter do modify.
   * @param combine tells whether the new clip region is an intersection
   *        of the current region with the childs region or whether only
   *        the childs region is set.
   */
  virtual void setClipRegion( TQPainter& painter, bool combine = true );

  /**
   * Transforms the painter (its worldmatrix and the clipping)
   * in such a way that the painter can be passed to the child part
   * for drawing.
   */
  virtual void transform( TQPainter& painter );

  /**
   * Sets the position of the content relative to the child frame.
   * This can be used to create a border between the frame border
   * and the actual content.
   */
  virtual void setContentsPos( int x, int y );

  /**
   * @return the contents rectangle that is visible.
   *         This value depends on the scaling and the tqgeometry.
   *         This is the value that is passed to KoDocument::paintContent.
   *
   * @see #xScaling #tqgeometry
   */
  virtual TQRect contentRect() const;

  /**
   * @return the region of the child frame.
   *         If solid is set to true the complete area of the child region
   *         is returned, otherwise only the child border is returned.
   */
  virtual TQRegion frameRegion( const TQWMatrix& matrix = TQWMatrix(), bool solid = false ) const;

  /**
   * @return the frame tqgeometry including a border (6 pixels) as a point
   *         array with 4 points, one for each corner, transformed by given matrix.
   */
  virtual TQPointArray framePointArray( const TQWMatrix &matrix = TQWMatrix() ) const;

  /**
   * @return the current transformation of this child as matrix.
   *         This includes translation, scale, rotation, shearing.
   *
   * @see #updateMatrix
   */
  virtual TQWMatrix matrix() const;

  /**
   * Locks this child and stores the current transformation.
   * A locked child does not emit changed signals.
   *
   * This is useful if a series of changes are done on this
   * child and only the final result is of interest (GUI updating,...).
   *
   * @see #locked #unlock
   */
  void lock();

  /**
   * Unlocks this child and emits a changed signal.
   */
  void unlock();

  /**
   * If the child is locked, tqgeometry changes
   * (including scaling, rotation, ...) are not backed up.
   *
   * As long as this child is locked, the backed up
   * tqgeometry state can be recovered with oldPointArray.
   *
   * @return true when this child is locked.
   *
   * @see #locked #unlock #oldPointArray
   */
  bool locked() const;

  /**
   * @return the backed up tqgeometry transformed by given matrix.
   */
  virtual TQPointArray oldPointArray( const TQWMatrix &matrix );

  /**
   * Marks this child as either transparent or not.
   * @param transparent set this child to transparent (true)
   *           or opaque (false).
   *
   * @see #isTransparent
   */
  virtual void setTransparent( bool transparent );

  /**
   * It might be interesting for view updates and repainting in general
   * whether a child is transparent or not.
   * @return true when this child is marked as transparent.
   */
  virtual bool isTransparent() const;

  /**
   * Different actions are taken depending on where a child frame is
   * hit. Two gadgets are known: one for the border (5 pixels) and one
   * for the inner area.
   * @return the gadget identification for the hit area.
   * @param p the hit position.
   *
   * @see #Gadget
   */
  virtual Gadget gadgetHitTest( const TQPoint& p );

signals:

  /**
   * Emitted every time this child changes, but only if this child is not
   * locked.
   * @see #locked
   */
  void changed( KoChild *thisChild );

protected:

  /**
   * @return point array with the 4 corners of given rectangle, which is
   *         transformed by given matrix.
   *
   *  @param matrix the transformation of r.
   *  @param r the rectangle for which the point array should be created.
   */
  virtual TQPointArray pointArray( const TQRect& r, const TQWMatrix& matrix = TQWMatrix() ) const;

  /**
   * Stores the current transformation of this child into a matrix.
   *
   * @see #matrix
   */
  virtual void updateMatrix();
private:

  class KoChildPrivate;
  KoChildPrivate *d;
};

#endif