home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoChild.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  9.0 KB  |  313 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.  * Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef __koChild_h__
  20. #define __koChild_h__
  21.  
  22. #include <qobject.h>
  23. #include <qwmatrix.h>
  24. #include <koffice_export.h>
  25.  
  26. /**
  27.  * KoChild is an abstract base class that represents the geometry
  28.  * associated with an embedded document. In general it handles its position
  29.  * relative to the embedded document's parent.
  30.  *
  31.  * In detail it handles size, matrix operations and can give you
  32.  * a clip region. It can deal with scaling, rotation etc. because it
  33.  * makes heavy usage of QWMatrix.
  34.  *
  35.  * After applying the matrix, viewGeometry() applies zooming, but can be
  36.  * reimplemented to also apply e.g. some translation by the application
  37.  * (e.g. for centering the page).
  38.  *
  39.  * @see KoDocumentChild KoViewChild
  40.  */
  41. class KOFFICECORE_EXPORT KoChild : public QObject
  42. {
  43.   Q_OBJECT
  44. public:
  45.  
  46.   /**
  47.    * The gadget generally identifies where a child has been hit (generally
  48.    * by the mouse pointer).
  49.    * Based on this information different actions can be taken, for example
  50.    * moving the child or opening a context menu. NoGadget means that
  51.    * this child has not been hit.
  52.    *
  53.    * @see #gadgetHitTest
  54.    */
  55.   enum Gadget { NoGadget, TopLeft, TopMid, TopRight, MidLeft, MidRight,
  56.         BottomLeft, BottomMid, BottomRight, Move };
  57.  
  58.   KoChild( QObject *parent = 0, const char *name = 0 );
  59.   virtual ~KoChild();
  60.  
  61.   /**
  62.    *  Sets a new geometry for this child document.
  63.    *  Use noEmit = true if you do not want the 'changed'-signal to be emitted
  64.    */
  65.   void setGeometry( const QRect &rect, bool noEmit = false );
  66.  
  67.   /**
  68.    * @return the rectangle that would be used to display this
  69.    *         child document if the child is not rotated or
  70.    *         subject to some other geometric transformation.
  71.    *         The rectangle is in the coordinate system of the parent,
  72.    *         using unzoomed coordinates in points.
  73.    *
  74.    * @see #setGeometry
  75.    */
  76.   QRect geometry() const;
  77.  
  78.   /**
  79.    * @return the region of this child part relative to the
  80.    *         coordinate system of the parent.
  81.    *         The region is transformed with the passed
  82.    *         matrix.
  83.    */
  84.   virtual QRegion region( const QWMatrix& = QWMatrix() ) const;
  85.  
  86.   /**
  87.    * @return the polygon which surrounds the child part. The points
  88.    *         are in coordinates of the parent.
  89.    *         The points are transformed with the
  90.    *         passed matrix.
  91.    */
  92.   virtual QPointArray pointArray( const QWMatrix &matrix = QWMatrix() ) const;
  93.  
  94.   /**
  95.    * Tests whether the part contains a certain point. The point is
  96.    * in the coordinate system of the parent.
  97.    */
  98.   //virtual bool contains( const QPoint& ) const;
  99.  
  100.   /**
  101.    * @return the effective bounding rect after all transformations.
  102.    *         The coordinates of the rectangle are in the coordinate system
  103.    *         of the parent.
  104.    */
  105.   QRect boundingRect() const;
  106.  
  107.   /**
  108.    * Scales the content of the child part. However, that does not
  109.    * affect the size of the child part.
  110.    */
  111.   virtual void setScaling( double x, double y );
  112.  
  113.   /**
  114.    * @return the x axis scaling of the child part
  115.    */
  116.   virtual double xScaling() const;
  117.  
  118.   /**
  119.    * @return the y axis scaling of the child part
  120.    */
  121.   virtual double yScaling() const;
  122.  
  123.   /**
  124.    * Shears the content of the child part.
  125.    */
  126.   virtual void setShearing( double x, double y );
  127.  
  128.   /**
  129.    * @return the x axis shearing of the child part
  130.    */
  131.   virtual double xShearing() const;
  132.  
  133.   /**
  134.    * @return the y axis shearing of the child part
  135.    */
  136.   virtual double yShearing() const;
  137.  
  138.   /**
  139.    * Sets the angle of rotation.
  140.    */
  141.   virtual void setRotation( double );
  142.  
  143.   /**
  144.    * @return the angle of rotation
  145.    */
  146.   virtual double rotation() const;
  147.  
  148.   /**
  149.    * Sets the center of the rotation to the point @p pos.
  150.    */
  151.   virtual void setRotationPoint( const QPoint& pos );
  152.  
  153.   /**
  154.    * @return the center of the rotation
  155.    */
  156.   virtual QPoint rotationPoint() const;
  157.  
  158.   /**
  159.    * @return true if the child part is an orthogonal rectangle relative
  160.    *         to its parents coordinate system.
  161.    */
  162.   bool isRectangle() const;
  163.  
  164.   /**
  165.    * Sets the clip region of the painter, so that only pixels of the
  166.    * child part can be drawn.
  167.    *
  168.    * @param painter the painter do modify.
  169.    * @param combine tells whether the new clip region is an intersection
  170.    *        of the current region with the childs region or whether only
  171.    *        the childs region is set.
  172.    */
  173.   virtual void setClipRegion( QPainter& painter, bool combine = true );
  174.  
  175.   /**
  176.    * Transforms the painter (its worldmatrix and the clipping)
  177.    * in such a way that the painter can be passed to the child part
  178.    * for drawing.
  179.    */
  180.   virtual void transform( QPainter& painter );
  181.  
  182.   /**
  183.    * Sets the position of the content relative to the child frame.
  184.    * This can be used to create a border between the frame border
  185.    * and the actual content.
  186.    */
  187.   virtual void setContentsPos( int x, int y );
  188.  
  189.   /**
  190.    * @return the contents rectangle that is visible.
  191.    *         This value depends on the scaling and the geometry.
  192.    *         This is the value that is passed to KoDocument::paintContent.
  193.    *
  194.    * @see #xScaling #geometry
  195.    */
  196.   virtual QRect contentRect() const;
  197.  
  198.   /**
  199.    * @return the region of the child frame.
  200.    *         If solid is set to true the complete area of the child region
  201.    *         is returned, otherwise only the child border is returned.
  202.    */
  203.   virtual QRegion frameRegion( const QWMatrix& matrix = QWMatrix(), bool solid = false ) const;
  204.  
  205.   /**
  206.    * @return the frame geometry including a border (6 pixels) as a point
  207.    *         array with 4 points, one for each corner, transformed by given matrix.
  208.    */
  209.   virtual QPointArray framePointArray( const QWMatrix &matrix = QWMatrix() ) const;
  210.  
  211.   /**
  212.    * @return the current transformation of this child as matrix.
  213.    *         This includes translation, scale, rotation, shearing.
  214.    *
  215.    * @see #updateMatrix
  216.    */
  217.   virtual QWMatrix matrix() const;
  218.  
  219.   /**
  220.    * Locks this child and stores the current transformation.
  221.    * A locked child does not emit changed signals.
  222.    *
  223.    * This is useful if a series of changes are done on this
  224.    * child and only the final result is of interest (GUI updating,...).
  225.    *
  226.    * @see #locked #unlock
  227.    */
  228.   void lock();
  229.  
  230.   /**
  231.    * Unlocks this child and emits a changed signal.
  232.    */
  233.   void unlock();
  234.  
  235.   /**
  236.    * If the child is locked, geometry changes
  237.    * (including scaling, rotation, ...) are not backed up.
  238.    *
  239.    * As long as this child is locked, the backed up
  240.    * geometry state can be recovered with oldPointArray.
  241.    *
  242.    * @return true when this child is locked.
  243.    *
  244.    * @see #locked #unlock #oldPointArray
  245.    */
  246.   bool locked() const;
  247.  
  248.   /**
  249.    * @return the backed up geometry transformed by given matrix.
  250.    */
  251.   virtual QPointArray oldPointArray( const QWMatrix &matrix );
  252.  
  253.   /**
  254.    * Marks this child as either transparent or not.
  255.    * @param transparent set this child to transparent (true)
  256.    *           or opaque (false).
  257.    *
  258.    * @see #isTransparent
  259.    */
  260.   virtual void setTransparent( bool transparent );
  261.  
  262.   /**
  263.    * It might be interesting for view updates and repainting in general
  264.    * whether a child is transparent or not.
  265.    * @return true when this child is marked as transparent.
  266.    */
  267.   virtual bool isTransparent() const;
  268.  
  269.   /**
  270.    * Different actions are taken depending on where a child frame is
  271.    * hit. Two gadgets are known: one for the border (5 pixels) and one
  272.    * for the inner area.
  273.    * @return the gadget identification for the hit area.
  274.    * @param p the hit position.
  275.    *
  276.    * @see #Gadget
  277.    */
  278.   virtual Gadget gadgetHitTest( const QPoint& p );
  279.  
  280. signals:
  281.  
  282.   /**
  283.    * Emitted every time this child changes, but only if this child is not
  284.    * locked.
  285.    * @see #locked
  286.    */
  287.   void changed( KoChild *thisChild );
  288.  
  289. protected:
  290.  
  291.   /**
  292.    * @return point array with the 4 corners of given rectangle, which is
  293.    *         transformed by given matrix.
  294.    *
  295.    *  @param matrix the transformation of r.
  296.    *  @param r the rectangle for which the point array should be created.
  297.    */
  298.   virtual QPointArray pointArray( const QRect& r, const QWMatrix& matrix = QWMatrix() ) const;
  299.  
  300.   /**
  301.    * Stores the current transformation of this child into a matrix.
  302.    *
  303.    * @see #matrix
  304.    */
  305.   virtual void updateMatrix();
  306. private:
  307.  
  308.   class KoChildPrivate;
  309.   KoChildPrivate *d;
  310. };
  311.  
  312. #endif
  313.