File indexing completed on 2024-05-05 04:35:18

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_NODE_ITEM_H
0021 #define TIKZ_UI_NODE_ITEM_H
0022 
0023 #include "tikzui_export.h"
0024 
0025 #include "TikzItem.h"
0026 
0027 #include <tikz/core/Node.h>
0028 
0029 class QPainter;
0030 
0031 namespace tikz {
0032 
0033 namespace core {
0034     class Style;
0035 }
0036 
0037 namespace ui {
0038 
0039 class DocumentPrivate;
0040 class NodeItemPrivate;
0041 
0042 class TIKZKITUI_EXPORT NodeItem : public TikzItem
0043 {
0044     Q_OBJECT
0045 
0046     public:
0047         /**
0048          * Constructor for @p node and parent @p parent.
0049          */
0050         NodeItem(tikz::core::Node * node, QGraphicsItem * parent = nullptr);
0051 
0052         /**
0053          * Destructor
0054          */
0055         virtual ~NodeItem();
0056 
0057         /**
0058          * Returns the associated document, if available.
0059          */
0060         DocumentPrivate * document() const;
0061 
0062         /**
0063          * Reimplment to return a proper UserType + 2.
0064          */
0065         int type() const override;
0066 
0067         /**
0068          * Returns the pointer to the associated Node.
0069          */
0070         tikz::core::Node * node();
0071 
0072         /**
0073          * Returns node().uid();
0074          */
0075         tikz::core::Uid uid() const;
0076 
0077         /**
0078          * Returns the style of this node.
0079          * This is the same as node().style().
0080          */
0081         tikz::core::Style* style() const;
0082 
0083     //
0084     // anchor methods
0085     //
0086     public:
0087         /**
0088          * Returns the list of supported anchors depending on the Node's current shape.
0089          */
0090         QStringList supportedAnchors() const;
0091 
0092         /**
0093          * Returns the @p anchor in scene coordinates.
0094          */
0095         tikz::Pos anchor(const QString & anchor) const;
0096 
0097         /**
0098          * Returns the contact point of this node's shape for the requested
0099          * @p anchor and angle @p rad in scene coordinates.
0100          * @param anchor the anchor
0101          * @param rad the angle in rad
0102          */
0103         QPointF contactPoint(const QString & anchor, qreal rad) const;
0104 
0105         /**
0106          * Returns the rect of this shape.
0107          * Node properties such as scaling and minimum size is included.
0108          * However, the style()->outerSep() is NOt included.
0109          */
0110         QRectF shapeRect() const;
0111 
0112     //
0113     // reimplemented from QGraphicsItem
0114     //
0115     public:
0116         /**
0117          * Paint this item.
0118          */
0119         void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
0120 
0121         /**
0122          * Returns the bounding rect of this item.
0123          */
0124         QRectF boundingRect() const override;
0125 
0126         /**
0127          * Returns an exact shape as painter path
0128          */
0129         QPainterPath shape() const override;
0130 
0131         /**
0132          * Returns @p true, if @p point is contained in this node.
0133          */
0134 //         bool contains(const QPointF &point) const;
0135 
0136     Q_SIGNALS:
0137         /**
0138          * This signal is emitted whenever this node changes, e.g. its style.
0139          */
0140         void changed();
0141 
0142     //
0143     // protected overrides
0144     //
0145     protected:
0146         QVariant itemChange(GraphicsItemChange change, const QVariant & value) override;
0147 
0148     protected Q_SLOTS:
0149         void slotSetPos(const QPointF& pos);
0150         void styleChanged();
0151 
0152     //
0153     // internal
0154     //
0155     private:
0156         /**
0157          * Private default constructor, not implemented
0158          */
0159         NodeItem();
0160 
0161     private:
0162         NodeItemPrivate * const d;
0163 };
0164 
0165 }
0166 }
0167 
0168 #endif // TIKZ_UI_NODE_ITEM_H
0169 
0170 // kate: indent-width 4; replace-tabs on;