comparison layer/TimeRulerLayer.cpp @ 1266:a34a2a25907c

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents ee01a4062747
children bc2cb82050a0
comparison
equal deleted inserted replaced
1265:6e724c81f18f 1266:a34a2a25907c
165 165
166 int incms; 166 int incms;
167 quarterTicks = false; 167 quarterTicks = false;
168 168
169 if (rtGap.sec > 0) { 169 if (rtGap.sec > 0) {
170 incms = 1000; 170 incms = 1000;
171 int s = rtGap.sec; 171 int s = rtGap.sec;
172 if (s > 0) { incms *= 5; s /= 5; } 172 if (s > 0) { incms *= 5; s /= 5; }
173 if (s > 0) { incms *= 2; s /= 2; } 173 if (s > 0) { incms *= 2; s /= 2; }
174 if (s > 0) { incms *= 6; s /= 6; quarterTicks = true; } 174 if (s > 0) { incms *= 6; s /= 6; quarterTicks = true; }
175 if (s > 0) { incms *= 5; s /= 5; quarterTicks = false; } 175 if (s > 0) { incms *= 5; s /= 5; quarterTicks = false; }
176 if (s > 0) { incms *= 2; s /= 2; } 176 if (s > 0) { incms *= 2; s /= 2; }
177 if (s > 0) { incms *= 6; s /= 6; quarterTicks = true; } 177 if (s > 0) { incms *= 6; s /= 6; quarterTicks = true; }
178 while (s > 0) { 178 while (s > 0) {
179 incms *= 10; 179 incms *= 10;
180 s /= 10; 180 s /= 10;
181 quarterTicks = false; 181 quarterTicks = false;
182 } 182 }
183 } else { 183 } else {
184 incms = 1; 184 incms = 1;
185 int ms = rtGap.msec(); 185 int ms = rtGap.msec();
186 // cerr << "rtGap.msec = " << ms << ", rtGap = " << rtGap << ", count = " << count << endl; 186 // cerr << "rtGap.msec = " << ms << ", rtGap = " << rtGap << ", count = " << count << endl;
187 // cerr << "startFrame = " << startFrame << ", endFrame = " << endFrame << " rtStart = " << rtStart << ", rtEnd = " << rtEnd << endl; 187 // cerr << "startFrame = " << startFrame << ", endFrame = " << endFrame << " rtStart = " << rtStart << ", rtEnd = " << rtEnd << endl;
188 if (ms > 0) { incms *= 10; ms /= 10; } 188 if (ms > 0) { incms *= 10; ms /= 10; }
189 if (ms > 0) { incms *= 10; ms /= 10; } 189 if (ms > 0) { incms *= 10; ms /= 10; }
190 if (ms > 0) { incms *= 5; ms /= 5; } 190 if (ms > 0) { incms *= 5; ms /= 5; }
191 if (ms > 0) { incms *= 2; ms /= 2; } 191 if (ms > 0) { incms *= 2; ms /= 2; }
192 } 192 }
193 193
194 return incms; 194 return incms;
195 } 195 }
196 196
197 void 197 void
198 TimeRulerLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const 198 TimeRulerLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
199 { 199 {
200 #ifdef DEBUG_TIME_RULER_LAYER 200 #ifdef DEBUG_TIME_RULER_LAYER
201 SVDEBUG << "TimeRulerLayer::paint (" << rect.x() << "," << rect.y() 201 SVDEBUG << "TimeRulerLayer::paint (" << rect.x() << "," << rect.y()
202 << ") [" << rect.width() << "x" << rect.height() << "]" << endl; 202 << ") [" << rect.width() << "x" << rect.height() << "]" << endl;
203 #endif 203 #endif
204 204
205 if (!m_model || !m_model->isOK()) return; 205 if (!m_model || !m_model->isOK()) return;
206 206
207 sv_samplerate_t sampleRate = m_model->getSampleRate(); 207 sv_samplerate_t sampleRate = m_model->getSampleRate();
231 int minPixelSpacing = 50; 231 int minPixelSpacing = 50;
232 sv_frame_t incFrame = lrint((incms * sampleRate) / 1000); 232 sv_frame_t incFrame = lrint((incms * sampleRate) / 1000);
233 int incX = int(incFrame / v->getZoomLevel()); 233 int incX = int(incFrame / v->getZoomLevel());
234 int ticks = 10; 234 int ticks = 10;
235 if (incX < minPixelSpacing * 2) { 235 if (incX < minPixelSpacing * 2) {
236 ticks = quarter ? 4 : 5; 236 ticks = quarter ? 4 : 5;
237 } 237 }
238 238
239 QColor greyColour = getPartialShades(v)[1]; 239 QColor greyColour = getPartialShades(v)[1];
240 240
241 paint.save(); 241 paint.save();
277 cerr << "X well out of range, ending here" << endl; 277 cerr << "X well out of range, ending here" << endl;
278 #endif 278 #endif
279 break; 279 break;
280 } 280 }
281 281
282 if (x >= rect.x() - 50 && ms >= minlabel) { 282 if (x >= rect.x() - 50 && ms >= minlabel) {
283 283
284 RealTime rt = RealTime::fromMilliseconds(ms); 284 RealTime rt = RealTime::fromMilliseconds(ms);
285 285
286 #ifdef DEBUG_TIME_RULER_LAYER 286 #ifdef DEBUG_TIME_RULER_LAYER
287 cerr << "X in range, drawing line here for time " << rt.toText() << endl; 287 cerr << "X in range, drawing line here for time " << rt.toText() << endl;
329 PaintAssistant::drawVisibleText(v, paint, x+2 - tw/2, y, text, PaintAssistant::OutlinedText); 329 PaintAssistant::drawVisibleText(v, paint, x+2 - tw/2, y, text, PaintAssistant::OutlinedText);
330 } 330 }
331 } 331 }
332 } 332 }
333 333
334 paint.setPen(greyColour); 334 paint.setPen(greyColour);
335 335
336 for (int i = 1; i < ticks; ++i) { 336 for (int i = 1; i < ticks; ++i) {
337 337
338 dms = ms + (i * double(incms)) / ticks; 338 dms = ms + (i * double(incms)) / ticks;
339 frame = lrint((dms * sampleRate) / 1000.0); 339 frame = lrint((dms * sampleRate) / 1000.0);
340 frame /= v->getZoomLevel(); 340 frame /= v->getZoomLevel();
341 frame *= v->getZoomLevel(); // exact pixel as above 341 frame *= v->getZoomLevel(); // exact pixel as above
351 351
352 #ifdef DEBUG_TIME_RULER_LAYER 352 #ifdef DEBUG_TIME_RULER_LAYER
353 cerr << "tick " << i << " in range, drawing at " << x << endl; 353 cerr << "tick " << i << " in range, drawing at " << x << endl;
354 #endif 354 #endif
355 355
356 int sz = 5; 356 int sz = 5;
357 if (ticks == 10) { 357 if (ticks == 10) {
358 if ((i % 2) == 1) { 358 if ((i % 2) == 1) {
359 if (i == 5) { 359 if (i == 5) {
360 paint.drawLine(x, 0, x, v->getPaintHeight()); 360 paint.drawLine(x, 0, x, v->getPaintHeight());
361 } else sz = 3; 361 } else sz = 3;
362 } else { 362 } else {
363 sz = 7; 363 sz = 7;
364 } 364 }
365 } 365 }
366 paint.drawLine(x, 0, x, sz); 366 paint.drawLine(x, 0, x, sz);
367 paint.drawLine(x, v->getPaintHeight() - sz - 1, x, v->getPaintHeight() - 1); 367 paint.drawLine(x, v->getPaintHeight() - sz - 1, x, v->getPaintHeight() - 1);
368 } 368 }
369 369
370 ms += incms; 370 ms += incms;
371 } 371 }
372 372
373 paint.restore(); 373 paint.restore();
374 } 374 }
375 375