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