00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "KoPathToolHandle.h"
00024 #include "KoPathTool.h"
00025 #include "KoPathPointMoveStrategy.h"
00026 #include "KoPathControlPointMoveStrategy.h"
00027 #include "KoPathConnectionPointStrategy.h"
00028 #include "commands/KoPathPointTypeCommand.h"
00029 #include "KoParameterChangeStrategy.h"
00030 #include <KoParameterShape.h>
00031 #include <KoCanvasBase.h>
00032 #include <KoCanvasResourceProvider.h>
00033 #include <KoShapeManager.h>
00034 #include <KoConnectionShape.h>
00035 #include <KoViewConverter.h>
00036 #include <KoPointerEvent.h>
00037 #include <QtGui/QPainter>
00038
00039 KoPathToolHandle::KoPathToolHandle(KoPathTool *tool)
00040 : m_tool(tool)
00041 {
00042 }
00043
00044 KoPathToolHandle::~KoPathToolHandle()
00045 {
00046 }
00047
00048 PointHandle::PointHandle(KoPathTool *tool, KoPathPoint *activePoint, KoPathPoint::KoPointType activePointType)
00049 : KoPathToolHandle(tool)
00050 , m_activePoint(activePoint)
00051 , m_activePointType(activePointType)
00052 {
00053 }
00054
00055 void PointHandle::paint(QPainter &painter, const KoViewConverter &converter)
00056 {
00057 painter.save();
00058 painter.setMatrix(m_activePoint->parent()->absoluteTransformation(&converter) * painter.matrix());
00059 KoShape::applyConversion(painter, converter);
00060
00061 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
00062
00063 KoPathPoint::KoPointType type = KoPathPoint::Node;
00064 if (selection && selection->contains(m_activePoint))
00065 type = KoPathPoint::All;
00066 int handleRadius = m_tool->canvas()->resourceProvider()->handleRadius();
00067 m_activePoint->paint(painter, handleRadius, type);
00068 painter.restore();
00069 }
00070
00071 void PointHandle::repaint() const
00072 {
00073 bool active = false;
00074 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
00075 if (selection && selection->contains(m_activePoint))
00076 active = true;
00077 m_tool->repaint(m_activePoint->boundingRect(!active));
00078 }
00079
00080 KoInteractionStrategy * PointHandle::handleMousePress(KoPointerEvent *event)
00081 {
00082 if ((event->button() & Qt::LeftButton) == 0)
00083 return 0;
00084 if ((event->modifiers() & Qt::ShiftModifier) == 0) {
00085 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
00086
00087
00088 if (event->modifiers() & Qt::ControlModifier) {
00089 if (selection->contains(m_activePoint)) {
00090 selection->remove(m_activePoint);
00091 } else {
00092 selection->add(m_activePoint, false);
00093 }
00094 m_tool->repaint(m_activePoint->boundingRect(false));
00095 } else {
00096
00097 if (!selection->contains(m_activePoint)) {
00098 selection->add(m_activePoint, true);
00099 m_tool->repaint(m_activePoint->boundingRect(false));
00100 }
00101 }
00102
00103 if (m_activePointType == KoPathPoint::Node) {
00104 QPointF startPoint = m_activePoint->parent()->shapeToDocument(m_activePoint->point());
00105 return new KoPathPointMoveStrategy(m_tool, m_tool->canvas(), startPoint);
00106 } else {
00107 KoPathShape * pathShape = m_activePoint->parent();
00108 KoPathPointData pd(pathShape, pathShape->pathPointIndex(m_activePoint));
00109 return new KoPathControlPointMoveStrategy(m_tool, m_tool->canvas(), pd, m_activePointType, event->point);
00110 }
00111 } else {
00112 KoPathPoint::KoPointProperties props = m_activePoint->properties();
00113 if (! m_activePoint->activeControlPoint1() || ! m_activePoint->activeControlPoint2())
00114 return 0;
00115
00116 KoPathPointTypeCommand::PointType pointType = KoPathPointTypeCommand::Smooth;
00117
00118 if (props & KoPathPoint::IsSmooth)
00119 pointType = KoPathPointTypeCommand::Symmetric;
00120 else if (props & KoPathPoint::IsSymmetric)
00121 pointType = KoPathPointTypeCommand::Corner;
00122
00123 QList<KoPathPointData> pointData;
00124 pointData.append(KoPathPointData(m_activePoint->parent(), m_activePoint->parent()->pathPointIndex(m_activePoint)));
00125 m_tool->canvas()->addCommand(new KoPathPointTypeCommand(pointData, pointType));
00126 }
00127 return 0;
00128 }
00129
00130 bool PointHandle::check()
00131 {
00132 if (m_tool->canvas()->shapeManager()->selection()->isSelected(m_activePoint->parent())) {
00133 return m_activePoint->parent()->pathPointIndex(m_activePoint) != KoPathPointIndex(-1, -1);
00134 }
00135 return false;
00136 }
00137
00138 KoPathPoint * PointHandle::activePoint() const
00139 {
00140 return m_activePoint;
00141 }
00142
00143 KoPathPoint::KoPointType PointHandle::activePointType() const
00144 {
00145 return m_activePointType;
00146 }
00147
00148 ParameterHandle::ParameterHandle(KoPathTool *tool, KoParameterShape *parameterShape, int handleId)
00149 : KoPathToolHandle(tool)
00150 , m_parameterShape(parameterShape)
00151 , m_handleId(handleId)
00152 {
00153 }
00154
00155 void ParameterHandle::paint(QPainter &painter, const KoViewConverter &converter)
00156 {
00157 painter.save();
00158 painter.setMatrix(m_parameterShape->absoluteTransformation(&converter) * painter.matrix());
00159
00160 int handleRadius = m_tool->canvas()->resourceProvider()->handleRadius();
00161 m_parameterShape->paintHandle(painter, converter, m_handleId, handleRadius);
00162 painter.restore();
00163 }
00164
00165 void ParameterHandle::repaint() const
00166 {
00167 m_tool->repaint(m_parameterShape->shapeToDocument(QRectF(m_parameterShape->handlePosition(m_handleId), QSize(1, 1))));
00168 }
00169
00170 KoInteractionStrategy * ParameterHandle::handleMousePress(KoPointerEvent *event)
00171 {
00172 if (event->button() & Qt::LeftButton) {
00173 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
00174 if (selection)
00175 selection->clear();
00176 return new KoParameterChangeStrategy(m_tool, m_tool->canvas(), m_parameterShape, m_handleId);
00177 }
00178 return 0;
00179 }
00180
00181 bool ParameterHandle::check()
00182 {
00183 return m_tool->canvas()->shapeManager()->selection()->isSelected(m_parameterShape);
00184 }
00185
00186
00187 ConnectionHandle::ConnectionHandle(KoPathTool *tool, KoParameterShape *parameterShape, int handleId)
00188 : ParameterHandle(tool, parameterShape, handleId)
00189 {
00190 }
00191
00192 KoInteractionStrategy * ConnectionHandle::handleMousePress(KoPointerEvent *event)
00193 {
00194 if (event->button() & Qt::LeftButton) {
00195 KoPathToolSelection * selection = dynamic_cast<KoPathToolSelection*>(m_tool->selection());
00196 if (selection)
00197 selection->clear();
00198 KoConnectionShape * shape = dynamic_cast<KoConnectionShape*>(m_parameterShape);
00199 if (! shape)
00200 return 0;
00201 return new KoPathConnectionPointStrategy(m_tool, m_tool->canvas(), shape, m_handleId);
00202 }
00203 return 0;
00204 }