Warning, file /office/calligra/libs/flake/KoShape.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) 2006-2008 Thorsten Zachmann <zachmann@kde.org> 0003 Copyright (C) 2006, 2008 C. Boemann <cbo@boemann.dk> 0004 Copyright (C) 2006-2010 Thomas Zander <zander@kde.org> 0005 Copyright (C) 2007-2009,2011 Jan Hambrecht <jaham@gmx.net> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 * Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #ifndef KOSHAPE_H 0024 #define KOSHAPE_H 0025 0026 #include "KoFlake.h" 0027 #include "KoConnectionPoint.h" 0028 0029 #include <QSharedPointer> 0030 #include <QSet> 0031 #include <QMetaType> 0032 0033 #include <KoXmlReaderForward.h> 0034 #include <KoShapeBackground.h> 0035 0036 //#include <KoSnapData.h> 0037 0038 #include "flake_export.h" 0039 0040 class QPainter; 0041 class QRectF; 0042 class QPainterPath; 0043 class QTransform; 0044 0045 class KoShapeContainer; 0046 class KoShapeStrokeModel; 0047 class KoShapeUserData; 0048 class KoViewConverter; 0049 class KoShapeApplicationData; 0050 class KoShapeSavingContext; 0051 class KoShapeLoadingContext; 0052 class KoGenStyle; 0053 class KoShapeShadow; 0054 class KoEventAction; 0055 class KoShapePrivate; 0056 class KoFilterEffectStack; 0057 class KoSnapData; 0058 class KoClipPath; 0059 class KoShapePaintingContext; 0060 class KoShapeAnchor; 0061 class KoBorder; 0062 struct KoInsets; 0063 0064 0065 /** 0066 * 0067 * Base class for all flake shapes. Shapes extend this class 0068 * to allow themselves to be manipulated. This class just represents 0069 * a graphical shape in the document and can be manipulated by some default 0070 * tools in this library. 0071 * 0072 * Due to the limited responsibility of this class, the extending object 0073 * can have any data backend and is responsible for painting itself. 0074 * 0075 * We strongly suggest that any extending class will use a Model View 0076 * Controller (MVC) design where the View part is all in this class, as well 0077 * as the one that inherits from this one. This allows the data that rests 0078 * in the model to be reused in different parts of the document. For example 0079 * by having two flake objects that show that same data. Or each showing a section of it. 0080 * 0081 * The KoShape data is completely in postscript-points (pt) (see KoUnit 0082 * for conversion methods to and from points). 0083 * This image will explain the real-world use of the shape and its options. 0084 * <img src="../flake_shape_coords.png" align=center><br> 0085 * The Rotation center can be returned with absolutePosition() 0086 * 0087 * <p>Flake objects can be created in three ways: 0088 * <ul> 0089 * <li>a simple new KoDerivedFlake(), 0090 * <li>through an associated tool, 0091 * <li>through a factory 0092 * </ul> 0093 * 0094 * <h1>Shape interaction notifications</h1> 0095 * We had several notification methods that allow your shape to be notified of changes in other 0096 * shapes positions or rotation etc. 0097 * <ol><li>The most general is KoShape::shapeChanged().<br> 0098 * a virtual method that you can use to check various changed to your shape made by tools or otherwise.</li> 0099 * <li>for shape hierarchies the parent may receive a notification when a child was modified. 0100 * This is done though KoShapeContainerModel::childChanged()</li> 0101 * <li>any shape that is at a similar position as another shape there is collision detection. 0102 * You can register your shape to be sensitive to any changes like moving or whatever to 0103 * <b>other</b> shapes that intersect yours. 0104 * Such changes will then be notified to your shape using the method from (1) You should call 0105 * KoShape::setCollisionDetection(bool) to enable this. 0106 * </ol> 0107 */ 0108 class FLAKE_EXPORT KoShape 0109 { 0110 public: 0111 /// Used by shapeChanged() to select which change was made 0112 enum ChangeType { 0113 PositionChanged, ///< used after a setPosition() 0114 RotationChanged, ///< used after a setRotation() 0115 ScaleChanged, ///< used after a scale() 0116 ShearChanged, ///< used after a shear() 0117 SizeChanged, ///< used after a setSize() 0118 GenericMatrixChange, ///< used after the matrix was changed without knowing which property explicitly changed 0119 ParentChanged, ///< used after a setParent() 0120 CollisionDetected, ///< used when another shape moved in our boundingrect 0121 Deleted, ///< the shape was deleted 0122 StrokeChanged, ///< the shapes stroke has changed 0123 BackgroundChanged, ///< the shapes background has changed 0124 ShadowChanged, ///< the shapes shadow has changed 0125 BorderChanged, ///< the shapes border has changed 0126 ParameterChanged, ///< the shapes parameter has changed (KoParameterShape only) 0127 ContentChanged, ///< the content of the shape changed e.g. a new image inside a pixmap/text change inside a textshape 0128 TextRunAroundChanged, ///< used after a setTextRunAroundSide() 0129 ChildChanged, ///< a child of a container was changed/removed. This is propagated to all parents 0130 ConnectionPointChanged, ///< a connection point has changed 0131 ClipPathChanged, ///< the shapes clip path has changed 0132 ControlPointChanged, ///< a control point has changed 0133 BeginResize, ///< used during resizing 0134 EndResize ///< used during resizing 0135 }; 0136 0137 /// The behavior text should do when intersecting this shape. 0138 enum TextRunAroundSide { 0139 BiggestRunAroundSide, ///< Run other text around the side that has the most space 0140 LeftRunAroundSide, ///< Run other text around the left side of the frame 0141 RightRunAroundSide, ///< Run other text around the right side of the frame 0142 EnoughRunAroundSide, ///< Run other text dynamically around both sides of the shape, provided there is sufficient space left 0143 BothRunAroundSide, ///< Run other text around both sides of the shape 0144 NoRunAround, ///< The text will be completely avoiding the frame by keeping the horizontal space that this frame occupies blank. 0145 RunThrough ///< The text will completely ignore the frame and layout as if it was not there 0146 }; 0147 0148 /// The behavior text should do when intersecting this shape. 0149 enum TextRunAroundContour { 0150 ContourBox, /// Run other text around a bounding rect of the outline 0151 ContourFull, ///< Run other text around also on the inside 0152 ContourOutside ///< Run other text around only on the outside 0153 }; 0154 0155 /** 0156 * TODO 0157 */ 0158 enum RunThroughLevel { 0159 Background, 0160 Foreground 0161 }; 0162 0163 /// Fine grained control of allowed user interactions 0164 enum AllowedInteraction { 0165 MoveAllowed = 1, ///< Moving the shape is allowed 0166 ResizeAllowed = 2, ///< Resizing the shape is allowed 0167 ShearingAllowed = 4, ///< Sharing the shape is allowed 0168 RotationAllowed = 8, ///< Rotating the shape is allowed 0169 SelectionAllowed = 16, ///< Selecting the shape is allowed 0170 ContentChangeAllowed = 32, ///< Editing the content is allowed 0171 DeletionAllowed = 64 ///< Deleting the shape is allowed 0172 }; 0173 Q_DECLARE_FLAGS(AllowedInteractions, AllowedInteraction) 0174 Q_FLAGS(AllowedInteractions) 0175 0176 /** 0177 * @brief Constructor 0178 */ 0179 KoShape(); 0180 0181 /** 0182 * @brief Destructor 0183 */ 0184 virtual ~KoShape(); 0185 0186 /** 0187 * @brief Paint the shape 0188 * The class extending this one is responsible for painting itself. Since we do not 0189 * assume the shape is square the paint must also clear its background if it will draw 0190 * something transparent on top. 0191 * This can be done with a method like: 0192 * <code> 0193 painter.fillRect(converter.normalToView(QRectF(QPointF(0.0,0.0), size())), background());</code> 0194 * Or equivalent for non-square objects. 0195 * Do note that a shape's top-left is always at coordinate 0,0. Even if the shape itself is rotated 0196 * or translated. 0197 * @param painter used for painting the shape 0198 * @param converter to convert between internal and view coordinates. 0199 * @see applyConversion() 0200 * @param paintcontext the painting context. 0201 */ 0202 virtual void paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext) = 0; 0203 0204 /** 0205 * @brief Paint the shape's border 0206 * This is a helper function that could be called from the paint() method of all shapes. 0207 * @param painter used for painting the shape 0208 * @param converter to convert between internal and view coordinates. 0209 * @see applyConversion() 0210 */ 0211 virtual void paintBorder(QPainter &painter, const KoViewConverter &converter); 0212 0213 /** 0214 * Load a shape from odf 0215 * 0216 * @param context the KoShapeLoadingContext used for loading 0217 * @param element element which represents the shape in odf 0218 * 0219 * @return false if loading failed 0220 */ 0221 virtual bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) = 0; 0222 0223 /** 0224 * @brief store the shape data as ODF XML. 0225 * This is the method that will be called when saving a shape as a described in 0226 * OpenDocument 9.2 Drawing Shapes. 0227 * @see saveOdfAttributes 0228 */ 0229 virtual void saveOdf(KoShapeSavingContext &context) const = 0; 0230 0231 /** 0232 * This method can be used while saving the shape as ODF to add the data 0233 * stored on this shape to the current element. 0234 * 0235 * @param context the context for the current save. 0236 * @param attributes a number of OdfAttribute items to state which attributes to save. 0237 * @see saveOdf 0238 */ 0239 void saveOdfAttributes(KoShapeSavingContext &context, int attributes) const; 0240 0241 /** 0242 * This method can be used while saving the shape as Odf to add common child elements 0243 * 0244 * The office:event-listeners and draw:glue-point are saved. 0245 * @param context the context for the current save. 0246 */ 0247 void saveOdfCommonChildElements(KoShapeSavingContext &context) const; 0248 0249 /** 0250 * This method can be used to save contour data from the clipPath() 0251 * 0252 * The draw:contour-polygon or draw:contour-path elements are saved. 0253 * @param context the context for the current save. 0254 * @param originalSize the original size of the unscaled image. 0255 */ 0256 void saveOdfClipContour(KoShapeSavingContext &context, const QSizeF &originalSize) const; 0257 0258 /** 0259 * @brief Scale the shape using the zero-point which is the top-left corner. 0260 * @see position() 0261 * 0262 * @param sx scale in x direction 0263 * @param sy scale in y direction 0264 */ 0265 void scale(qreal sx, qreal sy); 0266 0267 /** 0268 * @brief Rotate the shape (relative) 0269 * 0270 * The shape will be rotated from the current rotation using the center of the shape using the size() 0271 * 0272 * @param angle change the angle of rotation increasing it with 'angle' degrees 0273 */ 0274 void rotate(qreal angle); 0275 0276 /** 0277 * Return the current rotation in degrees. 0278 * It returns NaN if the shape has a shearing or scaling transformation applied. 0279 */ 0280 qreal rotation() const; 0281 0282 /** 0283 * @brief Shear the shape 0284 * The shape will be sheared using the zero-point which is the top-left corner. 0285 * @see position() 0286 * 0287 * @param sx shear in x direction 0288 * @param sy shear in y direction 0289 */ 0290 void shear(qreal sx, qreal sy); 0291 0292 /** 0293 * @brief Resize the shape 0294 * 0295 * @param size the new size of the shape. This is different from scaling as 0296 * scaling is a so called secondary operation which is comparable to zooming in 0297 * instead of changing the size of the basic shape. 0298 * Easiest example of this difference is that using this method will not distort the 0299 * size of pattern-fills and strokes. 0300 */ 0301 virtual void setSize(const QSizeF &size); 0302 0303 /** 0304 * @brief Get the size of the shape in pt. 0305 * 0306 * The size is in shape coordinates. 0307 * 0308 * @return the size of the shape as set by setSize() 0309 */ 0310 virtual QSizeF size() const; 0311 0312 /** 0313 * @brief Set the position of the shape in pt 0314 * 0315 * @param position the new position of the shape 0316 */ 0317 virtual void setPosition(const QPointF &position); 0318 0319 /** 0320 * @brief Get the position of the shape in pt 0321 * 0322 * @return the position of the shape 0323 */ 0324 QPointF position() const; 0325 0326 /** 0327 * @brief Check if the shape is hit on position 0328 * @param position the position where the user clicked. 0329 * @return true when it hits. 0330 */ 0331 virtual bool hitTest(const QPointF &position) const; 0332 0333 /** 0334 * @brief Get the bounding box of the shape 0335 * 0336 * This includes the line width and the shadow of the shape 0337 * 0338 * @return the bounding box of the shape 0339 */ 0340 virtual QRectF boundingRect() const; 0341 0342 /** 0343 * @brief Add a connector point to the shape 0344 * 0345 * A connector is a place on the shape that allows a graphical connection to be made 0346 * using a line, for example. 0347 * 0348 * @param point the connection point to add 0349 * @return the id of the new connection point 0350 */ 0351 int addConnectionPoint(const KoConnectionPoint &point); 0352 0353 /** 0354 * Sets data of connection point with specified id. 0355 * 0356 * The position of the connector is restricted to the bounding rectangle of the shape. 0357 * When setting a default connection point, the new position is ignored, as these 0358 * are fixed at their default position. 0359 * The function will insert a new connection point if the specified id was not used 0360 * before. 0361 * 0362 * @param connectionPointId the id of the connection point to set 0363 * @param point the connection point data 0364 * @return false if specified connection point id is invalid, else true 0365 */ 0366 bool setConnectionPoint(int connectionPointId, const KoConnectionPoint &point); 0367 0368 /// Checks if a connection point with the specified id exists 0369 bool hasConnectionPoint(int connectionPointId) const; 0370 0371 /// Returns connection point with specified connection point id 0372 KoConnectionPoint connectionPoint(int connectionPointId) const; 0373 0374 /** 0375 * Return a list of the connection points that have been added to this shape. 0376 * All the points are relative to the shape position, see absolutePosition(). 0377 * @return a list of the connectors that have been added to this shape. 0378 */ 0379 KoConnectionPoints connectionPoints() const; 0380 0381 /// Removes connection point with specified id 0382 void removeConnectionPoint(int connectionPointId); 0383 0384 /// Removes all connection points 0385 void clearConnectionPoints(); 0386 0387 /** 0388 * Add a event action 0389 */ 0390 void addEventAction(KoEventAction *action); 0391 0392 /** 0393 * Remove a event action 0394 */ 0395 void removeEventAction(KoEventAction *action); 0396 0397 /** 0398 * Get all event actions 0399 */ 0400 QSet<KoEventAction *> eventActions() const; 0401 0402 /** 0403 * Return the side text should flow around this shape. This implements the ODF style:wrap 0404 * attribute that specifies how text is displayed around a frame or graphic object. 0405 */ 0406 TextRunAroundSide textRunAroundSide() const; 0407 0408 /** 0409 * Set the side text should flow around this shape. 0410 * @param side the requested side 0411 * @param runThrough run through the foreground or background or... 0412 */ 0413 void setTextRunAroundSide(TextRunAroundSide side, RunThroughLevel runThrough = Background); 0414 0415 /** 0416 * The space between this shape's left edge and text that runs around this shape. 0417 * @return the space around this shape to keep free from text 0418 */ 0419 qreal textRunAroundDistanceLeft() const; 0420 0421 /** 0422 * Set the space between this shape's left edge and the text that run around this shape. 0423 * @param distance the space around this shape to keep free from text 0424 */ 0425 void setTextRunAroundDistanceLeft(qreal distance); 0426 0427 /** 0428 * The space between this shape's top edge and text that runs around this shape. 0429 * @return the space around this shape to keep free from text 0430 */ 0431 qreal textRunAroundDistanceTop() const; 0432 0433 /** 0434 * Set the space between this shape's top edge and the text that run around this shape. 0435 * @param distance the space around this shape to keep free from text 0436 */ 0437 void setTextRunAroundDistanceTop(qreal distance); 0438 0439 /** 0440 * The space between this shape's right edge and text that runs around this shape. 0441 * @return the space around this shape to keep free from text 0442 */ 0443 qreal textRunAroundDistanceRight() const; 0444 0445 /** 0446 * Set the space between this shape's right edge and the text that run around this shape. 0447 * @param distance the space around this shape to keep free from text 0448 */ 0449 void setTextRunAroundDistanceRight(qreal distance); 0450 0451 /** 0452 * The space between this shape's bottom edge and text that runs around this shape. 0453 * @return the space around this shape to keep free from text 0454 */ 0455 qreal textRunAroundDistanceBottom() const; 0456 0457 /** 0458 * Set the space between this shape's bottom edge and the text that run around this shape. 0459 * @param distance the space around this shape to keep free from text 0460 */ 0461 void setTextRunAroundDistanceBottom(qreal distance); 0462 0463 /** 0464 * Return the threshold above which text should flow around this shape. 0465 * The text will not flow around the shape on a side unless the space available on that side 0466 * is above this threshold. Only used when the text run around side is EnoughRunAroundSide. 0467 * @return threshold the threshold 0468 */ 0469 qreal textRunAroundThreshold() const; 0470 0471 /** 0472 * Set the threshold above which text should flow around this shape. 0473 * The text will not flow around the shape on a side unless the space available on that side 0474 * is above this threshold. Only used when the text run around side is EnoughRunAroundSide. 0475 * @param threshold the new threshold 0476 */ 0477 void setTextRunAroundThreshold(qreal threshold); 0478 0479 /** 0480 * Return the how tight text run around is done around this shape. 0481 * @return the contour 0482 */ 0483 TextRunAroundContour textRunAroundContour() const; 0484 0485 /** 0486 * Set how tight text run around is done around this shape. 0487 * @param contour the new contour 0488 */ 0489 void setTextRunAroundContour(TextRunAroundContour contour); 0490 0491 /** 0492 * Set the KoShapeAnchor 0493 */ 0494 void setAnchor(KoShapeAnchor *anchor); 0495 0496 /** 0497 * Return the KoShapeAnchor, or 0 0498 */ 0499 KoShapeAnchor *anchor() const; 0500 0501 /** 0502 * Set the minimum height of the shape. 0503 * Currently it's not respected but only for informational purpose 0504 * @param height the minimum height of the frame. 0505 */ 0506 void setMinimumHeight(qreal height); 0507 0508 /** 0509 * Return the minimum height of the shape. 0510 * @return the minimum height of the shape. Default is 0.0. 0511 */ 0512 qreal minimumHeight() const; 0513 0514 0515 /** 0516 * Set the background of the shape. 0517 * A shape background can be a plain color, a gradient, a pattern, be fully transparent 0518 * or have a complex fill. 0519 * Setting such a background will allow the shape to be filled and will be able to tell 0520 * if it is transparent or not. 0521 * @param background the new shape background. 0522 */ 0523 void setBackground(QSharedPointer<KoShapeBackground> background); 0524 0525 /** 0526 * return the brush used to paint te background of this shape with. 0527 * A QBrush can have a plain color, be fully transparent or have a complex fill. 0528 * setting such a brush will allow the shape to fill itself using that brush and 0529 * will be able to tell if its transparent or not. 0530 * @return the background-brush 0531 */ 0532 QSharedPointer<KoShapeBackground> background() const; 0533 0534 /** 0535 * Returns true if there is some transparency, false if the shape is fully opaque. 0536 * The default implementation will just return if the background has some transparency, 0537 * you should override it and always return true if your shape is not square. 0538 * @return if the shape is (partly) transparent. 0539 */ 0540 virtual bool hasTransparency() const; 0541 0542 /** 0543 * Sets shape level transparency. 0544 * @param transparency the new shape level transparency 0545 */ 0546 void setTransparency(qreal transparency); 0547 0548 /** 0549 * Returns the shape level transparency. 0550 * @param recursive when true takes the parents transparency into account 0551 */ 0552 qreal transparency(bool recursive=false) const; 0553 0554 /** 0555 * Retrieve the z-coordinate of this shape. 0556 * The zIndex property is used to determine which shape lies on top of other objects. 0557 * An shape with a higher z-order is on top, and can obscure another shape. 0558 * @return the z-index of this shape. 0559 * @see setZIndex() 0560 */ 0561 int zIndex() const; 0562 0563 /** 0564 * Set the z-coordinate of this shape. 0565 * The zIndex property is used to determine which shape lies on top of other objects. 0566 * An shape with a higher z-order is on top, and can obscure, another shape. 0567 * <p>Just like two objects having the same x or y coordinate will make them 'touch', 0568 * so will two objects with the same z-index touch on the z plane. In layering the 0569 * shape this, however, can cause a little confusion as one always has to be on top. 0570 * The layering if two overlapping objects have the same index is implementation dependent 0571 * and probably depends on the order in which they are added to the shape manager. 0572 * @param zIndex the new z-index; 0573 */ 0574 void setZIndex(int zIndex); 0575 0576 /** 0577 * Retrieve the run through property of this shape. 0578 * The run through property is used to determine if the shape is behind, inside or before text. 0579 * @return the run through of this shape. 0580 */ 0581 int runThrough(); 0582 0583 /** 0584 * Set the run through property of this shape. 0585 * The run through property is used to determine if the shape is behind, inside or before text. 0586 * @param runThrough the new run through; 0587 */ 0588 virtual void setRunThrough(short int runThrough); 0589 0590 /** 0591 * Changes the Shape to be visible or invisible. 0592 * Being visible means being painted, as well as being used for 0593 * things like guidelines or searches. 0594 * @param on when true; set the shape to be visible. 0595 * @see setGeometryProtected(), setContentProtected(), setSelectable() 0596 */ 0597 void setVisible(bool on); 0598 /** 0599 * Returns current visibility state of this shape. 0600 * Being visible means being painted, as well as being used for 0601 * things like guidelines or searches. 0602 * @param recursive when true, checks visibility recursively 0603 * @return current visibility state of this shape. 0604 * @see isGeometryProtected(), isContentProtected(), isSelectable() 0605 */ 0606 bool isVisible(bool recursive = false) const; 0607 0608 /** 0609 * Changes the shape to be printable or not. The default is true. 0610 * 0611 * If a Shape's print flag is true, the shape will be printed. If 0612 * false, the shape will not be printed. If a shape is not visible (@see isVisible), 0613 * it isPrinted will return false, too. 0614 */ 0615 void setPrintable(bool on); 0616 0617 /** 0618 * Returns the current printable state of this shape. 0619 * 0620 * A shape can be visible but not printable, not printable and not visible 0621 * or visible and printable, but not invisible and still printable. 0622 * 0623 * @return current printable state of this shape. 0624 */ 0625 bool isPrintable() const; 0626 0627 /** 0628 * Makes it possible for the user to select this shape. 0629 * This parameter defaults to true. 0630 * @param selectable when true; set the shape to be selectable by the user. 0631 * @see setGeometryProtected(), setContentProtected(), setVisible() 0632 */ 0633 void setSelectable(bool selectable); 0634 0635 /** 0636 * Returns if this shape can be selected by the user. 0637 * @return true only when the object is selectable. 0638 * @see isGeometryProtected(), isContentProtected(), isVisible() 0639 */ 0640 bool isSelectable() const; 0641 0642 /** 0643 * Tells the shape to have its position/rotation and size protected from user-changes. 0644 * The geometry being protected means the user can not change shape or position of the 0645 * shape. This includes any matrix operation such as rotation. 0646 * @param on when true; set the shape to have its geometry protected. 0647 * @see setContentProtected(), setSelectable(), setVisible() 0648 */ 0649 void setGeometryProtected(bool on); 0650 0651 /** 0652 * Returns current geometry protection state of this shape. 0653 * The geometry being protected means the user can not change shape or position of the 0654 * shape. This includes any matrix operation such as rotation. 0655 * @return current geometry protection state of this shape. 0656 * @see isContentProtected(), isSelectable(), isVisible() 0657 */ 0658 bool isGeometryProtected() const; 0659 0660 /** 0661 * Marks the shape to have its content protected against editing. 0662 * Content protection is a hint for tools to disallow the user editing the content. 0663 * @param protect when true set the shapes content to be protected from user modification. 0664 * @see setGeometryProtected(), setSelectable(), setVisible() 0665 */ 0666 void setContentProtected(bool protect); 0667 0668 /** 0669 * Returns current content protection state of this shape. 0670 * Content protection is a hint for tools to disallow the user editing the content. 0671 * @return current content protection state of this shape. 0672 * @see isGeometryProtected(), isSelectable(), isVisible() 0673 */ 0674 bool isContentProtected() const; 0675 0676 /** 0677 * Returns the parent, or 0 if there is no parent. 0678 * @return the parent, or 0 if there is no parent. 0679 */ 0680 KoShapeContainer *parent() const; 0681 0682 /** 0683 * Set the parent of this shape. 0684 * @param parent the new parent of this shape. Can be 0 if the shape has no parent anymore. 0685 */ 0686 void setParent(KoShapeContainer *parent); 0687 0688 /** 0689 * Request a repaint to be queued. 0690 * The repaint will be of the entire Shape, including its selection handles should this 0691 * shape be selected. 0692 * <p>This method will return immediately and only request a repaint. Successive calls 0693 * will be merged into an appropriate repaint action. 0694 */ 0695 virtual void update() const; 0696 0697 /** 0698 * Request a repaint to be queued. 0699 * The repaint will be restricted to the parameters rectangle, which is expected to be 0700 * in points (the internal coordinates system of KoShape) and it is expected to be 0701 * normalized. 0702 * <p>This method will return immediately and only request a repaint. Successive calls 0703 * will be merged into an appropriate repaint action. 0704 * @param rect the rectangle (in pt) to queue for repaint. 0705 */ 0706 virtual void update(const QRectF &rect) const; 0707 0708 /// Used by compareShapeZIndex() to order shapes 0709 enum ChildZOrderPolicy { 0710 ChildZDefault, 0711 ChildZParentChild = ChildZDefault, ///< normal parent/child ordering 0712 ChildZPassThrough ///< children are considered equal to this shape 0713 }; 0714 0715 /** 0716 * Returns if during compareShapeZIndex() how this shape portrays the values 0717 * of its children. The default behaviour is to let this shape's z values take 0718 * the place of its children values, so you get a parent/child relationship. 0719 * The children are naturally still ordered relatively to their z values 0720 * 0721 * But for special cases (like Calligra's TextShape) it can be overloaded to return 0722 * ChildZPassThrough which means the children keep their own z values 0723 * @returns the z order policy of this shape 0724 */ 0725 virtual ChildZOrderPolicy childZOrderPolicy(); 0726 0727 /** 0728 * This is a method used to sort a list using the STL sorting methods. 0729 * @param s1 the first shape 0730 * @param s2 the second shape 0731 */ 0732 static bool compareShapeZIndex(KoShape *s1, KoShape *s2); 0733 0734 /** 0735 * returns the outline of the shape in the form of a path. 0736 * The outline returned will always be relative to the position() of the shape, so 0737 * moving the shape will not alter the result. The outline is used to draw the stroke 0738 * on, for example. 0739 * @returns the outline of the shape in the form of a path. 0740 */ 0741 virtual QPainterPath outline() const; 0742 0743 /** 0744 * returns the outline of the shape in the form of a rect. 0745 * The outlineRect returned will always be relative to the position() of the shape, so 0746 * moving the shape will not alter the result. The outline is used to calculate 0747 * the boundingRect. 0748 * @returns the outline of the shape in the form of a rect. 0749 */ 0750 virtual QRectF outlineRect() const; 0751 0752 /** 0753 * returns the outline of the shape in the form of a path for the use of painting a shadow. 0754 * 0755 * Normally this would be the same as outline() if there is a fill (background) set on the 0756 * shape and empty if not. However, a shape could reimplement this to return an outline 0757 * even if no fill is defined. A typical example of this would be the picture shape 0758 * which has a picture but almost never a background. 0759 * 0760 * @returns the outline of the shape in the form of a path. 0761 */ 0762 virtual QPainterPath shadowOutline() const; 0763 0764 /** 0765 * Returns the currently set stroke, or 0 if there is no stroke. 0766 * @return the currently set stroke, or 0 if there is no stroke. 0767 */ 0768 KoShapeStrokeModel *stroke() const; 0769 0770 /** 0771 * Set a new stroke, removing the old one. 0772 * @param stroke the new stroke, or 0 if there should be no stroke. 0773 */ 0774 void setStroke(KoShapeStrokeModel *stroke); 0775 0776 /** 0777 * Return the insets of the stroke. 0778 * Convenience method for KoShapeStrokeModel::strokeInsets() 0779 */ 0780 KoInsets strokeInsets() const; 0781 0782 /// Sets the new shadow, removing the old one 0783 void setShadow(KoShapeShadow *shadow); 0784 0785 /// Returns the currently set shadow or 0 if there is no shadow set 0786 KoShapeShadow *shadow() const; 0787 0788 /// Sets the new border, removing the old one. 0789 void setBorder(KoBorder *border); 0790 0791 /// Returns the currently set border or 0 if there is no border set 0792 KoBorder *border() const; 0793 0794 /// Sets a new clip path, removing the old one 0795 void setClipPath(KoClipPath *clipPath); 0796 0797 /// Returns the currently set clip path or 0 if there is no clip path set 0798 KoClipPath * clipPath() const; 0799 0800 /** 0801 * Setting the shape to keep its aspect-ratio has the effect that user-scaling will 0802 * keep the width/hight ratio intact so as not to distort shapes that rely on that 0803 * ratio. 0804 * @param keepAspect the new value 0805 */ 0806 void setKeepAspectRatio(bool keepAspect); 0807 0808 /** 0809 * Setting the shape to keep its aspect-ratio has the effect that user-scaling will 0810 * keep the width/hight ratio intact so as not to distort shapes that rely on that 0811 * ratio. 0812 * @return whether to keep aspect ratio of this shape 0813 */ 0814 bool keepAspectRatio() const; 0815 0816 /** 0817 * Return the position of this shape regardless of rotation/skew/scaling and regardless of 0818 * this shape having a parent (being in a group) or not.<br> 0819 * @param anchor The place on the (unaltered) shape that you want the position of. 0820 * @return the point that is the absolute, centered position of this shape. 0821 */ 0822 QPointF absolutePosition(KoFlake::Position anchor = KoFlake::CenteredPosition) const; 0823 0824 /** 0825 * Move this shape to an absolute position where the end location will be the same 0826 * regardless of the shape's rotation/skew/scaling and regardless of this shape having 0827 * a parent (being in a group) or not.<br> 0828 * The newPosition is going to be the center of the shape. 0829 * This has the convenient effect that: <pre> 0830 shape->setAbsolutePosition(QPointF(0,0)); 0831 shape->rotate(45);</pre> 0832 Will result in the same visual position of the shape as the opposite:<pre> 0833 shape->rotate(45); 0834 shape->setAbsolutePosition(QPointF(0,0));</pre> 0835 * @param newPosition the new absolute center of the shape. 0836 * @param anchor The place on the (unaltered) shape that you set the position of. 0837 */ 0838 void setAbsolutePosition(const QPointF &newPosition, KoFlake::Position anchor = KoFlake::CenteredPosition); 0839 0840 /** 0841 * Set a data object on the shape to be used by an application. 0842 * This is specifically useful when a shape is created in a plugin and that data from that 0843 * shape should be accessible outside the plugin. 0844 * @param userData the new user data, or 0 to delete the current one. 0845 */ 0846 void setUserData(KoShapeUserData *userData); 0847 /** 0848 * Return the current userData. 0849 */ 0850 KoShapeUserData *userData() const; 0851 0852 /** 0853 * Set a data object on the shape to be used by an application. 0854 * This is specifically useful when an application wants to have data that is per shape 0855 * and should be deleted when the shape is destructed. 0856 * @param applicationData the new application data, or 0 to delete the current one. 0857 */ 0858 void setApplicationData(KoShapeApplicationData *applicationData); 0859 0860 /** 0861 * Return the current applicationData. 0862 */ 0863 KoShapeApplicationData *applicationData() const; 0864 0865 /** 0866 * Return the Id of this shape, identifying the type of shape by the id of the factory. 0867 * @see KoShapeFactoryBase::shapeId() 0868 * @return the id of the shape-type 0869 */ 0870 QString shapeId() const; 0871 0872 /** 0873 * Set the Id of this shape. A shapeFactory is expected to set the Id at creation 0874 * so applications can find out what kind of shape this is. 0875 * @see KoShapeFactoryBase::shapeId() 0876 * @param id the ID from the factory that created this shape 0877 */ 0878 void setShapeId(const QString &id); 0879 0880 /** 0881 * Create a matrix that describes all the transformations done on this shape. 0882 * 0883 * The absolute transformation is the combined transformation of this shape 0884 * and all its parents and grandparents. 0885 * 0886 * @param converter if not null, this method uses the converter to mark the right 0887 * offsets in the current view. 0888 */ 0889 QTransform absoluteTransformation(const KoViewConverter *converter) const; 0890 0891 /** 0892 * Applies a transformation to this shape. 0893 * 0894 * The transformation given is relative to the global coordinate system, i.e. the document. 0895 * This is a convenience function to apply a global transformation to this shape. 0896 * @see applyTransformation 0897 * 0898 * @param matrix the transformation matrix to apply 0899 */ 0900 void applyAbsoluteTransformation(const QTransform &matrix); 0901 0902 /** 0903 * Sets a new transformation matrix describing the local transformations on this shape. 0904 * @param matrix the new transformation matrix 0905 */ 0906 void setTransformation(const QTransform &matrix); 0907 0908 /// Returns the shapes local transformation matrix 0909 QTransform transformation() const; 0910 0911 /** 0912 * Applies a transformation to this shape. 0913 * 0914 * The transformation given is relative to the shape coordinate system. 0915 * 0916 * @param matrix the transformation matrix to apply 0917 */ 0918 void applyTransformation(const QTransform &matrix); 0919 0920 /** 0921 * Copy all the settings from the parameter shape and apply them to this shape. 0922 * Settings like the position and rotation to visible and locked. The parent 0923 * is a notable exclusion. 0924 * @param shape the shape to use as original 0925 */ 0926 void copySettings(const KoShape *shape); 0927 0928 /** 0929 * Convenience method that allows people implementing paint() to use the shape 0930 * internal coordinate system directly to paint itself instead of considering the 0931 * views zoom. 0932 * @param painter the painter to alter the zoom level of. 0933 * @param converter the converter for the current views zoom. 0934 */ 0935 static void applyConversion(QPainter &painter, const KoViewConverter &converter); 0936 0937 /** 0938 * @brief Transforms point from shape coordinates to document coordinates 0939 * @param point in shape coordinates 0940 * @return point in document coordinates 0941 */ 0942 QPointF shapeToDocument(const QPointF &point) const; 0943 0944 /** 0945 * @brief Transforms rect from shape coordinates to document coordinates 0946 * @param rect in shape coordinates 0947 * @return rect in document coordinates 0948 */ 0949 QRectF shapeToDocument(const QRectF &rect) const; 0950 0951 /** 0952 * @brief Transforms point from document coordinates to shape coordinates 0953 * @param point in document coordinates 0954 * @return point in shape coordinates 0955 */ 0956 QPointF documentToShape(const QPointF &point) const; 0957 0958 /** 0959 * @brief Transform rect from document coordinates to shape coordinates 0960 * @param rect in document coordinates 0961 * @return rect in shape coordinates 0962 */ 0963 QRectF documentToShape(const QRectF &rect) const; 0964 0965 /** 0966 * Returns the name of the shape. 0967 * @return the shapes name 0968 */ 0969 QString name() const; 0970 0971 /** 0972 * Sets the name of the shape. 0973 * @param name the new shape name 0974 */ 0975 void setName(const QString &name); 0976 0977 /** 0978 * Update the position of the shape in the tree of the KoShapeManager. 0979 */ 0980 void notifyChanged(); 0981 0982 /** 0983 * A shape can be in a state that it is doing processing data like loading or text layout. 0984 * In this case it can be shown on screen probably partially but it should really not be printed 0985 * until it is fully done processing. 0986 * Warning! This method can be blocking for a long time 0987 * @param converter The converter to convert between internal and view coordinates. 0988 * @param asynchronous If set to true the processing will can take place in a different thread and the 0989 * function will not block until the shape is finished. 0990 * In case of printing Flake will call this method from a non-main thread and only 0991 * start printing it when the in case of printing method returned. 0992 * If set to false the processing needs to be done synchronously and will 0993 * block until the result is finished. 0994 */ 0995 virtual void waitUntilReady(const KoViewConverter &converter, bool asynchronous = true) const; 0996 0997 /// checks recursively if the shape or one of its parents is not visible or locked 0998 bool isEditable() const; 0999 1000 /** 1001 * Adds a shape which depends on this shape. 1002 * Making a shape dependent on this one means it will get shapeChanged() called 1003 * on each update of this shape. 1004 * 1005 * If this shape already depends on the given shape, establishing the 1006 * dependency is refused to prevent circular dependencies. 1007 * 1008 * @param shape the shape which depends on this shape 1009 * @return true if dependency could be established, otherwise false 1010 * @see removeDependee(), hasDependee() 1011 */ 1012 bool addDependee(KoShape *shape); 1013 1014 /** 1015 * Removes as shape depending on this shape. 1016 * @see addDependee(), hasDependee() 1017 */ 1018 void removeDependee(KoShape *shape); 1019 1020 /// Returns if the given shape is dependent on this shape 1021 bool hasDependee(KoShape *shape) const; 1022 1023 /// Returns list of shapes depending on this shape 1024 QList<KoShape*> dependees() const; 1025 1026 /// Returns additional snap data the shape wants to have snapping to 1027 virtual KoSnapData snapData() const; 1028 1029 /** 1030 * Set additional attribute 1031 * 1032 * This can be used to attach additional attributes to a shape for attributes 1033 * that are application specific like presentation:placeholder 1034 * 1035 * @param name The name of the attribute in the following form prefix:tag e.g. presentation:placeholder 1036 * @param value The value of the attribute 1037 */ 1038 void setAdditionalAttribute(const QString &name, const QString &value); 1039 1040 /** 1041 * Remove additional attribute 1042 * 1043 * @param name The name of the attribute in the following form prefix:tag e.g. presentation:placeholder 1044 */ 1045 void removeAdditionalAttribute(const QString &name); 1046 1047 /** 1048 * Check if additional attribute is set 1049 * 1050 * @param name The name of the attribute in the following form prefix:tag e.g. presentation:placeholder 1051 * 1052 * @return true if there is a attribute with prefix:tag set, false otherwise 1053 */ 1054 bool hasAdditionalAttribute(const QString &name) const; 1055 1056 /** 1057 * Get additional attribute 1058 * 1059 * @param name The name of the attribute in the following form prefix:tag e.g. presentation:placeholder 1060 * 1061 * @return The value of the attribute if it exists or a null string if not found. 1062 */ 1063 QString additionalAttribute(const QString &name) const; 1064 1065 void setAdditionalStyleAttribute(const char *name, const QString &value); 1066 1067 void removeAdditionalStyleAttribute(const char *name); 1068 1069 QString additionalStyleAttribute(const QByteArray &name) const; 1070 1071 QMap<QByteArray, QString> additionalStyleAttributes() const; 1072 1073 /** 1074 * Returns the filter effect stack of the shape 1075 * 1076 * @return the list of filter effects applied on the shape when rendering. 1077 */ 1078 KoFilterEffectStack *filterEffectStack() const; 1079 1080 /// Sets the new filter effect stack, removing the old one 1081 void setFilterEffectStack(KoFilterEffectStack *filterEffectStack); 1082 1083 /** 1084 * Set the property collision detection. 1085 * Setting this to true will result in calls to shapeChanged() with the CollisionDetected 1086 * parameter whenever either this or another shape is moved/rotated etc and intersects this shape. 1087 * @param detect if true detect collisions. 1088 */ 1089 void setCollisionDetection(bool detect); 1090 1091 /** 1092 * get the property collision detection. 1093 * @returns true if collision detection is on. 1094 */ 1095 bool collisionDetection(); 1096 1097 /** 1098 * Return the tool delegates for this shape. 1099 * In Flake a shape being selected will cause the tool manager to make available all tools that 1100 * can edit the selected shapes. In some cases selecting one shape should allow the tool to 1101 * edit a related shape be available too. The tool delegates allows this to happen by taking 1102 * all the shapes in the set into account on tool selection. 1103 * Notice that if the set is non-empty 'this' shape is no longer looked at. You can choose 1104 * to add itself to the set too. 1105 */ 1106 QSet<KoShape*> toolDelegates() const; 1107 1108 /** 1109 * Set the tool delegates. 1110 * @param delegates the new delegates. 1111 * @see toolDelegates() 1112 */ 1113 void setToolDelegates(const QSet<KoShape*> &delegates); 1114 1115 /** 1116 * Return the hyperlink for this shape. 1117 */ 1118 QString hyperLink () const; 1119 1120 /** 1121 * Set hyperlink for this shape. 1122 * @param hyperLink name. 1123 */ 1124 void setHyperLink(const QString &hyperLink); 1125 1126 /** 1127 * Makes it possible for the user to delete this shape. 1128 * This parameter defaults to true. 1129 * @param deletable when true; set the shape to be deletable by the user. 1130 * @see isDeletable(), setGeometryProtected(), setContentProtected(), setSelectable() 1131 */ 1132 void setDeletable(bool deletable); 1133 1134 /** 1135 * Returns if this shape can be deleted by the user. 1136 * @return true only when this shape is deletable. 1137 * @see setDeletable(), isGeometryProtected(), isContentProtected(), isSelectable() 1138 */ 1139 bool isDeletable() const; 1140 1141 /// Sets the AllowedInteraction @p flag to @p value 1142 void setAllowedInteraction(AllowedInteraction flag, bool value); 1143 /// @return the AllowedInteraction state for @p flag. 1144 /// Convenience method that just calls allowedInteractions(recursive).testFlag(flag). 1145 /// @see allowedInteractions() 1146 bool allowedInteraction(AllowedInteraction flag, bool recursive = true) const; 1147 /// Sets the interactions the user is allowed to perform on this shape to @p interactions 1148 void setAllowedInteractions(AllowedInteractions interactions); 1149 /// @return the interactions the user is allowed to perform on this shape. 1150 /// If @p recursive is false, the shapes flags are returned as is. Use this e.g. for ui. 1151 /// If @p recursive is true: 1152 /// If the shape is not visible, no interactions are allowed. 1153 /// If there is a parent, the parent is checked. 1154 /// 1155 /// @see KoShapeContainer::allowedInteractions() 1156 AllowedInteractions allowedInteractions(bool recursive = true) const; 1157 1158 /** 1159 * \internal 1160 * Returns the private object for use within the flake lib 1161 */ 1162 KoShapePrivate *priv(); 1163 1164 protected: 1165 /// constructor 1166 KoShape(KoShapePrivate &); 1167 1168 /* ** loading saving helper methods */ 1169 /// attributes from ODF 1.1 chapter 9.2.15 Common Drawing Shape Attributes 1170 enum OdfAttribute { 1171 OdfTransformation = 1, ///< Store transformation information 1172 OdfSize = 2, ///< Store size information 1173 OdfPosition = 8, ///< Store position 1174 OdfAdditionalAttributes = 4, ///< Store additional attributes of the shape 1175 OdfCommonChildElements = 16, ///< Event actions and connection points 1176 OdfLayer = 64, ///< Store layer name 1177 OdfStyle = 128, ///< Store the style 1178 OdfId = 256, ///< Store the unique ID 1179 OdfName = 512, ///< Store the name of the shape 1180 OdfZIndex = 1024, ///< Store the z-index 1181 OdfViewbox = 2048, ///< Store the viewbox 1182 1183 /// A mask for all mandatory attributes 1184 OdfMandatories = OdfLayer | OdfStyle | OdfId | OdfName | OdfZIndex, 1185 /// A mask for geometry attributes 1186 OdfGeometry = OdfPosition | OdfSize, 1187 /// A mask for all the attributes 1188 OdfAllAttributes = OdfTransformation | OdfGeometry | OdfAdditionalAttributes | OdfMandatories | OdfCommonChildElements 1189 }; 1190 1191 /** 1192 * This method is used during loading of the shape to load common attributes 1193 * 1194 * @param context the KoShapeLoadingContext used for loading 1195 * @param element element which represents the shape in odf 1196 * @param attributes a number of OdfAttribute items to state which attributes to load. 1197 */ 1198 bool loadOdfAttributes(const KoXmlElement &element, KoShapeLoadingContext &context, int attributes); 1199 1200 /** 1201 * Parses the transformation attribute from the given string 1202 * @param transform the transform attribute string 1203 * @param context the loading context 1204 * @return the resulting transformation matrix 1205 */ 1206 QTransform parseOdfTransform(const QString &transform, KoShapeLoadingContext &context); 1207 1208 /** 1209 * @brief Saves the style used for the shape 1210 * 1211 * This method fills the given style object with the stroke and 1212 * background properties and then adds the style to the context. 1213 * 1214 * @param style the style object to fill 1215 * @param context used for saving 1216 * @return the name of the style 1217 * @see saveOdf 1218 */ 1219 virtual QString saveStyle(KoGenStyle &style, KoShapeSavingContext &context) const; 1220 1221 /** 1222 * Loads the stroke and fill style from the given element. 1223 * 1224 * @param element the xml element to load the style from 1225 * @param context the loading context used for loading 1226 */ 1227 virtual void loadStyle(const KoXmlElement &element, KoShapeLoadingContext &context); 1228 1229 /// Loads the stroke style 1230 KoShapeStrokeModel *loadOdfStroke(const KoXmlElement &element, KoShapeLoadingContext &context) const; 1231 1232 /// Loads the fill style 1233 QSharedPointer<KoShapeBackground> loadOdfFill(KoShapeLoadingContext &context) const; 1234 1235 /// Loads the connection points 1236 void loadOdfGluePoints(const KoXmlElement &element, KoShapeLoadingContext &context); 1237 1238 /// Loads the clip contour 1239 void loadOdfClipContour(const KoXmlElement &element, KoShapeLoadingContext &context, const QSizeF &scaleFactor); 1240 1241 /* ** end loading saving */ 1242 1243 /** 1244 * A hook that allows inheriting classes to do something after a KoShape property changed 1245 * This is called whenever the shape, position rotation or scale properties were altered. 1246 * @param type an indicator which type was changed. 1247 * @param shape the shape. 1248 */ 1249 virtual void shapeChanged(ChangeType type, KoShape *shape = 0); 1250 1251 /// return the current matrix that contains the rotation/scale/position of this shape 1252 QTransform transform() const; 1253 1254 KoShapePrivate *d_ptr; 1255 1256 private: 1257 Q_DECLARE_PRIVATE(KoShape) 1258 }; 1259 1260 Q_DECLARE_METATYPE(KoShape*) 1261 Q_DECLARE_OPERATORS_FOR_FLAGS(KoShape::AllowedInteractions) 1262 1263 #endif