Commit 31b61f43 authored by Boudewijn Rempt's avatar Boudewijn Rempt Committed by Boudewijn Rempt

Clean up the basicflakes library

parent 82c2321b
......@@ -25,7 +25,7 @@
#include <klocalizedstring.h>
KoCreatePathToolFactory::KoCreatePathToolFactory()
: KoToolFactoryBase(KoCreatePathTool_ID)
: KoToolFactoryBase(KoCreatePathTool_ID)
{
setToolTip(i18n("Draw path"));
setToolType(mainToolType());
......
......@@ -24,7 +24,7 @@
#include <klocalizedstring.h>
KoPencilToolFactory::KoPencilToolFactory()
: KoToolFactoryBase("KoPencilTool")
: KoToolFactoryBase("KoPencilTool")
{
setToolTip(i18n("Freehand path"));
setToolType("karbon, krita");
......
......@@ -25,8 +25,7 @@
#include <kpluginfactory.h>
K_PLUGIN_FACTORY_WITH_JSON(PluginFactory, "krita_tool_basicflakes.json",
registerPlugin<Plugin>();)
K_PLUGIN_FACTORY_WITH_JSON(PluginFactory, "krita_tool_basicflakes.json", registerPlugin<Plugin>();)
Plugin::Plugin(QObject * parent, const QVariantList &)
: QObject(parent)
......
......@@ -22,7 +22,8 @@
#include <QObject>
#include <QVariantList>
class Plugin : public QObject {
class Plugin : public QObject
{
Q_OBJECT
public:
......
......@@ -40,7 +40,7 @@
KoCreatePathTool::KoCreatePathTool(KoCanvasBase *canvas)
: KoToolBase(*(new KoCreatePathToolPrivate(this, canvas)))
: KoToolBase(*(new KoCreatePathToolPrivate(this, canvas)))
{
}
......@@ -51,11 +51,15 @@ KoCreatePathTool::~KoCreatePathTool()
void KoCreatePathTool::paint(QPainter &painter, const KoViewConverter &converter)
{
Q_D(KoCreatePathTool);
if (pathStarted()) {
KoShapeStroke *stroke(createStroke());
if (stroke) {
d->shape->setStroke(stroke);
}
painter.save();
paintPath(*(d->shape), painter, converter);
painter.restore();
......@@ -70,20 +74,24 @@ void KoCreatePathTool::paint(QPainter &painter, const KoViewConverter &converter
painter.setBrush(Qt::white); //TODO make configurable
const bool firstPoint = (d->firstPoint == d->activePoint);
if (d->pointIsDragged || firstPoint) {
const bool onlyPaintActivePoints = false;
KoPathPoint::PointTypes paintFlags = KoPathPoint::ControlPoint2;
if (d->activePoint->activeControlPoint1())
if (d->activePoint->activeControlPoint1()) {
paintFlags |= KoPathPoint::ControlPoint1;
}
d->activePoint->paint(painter, d->handleRadius, paintFlags, onlyPaintActivePoints);
}
// check if we have to color the first point
if (d->mouseOverFirstPoint)
if (d->mouseOverFirstPoint) {
painter.setBrush(Qt::red); //TODO make configurable
else
} else {
painter.setBrush(Qt::white); //TODO make configurable
}
d->firstPoint->paint(painter, d->handleRadius, KoPathPoint::Node);
......@@ -99,6 +107,7 @@ void KoCreatePathTool::paint(QPainter &painter, const KoViewConverter &converter
d->hoveredPoint->paint(painter, d->handleRadius, KoPathPoint::Node);
painter.restore();
}
painter.save();
KoShape::applyConversion(painter, converter);
canvas()->snapGuide()->paint(painter, converter);
......@@ -114,6 +123,7 @@ void KoCreatePathTool::paintPath(KoPathShape& pathShape, QPainter &painter, cons
KoShapePaintingContext paintContext; //FIXME
pathShape.paint(painter, converter, paintContext);
painter.restore();
if (pathShape.stroke()) {
painter.save();
pathShape.stroke()->paint(d->shape, painter, converter);
......@@ -127,12 +137,12 @@ void KoCreatePathTool::mousePressEvent(KoPointerEvent *event)
//Right click removes last point
if (event->button() == Qt::RightButton) {
removeLastPoint();
return;
removeLastPoint();
return;
}
const bool isOverFirstPoint = d->shape &&
handleGrabRect(d->firstPoint->point()).contains(event->point);
handleGrabRect(d->firstPoint->point()).contains(event->point);
bool haveCloseModifier = (listeningToModifiers() && (event->modifiers() & Qt::ShiftModifier));
if ((event->button() == Qt::LeftButton) && haveCloseModifier && !isOverFirstPoint) {
......@@ -179,7 +189,7 @@ void KoCreatePathTool::mousePressEvent(KoPointerEvent *event)
}
} else {
KoPathShape *pathShape = new KoPathShape();
d->shape=pathShape;
d->shape = pathShape;
pathShape->setShapeId(KoPathShapeId);
KoShapeStroke *stroke = new KoShapeStroke(canvas()->resourceManager()->activeStroke());
......@@ -191,9 +201,11 @@ void KoCreatePathTool::mousePressEvent(KoPointerEvent *event)
// check whether we hit an start/end node of an existing path
d->existingStartPoint = d->endPointAtPosition(point);
if (d->existingStartPoint.isValid()) {
point = d->existingStartPoint.path->shapeToDocument(d->existingStartPoint.point->point());
}
d->activePoint = pathShape->moveTo(point);
d->firstPoint = d->activePoint;
canvas()->updateCanvas(handlePaintRect(point));
......@@ -211,14 +223,14 @@ void KoCreatePathTool::mousePressEvent(KoPointerEvent *event)
bool KoCreatePathTool::listeningToModifiers()
{
Q_D(KoCreatePathTool);
return d->listeningToModifiers;
Q_D(KoCreatePathTool);
return d->listeningToModifiers;
}
bool KoCreatePathTool::pathStarted()
{
Q_D(KoCreatePathTool);
return ((bool) d->shape);
Q_D(KoCreatePathTool);
return ((bool) d->shape);
}
void KoCreatePathTool::mouseDoubleClickEvent(KoPointerEvent *event)
......@@ -235,11 +247,14 @@ void KoCreatePathTool::mouseMoveEvent(KoPointerEvent *event)
KoPathPoint *endPoint = d->endPointAtPosition(event->point);
if (d->hoveredPoint != endPoint) {
if (d->hoveredPoint) {
QPointF nodePos = d->hoveredPoint->parent()->shapeToDocument(d->hoveredPoint->point());
canvas()->updateCanvas(handlePaintRect(nodePos));
}
d->hoveredPoint = endPoint;
if (d->hoveredPoint) {
QPointF nodePos = d->hoveredPoint->parent()->shapeToDocument(d->hoveredPoint->point());
canvas()->updateCanvas(handlePaintRect(nodePos));
......@@ -247,6 +262,7 @@ void KoCreatePathTool::mouseMoveEvent(KoPointerEvent *event)
}
if (!pathStarted()) {
canvas()->updateCanvas(canvas()->snapGuide()->boundingRect());
canvas()->snapGuide()->snap(event->point, event->modifiers());
canvas()->updateCanvas(canvas()->snapGuide()->boundingRect());
......@@ -262,13 +278,16 @@ void KoCreatePathTool::mouseMoveEvent(KoPointerEvent *event)
QPointF snappedPosition = canvas()->snapGuide()->snap(event->point, event->modifiers());
d->repaintActivePoint();
if (event->buttons() & Qt::LeftButton) {
d->pointIsDragged = true;
QPointF offset = snappedPosition - d->activePoint->point();
d->activePoint->setControlPoint2(d->activePoint->point() + offset);
// pressing <alt> stops controls points moving symmetrically
if ((event->modifiers() & Qt::AltModifier) == 0)
if ((event->modifiers() & Qt::AltModifier) == 0) {
d->activePoint->setControlPoint1(d->activePoint->point() - offset);
}
d->repaintActivePoint();
} else {
d->activePoint->setPoint(snappedPosition);
......@@ -282,8 +301,7 @@ void KoCreatePathTool::mouseReleaseEvent(KoPointerEvent *event)
{
Q_D(KoCreatePathTool);
if (! d->shape || (event->buttons() & Qt::RightButton))
return;
if (! d->shape || (event->buttons() & Qt::RightButton)) return;
d->listeningToModifiers = true; // After the first press-and-release
d->repaintActivePoint();
......@@ -292,7 +310,7 @@ void KoCreatePathTool::mouseReleaseEvent(KoPointerEvent *event)
if (!d->finishAfterThisPoint) {
d->activePoint = d->shape->lineTo(event->point);
canvas()->snapGuide()->setIgnoredPathPoints((QList<KoPathPoint*>()<<d->activePoint));
canvas()->snapGuide()->setIgnoredPathPoints((QList<KoPathPoint*>() << d->activePoint));
}
// apply symmetric point property if applicable
......@@ -323,10 +341,11 @@ void KoCreatePathTool::mouseReleaseEvent(KoPointerEvent *event)
void KoCreatePathTool::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Escape)
if (event->key() == Qt::Key_Escape) {
emit done();
else
} else {
event->ignore();
}
}
void KoCreatePathTool::endPath()
......@@ -427,10 +446,12 @@ void KoCreatePathTool::addPathShape(KoPathShape *pathShape)
pathShape->setStroke(createStroke());
if (d->connectPaths(pathShape, d->existingStartPoint, d->existingEndPoint)) {
if (d->existingStartPoint.isValid())
if (d->existingStartPoint.isValid()) {
startShape = d->existingStartPoint.path;
if (d->existingEndPoint.isValid() && d->existingEndPoint != d->existingStartPoint)
}
if (d->existingEndPoint.isValid() && d->existingEndPoint != d->existingStartPoint) {
endShape = d->existingEndPoint.path;
}
}
KUndo2Command *cmd = canvas()->shapeController()->addShape(pathShape);
......@@ -438,10 +459,12 @@ void KoCreatePathTool::addPathShape(KoPathShape *pathShape)
KoSelection *selection = canvas()->shapeManager()->selection();
selection->deselectAll();
selection->select(pathShape);
if (startShape)
if (startShape) {
canvas()->shapeController()->removeShape(startShape, cmd);
if (endShape && startShape != endShape)
}
if (endShape && startShape != endShape) {
canvas()->shapeController()->removeShape(endShape, cmd);
}
canvas()->addCommand(cmd);
} else {
canvas()->updateCanvas(pathShape->boundingRect());
......@@ -482,7 +505,6 @@ QList<QPointer<QWidget> > KoCreatePathTool::createOptionWidgets()
d->strokeWidget->setActive(false);
list.append(d->strokeWidget);
connect(angleEdit, SIGNAL(valueChanged(int)), this, SLOT(angleDeltaChanged(int)));
connect(angleSnap, SIGNAL(stateChanged(int)), this, SLOT(angleSnapChanged(int)));
......
This diff is collapsed.
......@@ -52,10 +52,17 @@
#include "KoCreatePathTool_p.h"
KoPencilTool::KoPencilTool(KoCanvasBase *canvas)
: KoToolBase(canvas), m_mode(ModeCurve), m_optimizeRaw(false)
, m_optimizeCurve(false), m_combineAngle(15.0), m_fittingError(5.0)
, m_close(false), m_shape(0)
, m_existingStartPoint(0), m_existingEndPoint(0), m_hoveredPoint(0)
: KoToolBase(canvas)
, m_mode(ModeCurve)
, m_optimizeRaw(false)
, m_optimizeCurve(false)
, m_combineAngle(15.0)
, m_fittingError(5.0)
, m_close(false)
, m_shape(0)
, m_existingStartPoint(0)
, m_existingEndPoint(0)
, m_hoveredPoint(0)
{
}
......@@ -427,7 +434,7 @@ KoPathPoint* KoPencilTool::endPointAtPosition(const QPointF &position)
qreal minDistance = HUGE_VAL;
qreal maxDistance = canvas()->viewConverter()->viewToDocumentX(grabSensitivity());
foreach(KoShape *shape, shapes) {
Q_FOREACH(KoShape * shape, shapes) {
KoPathShape * path = dynamic_cast<KoPathShape*>(shape);
if (!path)
continue;
......@@ -540,10 +547,12 @@ bool KoPencilTool::connectPaths(KoPathShape *pathShape, KoPathPoint *pointAtStar
return true;
}
qreal KoPencilTool::getFittingError(){
qreal KoPencilTool::getFittingError()
{
return this->m_fittingError;
}
void KoPencilTool::setFittingError(qreal fittingError){
void KoPencilTool::setFittingError(qreal fittingError)
{
this->m_fittingError = fittingError;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment