File indexing completed on 2024-05-19 04:36:37

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2013-2014 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef TIKZ_UI_ABSTRACT_SHAPE_H
0021 #define TIKZ_UI_ABSTRACT_SHAPE_H
0022 
0023 #include <QPointF>
0024 #include <QPainterPath>
0025 #include <QStringList>
0026 
0027 #include <tikz/core/tikz.h>
0028 
0029 namespace tikz {
0030 namespace ui {
0031 
0032 class NodeItem;
0033 class AbstractShapePrivate;
0034 
0035 class AbstractShape
0036 {
0037     public:
0038         /**
0039          * Default constructor
0040          */
0041         AbstractShape(NodeItem * node);
0042 
0043         /**
0044          * Default constructor
0045          */
0046         virtual ~AbstractShape();
0047 
0048         /**
0049          * Returns the pointer to the node passed in the constructor.
0050          */
0051         NodeItem* node() const;
0052 
0053     //
0054     // Shape properties
0055     //
0056     public:
0057         /**
0058          * Returns the type of this shape.
0059          */
0060         virtual tikz::Shape type() const;
0061 
0062         /**
0063          * This function is called by NodeItem::shapeRect().
0064          * The shape can adjust the calculated @p shapeRect if needed.
0065          *
0066          * Example:
0067          * The shape 'rectangle' does not need to modify the @p shapeRect,
0068          * since the @p textRect perfectly fits into @p shapeRect.
0069          * The shape 'circle' however needs to increase the @p shapeRect such
0070          * that the circle filling @p shapeRect includes the @p textRect.
0071          *
0072          * @param textRect the bounding box of the textRect
0073          * @param shapeRect the rect of the shape, inner sep already included.
0074          */
0075         virtual void adjustShapeRect(const QRectF & textRect, QRectF & shapeRect) const;
0076 
0077         /**
0078          * Returns the painter path of this shape.
0079          * This path is also used to draw the shape.
0080          */
0081         virtual QPainterPath shape() const;
0082 
0083         /**
0084          * Returns the outline of this shape.
0085          *
0086          * Think of the outline as the shape(), stroked with a thick pen.
0087          * As result, the shape 'grows' a bit in all directions, depending on
0088          * the pen's width. Every shape should reimplement this function to
0089          * ensure the outline contains exactly the \e drawn shape.
0090          *
0091          * The outline is used to check mouse click & move events, and also
0092          * to check for collisions.
0093          *
0094          * The default implementation returns shape().
0095          */
0096         virtual QPainterPath outline() const;
0097 
0098         /**
0099          * Returns a list of anchors the shape supports.
0100          */
0101         virtual QStringList supportedAnchors() const;
0102 
0103         /**
0104          * Returns the position of @p anchor in local node coordinates.
0105          */
0106         virtual QPointF anchorPos(const QString & anchor) const;
0107 
0108         /**
0109          * Returns the contact point for @p anchor and angle @p rad.
0110          */
0111         virtual QPointF contactPoint(const QString & anchor, qreal rad) const;
0112 
0113     private:
0114         AbstractShapePrivate * const d;
0115 };
0116 
0117 /**
0118  * Factory function to get shapes
0119  */
0120 extern AbstractShape *createShape(tikz::Shape shape, NodeItem* node);
0121 
0122 }
0123 }
0124 
0125 #endif // TIKZ_UI_ABSTRACT_SHAPE_H
0126 
0127 // kate: indent-width 4; replace-tabs on;