Mercurial > hg > svgui
comparison layer/TimeRulerLayer.cpp @ 1356:dddfd28e4f02
Fix ugly text positioning/drawing on osx
author | Chris Cannam |
---|---|
date | Thu, 11 Oct 2018 10:15:45 +0100 |
parents | 4c28e3302045 |
children | c39f2d439d59 |
comparison
equal
deleted
inserted
replaced
1355:b9bfcb8cd5a1 | 1356:dddfd28e4f02 |
---|---|
152 sv_samplerate_t sampleRate = m_model->getSampleRate(); | 152 sv_samplerate_t sampleRate = m_model->getSampleRate(); |
153 if (!sampleRate) return 1000 * 1000; | 153 if (!sampleRate) return 1000 * 1000; |
154 | 154 |
155 sv_frame_t startFrame = v->getStartFrame(); | 155 sv_frame_t startFrame = v->getStartFrame(); |
156 sv_frame_t endFrame = v->getEndFrame(); | 156 sv_frame_t endFrame = v->getEndFrame(); |
157 | 157 if (endFrame == startFrame) { |
158 int minPixelSpacing = ViewManager::scalePixelSize(50); | 158 endFrame = startFrame + 1; |
159 } | |
160 | |
161 int exampleWidth = QFontMetrics(QFont()).width("10:42.987654"); | |
162 int minPixelSpacing = v->getXForViewX(exampleWidth); | |
159 | 163 |
160 RealTime rtStart = RealTime::frame2RealTime(startFrame, sampleRate); | 164 RealTime rtStart = RealTime::frame2RealTime(startFrame, sampleRate); |
161 RealTime rtEnd = RealTime::frame2RealTime(endFrame, sampleRate); | 165 RealTime rtEnd = RealTime::frame2RealTime(endFrame, sampleRate); |
162 | 166 |
163 int count = v->getPaintWidth() / minPixelSpacing; | 167 int count = v->getPaintWidth() / minPixelSpacing; |
164 if (count < 1) count = 1; | 168 if (count < 1) count = 1; |
165 RealTime rtGap = (rtEnd - rtStart) / count; | 169 RealTime rtGap = (rtEnd - rtStart) / count; |
170 | |
171 #ifdef DEBUG_TIME_RULER_LAYER | |
172 SVCERR << "zoomLevel = " << v->getZoomLevel() | |
173 << ", startFrame = " << startFrame << ", endFrame = " << endFrame | |
174 << ", rtStart = " << rtStart << ", rtEnd = " << rtEnd | |
175 << ", paint width = " << v->getPaintWidth() | |
176 << ", minPixelSpacing = " << minPixelSpacing | |
177 << ", count = " << count << ", rtGap = " << rtGap << endl; | |
178 #endif | |
166 | 179 |
167 int64_t incus; | 180 int64_t incus; |
168 quarterTicks = false; | 181 quarterTicks = false; |
169 | 182 |
170 if (rtGap.sec > 0) { | 183 if (rtGap.sec > 0) { |
195 if (us > 0) { incus *= 10; us /= 10; } | 208 if (us > 0) { incus *= 10; us /= 10; } |
196 if (us > 0) { incus *= 5; us /= 5; } | 209 if (us > 0) { incus *= 5; us /= 5; } |
197 if (us > 0) { incus *= 2; us /= 2; } | 210 if (us > 0) { incus *= 2; us /= 2; } |
198 } | 211 } |
199 | 212 |
213 #ifdef DEBUG_TIME_RULER_LAYER | |
214 SVCERR << "getMajorTickUSec: returning incus = " << incus << endl; | |
215 #endif | |
216 | |
200 return incus; | 217 return incus; |
201 } | 218 } |
202 | 219 |
203 int | 220 int |
204 TimeRulerLayer::getXForUSec(LayerGeometryProvider *v, double us) const | 221 TimeRulerLayer::getXForUSec(LayerGeometryProvider *v, double us) const |
275 // Calculate the number of ticks per increment -- approximate | 292 // Calculate the number of ticks per increment -- approximate |
276 // values for x and frame counts here will do, no rounding issue. | 293 // values for x and frame counts here will do, no rounding issue. |
277 // We always use the exact incus in our calculations for where to | 294 // We always use the exact incus in our calculations for where to |
278 // draw the actual ticks or lines. | 295 // draw the actual ticks or lines. |
279 | 296 |
280 int minPixelSpacing = 50; | 297 int minPixelSpacing = v->getXForViewX(50); |
281 sv_frame_t incFrame = lrint((double(incus) * sampleRate) / 1000000); | 298 sv_frame_t incFrame = lrint((double(incus) * sampleRate) / 1000000); |
282 int incX = int(round(v->getZoomLevel().framesToPixels(double(incFrame)))); | 299 int incX = int(round(v->getZoomLevel().framesToPixels(double(incFrame)))); |
283 int ticks = 10; | 300 int ticks = 10; |
284 if (incX < minPixelSpacing * 2) { | 301 if (incX < minPixelSpacing * 2) { |
285 ticks = quarter ? 4 : 5; | 302 ticks = quarter ? 4 : 5; |