show hover dot instead of cursor while drawing
This commit is contained in:
@@ -140,7 +140,7 @@ Item {
|
|||||||
const origY = point.pressPosition.y;
|
const origY = point.pressPosition.y;
|
||||||
|
|
||||||
if (point.pressedButtons & Qt.RightButton) {
|
if (point.pressedButtons & Qt.RightButton) {
|
||||||
root.drawing.clear();
|
root.drawing.content.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (x === 0 && y === 0 && origX === 0 && origY === 0)
|
if (x === 0 && y === 0 && origX === 0 && origY === 0)
|
||||||
@@ -159,7 +159,7 @@ Item {
|
|||||||
HoverHandler {
|
HoverHandler {
|
||||||
id: 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: {
|
onHoveredChanged: {
|
||||||
if (!hovered) {
|
if (!hovered) {
|
||||||
@@ -181,9 +181,16 @@ Item {
|
|||||||
const y = point.position.y;
|
const y = point.position.y;
|
||||||
|
|
||||||
if (root.visibilities.isDrawing) {
|
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;
|
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)
|
if (!root.visibilities.bar && Config.barConfig.autoHide && y < root.bar.implicitHeight)
|
||||||
|
|||||||
@@ -37,6 +37,45 @@ void StrokeCanvasItem::setPenColor(const QColor &color) {
|
|||||||
emit penColorChanged();
|
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) {
|
void StrokeCanvasItem::setPenWidth(float width) {
|
||||||
if (qFuzzyCompare(m_penWidth, width))
|
if (qFuzzyCompare(m_penWidth, width))
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -18,11 +18,26 @@ Q_OBJECT
|
|||||||
QML_NAMED_ELEMENT(StrokeCanvas)
|
QML_NAMED_ELEMENT(StrokeCanvas)
|
||||||
|
|
||||||
Q_PROPERTY(QColor penColor READ penColor WRITE setPenColor NOTIFY penColorChanged)
|
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(qreal penWidth READ penWidth WRITE setPenWidth NOTIFY penWidthChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StrokeCanvasItem(QQuickItem *parent = nullptr);
|
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 {
|
[[nodiscard]] QColor penColor() const {
|
||||||
return m_penColor;
|
return m_penColor;
|
||||||
}
|
}
|
||||||
@@ -42,6 +57,8 @@ Q_INVOKABLE void endStroke();
|
|||||||
signals:
|
signals:
|
||||||
void penColorChanged();
|
void penColorChanged();
|
||||||
void penWidthChanged();
|
void penWidthChanged();
|
||||||
|
void hoverVisibleChanged();
|
||||||
|
void hoverPointChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
[[nodiscard]] QCanvasPainterItemRenderer *createItemRenderer() const override;
|
[[nodiscard]] QCanvasPainterItemRenderer *createItemRenderer() const override;
|
||||||
@@ -49,6 +66,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
friend class StrokeCanvasRenderer;
|
friend class StrokeCanvasRenderer;
|
||||||
|
|
||||||
|
bool m_hoverVisible = false;
|
||||||
|
QPointF m_hoverPoint;
|
||||||
QColor m_penColor = Qt::white;
|
QColor m_penColor = Qt::white;
|
||||||
float m_penWidth = 4.f;
|
float m_penWidth = 4.f;
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,19 @@ static void drawStroke(
|
|||||||
painter->stroke();
|
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) {
|
void StrokeCanvasRenderer::synchronizeData(QCanvasPainterItem *item) {
|
||||||
auto *canvas = static_cast<StrokeCanvasItem *>(item);
|
auto *canvas = static_cast<StrokeCanvasItem *>(item);
|
||||||
|
|
||||||
@@ -45,6 +58,9 @@ void StrokeCanvasRenderer::synchronizeData(QCanvasPainterItem *item) {
|
|||||||
|
|
||||||
m_strokes = canvas->m_strokes;
|
m_strokes = canvas->m_strokes;
|
||||||
m_currentStroke = canvas->m_currentStroke;
|
m_currentStroke = canvas->m_currentStroke;
|
||||||
|
|
||||||
|
m_hoverVisible = canvas->m_hoverVisible;
|
||||||
|
m_hoverPoint = canvas->m_hoverPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StrokeCanvasRenderer::paint(QCanvasPainter *painter) {
|
void StrokeCanvasRenderer::paint(QCanvasPainter *painter) {
|
||||||
@@ -59,6 +75,15 @@ void StrokeCanvasRenderer::paint(QCanvasPainter *painter) {
|
|||||||
m_currentStroke.color,
|
m_currentStroke.color,
|
||||||
m_currentStroke.width
|
m_currentStroke.width
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (m_hoverVisible) {
|
||||||
|
drawDot(
|
||||||
|
painter,
|
||||||
|
m_hoverPoint,
|
||||||
|
m_penColor,
|
||||||
|
m_penWidth
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ void paint(QCanvasPainter *painter) override;
|
|||||||
private:
|
private:
|
||||||
QColor m_penColor;
|
QColor m_penColor;
|
||||||
float m_penWidth = 4.f;
|
float m_penWidth = 4.f;
|
||||||
|
bool m_hoverVisible = false;
|
||||||
|
QPointF m_hoverPoint;
|
||||||
|
|
||||||
QVector<Stroke> m_strokes;
|
QVector<Stroke> m_strokes;
|
||||||
Stroke m_currentStroke;
|
Stroke m_currentStroke;
|
||||||
|
|||||||
Reference in New Issue
Block a user