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_NODE_TOOL_H 0021 #define TIKZ_UI_NODE_TOOL_H 0022 0023 #include "AbstractTool.h" 0024 #include "Handle.h" 0025 0026 #include <QVector> 0027 #include <memory> 0028 0029 namespace tikz { 0030 0031 namespace core { 0032 class Transaction; 0033 } 0034 0035 namespace ui { 0036 0037 class NodeItem; 0038 0039 /** 0040 * The NodeTool allows to modify a NodeItem. 0041 * The supported operations are: move, resize, rotate. 0042 */ 0043 class NodeTool : public AbstractTool 0044 { 0045 Q_OBJECT 0046 0047 public: 0048 /** 0049 * Constructor with graphics scene @p scene. 0050 */ 0051 NodeTool(NodeItem * node, QGraphicsScene * scene); 0052 0053 /** 0054 * Virtual destructor. 0055 */ 0056 virtual ~NodeTool(); 0057 0058 // 0059 // sub classes: reimplement as needed 0060 // 0061 public: 0062 /** 0063 * This function is called whenever the mouse moves in the graphics 0064 * scene. 0065 */ 0066 void mouseMoveEvent(QGraphicsSceneMouseEvent * event) override; 0067 0068 /** 0069 * This function is called whenever a mouse button is pressed in the 0070 * graphics scene. 0071 */ 0072 void mousePressEvent(QGraphicsSceneMouseEvent * event) override; 0073 0074 /** 0075 * This function is called whenever a mouse button is released in the 0076 * graphics scene. 0077 */ 0078 void mouseReleaseEvent(QGraphicsSceneMouseEvent * event) override; 0079 0080 /** 0081 * Reimplemented to cache key events 0082 */ 0083 void keyPressEvent(QKeyEvent * event) override; 0084 0085 // 0086 // internal to NodeTool 0087 // 0088 protected Q_SLOTS: 0089 /** 0090 * Make sure the handles are positioned at the correct location 0091 */ 0092 void updateHandlePositions(); 0093 0094 /** 0095 * Create node handles for the node. 0096 */ 0097 void createNodeHandles(); 0098 0099 /** 0100 * This slot is called whenever a handle moved. 0101 * The node is then either moved, resized or rotated according to 0102 * the sender @p handle. 0103 * @param handle the handle that moved 0104 * @param scenePos the mouse move position in scene coordinates 0105 * @param view the view that generated this event 0106 */ 0107 void handleMoved(tikz::ui::Handle * handle, const QPointF & scenePos, QGraphicsView * view); 0108 0109 /** 0110 * This slot is called whenever a handle was pressed with the mouse. 0111 */ 0112 void handleMousePressed(tikz::ui::Handle * handle, const QPointF & scenePos, QGraphicsView * view); 0113 0114 /** 0115 * This slot is called whenever a handle was released with the mouse. 0116 */ 0117 void handleMouseReleased(tikz::ui::Handle * handle, const QPointF & scenePos, QGraphicsView * view); 0118 0119 protected: 0120 /** 0121 * Get the handle position for a specific handle in scene coordinates. 0122 */ 0123 QPointF handlePos(Handle::Position pos); 0124 0125 0126 private: 0127 NodeItem * m_node; 0128 QVector<Handle *> m_handles; 0129 std::unique_ptr<tikz::core::Transaction> m_transaction; 0130 }; 0131 0132 } 0133 } 0134 0135 #endif // TIKZ_UI_NODE_TOOL_H 0136 0137 // kate: indent-width 4; replace-tabs on;