| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "axisline_p.h" |
| 5 | |
| 6 | QT_BEGIN_NAMESPACE |
| 7 | |
| 8 | AxisLine::AxisLine(QQuickItem *parent) : |
| 9 | QQuickShaderEffect(parent) |
| 10 | { |
| 11 | |
| 12 | } |
| 13 | |
| 14 | AxisLine::~AxisLine() {} |
| 15 | |
| 16 | void AxisLine::componentComplete() |
| 17 | { |
| 18 | QQuickShaderEffect::componentComplete(); |
| 19 | setupShaders(); |
| 20 | } |
| 21 | |
| 22 | void AxisLine::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) |
| 23 | { |
| 24 | m_iResolution = QVector3D(newGeometry.width(), newGeometry.height(), 1.0); |
| 25 | emit iResolutionChanged(); |
| 26 | |
| 27 | QQuickShaderEffect::geometryChange(newGeometry, oldGeometry); |
| 28 | } |
| 29 | |
| 30 | void AxisLine::setupShaders() |
| 31 | { |
| 32 | if (m_isHorizontal) { |
| 33 | setFragmentShader(QUrl(QStringLiteral("qrc:/shaders/lineshaderhorizontal.frag.qsb"))); |
| 34 | setVertexShader(QUrl(QStringLiteral("qrc:/shaders/lineshaderhorizontal.vert.qsb"))); |
| 35 | } else { |
| 36 | setFragmentShader(QUrl(QStringLiteral("qrc:/shaders/lineshadervertical.frag.qsb"))); |
| 37 | setVertexShader(QUrl(QStringLiteral("qrc:/shaders/lineshadervertical.vert.qsb"))); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | QVector3D AxisLine::iResolution() const |
| 42 | { |
| 43 | return m_iResolution; |
| 44 | } |
| 45 | |
| 46 | qreal AxisLine::smoothing() const |
| 47 | { |
| 48 | return m_smoothing; |
| 49 | } |
| 50 | |
| 51 | void AxisLine::setSmoothing(qreal newSmoothing) |
| 52 | { |
| 53 | if (qFuzzyCompare(p1: m_smoothing, p2: newSmoothing)) |
| 54 | return; |
| 55 | m_smoothing = newSmoothing; |
| 56 | emit smoothingChanged(); |
| 57 | } |
| 58 | |
| 59 | QColor AxisLine::color() const |
| 60 | { |
| 61 | return m_color; |
| 62 | } |
| 63 | |
| 64 | void AxisLine::setColor(QColor newColor) |
| 65 | { |
| 66 | if (m_color == newColor) |
| 67 | return; |
| 68 | m_color = newColor; |
| 69 | emit colorChanged(); |
| 70 | } |
| 71 | |
| 72 | qreal AxisLine::lineWidth() const |
| 73 | { |
| 74 | return m_lineWidth; |
| 75 | } |
| 76 | |
| 77 | void AxisLine::setLineWidth(qreal newLineWidth) |
| 78 | { |
| 79 | if (qFuzzyCompare(p1: m_lineWidth, p2: newLineWidth)) |
| 80 | return; |
| 81 | m_lineWidth = newLineWidth; |
| 82 | emit lineWidthChanged(); |
| 83 | } |
| 84 | |
| 85 | bool AxisLine::isHorizontal() const |
| 86 | { |
| 87 | return m_isHorizontal; |
| 88 | } |
| 89 | |
| 90 | void AxisLine::setIsHorizontal(bool newIsHorizontal) |
| 91 | { |
| 92 | if (m_isHorizontal == newIsHorizontal) |
| 93 | return; |
| 94 | m_isHorizontal = newIsHorizontal; |
| 95 | emit isHorizontalChanged(); |
| 96 | } |
| 97 | |
| 98 | QT_END_NAMESPACE |
| 99 |
