Mercurial > hg > svcore
comparison base/View.cpp @ 15:47500c27ac26
* Add getXForFrame / getFrameForX in preference to using the zoom level everywhere
author | Chris Cannam |
---|---|
date | Mon, 30 Jan 2006 13:19:42 +0000 |
parents | f67ddc287bc3 |
children | cc98d496d52b |
comparison
equal
deleted
inserted
replaced
14:b101cc2ae1ab | 15:47500c27ac26 |
---|---|
231 } | 231 } |
232 | 232 |
233 return changeVisible; | 233 return changeVisible; |
234 } | 234 } |
235 | 235 |
236 int | |
237 View::getXForFrame(long frame) const | |
238 { | |
239 return (frame - getStartFrame()) / m_zoomLevel; | |
240 } | |
241 | |
242 long | |
243 View::getFrameForX(int x) const | |
244 { | |
245 return (long(x) * long(m_zoomLevel)) + getStartFrame(); | |
246 } | |
247 | |
236 void | 248 void |
237 View::setZoomLevel(size_t z) | 249 View::setZoomLevel(size_t z) |
238 { | 250 { |
239 if (m_zoomLevel != int(z)) { | 251 if (m_zoomLevel != int(z)) { |
240 m_zoomLevel = z; | 252 m_zoomLevel = z; |
412 m_cache = 0; | 424 m_cache = 0; |
413 | 425 |
414 if (long(startFrame) < myStartFrame) startFrame = myStartFrame; | 426 if (long(startFrame) < myStartFrame) startFrame = myStartFrame; |
415 if (endFrame > myEndFrame) endFrame = myEndFrame; | 427 if (endFrame > myEndFrame) endFrame = myEndFrame; |
416 | 428 |
417 int x0 = (startFrame - myStartFrame) / m_zoomLevel; | 429 int x0 = getXForFrame(startFrame); |
418 int x1 = (endFrame - myStartFrame) / m_zoomLevel; | 430 int x1 = getXForFrame(endFrame + 1); |
419 if (x1 < x0) return; | 431 if (x1 < x0) x1 = x0; |
420 | 432 |
421 checkProgress(obj); | 433 checkProgress(obj); |
422 | 434 |
423 update(x0, 0, x1 - x0 + 1, height()); | 435 update(x0, 0, x1 - x0 + 1, height()); |
424 } | 436 } |
488 if (m_manager) { | 500 if (m_manager) { |
489 if (sender() != m_manager) return; | 501 if (sender() != m_manager) return; |
490 } | 502 } |
491 | 503 |
492 if (m_playPointerFrame == f) return; | 504 if (m_playPointerFrame == f) return; |
493 bool visible = (m_playPointerFrame / m_zoomLevel != f / m_zoomLevel); | 505 bool visible = (getXForFrame(m_playPointerFrame) != getXForFrame(f)); |
494 size_t oldPlayPointerFrame = m_playPointerFrame; | 506 size_t oldPlayPointerFrame = m_playPointerFrame; |
495 m_playPointerFrame = f; | 507 m_playPointerFrame = f; |
496 if (!visible) return; | 508 if (!visible) return; |
497 | 509 |
498 switch (m_followPlay) { | 510 switch (m_followPlay) { |
504 } | 516 } |
505 break; | 517 break; |
506 | 518 |
507 case PlaybackScrollPage: | 519 case PlaybackScrollPage: |
508 { | 520 { |
509 int xold = (long(oldPlayPointerFrame) - getStartFrame()) / m_zoomLevel; | 521 int xold = getXForFrame(oldPlayPointerFrame); |
510 repaint(xold - 1, 0, 3, height()); | 522 repaint(xold - 1, 0, 3, height()); |
511 | 523 |
512 long w = width() * getZoomLevel(); | 524 long w = getEndFrame() - getStartFrame(); |
513 w -= w/5; | 525 w -= w/5; |
514 long sf = (f / w) * w - w/8; | 526 long sf = (f / w) * w - w/8; |
515 | 527 |
516 if (m_manager && | 528 if (m_manager && |
517 m_manager->isPlaying() && | 529 m_manager->isPlaying() && |
528 #ifdef DEBUG_VIEW_WIDGET_PAINT | 540 #ifdef DEBUG_VIEW_WIDGET_PAINT |
529 std::cerr << "PlaybackScrollPage: f = " << f << ", sf = " << sf << ", start frame " | 541 std::cerr << "PlaybackScrollPage: f = " << f << ", sf = " << sf << ", start frame " |
530 << getStartFrame() << std::endl; | 542 << getStartFrame() << std::endl; |
531 #endif | 543 #endif |
532 | 544 |
533 if (QApplication::mouseButtons() == Qt::NoButton && | 545 // We don't consider scrolling unless the pointer is outside |
534 QApplication::keyboardModifiers() == Qt::NoModifier) { | 546 // the clearly visible range already |
535 bool changed = | 547 |
536 setCentreFrame(sf + width() * getZoomLevel() / 2, false); | 548 int xnew = getXForFrame(m_playPointerFrame); |
537 if (changed) { | 549 |
538 xold = (long(oldPlayPointerFrame) - | 550 if (xnew < width()/8 || xnew > (width()*7)/8) { |
539 getStartFrame()) / m_zoomLevel; | 551 if (QApplication::mouseButtons() == Qt::NoButton && |
540 update(xold - 1, 0, 3, height()); | 552 QApplication::keyboardModifiers() == Qt::NoModifier) { |
541 } | 553 long offset = getFrameForX(width()/2) - getStartFrame(); |
542 } | 554 long newCentre = sf + offset; |
543 | 555 bool changed = setCentreFrame(newCentre, false); |
544 int xnew = (long(m_playPointerFrame) - getStartFrame()) / m_zoomLevel; | 556 if (changed) { |
557 xold = getXForFrame(oldPlayPointerFrame); | |
558 update(xold - 1, 0, 3, height()); | |
559 } | |
560 } | |
561 } | |
562 | |
545 update(xnew - 1, 0, 3, height()); | 563 update(xnew - 1, 0, 3, height()); |
546 | 564 |
547 break; | 565 break; |
548 } | 566 } |
549 | 567 |
757 void | 775 void |
758 View::scroll(bool right, bool lots) | 776 View::scroll(bool right, bool lots) |
759 { | 777 { |
760 long delta; | 778 long delta; |
761 if (lots) { | 779 if (lots) { |
762 delta = ((width() / 2) * m_zoomLevel); | 780 delta = (getEndFrame() - getStartFrame()) / 2; |
763 } else { | 781 } else { |
764 delta = ((width() / 20) * m_zoomLevel); | 782 delta = (getEndFrame() - getStartFrame()) / 20; |
765 } | 783 } |
766 if (right) delta = -delta; | 784 if (right) delta = -delta; |
767 | 785 |
768 if (int(m_centreFrame) < delta) { | 786 if (int(m_centreFrame) < delta) { |
769 setCentreFrame(0); | 787 setCentreFrame(0); |
919 repaintCache = true; | 937 repaintCache = true; |
920 } | 938 } |
921 | 939 |
922 } else if (m_cacheCentreFrame != m_centreFrame) { | 940 } else if (m_cacheCentreFrame != m_centreFrame) { |
923 | 941 |
924 long dx = long(m_cacheCentreFrame / m_zoomLevel) - | 942 long dx = |
925 long(m_centreFrame / m_zoomLevel); | 943 getXForFrame(m_cacheCentreFrame) - |
944 getXForFrame(m_centreFrame); | |
926 | 945 |
927 if (dx > -width() && dx < width()) { | 946 if (dx > -width() && dx < width()) { |
928 #if defined(Q_WS_WIN32) || defined(Q_WS_MAC) | 947 #if defined(Q_WS_WIN32) || defined(Q_WS_MAC) |
929 // Copying a pixmap to itself doesn't work properly on Windows | 948 // Copying a pixmap to itself doesn't work properly on Windows |
930 // or Mac (it only works when moving in one direction) | 949 // or Mac (it only works when moving in one direction) |
1068 paint.begin(this); | 1087 paint.begin(this); |
1069 | 1088 |
1070 if (long(m_playPointerFrame) > getStartFrame() && | 1089 if (long(m_playPointerFrame) > getStartFrame() && |
1071 m_playPointerFrame < getEndFrame()) { | 1090 m_playPointerFrame < getEndFrame()) { |
1072 | 1091 |
1073 int playx = (long(m_playPointerFrame) - getStartFrame()) / | 1092 int playx = getXForFrame(m_playPointerFrame); |
1074 m_zoomLevel; | |
1075 | 1093 |
1076 paint.setPen(Qt::black); | 1094 paint.setPen(Qt::black); |
1077 paint.drawLine(playx - 1, 0, playx - 1, height() - 1); | 1095 paint.drawLine(playx - 1, 0, playx - 1, height() - 1); |
1078 paint.drawLine(playx + 1, 0, playx + 1, height() - 1); | 1096 paint.drawLine(playx + 1, 0, playx + 1, height() - 1); |
1079 paint.drawPoint(playx, 0); | 1097 paint.drawPoint(playx, 0); |
1113 const QFontMetrics &metrics = paint.fontMetrics(); | 1131 const QFontMetrics &metrics = paint.fontMetrics(); |
1114 | 1132 |
1115 for (ViewManager::SelectionList::iterator i = selections.begin(); | 1133 for (ViewManager::SelectionList::iterator i = selections.begin(); |
1116 i != selections.end(); ++i) { | 1134 i != selections.end(); ++i) { |
1117 | 1135 |
1118 int p0 = -1, p1 = -1; | 1136 int p0 = getXForFrame(i->getStartFrame()); |
1119 | 1137 int p1 = getXForFrame(i->getEndFrame()); |
1120 p0 = (long(i->getStartFrame()) - getStartFrame()) / m_zoomLevel; | |
1121 p1 = (long(i->getEndFrame()) - getStartFrame()) / m_zoomLevel; | |
1122 | 1138 |
1123 if (p1 < 0 || p0 > width()) continue; | 1139 if (p1 < 0 || p0 > width()) continue; |
1124 | 1140 |
1125 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1141 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1126 std::cerr << "View::drawSelections: " << p0 << ",-1 [" << (p1-p0) << "x" << (height()+1) << "]" << std::endl; | 1142 std::cerr << "View::drawSelections: " << p0 << ",-1 [" << (p1-p0) << "x" << (height()+1) << "]" << std::endl; |