libs/flake

KoShape.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2006-2008 Thorsten Zachmann <zachmann@kde.org>
00003    Copyright (C) 2006, 2008 Casper Boemann <cbr@boemann.dk>
00004    Copyright (C) 2006-2009 Thomas Zander <zander@kde.org>
00005    Copyright (C) 2007-2009 Jan Hambrecht <jaham@gmx.net>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #ifndef KOSHAPE_H
00024 #define KOSHAPE_H
00025 
00026 #include "KoInsets.h"
00027 #include "KoFlake.h"
00028 
00029 #include <QMatrix>
00030 #include <QVector>
00031 #include <QSet>
00032 #include <QMap>
00033 #include <QBrush>
00034 #include <QMetaType>
00035 
00036 #include <KoXmlReaderForward.h>
00037 #include <KoSnapData.h>
00038 
00039 #include "flake_export.h"
00040 
00041 class QPainter;
00042 class QRectF;
00043 class QPainterPath;
00044 
00045 class KoShapeContainer;
00046 class KoShapeBorderModel;
00047 class KoShapeBackground;
00048 class KoShapeManager;
00049 class KoShapeUserData;
00050 class KoViewConverter;
00051 class KoShapeApplicationData;
00052 class KoShapeSavingContext;
00053 class KoCanvasBase;
00054 class KoShapeLoadingContext;
00055 class KoGenStyle;
00056 class KoShapeControllerBase;
00057 class KoDataCenter;
00058 class KoShapeShadow;
00059 class KoEventAction;
00060 class KoShapePrivate;
00061 class KoFilterEffectStack;
00062 
00106 class FLAKE_EXPORT KoShape
00107 {
00108 public:
00110     enum ChangeType {
00111         PositionChanged, 
00112         RotationChanged, 
00113         ScaleChanged,   
00114         ShearChanged,   
00115         SizeChanged,    
00116         GenericMatrixChange,    
00117         ParentChanged,   
00118         CollisionDetected, 
00119         Deleted, 
00120         BorderChanged, 
00121         BackgroundChanged, 
00122         ShadowChanged, 
00123         ParameterChanged, 
00124         ContentChanged, 
00125         ChildChanged 
00126     };
00127 
00131     KoShape();
00132 
00136     virtual ~KoShape();
00137 
00153     virtual void paint(QPainter &painter, const KoViewConverter &converter) = 0;
00154 
00164     virtual void paintDecorations(QPainter &painter, const KoViewConverter &converter, const KoCanvasBase *canvas);
00165 
00174     virtual bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) = 0;
00175 
00182     virtual void saveOdf(KoShapeSavingContext &context) const = 0;
00183 
00192     void saveOdfAttributes(KoShapeSavingContext &context, int attributes) const;
00193 
00199     void saveOdfCommonChildElements(KoShapeSavingContext &context) const;
00200 
00206     virtual void init(const QMap<QString, KoDataCenter*> &dataCenterMap);
00207 
00215     void setScale(qreal sx, qreal sy);
00216 
00224     void rotate(qreal angle);
00225 
00230     qreal rotation() const;
00231 
00240     void setShear(qreal sx, qreal sy);
00241 
00251     virtual void setSize(const QSizeF &size);
00252 
00260     virtual QSizeF size() const;
00261 
00267     virtual void setPosition(const QPointF &position);
00268 
00274     QPointF position() const;
00275 
00281     virtual bool hitTest(const QPointF &position) const;
00282 
00290     virtual QRectF boundingRect() const;
00291 
00302     void addConnectionPoint(const QPointF &point);
00303 
00309     QList<QPointF> connectionPoints() const;
00310 
00314     void addEventAction(KoEventAction *action);
00315 
00319     void removeEventAction(KoEventAction *action);
00320 
00324     QList<KoEventAction *> eventActions() const;
00325 
00334     void setBackground(KoShapeBackground *background);
00335 
00343     KoShapeBackground *background() const;
00344 
00351     virtual bool hasTransparency();
00352 
00360     int zIndex() const;
00361 
00373     void setZIndex(int zIndex);
00374 
00382     void setVisible(bool on);
00391     bool isVisible(bool recursive = false) const;
00392 
00400     void setPrintable(bool on);
00401 
00410     bool isPrintable() const;
00411 
00418     void setSelectable(bool selectable);
00419 
00425     bool isSelectable() const;
00426 
00434     void setGeometryProtected(bool on);
00435 
00443     bool isGeometryProtected() const;
00444 
00451     void setContentProtected(bool protect);
00452 
00459     bool isContentProtected() const;
00460 
00465     KoShapeContainer *parent() const;
00466 
00471     void setParent(KoShapeContainer *parent);
00472 
00480     virtual void update() const;
00481 
00491     virtual void update(const QRectF &shape) const;
00492 
00498     static bool compareShapeZIndex(KoShape *s1, KoShape *s2);
00499 
00507     virtual QPainterPath outline() const;
00508 
00513     KoShapeBorderModel *border() const;
00514 
00519     void setBorder(KoShapeBorderModel *border);
00520 
00525     KoInsets borderInsets() const;
00526 
00528     void setShadow(KoShapeShadow *shadow);
00529 
00531     KoShapeShadow *shadow() const;
00532 
00539     void setKeepAspectRatio(bool keepAspect);
00540 
00547     bool keepAspectRatio() const;
00548 
00555     QPointF absolutePosition(KoFlake::Position anchor = KoFlake::CenteredPosition) const;
00556 
00571     void setAbsolutePosition(QPointF newPosition, KoFlake::Position anchor = KoFlake::CenteredPosition);
00572 
00579     void setUserData(KoShapeUserData *userData);
00583     KoShapeUserData *userData() const;
00584 
00591     void setApplicationData(KoShapeApplicationData *applicationData);
00592 
00596     KoShapeApplicationData *applicationData() const;
00597 
00603     QString shapeId() const;
00604 
00611     void setShapeId(const QString &id);
00612 
00622     QMatrix absoluteTransformation(const KoViewConverter *converter) const;
00623 
00633     void applyAbsoluteTransformation(const QMatrix &matrix);
00634 
00639     void setTransformation(const QMatrix &matrix);
00640 
00642     QMatrix transformation() const;
00643 
00651     void applyTransformation(const QMatrix &matrix);
00652 
00659     virtual void copySettings(const KoShape *shape);
00660 
00668     static void applyConversion(QPainter &painter, const KoViewConverter &converter);
00669 
00675     QPointF shapeToDocument(const QPointF &point) const;
00676 
00682     QRectF shapeToDocument(const QRectF &rect) const;
00683 
00689     QPointF documentToShape(const QPointF &point) const;
00690 
00696     QRectF documentToShape(const QRectF &rect) const;
00697 
00702     QString name() const;
00703 
00708     void setName(const QString &name);
00709 
00713     void notifyChanged();
00714 
00727     virtual void waitUntilReady(const KoViewConverter &converter, bool asynchronous = true) const;
00728 
00740     void deleteLater();
00741 
00743     bool isEditable() const;
00744 
00746     void removeConnectionPoint(int index);
00747 
00757     bool addDependee(KoShape *shape);
00758 
00760     void removeDependee(KoShape *shape);
00761 
00763     bool hasDependee(KoShape *shape) const;
00764 
00766     virtual KoSnapData snapData() const;
00767 
00777     void setAdditionalAttribute(const char *name, const QString &value);
00778 
00784     void removeAdditionalAttribute(const char *name);
00785 
00793     bool hasAdditionalAttribute(const char *name) const;
00794 
00802     QString additionalAttribute(const char *name) const;
00803 
00804     void setAdditionalStyleAttribute(const char *name, const QString &value);
00805 
00806     void removeAdditionalStyleAttribute(const char *name);
00807 
00813     KoFilterEffectStack *filterEffectStack() const;
00814 
00816     void setFilterEffectStack(KoFilterEffectStack *filterEffectStack);
00817 
00818 protected:
00820     KoShape(KoShapePrivate &);
00821 
00822     /* ** loading saving helper methods */
00824     enum OdfAttribute {
00825         OdfTransformation = 1,       
00826         OdfSize = 2,                 
00827         OdfPosition = 8,             
00828         OdfAdditionalAttributes = 4, 
00829         OdfCommonChildElements = 16, 
00830         OdfLayer = 64,               
00831         OdfStyle = 128,              
00832         OdfId = 256,                 
00833         OdfName = 512,               
00834         OdfZIndex = 1024,            
00835         OdfViewbox = 2048,           
00836 
00838         OdfMandatories = OdfLayer | OdfStyle | OdfId | OdfName | OdfZIndex,
00840         OdfGeometry = OdfPosition | OdfSize,
00842         OdfAllAttributes = OdfTransformation | OdfGeometry | OdfAdditionalAttributes | OdfMandatories | OdfCommonChildElements
00843     };
00844 
00852     bool loadOdfAttributes(const KoXmlElement &element, KoShapeLoadingContext &context, int attributes);
00853 
00859     QMatrix parseOdfTransform(const QString &transform);
00860 
00872     virtual QString saveStyle(KoGenStyle &style, KoShapeSavingContext &context) const;
00873 
00880     virtual void loadStyle(const KoXmlElement &element, KoShapeLoadingContext &context);
00881 
00883     //QBrush loadOdfFill( const KoXmlElement & element, KoShapeLoadingContext & context );
00884     KoShapeBackground *loadOdfFill(const KoXmlElement &element, KoShapeLoadingContext &context);
00885 
00887     KoShapeBorderModel *loadOdfStroke(const KoXmlElement &element, KoShapeLoadingContext &context);
00888 
00890     KoShapeShadow *loadOdfShadow(const KoXmlElement &element, KoShapeLoadingContext &context);
00891 
00895     QString getStyleProperty(const char *property, const KoXmlElement &element, KoShapeLoadingContext &context);
00896 
00897     /* ** end loading saving */
00898 
00899 
00905     virtual void shapeChanged(ChangeType type, KoShape *shape = 0);
00906 
00913     void setCollisionDetection(bool detect);
00914 
00919     bool collisionDetection();
00920 
00922     QMatrix matrix() const;
00923 
00924     KoShapePrivate *d_ptr;
00925 
00926 private:
00927     friend class KoShapeManager;
00928     void addShapeManager(KoShapeManager *manager);
00929     void removeShapeManager(KoShapeManager *manager);
00930 
00931     Q_DECLARE_PRIVATE(KoShape)
00932 };
00933 
00934 Q_DECLARE_METATYPE(KoShape*)
00935 
00936 #endif