show hover dot instead of cursor while drawing
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 12s
Python / lint-format (pull_request) Successful in 17s
Python / test (pull_request) Successful in 28s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m11s

This commit is contained in:
2026-06-20 19:00:58 +02:00
parent 81eb56e1d0
commit e619632077
5 changed files with 96 additions and 4 deletions
+11 -4
View File
@@ -140,7 +140,7 @@ Item {
const origY = point.pressPosition.y;
if (point.pressedButtons & Qt.RightButton) {
root.drawing.clear();
root.drawing.content.clear();
return;
}
if (x === 0 && y === 0 && origX === 0 && origY === 0)
@@ -159,7 +159,7 @@ Item {
HoverHandler {
id: hoverHandler
cursorShape: root.visibilities.isDrawing && !root.inLeftPanel(root.panels.drawing, point.position.x, point.position.y) ? Qt.CrossCursor : undefined
cursorShape: root.visibilities.isDrawing && !root.inLeftPanel(root.panels.drawing, point.position.x, point.position.y) ? Qt.BlankCursor : undefined
onHoveredChanged: {
if (!hovered) {
@@ -181,9 +181,16 @@ Item {
const y = point.position.y;
if (root.visibilities.isDrawing) {
if (root.inLeftPanel(root.panels.drawing, x, y) && !(drawingHandler.point.pressedButtons & Qt.LeftButton))
if (root.inLeftPanel(root.panels.drawing, x, y) && !(drawingHandler.point.pressedButtons & Qt.LeftButton)) {
root.panels.drawing.expanded = true;
return;
root.drawing.content.hideHover();
return;
}
if (!drawingHandler.point.pressedButtons) {
root.drawing.content.showHover(x, y);
return;
}
}
if (!root.visibilities.bar && Config.barConfig.autoHide && y < root.bar.implicitHeight)
@@ -37,6 +37,45 @@ void StrokeCanvasItem::setPenColor(const QColor &color) {
emit penColorChanged();
}
void StrokeCanvasItem::setHoverVisible(bool visible) {
if (m_hoverVisible == visible)
return;
m_hoverVisible = visible;
update();
emit hoverVisibleChanged();
}
void StrokeCanvasItem::setHoverPoint(const QPointF &point) {
if (m_hoverPoint == point)
return;
m_hoverPoint = point;
update();
emit hoverPointChanged();
}
void StrokeCanvasItem::showHover(qreal x, qreal y) {
m_hoverPoint = {x, y};
m_hoverVisible = true;
update();
emit hoverPointChanged();
emit hoverVisibleChanged();
}
void StrokeCanvasItem::hideHover() {
if (!m_hoverVisible)
return;
m_hoverVisible = false;
update();
emit hoverVisibleChanged();
}
void StrokeCanvasItem::setPenWidth(float width) {
if (qFuzzyCompare(m_penWidth, width))
return;
@@ -18,11 +18,26 @@ Q_OBJECT
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)
public:
explicit StrokeCanvasItem(QQuickItem *parent = nullptr);
[[nodiscard]] bool hoverVisible() const {
return m_hoverVisible;
}
[[nodiscard]] QPointF hoverPoint() const {
return m_hoverPoint;
}
void setHoverVisible(bool visible);
void setHoverPoint(const QPointF &point);
Q_INVOKABLE void showHover(qreal x, qreal y);
Q_INVOKABLE void hideHover();
[[nodiscard]] QColor penColor() const {
return m_penColor;
}
@@ -42,6 +57,8 @@ Q_INVOKABLE void endStroke();
signals:
void penColorChanged();
void penWidthChanged();
void hoverVisibleChanged();
void hoverPointChanged();
protected:
[[nodiscard]] QCanvasPainterItemRenderer *createItemRenderer() const override;
@@ -49,6 +66,8 @@ protected:
private:
friend class StrokeCanvasRenderer;
bool m_hoverVisible = false;
QPointF m_hoverPoint;
QColor m_penColor = Qt::white;
float m_penWidth = 4.f;
@@ -37,6 +37,19 @@ static void drawStroke(
painter->stroke();
}
static void drawDot(
QCanvasPainter *painter,
const QPointF &point,
const QColor &color,
float width)
{
painter->setFillStyle(color);
painter->beginPath();
painter->circle(point, width * 0.5f);
painter->fill();
}
void StrokeCanvasRenderer::synchronizeData(QCanvasPainterItem *item) {
auto *canvas = static_cast<StrokeCanvasItem *>(item);
@@ -45,6 +58,9 @@ void StrokeCanvasRenderer::synchronizeData(QCanvasPainterItem *item) {
m_strokes = canvas->m_strokes;
m_currentStroke = canvas->m_currentStroke;
m_hoverVisible = canvas->m_hoverVisible;
m_hoverPoint = canvas->m_hoverPoint;
}
void StrokeCanvasRenderer::paint(QCanvasPainter *painter) {
@@ -59,6 +75,15 @@ void StrokeCanvasRenderer::paint(QCanvasPainter *painter) {
m_currentStroke.color,
m_currentStroke.width
);
if (m_hoverVisible) {
drawDot(
painter,
m_hoverPoint,
m_penColor,
m_penWidth
);
}
}
};
@@ -14,6 +14,8 @@ void paint(QCanvasPainter *painter) override;
private:
QColor m_penColor;
float m_penWidth = 4.f;
bool m_hoverVisible = false;
QPointF m_hoverPoint;
QVector<Stroke> m_strokes;
Stroke m_currentStroke;