screenshot tools baked-in: drawing uses optimized qcanvaspainter, direct to clipboard, eliminate forking to swappy
C++ / fmt (pull_request) Successful in 7s
JS/TS / lint (pull_request) Successful in 21s
JS/TS / fmt (pull_request) Successful in 20s
Python / lint (pull_request) Successful in 31s
Python / fmt (pull_request) Successful in 33s
Python / typecheck (pull_request) Failing after 1m4s
Python / test (pull_request) Successful in 1m7s
C++ / build (pull_request) Successful in 1m48s
Rust / fmt (pull_request) Successful in 37s
Rust / build (pull_request) Successful in 1m42s
Python / buildcheck (pull_request) Successful in 2m33s
Rust / clippy (pull_request) Successful in 1m32s
C++ / clang-tidy (pull_request) Successful in 3m35s

This commit is contained in:
2026-08-10 12:02:34 +02:00
parent 93c6ac251e
commit 47c842941f
9 changed files with 711 additions and 71 deletions
+1
View File
@@ -14,6 +14,7 @@ struct Stroke {
qreal width;
int groupId = -1;
bool isSinglePoint = false;
bool isPolyline = false;
};
}; // namespace ZShell::internal
+31 -4
View File
@@ -25,7 +25,8 @@ static bool shouldAddPoint(
return QPointF::dotProduct(delta, delta) >= minDistance * minDistance;
}
static QCanvasPath buildStrokePath(const QVector<QPointF>& points, qreal width) {
static QCanvasPath buildStrokePath(
const QVector<QPointF>& points, qreal width, bool polyline) {
QCanvasPath path;
if (points.size() == 1) {
@@ -33,6 +34,13 @@ static QCanvasPath buildStrokePath(const QVector<QPointF>& points, qreal width)
return path;
}
if (polyline) {
path.moveTo(points[0]);
for (int i = 1; i < points.size(); i++)
path.lineTo(points[i]);
return path;
}
auto catmullToBezier = [](const QPointF& p0,
const QPointF& p1,
const QPointF& p2,
@@ -61,6 +69,16 @@ static QCanvasPath buildStrokePath(const QVector<QPointF>& points, qreal width)
return path;
}
void StrokeCanvasItem::undoLastGroup() {
if (m_strokes.isEmpty()) return;
const int lastGroup = m_strokes.last().groupId;
for (int i = m_strokes.size() - 1;
i >= 0 && m_strokes[i].groupId == lastGroup;
--i)
m_strokes.remove(i);
update();
}
void StrokeCanvasItem::setPenColor(const QColor& color) {
if (m_penColor == color) return;
@@ -121,13 +139,14 @@ void StrokeCanvasItem::setPenWidth(qreal width) {
emit penWidthChanged();
}
void StrokeCanvasItem::beginStroke(qreal x, qreal y) {
void StrokeCanvasItem::beginStroke(qreal x, qreal y, bool polyline) {
m_isDrawing = true;
m_currentStroke.points.clear();
m_currentStroke.points.append({x, y});
m_currentStroke.color = m_penColor;
m_currentStroke.width = m_penWidth;
m_currentStroke.isPolyline = polyline;
update();
}
@@ -135,6 +154,12 @@ void StrokeCanvasItem::beginStroke(qreal x, qreal y) {
void StrokeCanvasItem::appendPoint(qreal x, qreal y) {
const QPointF incoming{x, y};
if (m_currentStroke.isPolyline) {
m_currentStroke.points.append(incoming);
update();
return;
}
if (!shouldAddPoint(m_currentStroke.points, incoming, 2.0)) return;
QPointF smoothed;
@@ -166,8 +191,10 @@ void StrokeCanvasItem::endStroke() {
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.isPolyline);
m_currentStroke.groupId = m_nextGroupId++;
m_currentStroke.points.clear();
m_strokes.append(m_currentStroke);
+2 -1
View File
@@ -39,6 +39,7 @@ class StrokeCanvasItem : public QCanvasPainterItem {
Q_INVOKABLE void showHover(qreal x, qreal y);
Q_INVOKABLE void hideHover();
Q_INVOKABLE void undoLastGroup();
[[nodiscard]] QColor penColor() const { return m_penColor; }
[[nodiscard]] qreal penWidth() const { return m_penWidth; }
@@ -48,7 +49,7 @@ class StrokeCanvasItem : public QCanvasPainterItem {
Q_INVOKABLE void clear();
Q_INVOKABLE void beginStroke(qreal x, qreal y);
Q_INVOKABLE void beginStroke(qreal x, qreal y, bool polyline = false);
Q_INVOKABLE void appendPoint(qreal x, qreal y);
Q_INVOKABLE void endStroke();
@@ -8,7 +8,8 @@ static void drawStroke(
QCanvasPainter* painter,
const QVector<QPointF>& points,
const QColor& color,
qreal width) {
qreal width,
bool polyline) {
if (points.isEmpty()) return;
painter->setStrokeStyle(color);
@@ -17,6 +18,15 @@ static void drawStroke(
painter->setLineCap(QCanvasPainter::LineCap::Round);
painter->setLineJoin(QCanvasPainter::LineJoin::Round);
if (polyline) {
painter->beginPath();
painter->moveTo(points[0]);
for (int i = 1; i < points.size(); i++)
painter->lineTo(points[i]);
painter->stroke();
return;
}
if (points.size() == 1) {
painter->beginPath();
painter->circle(points.front(), width * 0.5);
@@ -180,7 +190,8 @@ void StrokeCanvasRenderer::paint(QCanvasPainter* painter) {
painter,
m_currentStroke.points,
m_currentStroke.color,
m_currentStroke.width);
m_currentStroke.width,
m_currentStroke.isPolyline);
if (m_hoverVisible)
drawHoverCursor(