14#include <klocalizedstring.h>
17#include <QPainterPath>
27 :
RulerAssistant(
"infinite ruler", i18n(
"Infinite Ruler assistant"))
45 qreal dx = pt.x() - strokeBegin.x();
46 qreal dy = pt.y() - strokeBegin.y();
47 if (checkForInitialMovement &&
KisAlgebra2D::norm(QPointF(dx, dy)) < moveThresholdPt) {
59 invsqrlen = 1.0 / (dx2 + dy2);
60 QPointF r(dx2 * pt.x() + dy2 * snapLine.x1() + dx * dy * (pt.y() - snapLine.y1()),
61 dx2 * snapLine.y1() + dy2 * pt.y() + dx * dy * (pt.x() - snapLine.x1()));
69 return project(pt, strokeBegin,
true, moveThresholdPt);
75 point =
project(point, strokeBegin,
false, 0.0);
76 strokeBegin =
project(strokeBegin, strokeBegin,
false, 0.0);
87 QPointF
p1 = document2widget.map(*
handles()[0]);
88 QPointF
p2 = document2widget.map(*
handles()[1]);
90 const qreal scale = 16.0 / 2;
91 const qreal minorScale = scale / 2;
92 const QRectF clipping = QRectF(gc.viewport()).adjusted(-scale, -scale, scale, scale);
96 const qreal threshold = 3.0;
99 QPointF delta =
p2 -
p1;
104 if (stepsize >= threshold) {
105 QPointF normal = QPointF(delta.y(), -delta.x());
122 QPainterPath highlight;
125 for (
int ii = istart; ii < iend; ++ii) {
140 highlight.moveTo(pos - normal * scale);
141 highlight.lineTo(pos + normal * scale);
143 path.moveTo(pos - normal * scale);
144 path.lineTo(pos + normal * scale);
157 path.moveTo(mpos - normal * minorScale);
158 path.lineTo(mpos + normal * minorScale);
178 QLineF snapLine = QLineF(initialTransform.map(*
handles()[0]), initialTransform.map(*
handles()[1]));
179 QRect viewport = gc.viewport();
184 path.moveTo(snapLine.p1());
185 path.lineTo(snapLine.p2());
202 double dx = line.x2() - line.x1();
203 double dy = line.y2() - line.y1();
205 double q1 = line.x1() -
rect.x();
206 double q2 =
rect.x() +
rect.width() - line.x1();
207 double q3 = line.y1() -
rect.y();
208 double q4 =
rect.y() +
rect.height() - line.y1();
213 double tmin = extendFirst ? -std::numeric_limits<double>::infinity() : 0.0;
214 double tmax = extendSecond ? +std::numeric_limits<double>::infinity() : 1.0;
216 for (
int i = 0; i <
p.length(); i++) {
218 if (
p[i] == 0 && q[i] < 0) {
222 }
else if (
p[i] < 0) {
225 double t = q[i] /
p[i];
230 }
else if (
p[i] > 0) {
233 double t = q[i] /
p[i];
260 return "infinite ruler";
265 return i18n(
"Infinite Ruler");
qreal length(const QPointF &vec)
KisPaintingAssistant * createPaintingAssistant() const override
QString id() const override
QString name() const override
InfiniteRulerAssistantFactory()
~InfiniteRulerAssistantFactory() override
QPointF getDefaultEditorPosition() const override
void drawAssistant(QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, bool cached=true, KisCanvas2 *canvas=0, bool assistantVisible=true, bool previewVisible=true) override
void drawSubdivisions(QPainter &gc, const KisCoordinatesConverter *converter)
bool isAssistantComplete() const override
void adjustLine(QPointF &point, QPointF &strokeBegin) override
KisPaintingAssistantSP clone(QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap) const override
static ClippingResult clipLineParametric(QLineF line, QRectF rect, bool extendFirst=true, bool extendSecond=true)
QPointF project(const QPointF &pt, const QPointF &strokeBegin, const bool checkForInitialMovement, qreal moveThresholdPt)
QPointF adjustPosition(const QPointF &point, const QPointF &strokeBegin, const bool snapToAny, qreal moveThresholdPt) override
QTransform documentToWidgetTransform() const
bool isSnappingActive() const
void drawPath(QPainter &painter, const QPainterPath &path, bool drawActive=true)
void drawPreview(QPainter &painter, const QPainterPath &path)
static double norm2(const QPointF &p)
const QList< KisPaintingAssistantHandleSP > & handles() const
void drawAssistant(QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, bool cached, KisCanvas2 *canvas, bool assistantVisible=true, bool previewVisible=true) override
int minorSubdivisions() const
QSharedPointer< KisPaintingAssistant > KisPaintingAssistantSP
bool intersectLineRect(QLineF &line, const QRect rect, bool extend)