Mercurial > hg > svgui
comparison view/View.cpp @ 1183:57d192e26331 zoom
Some hackery toward having a zoomlevel type
author | Chris Cannam |
---|---|
date | Mon, 12 Dec 2016 15:18:52 +0000 |
parents | 52675a1f662c |
children | 13d9b422f7fe |
comparison
equal
deleted
inserted
replaced
1182:6605984fa98f | 1183:57d192e26331 |
---|---|
442 if (minf == maxf) return 0; | 442 if (minf == maxf) return 0; |
443 return minf + ((h - y) * (maxf - minf)) / h; | 443 return minf + ((h - y) * (maxf - minf)) / h; |
444 } | 444 } |
445 } | 445 } |
446 | 446 |
447 int | 447 ZoomLevel |
448 View::getZoomLevel() const | 448 View::getZoomLevel() const |
449 { | 449 { |
450 #ifdef DEBUG_VIEW_WIDGET_PAINT | 450 #ifdef DEBUG_VIEW_WIDGET_PAINT |
451 // cout << "zoom level: " << m_zoomLevel << endl; | 451 // cout << "zoom level: " << m_zoomLevel << endl; |
452 #endif | 452 #endif |
471 return 1; | 471 return 1; |
472 #endif | 472 #endif |
473 } | 473 } |
474 | 474 |
475 void | 475 void |
476 View::setZoomLevel(int z) | 476 View::setZoomLevel(ZoomLevel z) |
477 { | 477 { |
478 int dpratio = effectiveDevicePixelRatio(); | 478 int dpratio = effectiveDevicePixelRatio(); |
479 if (z < dpratio) return; | 479 if (z < dpratio) return; |
480 if (z < 1) z = 1; | 480 if (z < 1) z = 1; |
481 if (m_zoomLevel != int(z)) { | 481 if (m_zoomLevel != int(z)) { |
719 { | 719 { |
720 if (m_manager) { | 720 if (m_manager) { |
721 m_manager->disconnect(this, SLOT(globalCentreFrameChanged(sv_frame_t))); | 721 m_manager->disconnect(this, SLOT(globalCentreFrameChanged(sv_frame_t))); |
722 m_manager->disconnect(this, SLOT(viewCentreFrameChanged(View *, sv_frame_t))); | 722 m_manager->disconnect(this, SLOT(viewCentreFrameChanged(View *, sv_frame_t))); |
723 m_manager->disconnect(this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t))); | 723 m_manager->disconnect(this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t))); |
724 m_manager->disconnect(this, SLOT(viewZoomLevelChanged(View *, int, bool))); | 724 m_manager->disconnect(this, SLOT(viewZoomLevelChanged(View *, ZoomLevel, bool))); |
725 m_manager->disconnect(this, SLOT(toolModeChanged())); | 725 m_manager->disconnect(this, SLOT(toolModeChanged())); |
726 m_manager->disconnect(this, SLOT(selectionChanged())); | 726 m_manager->disconnect(this, SLOT(selectionChanged())); |
727 m_manager->disconnect(this, SLOT(overlayModeChanged())); | 727 m_manager->disconnect(this, SLOT(overlayModeChanged())); |
728 m_manager->disconnect(this, SLOT(zoomWheelsEnabledChanged())); | 728 m_manager->disconnect(this, SLOT(zoomWheelsEnabledChanged())); |
729 disconnect(m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode))); | 729 disconnect(m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode))); |
730 disconnect(m_manager, SLOT(zoomLevelChanged(int, bool))); | 730 disconnect(m_manager, SLOT(zoomLevelChanged(ZoomLevel, bool))); |
731 } | 731 } |
732 | 732 |
733 m_manager = manager; | 733 m_manager = manager; |
734 | 734 |
735 connect(m_manager, SIGNAL(globalCentreFrameChanged(sv_frame_t)), | 735 connect(m_manager, SIGNAL(globalCentreFrameChanged(sv_frame_t)), |
737 connect(m_manager, SIGNAL(viewCentreFrameChanged(View *, sv_frame_t)), | 737 connect(m_manager, SIGNAL(viewCentreFrameChanged(View *, sv_frame_t)), |
738 this, SLOT(viewCentreFrameChanged(View *, sv_frame_t))); | 738 this, SLOT(viewCentreFrameChanged(View *, sv_frame_t))); |
739 connect(m_manager, SIGNAL(playbackFrameChanged(sv_frame_t)), | 739 connect(m_manager, SIGNAL(playbackFrameChanged(sv_frame_t)), |
740 this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t))); | 740 this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t))); |
741 | 741 |
742 connect(m_manager, SIGNAL(viewZoomLevelChanged(View *, int, bool)), | 742 connect(m_manager, SIGNAL(viewZoomLevelChanged(View *, ZoomLevel, bool)), |
743 this, SLOT(viewZoomLevelChanged(View *, int, bool))); | 743 this, SLOT(viewZoomLevelChanged(View *, ZoomLevel, bool))); |
744 | 744 |
745 connect(m_manager, SIGNAL(toolModeChanged()), | 745 connect(m_manager, SIGNAL(toolModeChanged()), |
746 this, SLOT(toolModeChanged())); | 746 this, SLOT(toolModeChanged())); |
747 connect(m_manager, SIGNAL(selectionChanged()), | 747 connect(m_manager, SIGNAL(selectionChanged()), |
748 this, SLOT(selectionChanged())); | 748 this, SLOT(selectionChanged())); |
758 connect(this, SIGNAL(centreFrameChanged(sv_frame_t, bool, | 758 connect(this, SIGNAL(centreFrameChanged(sv_frame_t, bool, |
759 PlaybackFollowMode)), | 759 PlaybackFollowMode)), |
760 m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool, | 760 m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool, |
761 PlaybackFollowMode))); | 761 PlaybackFollowMode))); |
762 | 762 |
763 connect(this, SIGNAL(zoomLevelChanged(int, bool)), | 763 connect(this, SIGNAL(zoomLevelChanged(ZoomLevel, bool)), |
764 m_manager, SLOT(viewZoomLevelChanged(int, bool))); | 764 m_manager, SLOT(viewZoomLevelChanged(ZoomLevel, bool))); |
765 | 765 |
766 switch (m_followPlay) { | 766 switch (m_followPlay) { |
767 | 767 |
768 case PlaybackScrollPage: | 768 case PlaybackScrollPage: |
769 case PlaybackScrollPageWithCentre: | 769 case PlaybackScrollPageWithCentre: |
1121 break; | 1121 break; |
1122 } | 1122 } |
1123 } | 1123 } |
1124 | 1124 |
1125 void | 1125 void |
1126 View::viewZoomLevelChanged(View *p, int z, bool locked) | 1126 View::viewZoomLevelChanged(View *p, ZoomLevel z, bool locked) |
1127 { | 1127 { |
1128 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1128 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1129 cerr << "View[" << this << "]: viewZoomLevelChanged(" << p << ", " << z << ", " << locked << ")" << endl; | 1129 cerr << "View[" << this << "]: viewZoomLevelChanged(" << p << ", " << z << ", " << locked << ")" << endl; |
1130 #endif | 1130 #endif |
1131 if (m_followZoom && p != this && locked) { | 1131 if (m_followZoom && p != this && locked) { |
1448 } | 1448 } |
1449 | 1449 |
1450 void | 1450 void |
1451 View::zoom(bool in) | 1451 View::zoom(bool in) |
1452 { | 1452 { |
1453 int newZoomLevel = m_zoomLevel; | 1453 ZoomLevel newZoomLevel = m_zoomLevel; |
1454 | 1454 |
1455 if (in) { | 1455 if (in) { |
1456 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1, | 1456 newZoomLevel = getZoomConstraintLevel(m_zoomLevel.decremented(), |
1457 ZoomConstraint::RoundDown); | 1457 ZoomConstraint::RoundDown); |
1458 } else { | 1458 } else { |
1459 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1, | 1459 newZoomLevel = getZoomConstraintLevel(m_zoomLevel.incremented(), |
1460 ZoomConstraint::RoundUp); | 1460 ZoomConstraint::RoundUp); |
1461 } | 1461 } |
1462 | 1462 |
1463 if (newZoomLevel != m_zoomLevel) { | 1463 if (newZoomLevel != m_zoomLevel) { |
1464 setZoomLevel(newZoomLevel); | 1464 setZoomLevel(newZoomLevel); |
1465 } | 1465 } |