File indexing completed on 2024-05-12 15:56:39

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2011 Jan Hambrecht <jaham@gmx.net>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KOCLIPPATH_H
0008 #define KOCLIPPATH_H
0009 
0010 #include "kritaflake_export.h"
0011 
0012 #include <QScopedPointer>
0013 #include <QList>
0014 #include <QSharedDataPointer>
0015 #include <qnamespace.h>
0016 #include <KoFlakeCoordinateSystem.h>
0017 
0018 class KoShape;
0019 class KoPathShape;
0020 class QPainter;
0021 class QTransform;
0022 class QPainterPath;
0023 class QSizeF;
0024 
0025 /// Clip path used to clip shapes
0026 class KRITAFLAKE_EXPORT KoClipPath
0027 {
0028 public:
0029 
0030     /**
0031      * Create a new shape clipping using the given clip data
0032      * @param clipShapes define the clipping shapes, owned by KoClipPath!
0033      * @param coordinates shows if ObjectBoundingBox or UserSpaceOnUse coordinate
0034      *                    system is used.
0035      */
0036     KoClipPath(QList<KoShape*> clipShapes, KoFlake::CoordinateSystem coordinates);
0037     ~KoClipPath();
0038 
0039     // Work around MSVC inability to generate copy ops with QSharedDataPointer.
0040     KoClipPath(const KoClipPath &);
0041     KoClipPath &operator=(const KoClipPath &);
0042 
0043     KoClipPath *clone() const;
0044 
0045     KoFlake::CoordinateSystem coordinates() const;
0046 
0047     /// Sets the clip rule to be used for the clip path
0048     void setClipRule(Qt::FillRule clipRule);
0049 
0050     /// Returns the current clip rule
0051     Qt::FillRule clipRule() const;
0052 
0053     /// Returns the current clip path with coordinates in percent of the clipped shape size
0054     QPainterPath path() const;
0055 
0056     /// Returns the current clip path scaled to match the specified shape size
0057     QPainterPath pathForSize(const QSizeF &size) const;
0058 
0059     /// Returns the clip path shapes
0060     QList<KoPathShape*> clipPathShapes() const;
0061 
0062     QList<KoShape*> clipShapes() const;
0063 
0064     /**
0065      * Returns the transformation from the clip data path shapes to the
0066      * current document coordinates of the specified clipped shape.
0067      * If the specified clipped shape is null, the transformation 
0068      * from clip data path shapes to shape coordinates of the clipped shape 
0069      * at the time of creating this clip path is being returned.
0070      */
0071     QTransform clipDataTransformation(KoShape *clippedShape) const;
0072 
0073     /// Applies the clipping to the given painter
0074     static void applyClipping(KoShape *clippedShape, QPainter &painter);
0075 
0076 private:
0077     class Private;
0078     QSharedDataPointer<Private> d;
0079 };
0080 
0081 #endif // KOCLIPPATH_H