13#include <klocalizedstring.h>
16#include <QPainterPath>
17#include <QLinearGradient>
50 return QPointF(qQNaN(), qQNaN());
56 QPointF translation = (*
handles()[0]-strokeBegin)*-1.0;
57 snapLine = snapLine.translated(translation);
59 qreal dx = snapLine.dx();
60 qreal dy = snapLine.dy();
65 invsqrlen = 1.0 / (dx2 + dy2);
66 QPointF r(dx2 * pt.x() + dy2 * snapLine.x1() + dx * dy * (pt.y() - snapLine.y1()),
67 dx2 * snapLine.y1() + dy2 * pt.y() + dx * dy * (pt.x() - snapLine.x1()));
74 return project(pt, strokeBegin, moveThresholdPt);
79 point =
project(point, strokeBegin, 0.0);
89 QRectF localTransformed = initialTransform.mapRect(local);
90 const QRect viewport= gc.viewport();
91 QPolygonF viewportAndLocal = !localTransformed.isEmpty() ? QPolygonF(QRectF(viewport)).intersected(localTransformed) : QRectF(viewport);
98 path.moveTo(initialTransform.map(local.topLeft()));
100 path.lineTo(initialTransform.map(local.topRight()));
101 path.lineTo(initialTransform.map(local.bottomRight()));
102 path.lineTo(initialTransform.map(local.bottomLeft()));
103 path.lineTo(initialTransform.map(local.topLeft()));
110 QLineF snapLine= QLineF(initialTransform.map(*
handles()[0]), initialTransform.map(*
handles()[1]));
114 QPointF translation = (initialTransform.map(*
handles()[0])-mousePos)*-1.0;
115 snapLine= snapLine.translated(translation);
121 path.moveTo(snapLine.p1());
122 path.lineTo(snapLine.p2());
134 if (assistantVisible ==
false ||
handles().size() < 2) {
144 gc.setTransform(initialTransform);
166 }
else if (
handles().size() > 0) {
171 return QPointF(0, 0);
187 xml->writeStartElement(
"isLocal");
189 xml->writeEndElement();
194 if (xml && xml->name() ==
"isLocal") {
210 return "parallel ruler";
215 return i18n(
"Parallel Ruler");
QTransform documentToWidgetTransform() const
QPointF effectiveBrushPosition(const KisCoordinatesConverter *converter, KisCanvas2 *canvas) const
Query the effective brush position to be used for preview lines. This is intended to be used for pain...
bool isSnappingActive() const
void drawPath(QPainter &painter, const QPainterPath &path, bool drawActive=true)
void drawPreview(QPainter &painter, const QPainterPath &path)
QRectF getLocalRect() const
getLocalRect The function deals with local handles not being topLeft and bottomRight gracefully and r...
bool isLocal() const
isLocal
bool m_hasBeenInsideLocalRect
virtual void drawAssistant(QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, bool cached, KisCanvas2 *canvas=0, bool assistantVisible=true, bool previewVisible=true)
void setLocal(bool value)
setLocal
const QList< KisPaintingAssistantHandleSP > & handles() const
KisPaintingAssistant * createPaintingAssistant() const override
ParallelRulerAssistantFactory()
~ParallelRulerAssistantFactory() override
QString id() const override
QString name() const override
QPointF getDefaultEditorPosition() const override
QPointF project(const QPointF &pt, const QPointF &strokeBegin, qreal moveThresholdPt)
void adjustLine(QPointF &point, QPointF &strokeBegin) override
KisPaintingAssistantSP clone(QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap) const override
int numHandles() const override
void drawCache(QPainter &gc, const KisCoordinatesConverter *converter, bool assistantVisible=true) override
performance layer where the graphics can be drawn from a cache instead of generated every render upda...
void drawAssistant(QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, bool cached=true, KisCanvas2 *canvas=0, bool assistantVisible=true, bool previewVisible=true) override
bool loadCustomXml(QXmlStreamReader *xml) override
KisPaintingAssistantHandleSP secondLocalHandle() const override
secondLocalHandle Note: this doesn't guarantee it will be the bottomRight corner! For that,...
QPointF adjustPosition(const QPointF &point, const QPointF &strokeBegin, const bool snapToAny, qreal moveThresholdPt) override
void saveCustomXml(QXmlStreamWriter *xml) override
KisPaintingAssistantHandleSP firstLocalHandle() const override
firstLocalHandle Note: this doesn't guarantee it will be the topleft corner! For that,...
bool canBeLocal() const override
canBeLocal
bool isAssistantComplete() const override
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
QSharedPointer< KisPaintingAssistant > KisPaintingAssistantSP
void cropLineToConvexPolygon(QLineF &line, const QPolygonF polygon, bool extendFirst, bool extendSecond)
int toInt(const QString &str, bool *ok=nullptr)
QString toString(const QString &value)