File indexing completed on 2024-05-19 04:36:38
0001 /* This file is part of the TikZKit project. 0002 * 0003 * Copyright (C) 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_ANCHOR_MANAGER_H 0021 #define TIKZ_UI_ANCHOR_MANAGER_H 0022 0023 #include <QObject> 0024 #include <QVector> 0025 #include <QHash> 0026 0027 #include <tikz/core/MetaPos.h> 0028 0029 class QGraphicsScene; 0030 class QGraphicsView; 0031 0032 namespace tikz { 0033 namespace ui { 0034 0035 class DocumentPrivate; 0036 class NodeItem; 0037 class AnchorHandle; 0038 0039 class AnchorManager : public QObject 0040 { 0041 Q_OBJECT 0042 0043 public: 0044 /** 0045 * Constructor. 0046 */ 0047 AnchorManager(QGraphicsScene * scene, tikz::ui::DocumentPrivate * document, QObject * parent = nullptr); 0048 0049 /** 0050 * Destructor. 0051 */ 0052 virtual ~AnchorManager(); 0053 0054 /** 0055 * Returns the associated QGraphicsScene. 0056 */ 0057 QGraphicsScene * scene() const; 0058 0059 // 0060 // show/hide Node anchor handles 0061 // 0062 public Q_SLOTS: 0063 /** 0064 * Hide all existing anchor handles. 0065 */ 0066 void hideAnchors(); 0067 0068 /** 0069 * Show all existing anchor handles. 0070 */ 0071 void showAnchors(); 0072 0073 /** 0074 * Add all Node%s in the document. 0075 */ 0076 void addAllNodes(); 0077 0078 /** 0079 * Add all Node anchors for @p node. 0080 */ 0081 void addNode(NodeItem * node); 0082 0083 /** 0084 * Removes all Node anchors for @p node. 0085 */ 0086 void removeNode(NodeItem * node); 0087 0088 /** 0089 * Remove all 0090 */ 0091 void clear(); 0092 0093 public: 0094 /** 0095 * Get the node with anchor for the scene position @p scenePos. 0096 * If a node/anchor qt @p scenePos exists, the returned MetaPos 0097 * contains the metaPos->node() and metaPos->anchor(), otherwise 0098 * the returned MetaPos points to @p scenePos. 0099 * 0100 * The QGraphicsView @p view is required, since @p scenePos must first 0101 * be transformed into view coordinates as the handles have the flag 0102 * QGraphicsItem::ItemIgnoresTransformations is set. 0103 */ 0104 tikz::core::MetaPos anchorAt(const QPointF & scenePos, 0105 QGraphicsView * view); 0106 0107 // 0108 // internal to the manager 0109 // 0110 protected Q_SLOTS: 0111 /** 0112 * This slot is called right before a node is destroyed. At this point, 0113 * the node is already half destroyed, i.e., only the QObject part is 0114 * still valid. 0115 */ 0116 void nodeDestroyed(QObject * obj); 0117 0118 private: 0119 tikz::ui::DocumentPrivate * m_doc; 0120 QGraphicsScene * m_scene; 0121 QVector <NodeItem *> m_nodes; 0122 QHash <NodeItem *, QVector<AnchorHandle *>> m_handleMap; 0123 }; 0124 0125 } 0126 } 0127 0128 #endif // TIKZ_UI_ANCHOR_MANAGER_H 0129 0130 // kate: indent-width 4; replace-tabs on;