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

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2007, 2009-2010 Thomas Zander <zander@kde.org>
0003  * SPDX-FileCopyrightText: 2010 Ko Gmbh <cbo@kogmbh.com>
0004  * SPDX-FileCopyrightText: 2011 Matus Hanzes <matus.hanzes@ixonos.com>
0005  * SPDX-FileCopyrightText: 2013 C. Boemann <cbo@boemann.dk>
0006  *
0007  * SPDX-License-Identifier: LGPL-2.0-or-later
0008  */
0009 
0010 #include "KoShapeAnchor.h"
0011 
0012 #include <KoShapeContainer.h>
0013 #include <KoXmlWriter.h>
0014 #include <KoXmlNS.h>
0015 #include <KoShapeSavingContext.h>
0016 #include <KoShapeLoadingContext.h>
0017 
0018 #include <QRectF>
0019 #include <QTransform>
0020 #include <FlakeDebug.h>
0021 
0022 class Q_DECL_HIDDEN KoShapeAnchor::Private
0023 {
0024 public:
0025     Private(KoShape *s)
0026             : shape(s)
0027             , verticalPos(KoShapeAnchor::VTop)
0028             , verticalRel(KoShapeAnchor::VLine)
0029             , horizontalPos(KoShapeAnchor::HLeft)
0030             , horizontalRel(KoShapeAnchor::HChar)
0031             , flowWithText(true)
0032             , anchorType(KoShapeAnchor::AnchorToCharacter)
0033             , placementStrategy(0)
0034             , pageNumber(-1)
0035             , textLocation(0)
0036     {
0037     }
0038 
0039 
0040     QDebug printDebug(QDebug dbg) const
0041     {
0042 #ifndef NDEBUG
0043         dbg.space() << "KoShapeAnchor" << this;
0044         dbg.space() << "offset:" << offset;
0045         dbg.space() << "shape:" << shape->name();
0046 #endif
0047         return dbg.space();
0048     }
0049 
0050     KoShape * const shape;
0051     QPointF offset;
0052     KoShapeAnchor::VerticalPos verticalPos;
0053     KoShapeAnchor::VerticalRel verticalRel;
0054     KoShapeAnchor::HorizontalPos horizontalPos;
0055     KoShapeAnchor::HorizontalRel horizontalRel;
0056     QString wrapInfluenceOnPosition;
0057     bool flowWithText;
0058     KoShapeAnchor::AnchorType anchorType;
0059     KoShapeAnchor::PlacementStrategy *placementStrategy;
0060     int pageNumber;
0061     KoShapeAnchor::TextLocation *textLocation;
0062 };
0063 
0064 KoShapeAnchor::KoShapeAnchor(KoShape *shape)
0065     : d(new Private(shape))
0066 {
0067 }
0068 
0069 KoShapeAnchor::~KoShapeAnchor()
0070 {
0071     if (d->placementStrategy != 0) {
0072         delete d->placementStrategy;
0073     }
0074     delete d;
0075 }
0076 
0077 KoShape *KoShapeAnchor::shape() const
0078 {
0079     return d->shape;
0080 }
0081 
0082 KoShapeAnchor::AnchorType KoShapeAnchor::anchorType() const
0083 {
0084     return d->anchorType;
0085 }
0086 
0087 void KoShapeAnchor::setHorizontalPos(HorizontalPos hp)
0088 {
0089     d->horizontalPos = hp;
0090 }
0091 
0092 KoShapeAnchor::HorizontalPos KoShapeAnchor::horizontalPos() const
0093 {
0094     return d->horizontalPos;
0095 }
0096 
0097 void KoShapeAnchor::setHorizontalRel(HorizontalRel hr)
0098 {
0099     d->horizontalRel = hr;
0100 }
0101 
0102 KoShapeAnchor::HorizontalRel KoShapeAnchor::horizontalRel() const
0103 {
0104     return d->horizontalRel;
0105 }
0106 
0107 void KoShapeAnchor::setVerticalPos(VerticalPos vp)
0108 {
0109     d->verticalPos = vp;
0110 }
0111 
0112 KoShapeAnchor::VerticalPos KoShapeAnchor::verticalPos() const
0113 {
0114     return d->verticalPos;
0115 }
0116 
0117 void KoShapeAnchor::setVerticalRel(VerticalRel vr)
0118 {
0119     d->verticalRel = vr;
0120 }
0121 
0122 KoShapeAnchor::VerticalRel KoShapeAnchor::verticalRel() const
0123 {
0124     return d->verticalRel;
0125 }
0126 
0127 QString KoShapeAnchor::wrapInfluenceOnPosition() const
0128 {
0129     return d->wrapInfluenceOnPosition;
0130 }
0131 
0132 bool KoShapeAnchor::flowWithText() const
0133 {
0134     return d->flowWithText;
0135 }
0136 
0137 int KoShapeAnchor::pageNumber() const
0138 {
0139     return d->pageNumber;
0140 }
0141 
0142 const QPointF &KoShapeAnchor::offset() const
0143 {
0144     return d->offset;
0145 }
0146 
0147 void KoShapeAnchor::setOffset(const QPointF &offset)
0148 {
0149     d->offset = offset;
0150 }
0151 
0152 void KoShapeAnchor::setAnchorType(KoShapeAnchor::AnchorType type)
0153 {
0154     d->anchorType = type;
0155     if (type == AnchorAsCharacter) {
0156         d->horizontalRel = HChar;
0157         d->horizontalPos = HLeft;
0158     }
0159 }
0160 
0161 KoShapeAnchor::TextLocation *KoShapeAnchor::textLocation() const
0162 {
0163     return d->textLocation;
0164 }
0165 
0166 void KoShapeAnchor::setTextLocation(TextLocation *textLocation)
0167 {
0168     d->textLocation = textLocation;
0169 }
0170 
0171 KoShapeAnchor::PlacementStrategy *KoShapeAnchor::placementStrategy() const
0172 {
0173     return d->placementStrategy;
0174 }
0175 
0176 void KoShapeAnchor::setPlacementStrategy(PlacementStrategy *placementStrategy)
0177 {
0178     if (placementStrategy != d->placementStrategy) {
0179         delete d->placementStrategy;
0180 
0181         d->placementStrategy = placementStrategy;
0182     }
0183 }