comparison layer/Layer.cpp @ 978:64c2b3a4435a 3.0-integration

Merge from branch osx-retina
author Chris Cannam
date Fri, 26 Jun 2015 14:10:40 +0100
parents 4fe7a09be0fe
children a34a2a25907c
comparison
equal deleted inserted replaced
977:f40ccbf228c2 978:64c2b3a4435a
113 } 113 }
114 return 0; 114 return 0;
115 } 115 }
116 116
117 void 117 void
118 Layer::setLayerDormant(const View *v, bool dormant) 118 Layer::setLayerDormant(const LayerGeometryProvider *v, bool dormant)
119 { 119 {
120 const void *vv = (const void *)v; 120 const void *vv = (const void *)v;
121 QMutexLocker locker(&m_dormancyMutex); 121 QMutexLocker locker(&m_dormancyMutex);
122 m_dormancy[vv] = dormant; 122 m_dormancy[vv] = dormant;
123 } 123 }
124 124
125 bool 125 bool
126 Layer::isLayerDormant(const View *v) const 126 Layer::isLayerDormant(const LayerGeometryProvider *v) const
127 { 127 {
128 const void *vv = (const void *)v; 128 const void *vv = (const void *)v;
129 QMutexLocker locker(&m_dormancyMutex); 129 QMutexLocker locker(&m_dormancyMutex);
130 if (m_dormancy.find(vv) == m_dormancy.end()) return false; 130 if (m_dormancy.find(vv) == m_dormancy.end()) return false;
131 return m_dormancy.find(vv)->second; 131 return m_dormancy.find(vv)->second;
132 } 132 }
133 133
134 void 134 void
135 Layer::showLayer(View *view, bool show) 135 Layer::showLayer(LayerGeometryProvider *view, bool show)
136 { 136 {
137 setLayerDormant(view, !show); 137 setLayerDormant(view, !show);
138 emit layerParametersChanged(); 138 emit layerParametersChanged();
139 } 139 }
140 140
141 bool 141 bool
142 Layer::getXScaleValue(const View *v, int x, double &value, QString &unit) const 142 Layer::getXScaleValue(const LayerGeometryProvider *v, int x, double &value, QString &unit) const
143 { 143 {
144 if (!hasTimeXAxis()) return false; 144 if (!hasTimeXAxis()) return false;
145 145
146 const Model *m = getModel(); 146 const Model *m = getModel();
147 if (!m) return false; 147 if (!m) return false;
150 unit = "s"; 150 unit = "s";
151 return true; 151 return true;
152 } 152 }
153 153
154 bool 154 bool
155 Layer::getYScaleDifference(const View *v, int y0, int y1, 155 Layer::getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1,
156 double &diff, QString &unit) const 156 double &diff, QString &unit) const
157 { 157 {
158 double v0, v1; 158 double v0, v1;
159 if (!getYScaleValue(v, y0, v0, unit) || 159 if (!getYScaleValue(v, y0, v0, unit) ||
160 !getYScaleValue(v, y1, v1, unit)) { 160 !getYScaleValue(v, y1, v1, unit)) {
164 diff = fabs(v1 - v0); 164 diff = fabs(v1 - v0);
165 return true; 165 return true;
166 } 166 }
167 167
168 sv_frame_t 168 sv_frame_t
169 Layer::alignToReference(View *v, sv_frame_t frame) const 169 Layer::alignToReference(LayerGeometryProvider *v, sv_frame_t frame) const
170 { 170 {
171 const Model *m = getModel(); 171 const Model *m = getModel();
172 SVDEBUG << "Layer::alignToReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl; 172 SVDEBUG << "Layer::alignToReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl;
173 if (m && m->getAlignmentReference()) { 173 if (m && m->getAlignmentReference()) {
174 return m->alignToReference(frame); 174 return m->alignToReference(frame);
175 } else { 175 } else {
176 return v->alignToReference(frame); 176 return v->getView()->alignToReference(frame);
177 } 177 }
178 } 178 }
179 179
180 sv_frame_t 180 sv_frame_t
181 Layer::alignFromReference(View *v, sv_frame_t frame) const 181 Layer::alignFromReference(LayerGeometryProvider *v, sv_frame_t frame) const
182 { 182 {
183 const Model *m = getModel(); 183 const Model *m = getModel();
184 SVDEBUG << "Layer::alignFromReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl; 184 SVDEBUG << "Layer::alignFromReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl;
185 if (m && m->getAlignmentReference()) { 185 if (m && m->getAlignmentReference()) {
186 return m->alignFromReference(frame); 186 return m->alignFromReference(frame);
187 } else { 187 } else {
188 return v->alignFromReference(frame); 188 return v->getView()->alignFromReference(frame);
189 } 189 }
190 } 190 }
191 191
192 bool 192 bool
193 Layer::clipboardHasDifferentAlignment(View *v, const Clipboard &clip) const 193 Layer::clipboardHasDifferentAlignment(LayerGeometryProvider *v, const Clipboard &clip) const
194 { 194 {
195 // Notes on pasting to an aligned layer: 195 // Notes on pasting to an aligned layer:
196 // 196 //
197 // Each point may have a reference frame that may differ from the 197 // Each point may have a reference frame that may differ from the
198 // point's given frame (in its source model). If it has no 198 // point's given frame (in its source model). If it has no
369 { 369 {
370 m_layer->addMeasureRectToSet(m_rect); 370 m_layer->addMeasureRectToSet(m_rect);
371 } 371 }
372 372
373 void 373 void
374 Layer::measureStart(View *v, QMouseEvent *e) 374 Layer::measureStart(LayerGeometryProvider *v, QMouseEvent *e)
375 { 375 {
376 setMeasureRectFromPixrect(v, m_draggingRect, 376 setMeasureRectFromPixrect(v, m_draggingRect,
377 QRect(e->x(), e->y(), 0, 0)); 377 QRect(e->x(), e->y(), 0, 0));
378 m_haveDraggingRect = true; 378 m_haveDraggingRect = true;
379 } 379 }
380 380
381 void 381 void
382 Layer::measureDrag(View *v, QMouseEvent *e) 382 Layer::measureDrag(LayerGeometryProvider *v, QMouseEvent *e)
383 { 383 {
384 if (!m_haveDraggingRect) return; 384 if (!m_haveDraggingRect) return;
385 385
386 setMeasureRectFromPixrect(v, m_draggingRect, 386 setMeasureRectFromPixrect(v, m_draggingRect,
387 QRect(m_draggingRect.pixrect.x(), 387 QRect(m_draggingRect.pixrect.x(),
389 e->x() - m_draggingRect.pixrect.x(), 389 e->x() - m_draggingRect.pixrect.x(),
390 e->y() - m_draggingRect.pixrect.y())); 390 e->y() - m_draggingRect.pixrect.y()));
391 } 391 }
392 392
393 void 393 void
394 Layer::measureEnd(View *v, QMouseEvent *e) 394 Layer::measureEnd(LayerGeometryProvider *v, QMouseEvent *e)
395 { 395 {
396 if (!m_haveDraggingRect) return; 396 if (!m_haveDraggingRect) return;
397 measureDrag(v, e); 397 measureDrag(v, e);
398 398
399 if (!m_draggingRect.pixrect.isNull()) { 399 if (!m_draggingRect.pixrect.isNull()) {
403 403
404 m_haveDraggingRect = false; 404 m_haveDraggingRect = false;
405 } 405 }
406 406
407 void 407 void
408 Layer::measureDoubleClick(View *, QMouseEvent *) 408 Layer::measureDoubleClick(LayerGeometryProvider *, QMouseEvent *)
409 { 409 {
410 // nothing, in the base class 410 // nothing, in the base class
411 } 411 }
412 412
413 void 413 void
423 CommandHistory::getInstance()->addCommand 423 CommandHistory::getInstance()->addCommand
424 (new DeleteMeasurementRectCommand(this, *focusRectItr)); 424 (new DeleteMeasurementRectCommand(this, *focusRectItr));
425 } 425 }
426 426
427 void 427 void
428 Layer::paintMeasurementRects(View *v, QPainter &paint, 428 Layer::paintMeasurementRects(LayerGeometryProvider *v, QPainter &paint,
429 bool showFocus, QPoint focusPoint) const 429 bool showFocus, QPoint focusPoint) const
430 { 430 {
431 updateMeasurePixrects(v); 431 updateMeasurePixrects(v);
432 432
433 MeasureRectSet::const_iterator focusRectItr = m_measureRects.end(); 433 MeasureRectSet::const_iterator focusRectItr = m_measureRects.end();
455 } 455 }
456 } 456 }
457 } 457 }
458 458
459 bool 459 bool
460 Layer::nearestMeasurementRectChanged(View *v, QPoint prev, QPoint now) const 460 Layer::nearestMeasurementRectChanged(LayerGeometryProvider *v, QPoint prev, QPoint now) const
461 { 461 {
462 updateMeasurePixrects(v); 462 updateMeasurePixrects(v);
463 463
464 MeasureRectSet::const_iterator i0 = findFocusedMeasureRect(prev); 464 MeasureRectSet::const_iterator i0 = findFocusedMeasureRect(prev);
465 MeasureRectSet::const_iterator i1 = findFocusedMeasureRect(now); 465 MeasureRectSet::const_iterator i1 = findFocusedMeasureRect(now);
466 466
467 return (i0 != i1); 467 return (i0 != i1);
468 } 468 }
469 469
470 void 470 void
471 Layer::updateMeasurePixrects(View *v) const 471 Layer::updateMeasurePixrects(LayerGeometryProvider *v) const
472 { 472 {
473 sv_frame_t sf = v->getStartFrame(); 473 sv_frame_t sf = v->getStartFrame();
474 sv_frame_t ef = v->getEndFrame(); 474 sv_frame_t ef = v->getEndFrame();
475 475
476 for (MeasureRectSet::const_iterator i = m_measureRects.begin(); 476 for (MeasureRectSet::const_iterator i = m_measureRects.begin();
505 updateMeasureRectYCoords(v, *i); 505 updateMeasureRectYCoords(v, *i);
506 } 506 }
507 } 507 }
508 508
509 void 509 void
510 Layer::updateMeasureRectYCoords(View *v, const MeasureRect &r) const 510 Layer::updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const
511 { 511 {
512 int y0 = int(lrint(r.startY * v->height())); 512 int y0 = int(lrint(r.startY * v->getPaintHeight()));
513 int y1 = int(lrint(r.endY * v->height())); 513 int y1 = int(lrint(r.endY * v->getPaintHeight()));
514 r.pixrect = QRect(r.pixrect.x(), y0, r.pixrect.width(), y1 - y0); 514 r.pixrect = QRect(r.pixrect.x(), y0, r.pixrect.width(), y1 - y0);
515 } 515 }
516 516
517 void 517 void
518 Layer::setMeasureRectYCoord(View *v, MeasureRect &r, bool start, int y) const 518 Layer::setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const
519 { 519 {
520 if (start) { 520 if (start) {
521 r.startY = double(y) / double(v->height()); 521 r.startY = double(y) / double(v->getPaintHeight());
522 r.endY = r.startY; 522 r.endY = r.startY;
523 } else { 523 } else {
524 r.endY = double(y) / double(v->height()); 524 r.endY = double(y) / double(v->getPaintHeight());
525 } 525 }
526 } 526 }
527 527
528 void 528 void
529 Layer::setMeasureRectFromPixrect(View *v, MeasureRect &r, QRect pixrect) const 529 Layer::setMeasureRectFromPixrect(LayerGeometryProvider *v, MeasureRect &r, QRect pixrect) const
530 { 530 {
531 r.pixrect = pixrect; 531 r.pixrect = pixrect;
532 r.haveFrames = hasTimeXAxis(); 532 r.haveFrames = hasTimeXAxis();
533 if (r.haveFrames) { 533 if (r.haveFrames) {
534 r.startFrame = v->getFrameForX(pixrect.x()); 534 r.startFrame = v->getFrameForX(pixrect.x());
564 564
565 return focusRectItr; 565 return focusRectItr;
566 } 566 }
567 567
568 void 568 void
569 Layer::paintMeasurementRect(View *v, QPainter &paint, 569 Layer::paintMeasurementRect(LayerGeometryProvider *v, QPainter &paint,
570 const MeasureRect &r, bool focus) const 570 const MeasureRect &r, bool focus) const
571 { 571 {
572 if (r.haveFrames) { 572 if (r.haveFrames) {
573 573
574 int x0 = -1; 574 int x0 = -1;
575 int x1 = v->width() + 1; 575 int x1 = v->getPaintWidth() + 1;
576 576
577 if (r.startFrame >= v->getStartFrame()) { 577 if (r.startFrame >= v->getStartFrame()) {
578 x0 = v->getXForFrame(r.startFrame); 578 x0 = v->getXForFrame(r.startFrame);
579 } 579 }
580 if (r.endFrame <= v->getEndFrame()) { 580 if (r.endFrame <= v->getEndFrame()) {