Mercurial > hg > svgui
comparison layer/TimeInstantLayer.cpp @ 20:1deb5f87a18c
* Add getXForFrame / getFrameForX in preference to using the zoom level everywhere
author | Chris Cannam |
---|---|
date | Mon, 30 Jan 2006 13:19:42 +0000 |
parents | 7c767d41bcee |
children | 3a506d25d95a |
comparison
equal
deleted
inserted
replaced
19:46d8f5add6f0 | 20:1deb5f87a18c |
---|---|
56 list.push_back(tr("Colour")); | 56 list.push_back(tr("Colour")); |
57 return list; | 57 return list; |
58 } | 58 } |
59 | 59 |
60 Layer::PropertyType | 60 Layer::PropertyType |
61 TimeInstantLayer::getPropertyType(const PropertyName &name) const | 61 TimeInstantLayer::getPropertyType(const PropertyName &) const |
62 { | 62 { |
63 return ValueProperty; | 63 return ValueProperty; |
64 } | 64 } |
65 | 65 |
66 int | 66 int |
149 SparseOneDimensionalModel::PointList | 149 SparseOneDimensionalModel::PointList |
150 TimeInstantLayer::getLocalPoints(int x) const | 150 TimeInstantLayer::getLocalPoints(int x) const |
151 { | 151 { |
152 if (!m_model) return SparseOneDimensionalModel::PointList(); | 152 if (!m_model) return SparseOneDimensionalModel::PointList(); |
153 | 153 |
154 long startFrame = m_view->getStartFrame(); | 154 long frame = getFrameForX(x); |
155 long endFrame = m_view->getEndFrame(); | |
156 int zoomLevel = m_view->getZoomLevel(); | |
157 long frame = startFrame + x * zoomLevel; | |
158 | 155 |
159 SparseOneDimensionalModel::PointList onPoints = | 156 SparseOneDimensionalModel::PointList onPoints = |
160 m_model->getPoints(frame); | 157 m_model->getPoints(frame); |
161 | 158 |
162 if (!onPoints.empty()) { | 159 if (!onPoints.empty()) { |
170 | 167 |
171 SparseOneDimensionalModel::PointList usePoints = prevPoints; | 168 SparseOneDimensionalModel::PointList usePoints = prevPoints; |
172 | 169 |
173 if (prevPoints.empty()) { | 170 if (prevPoints.empty()) { |
174 usePoints = nextPoints; | 171 usePoints = nextPoints; |
175 } else if (prevPoints.begin()->frame < startFrame && | 172 } else if (prevPoints.begin()->frame < m_view->getStartFrame() && |
176 !(nextPoints.begin()->frame > endFrame)) { | 173 !(nextPoints.begin()->frame > m_view->getEndFrame())) { |
177 usePoints = nextPoints; | 174 usePoints = nextPoints; |
178 } else if (nextPoints.begin()->frame - frame < | 175 } else if (nextPoints.begin()->frame - frame < |
179 frame - prevPoints.begin()->frame) { | 176 frame - prevPoints.begin()->frame) { |
180 usePoints = nextPoints; | 177 usePoints = nextPoints; |
181 } | 178 } |
264 { | 261 { |
265 if (!m_model || !m_model->isOK()) return; | 262 if (!m_model || !m_model->isOK()) return; |
266 | 263 |
267 // Profiler profiler("TimeInstantLayer::paint", true); | 264 // Profiler profiler("TimeInstantLayer::paint", true); |
268 | 265 |
269 long startFrame = m_view->getStartFrame(); | |
270 int zoomLevel = m_view->getZoomLevel(); | |
271 | |
272 int x0 = rect.left(), x1 = rect.right(); | 266 int x0 = rect.left(), x1 = rect.right(); |
273 long frame0 = startFrame + x0 * zoomLevel; | 267 |
274 long frame1 = startFrame + x1 * zoomLevel; | 268 long frame0 = getFrameForX(x0); |
269 long frame1 = getFrameForX(x1); | |
275 | 270 |
276 SparseOneDimensionalModel::PointList points(m_model->getPoints | 271 SparseOneDimensionalModel::PointList points(m_model->getPoints |
277 (frame0, frame1)); | 272 (frame0, frame1)); |
278 | 273 |
279 paint.setPen(m_colour); | 274 paint.setPen(m_colour); |
299 | 294 |
300 const SparseOneDimensionalModel::Point &p(*i); | 295 const SparseOneDimensionalModel::Point &p(*i); |
301 SparseOneDimensionalModel::PointList::const_iterator j = i; | 296 SparseOneDimensionalModel::PointList::const_iterator j = i; |
302 ++j; | 297 ++j; |
303 | 298 |
304 int x = (p.frame - startFrame) / zoomLevel; | 299 int x = getXForFrame(p.frame); |
305 float w = float(m_model->getResolution()) / zoomLevel; | 300 int iw = getXForFrame(p.frame + m_model->getResolution()) - x; |
306 int iw = w; | |
307 if (iw < 2) { | 301 if (iw < 2) { |
308 if (iw < 1) { | 302 if (iw < 1) { |
309 iw = 2; | 303 iw = 2; |
310 if (j != points.end()) { | 304 if (j != points.end()) { |
311 int nx = ((*j).frame - startFrame) / zoomLevel; | 305 int nx = getXForFrame(j->frame); |
312 if (nx < x + 3) iw = 1; | 306 if (nx < x + 3) iw = 1; |
313 } | 307 } |
314 } else { | 308 } else { |
315 iw = 2; | 309 iw = 2; |
316 } | 310 } |
317 } | 311 } |
318 | 312 |
319 if (p.frame == illuminateFrame) { | 313 if (p.frame == illuminateFrame) { |
320 paint.setPen(Qt::black); //!!! | 314 paint.setPen(Qt::black); //!!! |
321 } else { | 315 } else { |
322 paint.setPen(brushColour); | 316 paint.setPen(brushColour); |
323 } | 317 } |
330 | 324 |
331 int lw = paint.fontMetrics().width(p.label); | 325 int lw = paint.fontMetrics().width(p.label); |
332 bool good = true; | 326 bool good = true; |
333 | 327 |
334 if (j != points.end()) { | 328 if (j != points.end()) { |
335 int nx = (j->frame - startFrame) / zoomLevel; | 329 int nx = getXForFrame(j->frame); |
336 if (nx >= x && nx - x - w - 3 <= lw) good = false; | 330 if (nx >= x && nx - x - iw - 3 <= lw) good = false; |
337 } | 331 } |
338 | 332 |
339 if (good) { | 333 if (good) { |
340 paint.drawText(x + w + 2, | 334 paint.drawText(x + iw + 2, |
341 m_view->height() - paint.fontMetrics().height(), | 335 m_view->height() - paint.fontMetrics().height(), |
342 p.label); | 336 p.label); |
343 } | 337 } |
344 } | 338 } |
345 } | 339 } |
350 { | 344 { |
351 std::cerr << "TimeInstantLayer::drawStart(" << e->x() << ")" << std::endl; | 345 std::cerr << "TimeInstantLayer::drawStart(" << e->x() << ")" << std::endl; |
352 | 346 |
353 if (!m_model) return; | 347 if (!m_model) return; |
354 | 348 |
355 long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); | 349 long frame = getFrameForX(e->x()); |
356 if (frame < 0) frame = 0; | 350 if (frame < 0) frame = 0; |
357 m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point")); | 351 m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point")); |
358 m_model->addPoint(m_editingPoint); | 352 m_model->addPoint(m_editingPoint); |
359 m_editing = true; | 353 m_editing = true; |
360 } | 354 } |
364 { | 358 { |
365 std::cerr << "TimeInstantLayer::drawDrag(" << e->x() << ")" << std::endl; | 359 std::cerr << "TimeInstantLayer::drawDrag(" << e->x() << ")" << std::endl; |
366 | 360 |
367 if (!m_model || !m_editing) return; | 361 if (!m_model || !m_editing) return; |
368 | 362 |
369 long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); | 363 long frame = getFrameForX(e->x()); |
370 if (frame < 0) frame = 0; | 364 if (frame < 0) frame = 0; |
371 m_model->deletePoint(m_editingPoint); | 365 m_model->deletePoint(m_editingPoint); |
372 m_editingPoint.frame = frame; | 366 m_editingPoint.frame = frame; |
373 m_model->addPoint(m_editingPoint); | 367 m_model->addPoint(m_editingPoint); |
374 } | 368 } |
400 { | 394 { |
401 std::cerr << "TimeInstantLayer::editDrag(" << e->x() << ")" << std::endl; | 395 std::cerr << "TimeInstantLayer::editDrag(" << e->x() << ")" << std::endl; |
402 | 396 |
403 if (!m_model || !m_editing) return; | 397 if (!m_model || !m_editing) return; |
404 | 398 |
405 long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); | 399 long frame = getFrameForX(e->x()); |
406 if (frame < 0) frame = 0; | 400 if (frame < 0) frame = 0; |
407 m_model->deletePoint(m_editingPoint); | 401 m_model->deletePoint(m_editingPoint); |
408 m_editingPoint.frame = frame; | 402 m_editingPoint.frame = frame; |
409 m_model->addPoint(m_editingPoint); | 403 m_model->addPoint(m_editingPoint); |
410 } | 404 } |