fix(strokecanvasitem): use qreal instead of float to suppress -Wdouble-promotion
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 16s
Python / lint-format (pull_request) Successful in 23s
Python / test (pull_request) Successful in 48s
C++ / build (pull_request) Successful in 2m20s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m59s
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 16s
Python / lint-format (pull_request) Successful in 23s
Python / test (pull_request) Successful in 48s
C++ / build (pull_request) Successful in 2m20s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m59s
This commit is contained in:
@@ -11,9 +11,9 @@ struct Stroke {
|
||||
QVector<QPointF> points;
|
||||
QCanvasPath path;
|
||||
QColor color;
|
||||
float width;
|
||||
qreal width;
|
||||
int groupId = -1;
|
||||
bool isSinglePoint = false;
|
||||
};
|
||||
|
||||
};
|
||||
}; // namespace ZShell::internal
|
||||
|
||||
@@ -6,55 +6,52 @@
|
||||
|
||||
namespace ZShell::internal {
|
||||
|
||||
StrokeCanvasItem::StrokeCanvasItem(QQuickItem *parent) : QCanvasPainterItem(parent) {
|
||||
StrokeCanvasItem::StrokeCanvasItem(QQuickItem* parent)
|
||||
: QCanvasPainterItem(parent) {
|
||||
setFillColor(Qt::transparent);
|
||||
setAlphaBlending(true);
|
||||
}
|
||||
|
||||
QCanvasPainterItemRenderer *StrokeCanvasItem::createItemRenderer() const {
|
||||
QCanvasPainterItemRenderer* StrokeCanvasItem::createItemRenderer() const {
|
||||
return new StrokeCanvasRenderer;
|
||||
}
|
||||
|
||||
static bool shouldAddPoint(
|
||||
const QVector<QPointF> &points,
|
||||
const QPointF &p,
|
||||
qreal minDistance)
|
||||
{
|
||||
if (points.isEmpty())
|
||||
return true;
|
||||
const QVector<QPointF>& points, const QPointF& p, qreal minDistance) {
|
||||
if (points.isEmpty()) return true;
|
||||
|
||||
const QPointF delta = p - points.last();
|
||||
|
||||
return QPointF::dotProduct(delta, delta)
|
||||
>= minDistance * minDistance;
|
||||
return QPointF::dotProduct(delta, delta) >= minDistance * minDistance;
|
||||
}
|
||||
|
||||
static QCanvasPath buildStrokePath(const QVector<QPointF> &points, float width) {
|
||||
static QCanvasPath buildStrokePath(const QVector<QPointF>& points, qreal width) {
|
||||
QCanvasPath path;
|
||||
|
||||
if (points.size() == 1) {
|
||||
path.circle(points[0], width * 0.5f);
|
||||
path.circle(points[0], width * 0.5);
|
||||
return path;
|
||||
}
|
||||
|
||||
auto catmullToBezier = [](
|
||||
const QPointF &p0, const QPointF &p1,
|
||||
const QPointF &p2, const QPointF &p3,
|
||||
float tension,
|
||||
QPointF &cp1, QPointF &cp2)
|
||||
{
|
||||
cp1 = p1 + (p2 - p0) * tension / 3.0f;
|
||||
cp2 = p2 - (p3 - p1) * tension / 3.0f;
|
||||
};
|
||||
auto catmullToBezier = [](const QPointF& p0,
|
||||
const QPointF& p1,
|
||||
const QPointF& p2,
|
||||
const QPointF& p3,
|
||||
qreal tension,
|
||||
QPointF& cp1,
|
||||
QPointF& cp2) {
|
||||
cp1 = p1 + (p2 - p0) * tension / 3.0;
|
||||
cp2 = p2 - (p3 - p1) * tension / 3.0;
|
||||
};
|
||||
|
||||
const float tension = 0.5f;
|
||||
const qreal tension = 0.5;
|
||||
path.moveTo(points[0]);
|
||||
|
||||
for (int i = 0; i < points.size() - 1; ++i) {
|
||||
const QPointF &p0 = points[qMax(i - 1, 0)];
|
||||
const QPointF &p1 = points[i];
|
||||
const QPointF &p2 = points[i + 1];
|
||||
const QPointF &p3 = points[qMin(i + 2, points.size() - 1)];
|
||||
const QPointF& p0 = points[qMax(i - 1, 0)];
|
||||
const QPointF& p1 = points[i];
|
||||
const QPointF& p2 = points[i + 1];
|
||||
const QPointF& p3 = points[qMin(i + 2, points.size() - 1)];
|
||||
|
||||
QPointF cp1, cp2;
|
||||
catmullToBezier(p0, p1, p2, p3, tension, cp1, cp2);
|
||||
@@ -64,9 +61,8 @@ static QCanvasPath buildStrokePath(const QVector<QPointF> &points, float width)
|
||||
return path;
|
||||
}
|
||||
|
||||
void StrokeCanvasItem::setPenColor(const QColor &color) {
|
||||
if (m_penColor == color)
|
||||
return;
|
||||
void StrokeCanvasItem::setPenColor(const QColor& color) {
|
||||
if (m_penColor == color) return;
|
||||
|
||||
m_penColor = color;
|
||||
update();
|
||||
@@ -75,8 +71,7 @@ void StrokeCanvasItem::setPenColor(const QColor &color) {
|
||||
}
|
||||
|
||||
void StrokeCanvasItem::setHoverVisible(bool visible) {
|
||||
if (m_hoverVisible == visible)
|
||||
return;
|
||||
if (m_hoverVisible == visible) return;
|
||||
|
||||
m_hoverVisible = visible;
|
||||
update();
|
||||
@@ -84,9 +79,8 @@ void StrokeCanvasItem::setHoverVisible(bool visible) {
|
||||
emit hoverVisibleChanged();
|
||||
}
|
||||
|
||||
void StrokeCanvasItem::setHoverPoint(const QPointF &point) {
|
||||
if (m_hoverPoint == point)
|
||||
return;
|
||||
void StrokeCanvasItem::setHoverPoint(const QPointF& point) {
|
||||
if (m_hoverPoint == point) return;
|
||||
|
||||
m_hoverPoint = point;
|
||||
update();
|
||||
@@ -110,8 +104,7 @@ void StrokeCanvasItem::showHover(qreal x, qreal y) {
|
||||
}
|
||||
|
||||
void StrokeCanvasItem::hideHover() {
|
||||
if (!m_hoverVisible)
|
||||
return;
|
||||
if (!m_hoverVisible) return;
|
||||
|
||||
m_hoverVisible = false;
|
||||
update();
|
||||
@@ -119,9 +112,8 @@ void StrokeCanvasItem::hideHover() {
|
||||
emit hoverVisibleChanged();
|
||||
}
|
||||
|
||||
void StrokeCanvasItem::setPenWidth(float width) {
|
||||
if (qFuzzyCompare(m_penWidth, width))
|
||||
return;
|
||||
void StrokeCanvasItem::setPenWidth(qreal width) {
|
||||
if (qFuzzyCompare(m_penWidth, width)) return;
|
||||
|
||||
m_penWidth = width;
|
||||
update();
|
||||
@@ -143,8 +135,7 @@ void StrokeCanvasItem::beginStroke(qreal x, qreal y) {
|
||||
void StrokeCanvasItem::appendPoint(qreal x, qreal y) {
|
||||
const QPointF incoming{x, y};
|
||||
|
||||
if (!shouldAddPoint(m_currentStroke.points, incoming, 2.0))
|
||||
return;
|
||||
if (!shouldAddPoint(m_currentStroke.points, incoming, 2.0)) return;
|
||||
|
||||
QPointF smoothed;
|
||||
if (m_currentStroke.points.isEmpty()) {
|
||||
@@ -159,7 +150,8 @@ void StrokeCanvasItem::appendPoint(qreal x, qreal y) {
|
||||
constexpr qreal minAlpha = 0.1;
|
||||
constexpr qreal maxAlpha = 0.3;
|
||||
|
||||
const qreal t = std::clamp((dist - minDist) / (maxDist - minDist), 0.0, 1.0);
|
||||
const qreal t =
|
||||
std::clamp((dist - minDist) / (maxDist - minDist), 0.0, 1.0);
|
||||
const qreal alpha = minAlpha + t * (maxAlpha - minAlpha);
|
||||
|
||||
smoothed = last * (1.0 - alpha) + incoming * alpha;
|
||||
@@ -171,11 +163,11 @@ void StrokeCanvasItem::appendPoint(qreal x, qreal y) {
|
||||
|
||||
void StrokeCanvasItem::endStroke() {
|
||||
m_isDrawing = false;
|
||||
if (m_currentStroke.points.isEmpty())
|
||||
return;
|
||||
if (m_currentStroke.points.isEmpty()) return;
|
||||
|
||||
m_currentStroke.isSinglePoint = (m_currentStroke.points.size() == 1);
|
||||
m_currentStroke.path = buildStrokePath(m_currentStroke.points, m_currentStroke.width);
|
||||
m_currentStroke.path =
|
||||
buildStrokePath(m_currentStroke.points, m_currentStroke.width);
|
||||
m_currentStroke.groupId = m_nextGroupId++;
|
||||
m_currentStroke.points.clear();
|
||||
m_strokes.append(m_currentStroke);
|
||||
@@ -190,4 +182,4 @@ void StrokeCanvasItem::clear() {
|
||||
update();
|
||||
}
|
||||
|
||||
};
|
||||
}; // namespace ZShell::internal
|
||||
|
||||
@@ -13,68 +13,67 @@ namespace ZShell::internal {
|
||||
class StrokeCanvasRenderer;
|
||||
|
||||
class StrokeCanvasItem : public QCanvasPainterItem {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
QML_NAMED_ELEMENT(StrokeCanvas)
|
||||
QML_NAMED_ELEMENT(StrokeCanvas)
|
||||
|
||||
Q_PROPERTY(QColor penColor READ penColor WRITE setPenColor NOTIFY penColorChanged)
|
||||
Q_PROPERTY(bool hoverVisible READ hoverVisible WRITE setHoverVisible NOTIFY hoverVisibleChanged)
|
||||
Q_PROPERTY(QPointF hoverPoint READ hoverPoint WRITE setHoverPoint NOTIFY hoverPointChanged)
|
||||
Q_PROPERTY(qreal penWidth READ penWidth WRITE setPenWidth NOTIFY penWidthChanged)
|
||||
Q_PROPERTY(
|
||||
QColor penColor READ penColor WRITE setPenColor NOTIFY penColorChanged)
|
||||
Q_PROPERTY(
|
||||
bool hoverVisible READ hoverVisible WRITE setHoverVisible NOTIFY
|
||||
hoverVisibleChanged)
|
||||
Q_PROPERTY(
|
||||
QPointF hoverPoint READ hoverPoint WRITE setHoverPoint NOTIFY
|
||||
hoverPointChanged)
|
||||
Q_PROPERTY(
|
||||
qreal penWidth READ penWidth WRITE setPenWidth NOTIFY penWidthChanged)
|
||||
|
||||
public:
|
||||
explicit StrokeCanvasItem(QQuickItem *parent = nullptr);
|
||||
public:
|
||||
explicit StrokeCanvasItem(QQuickItem* parent = nullptr);
|
||||
|
||||
[[nodiscard]] bool hoverVisible() const {
|
||||
return m_hoverVisible;
|
||||
}
|
||||
[[nodiscard]] QPointF hoverPoint() const {
|
||||
return m_hoverPoint;
|
||||
}
|
||||
[[nodiscard]] bool hoverVisible() const { return m_hoverVisible; }
|
||||
[[nodiscard]] QPointF hoverPoint() const { return m_hoverPoint; }
|
||||
|
||||
void setHoverVisible(bool visible);
|
||||
void setHoverPoint(const QPointF &point);
|
||||
void setHoverVisible(bool visible);
|
||||
void setHoverPoint(const QPointF& point);
|
||||
|
||||
Q_INVOKABLE void showHover(qreal x, qreal y);
|
||||
Q_INVOKABLE void hideHover();
|
||||
Q_INVOKABLE void showHover(qreal x, qreal y);
|
||||
Q_INVOKABLE void hideHover();
|
||||
|
||||
[[nodiscard]] QColor penColor() const {
|
||||
return m_penColor;
|
||||
}
|
||||
[[nodiscard]] float penWidth() const {
|
||||
return m_penWidth;
|
||||
}
|
||||
[[nodiscard]] QColor penColor() const { return m_penColor; }
|
||||
[[nodiscard]] qreal penWidth() const { return m_penWidth; }
|
||||
|
||||
void setPenColor(const QColor &color);
|
||||
void setPenWidth(float width);
|
||||
void setPenColor(const QColor& color);
|
||||
void setPenWidth(qreal width);
|
||||
|
||||
Q_INVOKABLE void clear();
|
||||
Q_INVOKABLE void clear();
|
||||
|
||||
Q_INVOKABLE void beginStroke(qreal x, qreal y);
|
||||
Q_INVOKABLE void appendPoint(qreal x, qreal y);
|
||||
Q_INVOKABLE void endStroke();
|
||||
Q_INVOKABLE void beginStroke(qreal x, qreal y);
|
||||
Q_INVOKABLE void appendPoint(qreal x, qreal y);
|
||||
Q_INVOKABLE void endStroke();
|
||||
|
||||
signals:
|
||||
void penColorChanged();
|
||||
void penWidthChanged();
|
||||
void hoverVisibleChanged();
|
||||
void hoverPointChanged();
|
||||
signals:
|
||||
void penColorChanged();
|
||||
void penWidthChanged();
|
||||
void hoverVisibleChanged();
|
||||
void hoverPointChanged();
|
||||
|
||||
protected:
|
||||
[[nodiscard]] QCanvasPainterItemRenderer *createItemRenderer() const override;
|
||||
protected:
|
||||
[[nodiscard]] QCanvasPainterItemRenderer* createItemRenderer()
|
||||
const override;
|
||||
|
||||
private:
|
||||
friend class StrokeCanvasRenderer;
|
||||
private:
|
||||
friend class StrokeCanvasRenderer;
|
||||
|
||||
bool m_hoverVisible = false;
|
||||
QPointF m_hoverPoint;
|
||||
QColor m_penColor = Qt::white;
|
||||
float m_penWidth = 4.f;
|
||||
bool m_isDrawing = false;
|
||||
bool m_hoverVisible = false;
|
||||
QPointF m_hoverPoint;
|
||||
QColor m_penColor = Qt::white;
|
||||
qreal m_penWidth = 4.0;
|
||||
bool m_isDrawing = false;
|
||||
|
||||
int m_nextGroupId = 0;
|
||||
QVector<Stroke> m_strokes;
|
||||
Stroke m_currentStroke;
|
||||
int m_nextGroupId = 0;
|
||||
QVector<Stroke> m_strokes;
|
||||
Stroke m_currentStroke;
|
||||
};
|
||||
|
||||
};
|
||||
}; // namespace ZShell::internal
|
||||
|
||||
@@ -5,13 +5,11 @@
|
||||
namespace ZShell::internal {
|
||||
|
||||
static void drawStroke(
|
||||
QCanvasPainter *painter,
|
||||
const QVector<QPointF> &points,
|
||||
const QColor &color,
|
||||
float width) {
|
||||
|
||||
if (points.isEmpty())
|
||||
return;
|
||||
QCanvasPainter* painter,
|
||||
const QVector<QPointF>& points,
|
||||
const QColor& color,
|
||||
qreal width) {
|
||||
if (points.isEmpty()) return;
|
||||
|
||||
painter->setStrokeStyle(color);
|
||||
painter->setFillStyle(color);
|
||||
@@ -26,26 +24,27 @@ static void drawStroke(
|
||||
return;
|
||||
}
|
||||
|
||||
auto catmullToBezier = [](
|
||||
const QPointF &p0, const QPointF &p1,
|
||||
const QPointF &p2, const QPointF &p3,
|
||||
float tension,
|
||||
QPointF &cp1, QPointF &cp2)
|
||||
{
|
||||
cp1 = p1 + (p2 - p0) * tension / 3.0f;
|
||||
cp2 = p2 - (p3 - p1) * tension / 3.0f;
|
||||
};
|
||||
auto catmullToBezier = [](const QPointF& p0,
|
||||
const QPointF& p1,
|
||||
const QPointF& p2,
|
||||
const QPointF& p3,
|
||||
qreal tension,
|
||||
QPointF& cp1,
|
||||
QPointF& cp2) {
|
||||
cp1 = p1 + (p2 - p0) * tension / 3.0;
|
||||
cp2 = p2 - (p3 - p1) * tension / 3.0;
|
||||
};
|
||||
|
||||
const float tension = 0.5f; // increase toward 1.0 for tighter curves
|
||||
const qreal tension = 0.5; // increase toward 1.0 for tighter curves
|
||||
|
||||
painter->beginPath();
|
||||
painter->moveTo(points[0]);
|
||||
|
||||
for (int i = 0; i < points.size() - 1; ++i) {
|
||||
const QPointF &p0 = points[qMax(i - 1, 0)];
|
||||
const QPointF &p1 = points[i];
|
||||
const QPointF &p2 = points[i + 1];
|
||||
const QPointF &p3 = points[qMin(i + 2, points.size() - 1)];
|
||||
const QPointF& p0 = points[qMax(i - 1, 0)];
|
||||
const QPointF& p1 = points[i];
|
||||
const QPointF& p2 = points[i + 1];
|
||||
const QPointF& p3 = points[qMin(i + 2, points.size() - 1)];
|
||||
|
||||
QPointF cp1, cp2;
|
||||
catmullToBezier(p0, p1, p2, p3, tension, cp1, cp2);
|
||||
@@ -56,13 +55,12 @@ static void drawStroke(
|
||||
}
|
||||
|
||||
static void drawHoverCursor(
|
||||
QCanvasPainter *painter,
|
||||
const QPointF &point,
|
||||
float penWidth,
|
||||
QCanvasPainter* painter,
|
||||
const QPointF& point,
|
||||
qreal penWidth,
|
||||
QColor penColor,
|
||||
bool isDrawing)
|
||||
{
|
||||
const float radius = penWidth * 0.5f;
|
||||
bool isDrawing) {
|
||||
const qreal radius = penWidth * 0.5;
|
||||
|
||||
if (isDrawing) {
|
||||
painter->setFillStyle(penColor);
|
||||
@@ -73,55 +71,59 @@ static void drawHoverCursor(
|
||||
|
||||
const float lineWidth = 1.5f;
|
||||
const float crosshairSize = 6.0f;
|
||||
const bool useDashes = penWidth > 10.0f;
|
||||
const bool useDashes = penWidth > 10.0;
|
||||
|
||||
auto drawOutline = [&](const QColor &color, float width) {
|
||||
painter->setStrokeStyle(color);
|
||||
painter->setLineWidth(width);
|
||||
painter->setLineCap(QCanvasPainter::LineCap::Round);
|
||||
auto drawOutline = [&](const QColor& color, qreal width) {
|
||||
painter->setStrokeStyle(color);
|
||||
painter->setLineWidth(width);
|
||||
painter->setLineCap(QCanvasPainter::LineCap::Round);
|
||||
|
||||
|
||||
if (useDashes) {
|
||||
const int dashCount = 12;
|
||||
const float fullAngle = 2.0f * M_PI;
|
||||
const float dashAngle = fullAngle / dashCount * 0.5f;
|
||||
const float gapAngle = fullAngle / dashCount * 0.5f;
|
||||
if (useDashes) {
|
||||
const int dashCount = 12;
|
||||
const float fullAngle = 2.0f * M_PI;
|
||||
const float dashAngle = fullAngle / dashCount * 0.5f;
|
||||
const float gapAngle = fullAngle / dashCount * 0.5f;
|
||||
|
||||
float angle = 0.0f;
|
||||
for (int i = 0; i < dashCount; ++i) {
|
||||
painter->beginPath();
|
||||
painter->arc(point, radius, angle, angle + dashAngle,
|
||||
QCanvasPainter::PathWinding::ClockWise,
|
||||
QCanvasPainter::PathConnection::NotConnected);
|
||||
painter->stroke();
|
||||
angle += dashAngle + gapAngle;
|
||||
}
|
||||
} else {
|
||||
painter->beginPath();
|
||||
painter->circle(point, radius);
|
||||
painter->stroke();
|
||||
}
|
||||
};
|
||||
float angle = 0.0f;
|
||||
for (int i = 0; i < dashCount; ++i) {
|
||||
painter->beginPath();
|
||||
painter->arc(
|
||||
point,
|
||||
radius,
|
||||
angle,
|
||||
angle + dashAngle,
|
||||
QCanvasPainter::PathWinding::ClockWise,
|
||||
QCanvasPainter::PathConnection::NotConnected);
|
||||
painter->stroke();
|
||||
angle += dashAngle + gapAngle;
|
||||
}
|
||||
} else {
|
||||
painter->beginPath();
|
||||
painter->circle(point, radius);
|
||||
painter->stroke();
|
||||
}
|
||||
};
|
||||
|
||||
auto drawCrosshair = [&](const QColor &color, float width) {
|
||||
painter->setStrokeStyle(color);
|
||||
painter->setLineWidth(width);
|
||||
painter->setLineCap(QCanvasPainter::LineCap::Round);
|
||||
auto drawCrosshair = [&](const QColor& color, qreal width) {
|
||||
painter->setStrokeStyle(color);
|
||||
painter->setLineWidth(width);
|
||||
painter->setLineCap(QCanvasPainter::LineCap::Round);
|
||||
|
||||
const float inner = radius + 3.0f;
|
||||
const float outer = radius + 3.0f + crosshairSize;
|
||||
const float inner = radius + 3.0f;
|
||||
const float outer = radius + 3.0f + crosshairSize;
|
||||
|
||||
painter->beginPath();
|
||||
painter->moveTo(point + QPointF(0, -outer));
|
||||
painter->lineTo(point + QPointF(0, -inner));
|
||||
painter->moveTo(point + QPointF(0, outer));
|
||||
painter->lineTo(point + QPointF(0, inner));
|
||||
painter->moveTo(point + QPointF(-outer, 0));
|
||||
painter->lineTo(point + QPointF(-inner, 0));
|
||||
painter->moveTo(point + QPointF( outer, 0));
|
||||
painter->lineTo(point + QPointF( inner, 0));
|
||||
painter->stroke();
|
||||
};
|
||||
painter->beginPath();
|
||||
painter->moveTo(point + QPointF(0, -outer));
|
||||
painter->lineTo(point + QPointF(0, -inner));
|
||||
painter->moveTo(point + QPointF(0, outer));
|
||||
painter->lineTo(point + QPointF(0, inner));
|
||||
painter->moveTo(point + QPointF(-outer, 0));
|
||||
painter->lineTo(point + QPointF(-inner, 0));
|
||||
painter->moveTo(point + QPointF(outer, 0));
|
||||
painter->lineTo(point + QPointF(inner, 0));
|
||||
painter->stroke();
|
||||
};
|
||||
|
||||
drawOutline(QColor(0, 0, 0, 160), lineWidth + 1.0f);
|
||||
drawCrosshair(QColor(0, 0, 0, 160), lineWidth + 1.0f);
|
||||
@@ -130,8 +132,8 @@ static void drawHoverCursor(
|
||||
drawCrosshair(QColor(255, 255, 255, 220), lineWidth);
|
||||
}
|
||||
|
||||
void StrokeCanvasRenderer::synchronizeData(QCanvasPainterItem *item) {
|
||||
auto *canvas = static_cast<StrokeCanvasItem *>(item);
|
||||
void StrokeCanvasRenderer::synchronizeData(QCanvasPainterItem* item) {
|
||||
auto* canvas = static_cast<StrokeCanvasItem*>(item);
|
||||
|
||||
m_penColor = canvas->m_penColor;
|
||||
m_penWidth = canvas->m_penWidth;
|
||||
@@ -140,7 +142,7 @@ void StrokeCanvasRenderer::synchronizeData(QCanvasPainterItem *item) {
|
||||
m_strokes.append(canvas->m_strokes[m_strokes.size()]);
|
||||
|
||||
if (canvas->m_strokes.isEmpty() && !m_strokes.isEmpty()) {
|
||||
for (const auto &stroke : m_strokes)
|
||||
for (const auto& stroke : m_strokes)
|
||||
if (stroke.groupId >= 0)
|
||||
m_pendingGroupRemovals.append(stroke.groupId);
|
||||
m_strokes.clear();
|
||||
@@ -153,14 +155,14 @@ void StrokeCanvasRenderer::synchronizeData(QCanvasPainterItem *item) {
|
||||
m_isDrawing = canvas->m_isDrawing;
|
||||
}
|
||||
|
||||
void StrokeCanvasRenderer::paint(QCanvasPainter *painter) {
|
||||
void StrokeCanvasRenderer::paint(QCanvasPainter* painter) {
|
||||
for (int id : m_pendingGroupRemovals)
|
||||
painter->removePathGroup(id);
|
||||
m_pendingGroupRemovals.clear();
|
||||
|
||||
painter->clearRect(0, 0, width(), height());
|
||||
|
||||
for (const auto &stroke : m_strokes) {
|
||||
for (const auto& stroke : m_strokes) {
|
||||
painter->setStrokeStyle(stroke.color);
|
||||
painter->setFillStyle(stroke.color);
|
||||
painter->setLineWidth(stroke.width);
|
||||
@@ -174,10 +176,15 @@ void StrokeCanvasRenderer::paint(QCanvasPainter *painter) {
|
||||
}
|
||||
}
|
||||
|
||||
drawStroke(painter, m_currentStroke.points, m_currentStroke.color, m_currentStroke.width);
|
||||
drawStroke(
|
||||
painter,
|
||||
m_currentStroke.points,
|
||||
m_currentStroke.color,
|
||||
m_currentStroke.width);
|
||||
|
||||
if (m_hoverVisible)
|
||||
drawHoverCursor(painter, m_hoverPoint, m_penWidth, m_penColor, m_isDrawing);
|
||||
drawHoverCursor(
|
||||
painter, m_hoverPoint, m_penWidth, m_penColor, m_isDrawing);
|
||||
}
|
||||
|
||||
};
|
||||
}; // namespace ZShell::internal
|
||||
|
||||
@@ -7,22 +7,20 @@
|
||||
namespace ZShell::internal {
|
||||
|
||||
class StrokeCanvasRenderer final : public QCanvasPainterItemRenderer {
|
||||
public:
|
||||
void synchronizeData(QCanvasPainterItem* item) override;
|
||||
void paint(QCanvasPainter* painter) override;
|
||||
|
||||
public:
|
||||
void synchronizeData(QCanvasPainterItem *item) override;
|
||||
void paint(QCanvasPainter *painter) override;
|
||||
|
||||
private:
|
||||
QColor m_penColor;
|
||||
float m_penWidth = 4.f;
|
||||
bool m_hoverVisible = false;
|
||||
QPointF m_hoverPoint;
|
||||
bool m_isDrawing = false;
|
||||
|
||||
QVector<Stroke> m_strokes;
|
||||
Stroke m_currentStroke;
|
||||
QVector<int> m_pendingGroupRemovals;
|
||||
private:
|
||||
QColor m_penColor;
|
||||
qreal m_penWidth = 4.0;
|
||||
bool m_hoverVisible = false;
|
||||
QPointF m_hoverPoint;
|
||||
bool m_isDrawing = false;
|
||||
|
||||
QVector<Stroke> m_strokes;
|
||||
Stroke m_currentStroke;
|
||||
QVector<int> m_pendingGroupRemovals;
|
||||
};
|
||||
|
||||
};
|
||||
}; // namespace ZShell::internal
|
||||
|
||||
Reference in New Issue
Block a user