1 | // Copyright (C) 2023 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "axisticker_p.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | AxisTicker::AxisTicker(QQuickItem *parent) : |
9 | QQuickShaderEffect(parent) |
10 | { |
11 | } |
12 | |
13 | AxisTicker::~AxisTicker() {} |
14 | |
15 | void AxisTicker::componentComplete() |
16 | { |
17 | QQuickShaderEffect::componentComplete(); |
18 | setupShaders(); |
19 | } |
20 | |
21 | void AxisTicker::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) |
22 | { |
23 | m_iResolution = QVector3D(newGeometry.width(), newGeometry.height(), 1.0); |
24 | emit iResolutionChanged(); |
25 | |
26 | QQuickShaderEffect::geometryChange(newGeometry, oldGeometry); |
27 | } |
28 | |
29 | void AxisTicker::setupShaders() |
30 | { |
31 | if (m_isHorizontal) { |
32 | setFragmentShader(QUrl(QStringLiteral("qrc:/shaders/tickershaderhorizontal.frag.qsb"))); |
33 | setVertexShader(QUrl(QStringLiteral("qrc:/shaders/tickershaderhorizontal.vert.qsb"))); |
34 | } else { |
35 | setFragmentShader(QUrl(QStringLiteral("qrc:/shaders/tickershader.frag.qsb"))); |
36 | setVertexShader(QUrl(QStringLiteral("qrc:/shaders/tickershader.vert.qsb"))); |
37 | } |
38 | } |
39 | |
40 | QVector3D AxisTicker::iResolution() const |
41 | { |
42 | return m_iResolution; |
43 | } |
44 | |
45 | qreal AxisTicker::smoothing() const |
46 | { |
47 | return m_smoothing; |
48 | } |
49 | |
50 | void AxisTicker::setSmoothing(qreal newSmoothing) |
51 | { |
52 | if (qFuzzyCompare(p1: m_smoothing, p2: newSmoothing)) |
53 | return; |
54 | m_smoothing = newSmoothing; |
55 | emit smoothingChanged(); |
56 | } |
57 | |
58 | int AxisTicker::origo() const |
59 | { |
60 | return m_origo; |
61 | } |
62 | |
63 | void AxisTicker::setOrigo(int newOrigo) |
64 | { |
65 | if (m_origo == newOrigo) |
66 | return; |
67 | m_origo = newOrigo; |
68 | emit origoChanged(); |
69 | } |
70 | |
71 | bool AxisTicker::subTicksVisible() const |
72 | { |
73 | return m_subTicksVisible; |
74 | } |
75 | |
76 | void AxisTicker::setSubTicksVisible(bool newSubTicksVisible) |
77 | { |
78 | if (m_subTicksVisible == newSubTicksVisible) |
79 | return; |
80 | m_subTicksVisible = newSubTicksVisible; |
81 | emit subTicksVisibleChanged(); |
82 | } |
83 | |
84 | qreal AxisTicker::spacing() const |
85 | { |
86 | return m_spacing; |
87 | } |
88 | |
89 | void AxisTicker::setSpacing(qreal newSpacing) |
90 | { |
91 | if (qFuzzyCompare(p1: m_spacing, p2: newSpacing)) |
92 | return; |
93 | m_spacing = newSpacing; |
94 | emit spacingChanged(); |
95 | } |
96 | |
97 | qreal AxisTicker::displacement() const |
98 | { |
99 | return m_displacement; |
100 | } |
101 | |
102 | void AxisTicker::setDisplacement(qreal newDisplacement) |
103 | { |
104 | if (qFuzzyCompare(p1: m_displacement, p2: newDisplacement)) |
105 | return; |
106 | m_displacement = newDisplacement; |
107 | emit displacementChanged(); |
108 | } |
109 | |
110 | QColor AxisTicker::subTickColor() const |
111 | { |
112 | return m_subTickColor; |
113 | } |
114 | |
115 | void AxisTicker::setSubTickColor(QColor newSubTickColor) |
116 | { |
117 | if (m_subTickColor == newSubTickColor) |
118 | return; |
119 | m_subTickColor = newSubTickColor; |
120 | emit subTickColorChanged(); |
121 | } |
122 | |
123 | QColor AxisTicker::tickColor() const |
124 | { |
125 | return m_tickColor; |
126 | } |
127 | |
128 | void AxisTicker::setTickColor(QColor newTickColor) |
129 | { |
130 | if (m_tickColor == newTickColor) |
131 | return; |
132 | m_tickColor = newTickColor; |
133 | emit tickColorChanged(); |
134 | } |
135 | |
136 | qreal AxisTicker::subTickLineWidth() const |
137 | { |
138 | return m_subTickLineWidth; |
139 | } |
140 | |
141 | void AxisTicker::setSubTickLineWidth(qreal newSubTickLineWidth) |
142 | { |
143 | if (qFuzzyCompare(p1: m_subTickLineWidth, p2: newSubTickLineWidth)) |
144 | return; |
145 | m_subTickLineWidth = newSubTickLineWidth; |
146 | emit subTickLineWidthChanged(); |
147 | } |
148 | |
149 | qreal AxisTicker::tickLineWidth() const |
150 | { |
151 | return m_tickLineWidth; |
152 | } |
153 | |
154 | void AxisTicker::setTickLineWidth(qreal newTickLineWidth) |
155 | { |
156 | if (qFuzzyCompare(p1: m_tickLineWidth, p2: newTickLineWidth)) |
157 | return; |
158 | m_tickLineWidth = newTickLineWidth; |
159 | emit tickLineWidthChanged(); |
160 | } |
161 | |
162 | qreal AxisTicker::subTickScale() const |
163 | { |
164 | return m_subTickScale; |
165 | } |
166 | |
167 | void AxisTicker::setSubTickScale(qreal newSubTickScale) |
168 | { |
169 | if (qFuzzyCompare(p1: m_subTickScale, p2: newSubTickScale)) |
170 | return; |
171 | m_subTickScale = newSubTickScale; |
172 | emit subTickScaleChanged(); |
173 | } |
174 | |
175 | qreal AxisTicker::subTickLength() const |
176 | { |
177 | return m_subTickLength; |
178 | } |
179 | |
180 | void AxisTicker::setSubTickLength(qreal newSubTickLength) |
181 | { |
182 | if (qFuzzyCompare(p1: m_subTickLength, p2: newSubTickLength)) |
183 | return; |
184 | m_subTickLength = newSubTickLength; |
185 | emit subTickLengthChanged(); |
186 | } |
187 | |
188 | bool AxisTicker::isHorizontal() const |
189 | { |
190 | return m_isHorizontal; |
191 | } |
192 | |
193 | void AxisTicker::setIsHorizontal(bool newIsHorizontal) |
194 | { |
195 | if (m_isHorizontal == newIsHorizontal) |
196 | return; |
197 | m_isHorizontal = newIsHorizontal; |
198 | setupShaders(); |
199 | emit isHorizontalChanged(); |
200 | } |
201 | |
202 | bool AxisTicker::isFlipped() const |
203 | { |
204 | return m_flipped; |
205 | } |
206 | |
207 | void AxisTicker::setFlipped(bool newFlipped) |
208 | { |
209 | if (m_flipped == newFlipped) |
210 | return; |
211 | m_flipped = newFlipped; |
212 | emit flippedChanged(); |
213 | } |
214 | |
215 | QT_END_NAMESPACE |
216 |
Definitions
- AxisTicker
- ~AxisTicker
- componentComplete
- geometryChange
- setupShaders
- iResolution
- smoothing
- setSmoothing
- origo
- setOrigo
- subTicksVisible
- setSubTicksVisible
- spacing
- setSpacing
- displacement
- setDisplacement
- subTickColor
- setSubTickColor
- tickColor
- setTickColor
- subTickLineWidth
- setSubTickLineWidth
- tickLineWidth
- setTickLineWidth
- subTickScale
- setSubTickScale
- subTickLength
- setSubTickLength
- isHorizontal
- setIsHorizontal
- isFlipped
Learn Advanced QML with KDAB
Find out more