Mercurial > hg > svgui
comparison widgets/Pane.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 | 46d8f5add6f0 |
children | 3a506d25d95a |
comparison
equal
deleted
inserted
replaced
19:46d8f5add6f0 | 20:1deb5f87a18c |
---|---|
245 { | 245 { |
246 closeToLeftEdge = closeToRightEdge = false; | 246 closeToLeftEdge = closeToRightEdge = false; |
247 | 247 |
248 if (!m_manager) return Selection(); | 248 if (!m_manager) return Selection(); |
249 | 249 |
250 long testFrame = (x - 5) * m_zoomLevel + getStartFrame(); | 250 long testFrame = getFrameForX(x - 5); |
251 if (testFrame < 0) { | 251 if (testFrame < 0) { |
252 testFrame = x * m_zoomLevel + getStartFrame(); | 252 testFrame = getFrameForX(x); |
253 if (testFrame < 0) return Selection(); | 253 if (testFrame < 0) return Selection(); |
254 } | 254 } |
255 | 255 |
256 Selection selection = m_manager->getContainingSelection(testFrame, true); | 256 Selection selection = m_manager->getContainingSelection(testFrame, true); |
257 if (selection.isEmpty()) return selection; | 257 if (selection.isEmpty()) return selection; |
258 | 258 |
259 int lx = (int(selection.getStartFrame()) - getStartFrame()) / m_zoomLevel; | 259 int lx = getXForFrame(selection.getStartFrame()); |
260 int rx = (int(selection.getEndFrame()) - getStartFrame()) / m_zoomLevel; | 260 int rx = getXForFrame(selection.getEndFrame()); |
261 | 261 |
262 int fuzz = 2; | 262 int fuzz = 2; |
263 if (x < lx - fuzz || x > rx + fuzz) return Selection(); | 263 if (x < lx - fuzz || x > rx + fuzz) return Selection(); |
264 | 264 |
265 int width = rx - lx; | 265 int width = rx - lx; |
313 m_manager->setInProgressSelection(selection, false); | 313 m_manager->setInProgressSelection(selection, false); |
314 m_resizing = true; | 314 m_resizing = true; |
315 | 315 |
316 } else { | 316 } else { |
317 | 317 |
318 int mouseFrame = e->x() * m_zoomLevel + getStartFrame(); | 318 int mouseFrame = getFrameForX(e->x()); |
319 size_t resolution = 1; | 319 size_t resolution = 1; |
320 int snapFrame = mouseFrame; | 320 int snapFrame = mouseFrame; |
321 | 321 |
322 Layer *layer = getSelectedLayer(); | 322 Layer *layer = getSelectedLayer(); |
323 if (layer) { | 323 if (layer) { |
379 | 379 |
380 int x0 = std::min(m_clickPos.x(), m_mousePos.x()); | 380 int x0 = std::min(m_clickPos.x(), m_mousePos.x()); |
381 int x1 = std::max(m_clickPos.x(), m_mousePos.x()); | 381 int x1 = std::max(m_clickPos.x(), m_mousePos.x()); |
382 int w = x1 - x0; | 382 int w = x1 - x0; |
383 | 383 |
384 long newStartFrame = getStartFrame() + m_zoomLevel * x0; | 384 long newStartFrame = getFrameForX(x0); |
385 | 385 |
386 if (newStartFrame <= -long(width() * m_zoomLevel)) { | 386 long visibleFrames = getEndFrame() - getStartFrame(); |
387 newStartFrame = -long(width() * m_zoomLevel) + 1; | 387 if (newStartFrame <= -visibleFrames) { |
388 newStartFrame = -visibleFrames + 1; | |
388 } | 389 } |
389 | 390 |
390 if (newStartFrame >= long(getModelsEndFrame())) { | 391 if (newStartFrame >= long(getModelsEndFrame())) { |
391 newStartFrame = getModelsEndFrame() - 1; | 392 newStartFrame = getModelsEndFrame() - 1; |
392 } | 393 } |
490 m_mousePos = e->pos(); | 491 m_mousePos = e->pos(); |
491 update(); | 492 update(); |
492 | 493 |
493 } else { | 494 } else { |
494 | 495 |
495 long xoff = int(e->x()) - int(m_clickPos.x()); | 496 long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x()); |
496 long frameOff = xoff * m_zoomLevel; | 497 |
497 | |
498 size_t newCentreFrame = m_dragCentreFrame; | 498 size_t newCentreFrame = m_dragCentreFrame; |
499 | 499 |
500 if (frameOff < 0) { | 500 if (frameOff < 0) { |
501 newCentreFrame -= frameOff; | 501 newCentreFrame -= frameOff; |
502 } else if (newCentreFrame >= size_t(frameOff)) { | 502 } else if (newCentreFrame >= size_t(frameOff)) { |
507 | 507 |
508 if (newCentreFrame >= getModelsEndFrame()) { | 508 if (newCentreFrame >= getModelsEndFrame()) { |
509 newCentreFrame = getModelsEndFrame(); | 509 newCentreFrame = getModelsEndFrame(); |
510 if (newCentreFrame > 0) --newCentreFrame; | 510 if (newCentreFrame > 0) --newCentreFrame; |
511 } | 511 } |
512 | 512 |
513 if (std::max(m_centreFrame, newCentreFrame) - | 513 if (getXForFrame(m_centreFrame) != getXForFrame(newCentreFrame)) { |
514 std::min(m_centreFrame, newCentreFrame) > size_t(m_zoomLevel)) { | |
515 setCentreFrame(newCentreFrame); | 514 setCentreFrame(newCentreFrame); |
516 } | 515 } |
517 } | 516 } |
518 | 517 |
519 } else if (mode == ViewManager::SelectMode) { | 518 } else if (mode == ViewManager::SelectMode) { |
520 | 519 |
521 int mouseFrame = e->x() * m_zoomLevel + getStartFrame(); | 520 int mouseFrame = getFrameForX(e->x()); |
522 size_t resolution = 1; | 521 size_t resolution = 1; |
523 int snapFrameLeft = mouseFrame; | 522 int snapFrameLeft = mouseFrame; |
524 int snapFrameRight = mouseFrame; | 523 int snapFrameRight = mouseFrame; |
525 | 524 |
526 Layer *layer = getSelectedLayer(); | 525 Layer *layer = getSelectedLayer(); |
624 else count = -1; | 623 else count = -1; |
625 } | 624 } |
626 | 625 |
627 if (e->modifiers() & Qt::ControlModifier) { | 626 if (e->modifiers() & Qt::ControlModifier) { |
628 | 627 |
628 // Scroll left or right, rapidly | |
629 | |
629 if (getStartFrame() < 0 && | 630 if (getStartFrame() < 0 && |
630 getEndFrame() >= getModelsEndFrame()) return; | 631 getEndFrame() >= getModelsEndFrame()) return; |
631 | 632 |
632 long delta = ((width() / 2) * count * m_zoomLevel); | 633 long delta = ((width() / 2) * count * m_zoomLevel); |
633 | 634 |
639 setCentreFrame(m_centreFrame - delta); | 640 setCentreFrame(m_centreFrame - delta); |
640 } | 641 } |
641 | 642 |
642 } else { | 643 } else { |
643 | 644 |
645 // Zoom in or out | |
646 | |
644 int newZoomLevel = m_zoomLevel; | 647 int newZoomLevel = m_zoomLevel; |
645 | 648 |
646 while (count > 0) { | 649 while (count > 0) { |
647 if (newZoomLevel <= 2) { | 650 if (newZoomLevel <= 2) { |
648 newZoomLevel = 1; | 651 newZoomLevel = 1; |