Warning, file /office/calligra/libs/flake/KoShapeAnchor.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2007, 2009 Thomas Zander <zander@kde.org> 0003 * Copyright (C) 2011 Matus Hanzes <matus.hanzes@ixonos.com> 0004 * Copyright (C) 2013 C. Boemann <cbo@boemann.dk> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 #ifndef KOSHAPEANCHOR_H 0022 #define KOSHAPEANCHOR_H 0023 0024 #include "flake_export.h" 0025 0026 0027 class KoShape; 0028 class KoXmlElement; 0029 class KoShapeLoadingContext; 0030 class KoShapeSavingContext; 0031 class KoShapeAnchorPrivate; 0032 0033 class QTextDocument; 0034 class QPointF; 0035 class QString; 0036 0037 /** 0038 * This class is the object that explains how a shape is anchored to something. 0039 * 0040 * The anchored shape will be positioned (in supporting applications) based on the properties 0041 * defined in this class. 0042 * 0043 * This class can be used in three different ways: 0044 * -page anchor 0045 * -as-char 0046 * -char, paragraph anchor 0047 * 0048 * If it's a page anchor it just provide the info about how the shape relates to a page with a specific 0049 * page number. 0050 * 0051 * For the other types of anchoring it has to have a TextLocation in a QTextDocument. This TextLocation 0052 * can either be an inline character (type as-char) or a position (type char or paragraph) The 0053 * KoShapeAnchor and TextLocation connects the anchored-shape to the text flow so the anchored shape 0054 * can be repositioned on the canvas if new text is inserted or removed before the anchor character. 0055 * 0056 * For as-char, char and paragraph use cases: 0057 * @see KoAnchorInlineObject 0058 * @see KoAnchorTextRange 0059 * which are both implemented as subclasses of TextLocation 0060 * 0061 * The position of the shape relative to the anchor is called the offset. It's loaded by loadOdf(). 0062 * @see PlacementStrategy for more information about the layout of anchors/shapes. 0063 */ 0064 class FLAKE_EXPORT KoShapeAnchor 0065 { 0066 public: 0067 /** 0068 * This class is an interface that positions the shape linked to text anchor 0069 */ 0070 class PlacementStrategy { 0071 public: 0072 PlacementStrategy(){}; 0073 virtual ~PlacementStrategy(){}; 0074 0075 /** 0076 * Reparent the anchored shape to not have a parent shape container (and model) 0077 * 0078 */ 0079 virtual void detachFromModel() = 0; 0080 0081 /** 0082 * Reparent the anchored shape under an appropriate shape container (and model) 0083 * 0084 * If needed, it changes the parent KoShapeContainerModel and KoShapeContainer of the anchored 0085 * shape. 0086 */ 0087 virtual void updateContainerModel() = 0; 0088 }; 0089 0090 class TextLocation { 0091 public: 0092 TextLocation(){}; 0093 virtual ~TextLocation(){}; 0094 virtual const QTextDocument *document() const = 0; 0095 virtual int position() const = 0; 0096 }; 0097 0098 enum HorizontalPos { 0099 HCenter, 0100 HFromInside, 0101 HFromLeft, 0102 HInside, 0103 HLeft, 0104 HOutside, 0105 HRight 0106 }; 0107 0108 enum HorizontalRel { //NOTE: update KWAnchoringProperties if you change this 0109 HChar, 0110 HPage, 0111 HPageContent, 0112 HPageStartMargin, 0113 HPageEndMargin, 0114 HFrame, 0115 HFrameContent, 0116 HFrameEndMargin, 0117 HFrameStartMargin, 0118 HParagraph, 0119 HParagraphContent, 0120 HParagraphEndMargin, 0121 HParagraphStartMargin 0122 }; 0123 0124 enum VerticalPos { 0125 VBelow, 0126 VBottom, 0127 VFromTop, 0128 VMiddle, 0129 VTop 0130 }; 0131 0132 enum VerticalRel { //NOTE: update KWAnchoringProperties if you change this 0133 VBaseline, 0134 VChar, 0135 VFrame, 0136 VFrameContent, 0137 VLine, 0138 VPage, 0139 VPageContent, 0140 VParagraph, 0141 VParagraphContent, 0142 VText 0143 }; 0144 0145 enum AnchorType { 0146 AnchorAsCharacter, 0147 AnchorToCharacter, 0148 AnchorParagraph, 0149 AnchorPage 0150 }; 0151 0152 /** 0153 * Constructor for an in-place anchor. 0154 * @param shape the anchored shape that this anchor links to. 0155 */ 0156 explicit KoShapeAnchor(KoShape *shape); 0157 virtual ~KoShapeAnchor(); 0158 0159 /** 0160 * Return the shape that is linked to from the text anchor. 0161 */ 0162 KoShape *shape() const; 0163 0164 /** 0165 * Returns the type of the anchor. 0166 * 0167 * The text:anchor-type attribute specifies how a frame is bound to a 0168 * text document. The anchor position is the point at which a frame is 0169 * bound to a text document. The defined values for the text:anchor-type 0170 * attribute are; 0171 * 0172 * - as-char 0173 * There is no anchor position. The drawing shape behaves like a 0174 * character. 0175 * - char 0176 * The character after the drawing shape element. 0177 * - frame 0178 * The parent text box that the current drawing shape element is 0179 * contained in. 0180 * FIXME we don't support type frame 0181 * - page 0182 * The page that has the same physical page number as the value of the 0183 * text:anchor-page-number attribute that is attached to the drawing 0184 * shape element. 0185 * - paragraph 0186 * The paragraph that the current drawing shape element is contained in. 0187 */ 0188 AnchorType anchorType() const; 0189 0190 /** 0191 * Set how the anchor behaves 0192 */ 0193 void setAnchorType(AnchorType type); 0194 0195 /// set the current vertical-pos 0196 void setHorizontalPos(HorizontalPos); 0197 0198 /// return the current vertical-pos 0199 HorizontalPos horizontalPos() const; 0200 0201 /// set the current vertical-rel 0202 void setHorizontalRel(HorizontalRel); 0203 0204 /// return the current vertical-rel 0205 HorizontalRel horizontalRel() const; 0206 0207 /// set the current horizontal-pos 0208 void setVerticalPos(VerticalPos); 0209 0210 /// return the current horizontal-pos 0211 VerticalPos verticalPos() const; 0212 0213 /// set the current horizontal-rel 0214 void setVerticalRel(VerticalRel); 0215 0216 /// return the current horizontal-rel 0217 VerticalRel verticalRel() const; 0218 0219 /// return the wrap influence on position 0220 QString wrapInfluenceOnPosition() const; 0221 0222 /// return if flow-with-text (odf attribute) 0223 bool flowWithText() const; 0224 0225 /// return the page number of the shape (valid with page anchoring, -1 indicates auto). 0226 int pageNumber() const; 0227 0228 /// return the offset of the shape from the anchor. 0229 const QPointF &offset() const; 0230 0231 /// set the new offset of the shape. Causes a new layout soon. 0232 void setOffset(const QPointF &offset); 0233 0234 /// Load the additional attributes. 0235 /// This will also make the shape invisible so it doesn't mess up any layout 0236 /// before it's ready to be placed where it belongs 0237 /// The textlayout should make it visible again 0238 bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context); 0239 0240 /// Save the additional attributes. 0241 void saveOdf(KoShapeSavingContext &context) const; 0242 0243 /// Get extra data structure that is what is actually inside a text document 0244 TextLocation *textLocation() const; 0245 0246 /// Set extra data structure that is what is actually inside a text document 0247 /// We do NOT take ownership (may change in the future) 0248 void setTextLocation(TextLocation *textLocation); 0249 0250 /// Get placement strategy which is used to position shape linked to text anchor 0251 PlacementStrategy *placementStrategy() const; 0252 0253 /// Set placement strategy which is used to position shape linked to text anchor 0254 /// We take owner ship and will make sure the strategy is deleted 0255 void setPlacementStrategy(PlacementStrategy *placementStrategy); 0256 0257 private: 0258 class Private; 0259 Private * const d; 0260 }; 0261 0262 #endif