KoParameterShape.h 5.01 KB
Newer Older
1 2
/* This file is part of the KDE project
   Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
3
   Copyright (C) 2007 Thomas Zander <zander@kde.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

   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 KOPARAMETERSHAPE_H
#define KOPARAMETERSHAPE_H

#include "KoPathShape.h"
25
#include <flake_export.h>
26

Jan Hambrecht's avatar
Jan Hambrecht committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/**
 * KoParameterShape is the base class for all parametric shapes
 * in flake.
 * Parametric shapes are those whose appearance can be completely
 * defined by a few numerical parameters. Rectangle, ellipse and star
 * are examples of parametric shapes.
 * In flake, these shape parameters can be manipulated visually by means
 * of control points. These control points can be moved with the mouse
 * on the canvas which changes the shapes parameter values and hence the
 * shapes apperance in realtime.
 * KoParameterShape is derived from the KoPathShape class that means
 * by changing the shape parameters, the underlying path is manipulated.
 * A parametric shape can be converted into a path shape by simply calling
 * the setModified method. This makes the path tool know that it can handle
 * the shape like a path shape, so that modifying the single path points
 * is possible.
 */
Laurent Montel's avatar
Laurent Montel committed
44
class FLAKE_EXPORT KoParameterShape : public KoPathShape
45 46 47 48 49 50 51 52 53 54 55 56
{
public:
    KoParameterShape();
    ~KoParameterShape();

    /**
     * @brief Move handle to point
     *
     * This method calls moveHandleAction. Overload moveHandleAction to get the behaviour you want.
     * After that updatePath and a repaint is called.
     *
     * @param handleId of the handle
57
     * @param point to move the handle to in document coordinates
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
     * @param modifiers used during move to point
     */
    virtual void moveHandle( int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers = Qt::NoModifier );

    /**
     * @brief Get the handleId in the rect
     *
     * @param rect in shape coordinates
     * @return id of the found handle or -1 if one was found
     */
    virtual int handleIdAt( const QRectF & rect ) const;

    /**
     * @brief Get the handle position 
     * 
     * @param handleId for which ti get the position in shape coordinates
     */
    virtual QPointF handlePosition( int handleId );

    /**
     * @brief Paint the handles
     *
Jan Hambrecht's avatar
Jan Hambrecht committed
80 81
     * @param painter the painter to paint the handles on
     * @param converter the view converter for applying the actual zoom
82
     * @param handleRadius the radius of the handles used for painting
83
     */
84
    virtual void paintHandles( QPainter & painter, const KoViewConverter & converter, int handleRadius );
85 86 87 88

    /**
     * @brief Paint the given handles
     *
Jan Hambrecht's avatar
Jan Hambrecht committed
89 90
     * @param painter the painter to paint the handles on
     * @param converter the view converter for applying the actual zoom
91
     * @param handleId of the handle which should be repainted
92
     * @param handleRadius the radius of the handle used for painting
93
     */
94
    virtual void paintHandle( QPainter & painter, const KoViewConverter & converter, int handleId, int handleRadius );
95

96
    virtual void setSize( const QSizeF &size );
97 98 99 100 101 102 103 104

    /**
     * @brief Check if object is a parametric shape 
     *
     * It is no longer a parametric shape when the path was manipulated 
     *
     * @return true if it is a parametic shape, false otherwise
     */
105
    bool isParametricShape() const;
106 107 108 109 110 111 112 113 114

    /**
     * @brief Set the modified status.
     * 
     * After the state is set to modified it is no longer possible to work 
     * with parameters on this shape.
     *
     * @param modified the modification state
     */
115
    void setModified( bool modified );
116

117 118
    virtual QPointF normalize();

119 120 121 122 123 124 125
protected:
    /**
     * @brief Updates the internal state of a KoParameterShape.
     *
     * This method is called from moveHandle.
     *
     * @param handleId of the handle
126
     * @param point to move the handle to in shape coordinates
127 128 129 130 131 132 133 134 135 136 137
     * @param modifiers used during move to point
     */
    virtual void moveHandleAction( int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers = Qt::NoModifier ) = 0;

    /**
     * @brief Update the path of the parameter shape
     *
     * @param size of the shape
     */
    virtual void updatePath( const QSizeF &size ) = 0;

Thomas Zander's avatar
Thomas Zander committed
138
    /// the handles that the user can grab and change
139
    QList<QPointF> m_handles;
Thomas Zander's avatar
Thomas Zander committed
140 141

private:
142 143
    class Private;
    Private * const d;
144 145 146
};

#endif /* KOPARAMETERSHAPE_H */