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

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2008 Jan Hambrecht <jaham@gmx.net>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KOPATTERNBACKGROUND_H
0008 #define KOPATTERNBACKGROUND_H
0009 
0010 #include "KoShapeBackground.h"
0011 #include "kritaflake_export.h"
0012 
0013 #include <QSharedDataPointer>
0014 
0015 class KoPatternBackgroundPrivate;
0016 
0017 class QTransform;
0018 class QImage;
0019 class QPointF;
0020 class QRectF;
0021 
0022 /// A pattern shape background
0023 class KRITAFLAKE_EXPORT KoPatternBackground : public KoShapeBackground
0024 {
0025 public:
0026     /// Pattern rendering style
0027     enum PatternRepeat {
0028         Original,
0029         Tiled,
0030         Stretched
0031     };
0032     /// Pattern reference point
0033     enum ReferencePoint {
0034         TopLeft,
0035         Top,
0036         TopRight,
0037         Left,
0038         Center,
0039         Right,
0040         BottomLeft,
0041         Bottom,
0042         BottomRight
0043     };
0044 
0045     explicit KoPatternBackground();
0046 
0047     ~KoPatternBackground() override;
0048 
0049     // Work around MSVC inability to generate copy ops with QSharedDataPointer.
0050     KoPatternBackground(const KoPatternBackground &);
0051     KoPatternBackground& operator=(const KoPatternBackground &);
0052 
0053     bool compareTo(const KoShapeBackground *other) const override;
0054 
0055     /// Sets the transform matrix
0056     void setTransform(const QTransform &matrix);
0057 
0058     /// Returns the transform matrix
0059     QTransform transform() const;
0060 
0061     /// Sets a new pattern
0062     void setPattern(const QImage &pattern);
0063 
0064     /// Returns the pattern
0065     QImage pattern() const;
0066 
0067     /// Sets the pattern repeatgfl
0068     void setRepeat(PatternRepeat repeat);
0069 
0070     /// Returns the pattern repeat
0071     PatternRepeat repeat() const;
0072 
0073     /// Returns the pattern reference point identifier
0074     ReferencePoint referencePoint() const;
0075 
0076     /// Sets the pattern reference point
0077     void setReferencePoint(ReferencePoint referencePoint);
0078 
0079     /// Returns reference point offset in percent of the pattern display size
0080     QPointF referencePointOffset() const;
0081 
0082     /// Sets the reference point offset in percent of the pattern display size
0083     void setReferencePointOffset(const QPointF &offset);
0084 
0085     /// Returns tile repeat offset in percent of the pattern display size
0086     QPointF tileRepeatOffset() const;
0087 
0088     /// Sets the tile repeat offset in percent of the pattern display size
0089     void setTileRepeatOffset(const QPointF &offset);
0090 
0091     /// Returns the pattern display size
0092     QSizeF patternDisplaySize() const;
0093 
0094     /// Sets pattern display size
0095     void setPatternDisplaySize(const QSizeF &size);
0096 
0097     /// Returns the original image size
0098     QSizeF patternOriginalSize() const;
0099 
0100     /// reimplemented from KoShapeBackground
0101     void paint(QPainter &painter, const QPainterPath &fillPath) const override;
0102 
0103     /// Returns the bounding rect of the pattern image based on the given fill size
0104     QRectF patternRectFromFillSize(const QSizeF &size);
0105 private:
0106     class Private;
0107     QSharedDataPointer<Private> d;
0108 };
0109 
0110 #endif // KOPATTERNBACKGROUND_H