1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
/* This file is part of the KDE project
*
* Copyright (C) 2009 Jean-Nicolas Artaud <jeannicolasartaud@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KO_CONNECTION_TOOL_H
#define KO_CONNECTION_TOOL_H
#define ConnectionTool_ID "ConnectionTool"
#include "KoPathTool.h"
#include <KoConnectionShape.h>
#include <KoCanvasBase.h>
class ConnectionTool : public KoPathTool
{
Q_OBJECT
public:
/**
* @brief Constructor
*/
explicit ConnectionTool( KoCanvasBase * canvas );
/**
* @brief Destructor
*/
~ConnectionTool();
/// reimplemented from superclass
virtual void paint( QPainter &painter, const KoViewConverter &converter );
/// reimplemented from superclass
virtual void mousePressEvent( KoPointerEvent *event ) ;
/// reimplemented from superclass
virtual void mouseMoveEvent( KoPointerEvent *event );
/// reimplemented from superclass
virtual void mouseReleaseEvent( KoPointerEvent *event );
/// reimplemented from superclass
virtual void keyPressEvent( QKeyEvent *event );
/// reimplemented from superclass
virtual void activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes);
/// reimplemented from superclass
virtual void deactivate();
/**
* @brief Modify connections if they are on a shape and not the nearest one
*/
void updateConnections();
/**
* @brief Return the index of the nearest connection point of the shape with the point
*
* @param shape The shape to connect
* @param point The point to connect
* @return The index of the nearest point
*/
int getConnectionIndex( KoShape * shape, QPointF point );
/**
* @brief Return the square of the absolute distance between p1 and p2
*
* @param p1 The first point
* @param p2 The second point
* @return The float which is the square of the distance
*/
float distanceSquare( QPointF p1, QPointF p2 );
/**
* @brief Return true if the mouse is near to a connection point
*/
bool isInRoi();
/**
* @brief Permit to activate the connection with a comand
*/
void command();
private:
KoShape * m_shape1;
int m_firstHandleIndex;
KoShape * m_shapeOn;
KoShape * m_lastShapeOn;
QPointF * m_pointSelected;
QPointF m_mouse;
int m_activeHandle;
KoConnectionShape * m_connectionShape;
KoConnectionShape * m_lastConnectionShapeOn;
QPair<bool,bool> * m_isTied;
bool m_modifyConnection;
};
#endif
|