libs/flake

KoConnectionShape.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  * Copyright (C) 2007 Boudewijn Rempt <boud@kde.org>
00003  * Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
00004  * Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #ifndef KO_CONNECTION_SHAPE_H
00023 #define KO_CONNECTION_SHAPE_H
00024 
00025 #include <KoParameterShape.h>
00026 
00027 #include "flake_export.h"
00028 
00029 #define KOCONNECTIONSHAPEID "KoConnectionShape"
00030 
00032 typedef QPair<KoShape*, int> KoConnection;
00033 
00034 class FLAKE_EXPORT KoConnectionShape : public KoParameterShape
00035 {
00036 public:
00037     enum Type {
00038         Standard, 
00039         Lines,    
00040         Straight, 
00041         Curve     
00042     };
00043 
00044     explicit KoConnectionShape();
00045     virtual ~KoConnectionShape();
00046 
00047     // reimplemented
00048     virtual void paint(QPainter& painter, const KoViewConverter& converter);
00049 
00050     // reimplemented
00051     virtual void saveOdf(KoShapeSavingContext & context) const;
00052 
00053     // reimplemented
00054     virtual bool loadOdf(const KoXmlElement & element, KoShapeLoadingContext &context);
00055 
00056     // reimplemented
00057     inline QString pathShapeId() const {
00058         return KOCONNECTIONSHAPEID;
00059     }
00060 
00061     // reimplemented
00062     virtual bool hitTest(const QPointF &position) const;
00063 
00073     bool setConnection1(KoShape * shape1, int connectionPointIndex);
00074 
00084     bool setConnection2(KoShape * shape2, int connectionPointIndex);
00085 
00087     KoConnection connection1() const;
00088 
00090     KoConnection connection2() const;
00091 
00093     void updateConnections();
00094 
00096     Type connectionType() const;
00097 
00099     void setConnectionType(Type connectionType);
00100 
00101 protected:
00103     void moveHandleAction(int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
00104 
00106     void updatePath(const QSizeF &size);
00107 
00109     bool handleConnected(int handleId) const;
00110 
00112     QPointF escapeDirection(int handleId) const;
00113 
00115     bool intersects(const QPointF &p1, const QPointF &d1, const QPointF &p2, const QPointF &d2, QPointF &isect);
00116 
00118     QPointF perpendicularDirection(const QPointF &p1, const QPointF &d1, const QPointF &p2);
00119 
00121     virtual void shapeChanged(ChangeType type, KoShape * shape);
00122 
00124     void normalPath( const qreal MinimumEscapeLength );
00125 
00126 private:
00127     qreal scalarProd(const QPointF &v1, const QPointF &v2);
00128     qreal crossProd(const QPointF &v1, const QPointF &v2);
00129 
00130     QList<QPointF> m_path;
00131     bool m_hasMoved;
00132 
00133     struct Private;
00134     Private * const d;
00135 };
00136 
00137 
00138 #endif