comparison view/View.cpp @ 810:b68af2be4545 tonioni

Merge from branch warnfix_no_size_t
author Chris Cannam
date Wed, 18 Jun 2014 13:42:25 +0100
parents 40c6c9344ff6
children 09026c875301
comparison
equal deleted inserted replaced
802:584b11df8e4f 810:b68af2be4545
156 case 2: setPlaybackFollow(PlaybackIgnore); break; 156 case 2: setPlaybackFollow(PlaybackIgnore); break;
157 } 157 }
158 } 158 }
159 } 159 }
160 160
161 size_t 161 int
162 View::getPropertyContainerCount() const 162 View::getPropertyContainerCount() const
163 { 163 {
164 return m_layers.size() + 1; // the 1 is for me 164 return m_layers.size() + 1; // the 1 is for me
165 } 165 }
166 166
167 const PropertyContainer * 167 const PropertyContainer *
168 View::getPropertyContainer(size_t i) const 168 View::getPropertyContainer(int i) const
169 { 169 {
170 return (const PropertyContainer *)(((View *)this)-> 170 return (const PropertyContainer *)(((View *)this)->
171 getPropertyContainer(i)); 171 getPropertyContainer(i));
172 } 172 }
173 173
174 PropertyContainer * 174 PropertyContainer *
175 View::getPropertyContainer(size_t i) 175 View::getPropertyContainer(int i)
176 { 176 {
177 if (i == 0) return m_propertyContainer; 177 if (i == 0) return m_propertyContainer;
178 return m_layers[i-1]; 178 return m_layers[i-1];
179 } 179 }
180 180
293 View::zoomWheelsEnabledChanged() 293 View::zoomWheelsEnabledChanged()
294 { 294 {
295 // subclass might override this 295 // subclass might override this
296 } 296 }
297 297
298 long 298 int
299 View::getStartFrame() const 299 View::getStartFrame() const
300 { 300 {
301 return getFrameForX(0); 301 return getFrameForX(0);
302 } 302 }
303 303
304 size_t 304 int
305 View::getEndFrame() const 305 View::getEndFrame() const
306 { 306 {
307 return getFrameForX(width()) - 1; 307 return getFrameForX(width()) - 1;
308 } 308 }
309 309
310 void 310 void
311 View::setStartFrame(long f) 311 View::setStartFrame(int f)
312 { 312 {
313 setCentreFrame(f + m_zoomLevel * (width() / 2)); 313 setCentreFrame(f + m_zoomLevel * (width() / 2));
314 } 314 }
315 315
316 bool 316 bool
317 View::setCentreFrame(size_t f, bool e) 317 View::setCentreFrame(int f, bool e)
318 { 318 {
319 bool changeVisible = false; 319 bool changeVisible = false;
320 320
321 if (m_centreFrame != f) { 321 if (m_centreFrame != f) {
322 322
335 335
336 changeVisible = true; 336 changeVisible = true;
337 } 337 }
338 338
339 if (e) { 339 if (e) {
340 size_t rf = alignToReference(f); 340 int rf = alignToReference(f);
341 #ifdef DEBUG_VIEW_WIDGET_PAINT 341 #ifdef DEBUG_VIEW_WIDGET_PAINT
342 cerr << "View[" << this << "]::setCentreFrame(" << f 342 cerr << "View[" << this << "]::setCentreFrame(" << f
343 << "): emitting centreFrameChanged(" 343 << "): emitting centreFrameChanged("
344 << rf << ")" << endl; 344 << rf << ")" << endl;
345 #endif 345 #endif
349 349
350 return changeVisible; 350 return changeVisible;
351 } 351 }
352 352
353 int 353 int
354 View::getXForFrame(long frame) const 354 View::getXForFrame(int frame) const
355 { 355 {
356 return (frame - getStartFrame()) / m_zoomLevel; 356 return (frame - getStartFrame()) / m_zoomLevel;
357 } 357 }
358 358
359 long 359 int
360 View::getFrameForX(int x) const 360 View::getFrameForX(int x) const
361 { 361 {
362 long z = (long)m_zoomLevel; 362 int z = m_zoomLevel;
363 long frame = m_centreFrame - (width()/2) * z; 363 int frame = m_centreFrame - (width()/2) * z;
364 364
365 #ifdef DEBUG_VIEW_WIDGET_PAINT 365 #ifdef DEBUG_VIEW_WIDGET_PAINT
366 SVDEBUG << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl; 366 SVDEBUG << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl;
367 #endif 367 #endif
368 368
444 #endif 444 #endif
445 return m_zoomLevel; 445 return m_zoomLevel;
446 } 446 }
447 447
448 void 448 void
449 View::setZoomLevel(size_t z) 449 View::setZoomLevel(int z)
450 { 450 {
451 if (z < 1) z = 1; 451 if (z < 1) z = 1;
452 if (m_zoomLevel != int(z)) { 452 if (m_zoomLevel != int(z)) {
453 m_zoomLevel = z; 453 m_zoomLevel = z;
454 emit zoomLevelChanged(z, m_followZoom); 454 emit zoomLevelChanged(z, m_followZoom);
574 this, SLOT(modelChanged())); 574 this, SLOT(modelChanged()));
575 connect(layer, SIGNAL(modelCompletionChanged()), 575 connect(layer, SIGNAL(modelCompletionChanged()),
576 this, SLOT(modelCompletionChanged())); 576 this, SLOT(modelCompletionChanged()));
577 connect(layer, SIGNAL(modelAlignmentCompletionChanged()), 577 connect(layer, SIGNAL(modelAlignmentCompletionChanged()),
578 this, SLOT(modelAlignmentCompletionChanged())); 578 this, SLOT(modelAlignmentCompletionChanged()));
579 connect(layer, SIGNAL(modelChanged(size_t, size_t)), 579 connect(layer, SIGNAL(modelChangedWithin(int, int)),
580 this, SLOT(modelChanged(size_t, size_t))); 580 this, SLOT(modelChangedWithin(int, int)));
581 connect(layer, SIGNAL(modelReplaced()), 581 connect(layer, SIGNAL(modelReplaced()),
582 this, SLOT(modelReplaced())); 582 this, SLOT(modelReplaced()));
583 583
584 update(); 584 update();
585 585
619 this, SLOT(modelChanged())); 619 this, SLOT(modelChanged()));
620 disconnect(layer, SIGNAL(modelCompletionChanged()), 620 disconnect(layer, SIGNAL(modelCompletionChanged()),
621 this, SLOT(modelCompletionChanged())); 621 this, SLOT(modelCompletionChanged()));
622 disconnect(layer, SIGNAL(modelAlignmentCompletionChanged()), 622 disconnect(layer, SIGNAL(modelAlignmentCompletionChanged()),
623 this, SLOT(modelAlignmentCompletionChanged())); 623 this, SLOT(modelAlignmentCompletionChanged()));
624 disconnect(layer, SIGNAL(modelChanged(size_t, size_t)), 624 disconnect(layer, SIGNAL(modelChangedWithin(int, int)),
625 this, SLOT(modelChanged(size_t, size_t))); 625 this, SLOT(modelChangedWithin(int, int)));
626 disconnect(layer, SIGNAL(modelReplaced()), 626 disconnect(layer, SIGNAL(modelReplaced()),
627 this, SLOT(modelReplaced())); 627 this, SLOT(modelReplaced()));
628 628
629 update(); 629 update();
630 630
657 657
658 void 658 void
659 View::setViewManager(ViewManager *manager) 659 View::setViewManager(ViewManager *manager)
660 { 660 {
661 if (m_manager) { 661 if (m_manager) {
662 m_manager->disconnect(this, SLOT(globalCentreFrameChanged(unsigned long))); 662 m_manager->disconnect(this, SLOT(globalCentreFrameChanged(int)));
663 m_manager->disconnect(this, SLOT(viewCentreFrameChanged(View *, unsigned long))); 663 m_manager->disconnect(this, SLOT(viewCentreFrameChanged(View *, int)));
664 m_manager->disconnect(this, SLOT(viewManagerPlaybackFrameChanged(unsigned long))); 664 m_manager->disconnect(this, SLOT(viewManagerPlaybackFrameChanged(int)));
665 m_manager->disconnect(this, SLOT(viewZoomLevelChanged(View *, unsigned long, bool))); 665 m_manager->disconnect(this, SLOT(viewZoomLevelChanged(View *, int, bool)));
666 m_manager->disconnect(this, SLOT(toolModeChanged())); 666 m_manager->disconnect(this, SLOT(toolModeChanged()));
667 m_manager->disconnect(this, SLOT(selectionChanged())); 667 m_manager->disconnect(this, SLOT(selectionChanged()));
668 m_manager->disconnect(this, SLOT(overlayModeChanged())); 668 m_manager->disconnect(this, SLOT(overlayModeChanged()));
669 m_manager->disconnect(this, SLOT(zoomWheelsEnabledChanged())); 669 m_manager->disconnect(this, SLOT(zoomWheelsEnabledChanged()));
670 disconnect(m_manager, SLOT(viewCentreFrameChanged(unsigned long, bool, PlaybackFollowMode))); 670 disconnect(m_manager, SLOT(viewCentreFrameChanged(int, bool, PlaybackFollowMode)));
671 disconnect(m_manager, SLOT(zoomLevelChanged(unsigned long, bool))); 671 disconnect(m_manager, SLOT(zoomLevelChanged(int, bool)));
672 } 672 }
673 673
674 m_manager = manager; 674 m_manager = manager;
675 675
676 connect(m_manager, SIGNAL(globalCentreFrameChanged(unsigned long)), 676 connect(m_manager, SIGNAL(globalCentreFrameChanged(int)),
677 this, SLOT(globalCentreFrameChanged(unsigned long))); 677 this, SLOT(globalCentreFrameChanged(int)));
678 connect(m_manager, SIGNAL(viewCentreFrameChanged(View *, unsigned long)), 678 connect(m_manager, SIGNAL(viewCentreFrameChanged(View *, int)),
679 this, SLOT(viewCentreFrameChanged(View *, unsigned long))); 679 this, SLOT(viewCentreFrameChanged(View *, int)));
680 connect(m_manager, SIGNAL(playbackFrameChanged(unsigned long)), 680 connect(m_manager, SIGNAL(playbackFrameChanged(int)),
681 this, SLOT(viewManagerPlaybackFrameChanged(unsigned long))); 681 this, SLOT(viewManagerPlaybackFrameChanged(int)));
682 682
683 connect(m_manager, SIGNAL(viewZoomLevelChanged(View *, unsigned long, bool)), 683 connect(m_manager, SIGNAL(viewZoomLevelChanged(View *, int, bool)),
684 this, SLOT(viewZoomLevelChanged(View *, unsigned long, bool))); 684 this, SLOT(viewZoomLevelChanged(View *, int, bool)));
685 685
686 connect(m_manager, SIGNAL(toolModeChanged()), 686 connect(m_manager, SIGNAL(toolModeChanged()),
687 this, SLOT(toolModeChanged())); 687 this, SLOT(toolModeChanged()));
688 connect(m_manager, SIGNAL(selectionChanged()), 688 connect(m_manager, SIGNAL(selectionChanged()),
689 this, SLOT(selectionChanged())); 689 this, SLOT(selectionChanged()));
694 connect(m_manager, SIGNAL(showCentreLineChanged()), 694 connect(m_manager, SIGNAL(showCentreLineChanged()),
695 this, SLOT(overlayModeChanged())); 695 this, SLOT(overlayModeChanged()));
696 connect(m_manager, SIGNAL(zoomWheelsEnabledChanged()), 696 connect(m_manager, SIGNAL(zoomWheelsEnabledChanged()),
697 this, SLOT(zoomWheelsEnabledChanged())); 697 this, SLOT(zoomWheelsEnabledChanged()));
698 698
699 connect(this, SIGNAL(centreFrameChanged(unsigned long, bool, 699 connect(this, SIGNAL(centreFrameChanged(int, bool,
700 PlaybackFollowMode)), 700 PlaybackFollowMode)),
701 m_manager, SLOT(viewCentreFrameChanged(unsigned long, bool, 701 m_manager, SLOT(viewCentreFrameChanged(int, bool,
702 PlaybackFollowMode))); 702 PlaybackFollowMode)));
703 703
704 connect(this, SIGNAL(zoomLevelChanged(unsigned long, bool)), 704 connect(this, SIGNAL(zoomLevelChanged(int, bool)),
705 m_manager, SLOT(viewZoomLevelChanged(unsigned long, bool))); 705 m_manager, SLOT(viewZoomLevelChanged(int, bool)));
706 706
707 // setCentreFrame(m_manager->getViewInitialCentreFrame()); 707 // setCentreFrame(m_manager->getViewInitialCentreFrame());
708 708
709 if (m_followPlay == PlaybackScrollPage) { 709 if (m_followPlay == PlaybackScrollPage) {
710 // SVDEBUG << "View::setViewManager: setting centre frame to global centre frame: " << m_manager->getGlobalCentreFrame() << endl; 710 // SVDEBUG << "View::setViewManager: setting centre frame to global centre frame: " << m_manager->getGlobalCentreFrame() << endl;
723 723
724 toolModeChanged(); 724 toolModeChanged();
725 } 725 }
726 726
727 void 727 void
728 View::setViewManager(ViewManager *vm, long initialCentreFrame) 728 View::setViewManager(ViewManager *vm, int initialCentreFrame)
729 { 729 {
730 setViewManager(vm); 730 setViewManager(vm);
731 setCentreFrame(initialCentreFrame, false); 731 setCentreFrame(initialCentreFrame, false);
732 } 732 }
733 733
837 837
838 update(); 838 update();
839 } 839 }
840 840
841 void 841 void
842 View::modelChanged(size_t startFrame, size_t endFrame) 842 View::modelChangedWithin(int startFrame, int endFrame)
843 { 843 {
844 QObject *obj = sender(); 844 QObject *obj = sender();
845 845
846 long myStartFrame = getStartFrame(); 846 int myStartFrame = getStartFrame();
847 size_t myEndFrame = getEndFrame(); 847 int myEndFrame = getEndFrame();
848 848
849 #ifdef DEBUG_VIEW_WIDGET_PAINT 849 #ifdef DEBUG_VIEW_WIDGET_PAINT
850 cerr << "View(" << this << ")::modelChanged(" << startFrame << "," << endFrame << ") [me " << myStartFrame << "," << myEndFrame << "]" << endl; 850 cerr << "View(" << this << ")::modelChangedWithin(" << startFrame << "," << endFrame << ") [me " << myStartFrame << "," << myEndFrame << "]" << endl;
851 #endif 851 #endif
852 852
853 if (myStartFrame > 0 && endFrame < size_t(myStartFrame)) { 853 if (myStartFrame > 0 && endFrame < int(myStartFrame)) {
854 checkProgress(obj); 854 checkProgress(obj);
855 return; 855 return;
856 } 856 }
857 if (startFrame > myEndFrame) { 857 if (startFrame > myEndFrame) {
858 checkProgress(obj); 858 checkProgress(obj);
877 if (recreate) { 877 if (recreate) {
878 delete m_cache; 878 delete m_cache;
879 m_cache = 0; 879 m_cache = 0;
880 } 880 }
881 881
882 if (long(startFrame) < myStartFrame) startFrame = myStartFrame; 882 if (startFrame < myStartFrame) startFrame = myStartFrame;
883 if (endFrame > myEndFrame) endFrame = myEndFrame; 883 if (endFrame > myEndFrame) endFrame = myEndFrame;
884 884
885 checkProgress(obj); 885 checkProgress(obj);
886 886
887 update(); 887 update();
955 Layer *layer = dynamic_cast<Layer *>(sender()); 955 Layer *layer = dynamic_cast<Layer *>(sender());
956 if (layer) emit propertyContainerNameChanged(layer); 956 if (layer) emit propertyContainerNameChanged(layer);
957 } 957 }
958 958
959 void 959 void
960 View::globalCentreFrameChanged(unsigned long rf) 960 View::globalCentreFrameChanged(int rf)
961 { 961 {
962 if (m_followPan) { 962 if (m_followPan) {
963 size_t f = alignFromReference(rf); 963 int f = alignFromReference(rf);
964 #ifdef DEBUG_VIEW_WIDGET_PAINT 964 #ifdef DEBUG_VIEW_WIDGET_PAINT
965 cerr << "View[" << this << "]::globalCentreFrameChanged(" << rf 965 cerr << "View[" << this << "]::globalCentreFrameChanged(" << rf
966 << "): setting centre frame to " << f << endl; 966 << "): setting centre frame to " << f << endl;
967 #endif 967 #endif
968 setCentreFrame(f, false); 968 setCentreFrame(f, false);
969 } 969 }
970 } 970 }
971 971
972 void 972 void
973 View::viewCentreFrameChanged(View *, unsigned long ) 973 View::viewCentreFrameChanged(View *, int )
974 { 974 {
975 // We do nothing with this, but a subclass might 975 // We do nothing with this, but a subclass might
976 } 976 }
977 977
978 void 978 void
979 View::viewManagerPlaybackFrameChanged(unsigned long f) 979 View::viewManagerPlaybackFrameChanged(int f)
980 { 980 {
981 if (m_manager) { 981 if (m_manager) {
982 if (sender() != m_manager) return; 982 if (sender() != m_manager) return;
983 } 983 }
984 984
986 986
987 movePlayPointer(f); 987 movePlayPointer(f);
988 } 988 }
989 989
990 void 990 void
991 View::movePlayPointer(unsigned long newFrame) 991 View::movePlayPointer(int newFrame)
992 { 992 {
993 if (m_playPointerFrame == newFrame) return; 993 if (m_playPointerFrame == newFrame) return;
994 bool visibleChange = 994 bool visibleChange =
995 (getXForFrame(m_playPointerFrame) != getXForFrame(newFrame)); 995 (getXForFrame(m_playPointerFrame) != getXForFrame(newFrame));
996 size_t oldPlayPointerFrame = m_playPointerFrame; 996 int oldPlayPointerFrame = m_playPointerFrame;
997 m_playPointerFrame = newFrame; 997 m_playPointerFrame = newFrame;
998 if (!visibleChange) return; 998 if (!visibleChange) return;
999 999
1000 bool somethingGoingOn = 1000 bool somethingGoingOn =
1001 ((QApplication::mouseButtons() != Qt::NoButton) || 1001 ((QApplication::mouseButtons() != Qt::NoButton) ||
1028 } else { 1028 } else {
1029 1029
1030 int xold = getXForFrame(oldPlayPointerFrame); 1030 int xold = getXForFrame(oldPlayPointerFrame);
1031 update(xold - 4, 0, 9, height()); 1031 update(xold - 4, 0, 9, height());
1032 1032
1033 long w = getEndFrame() - getStartFrame(); 1033 int w = getEndFrame() - getStartFrame();
1034 w -= w/5; 1034 w -= w/5;
1035 long sf = (m_playPointerFrame / w) * w - w/8; 1035 int sf = (m_playPointerFrame / w) * w - w/8;
1036 1036
1037 if (m_manager && 1037 if (m_manager &&
1038 m_manager->isPlaying() && 1038 m_manager->isPlaying() &&
1039 m_manager->getPlaySelectionMode()) { 1039 m_manager->getPlaySelectionMode()) {
1040 MultiSelection::SelectionList selections = m_manager->getSelections(); 1040 MultiSelection::SelectionList selections = m_manager->getSelections();
1041 if (!selections.empty()) { 1041 if (!selections.empty()) {
1042 size_t selectionStart = selections.begin()->getStartFrame(); 1042 int selectionStart = selections.begin()->getStartFrame();
1043 if (sf < long(selectionStart) - w / 10) { 1043 if (sf < selectionStart - w / 10) {
1044 sf = long(selectionStart) - w / 10; 1044 sf = selectionStart - w / 10;
1045 } 1045 }
1046 } 1046 }
1047 } 1047 }
1048 1048
1049 #ifdef DEBUG_VIEW_WIDGET_PAINT 1049 #ifdef DEBUG_VIEW_WIDGET_PAINT
1071 } else if (somethingGoingOn) { 1071 } else if (somethingGoingOn) {
1072 m_followPlayIsDetached = true; 1072 m_followPlayIsDetached = true;
1073 } 1073 }
1074 1074
1075 if (!somethingGoingOn && shouldScroll) { 1075 if (!somethingGoingOn && shouldScroll) {
1076 long offset = getFrameForX(width()/2) - getStartFrame(); 1076 int offset = getFrameForX(width()/2) - getStartFrame();
1077 long newCentre = sf + offset; 1077 int newCentre = sf + offset;
1078 bool changed = setCentreFrame(newCentre, false); 1078 bool changed = setCentreFrame(newCentre, false);
1079 if (changed) { 1079 if (changed) {
1080 xold = getXForFrame(oldPlayPointerFrame); 1080 xold = getXForFrame(oldPlayPointerFrame);
1081 update(xold - 4, 0, 9, height()); 1081 update(xold - 4, 0, 9, height());
1082 } 1082 }
1085 update(xnew - 4, 0, 9, height()); 1085 update(xnew - 4, 0, 9, height());
1086 } 1086 }
1087 break; 1087 break;
1088 1088
1089 case PlaybackIgnore: 1089 case PlaybackIgnore:
1090 if (long(m_playPointerFrame) >= getStartFrame() && 1090 if (m_playPointerFrame >= getStartFrame() &&
1091 m_playPointerFrame < getEndFrame()) { 1091 m_playPointerFrame < getEndFrame()) {
1092 update(); 1092 update();
1093 } 1093 }
1094 break; 1094 break;
1095 } 1095 }
1096 } 1096 }
1097 1097
1098 void 1098 void
1099 View::viewZoomLevelChanged(View *p, unsigned long z, bool locked) 1099 View::viewZoomLevelChanged(View *p, int z, bool locked)
1100 { 1100 {
1101 #ifdef DEBUG_VIEW_WIDGET_PAINT 1101 #ifdef DEBUG_VIEW_WIDGET_PAINT
1102 cerr << "View[" << this << "]: viewZoomLevelChanged(" << p << ", " << z << ", " << locked << ")" << endl; 1102 cerr << "View[" << this << "]: viewZoomLevelChanged(" << p << ", " << z << ", " << locked << ")" << endl;
1103 #endif 1103 #endif
1104 if (m_followZoom && p != this && locked) { 1104 if (m_followZoom && p != this && locked) {
1115 m_selectionCached = false; 1115 m_selectionCached = false;
1116 } 1116 }
1117 update(); 1117 update();
1118 } 1118 }
1119 1119
1120 size_t 1120 int
1121 View::getFirstVisibleFrame() const 1121 View::getFirstVisibleFrame() const
1122 { 1122 {
1123 long f0 = getStartFrame(); 1123 int f0 = getStartFrame();
1124 size_t f = getModelsStartFrame(); 1124 int f = getModelsStartFrame();
1125 if (f0 < 0 || f0 < long(f)) return f; 1125 if (f0 < 0 || f0 < f) return f;
1126 return f0; 1126 return f0;
1127 } 1127 }
1128 1128
1129 size_t 1129 int
1130 View::getLastVisibleFrame() const 1130 View::getLastVisibleFrame() const
1131 { 1131 {
1132 size_t f0 = getEndFrame(); 1132 int f0 = getEndFrame();
1133 size_t f = getModelsEndFrame(); 1133 int f = getModelsEndFrame();
1134 if (f0 > f) return f; 1134 if (f0 > f) return f;
1135 return f0; 1135 return f0;
1136 } 1136 }
1137 1137
1138 size_t 1138 int
1139 View::getModelsStartFrame() const 1139 View::getModelsStartFrame() const
1140 { 1140 {
1141 bool first = true; 1141 bool first = true;
1142 size_t startFrame = 0; 1142 int startFrame = 0;
1143 1143
1144 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 1144 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
1145 1145
1146 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1146 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
1147 1147
1148 size_t thisStartFrame = (*i)->getModel()->getStartFrame(); 1148 int thisStartFrame = (*i)->getModel()->getStartFrame();
1149 1149
1150 if (first || thisStartFrame < startFrame) { 1150 if (first || thisStartFrame < startFrame) {
1151 startFrame = thisStartFrame; 1151 startFrame = thisStartFrame;
1152 } 1152 }
1153 first = false; 1153 first = false;
1154 } 1154 }
1155 } 1155 }
1156 return startFrame; 1156 return startFrame;
1157 } 1157 }
1158 1158
1159 size_t 1159 int
1160 View::getModelsEndFrame() const 1160 View::getModelsEndFrame() const
1161 { 1161 {
1162 bool first = true; 1162 bool first = true;
1163 size_t endFrame = 0; 1163 int endFrame = 0;
1164 1164
1165 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 1165 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
1166 1166
1167 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1167 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
1168 1168
1169 size_t thisEndFrame = (*i)->getModel()->getEndFrame(); 1169 int thisEndFrame = (*i)->getModel()->getEndFrame();
1170 1170
1171 if (first || thisEndFrame > endFrame) { 1171 if (first || thisEndFrame > endFrame) {
1172 endFrame = thisEndFrame; 1172 endFrame = thisEndFrame;
1173 } 1173 }
1174 first = false; 1174 first = false;
1256 if (goodModel) return goodModel; 1256 if (goodModel) return goodModel;
1257 else if (alignedModel) return alignedModel; 1257 else if (alignedModel) return alignedModel;
1258 else return anyModel; 1258 else return anyModel;
1259 } 1259 }
1260 1260
1261 size_t 1261 int
1262 View::alignFromReference(size_t f) const 1262 View::alignFromReference(int f) const
1263 { 1263 {
1264 if (!m_manager->getAlignMode()) return f; 1264 if (!m_manager->getAlignMode()) return f;
1265 Model *aligningModel = getAligningModel(); 1265 Model *aligningModel = getAligningModel();
1266 if (!aligningModel) return f; 1266 if (!aligningModel) return f;
1267 return aligningModel->alignFromReference(f); 1267 return aligningModel->alignFromReference(f);
1268 } 1268 }
1269 1269
1270 size_t 1270 int
1271 View::alignToReference(size_t f) const 1271 View::alignToReference(int f) const
1272 { 1272 {
1273 if (!m_manager->getAlignMode()) return f; 1273 if (!m_manager->getAlignMode()) return f;
1274 Model *aligningModel = getAligningModel(); 1274 Model *aligningModel = getAligningModel();
1275 if (!aligningModel) return f; 1275 if (!aligningModel) return f;
1276 return aligningModel->alignToReference(f); 1276 return aligningModel->alignToReference(f);
1376 } 1376 }
1377 1377
1378 return nonScrollables; 1378 return nonScrollables;
1379 } 1379 }
1380 1380
1381 size_t 1381 int
1382 View::getZoomConstraintBlockSize(size_t blockSize, 1382 View::getZoomConstraintBlockSize(int blockSize,
1383 ZoomConstraint::RoundingDirection dir) 1383 ZoomConstraint::RoundingDirection dir)
1384 const 1384 const
1385 { 1385 {
1386 size_t candidate = blockSize; 1386 int candidate = blockSize;
1387 bool haveCandidate = false; 1387 bool haveCandidate = false;
1388 1388
1389 PowerOfSqrtTwoZoomConstraint defaultZoomConstraint; 1389 PowerOfSqrtTwoZoomConstraint defaultZoomConstraint;
1390 1390
1391 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 1391 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
1392 1392
1393 const ZoomConstraint *zoomConstraint = (*i)->getZoomConstraint(); 1393 const ZoomConstraint *zoomConstraint = (*i)->getZoomConstraint();
1394 if (!zoomConstraint) zoomConstraint = &defaultZoomConstraint; 1394 if (!zoomConstraint) zoomConstraint = &defaultZoomConstraint;
1395 1395
1396 size_t thisBlockSize = 1396 int thisBlockSize =
1397 zoomConstraint->getNearestBlockSize(blockSize, dir); 1397 zoomConstraint->getNearestBlockSize(blockSize, dir);
1398 1398
1399 // Go for the block size that's furthest from the one 1399 // Go for the block size that's furthest from the one
1400 // passed in. Most of the time, that's what we want. 1400 // passed in. Most of the time, that's what we want.
1401 if (!haveCandidate || 1401 if (!haveCandidate ||
1448 } 1448 }
1449 1449
1450 void 1450 void
1451 View::scroll(bool right, bool lots, bool e) 1451 View::scroll(bool right, bool lots, bool e)
1452 { 1452 {
1453 long delta; 1453 int delta;
1454 if (lots) { 1454 if (lots) {
1455 delta = (getEndFrame() - getStartFrame()) / 2; 1455 delta = (getEndFrame() - getStartFrame()) / 2;
1456 } else { 1456 } else {
1457 delta = (getEndFrame() - getStartFrame()) / 20; 1457 delta = (getEndFrame() - getStartFrame()) / 20;
1458 } 1458 }
1658 bool layersChanged = false; 1658 bool layersChanged = false;
1659 LayerList scrollables = getScrollableBackLayers(true, layersChanged); 1659 LayerList scrollables = getScrollableBackLayers(true, layersChanged);
1660 LayerList nonScrollables = getNonScrollableFrontLayers(true, layersChanged); 1660 LayerList nonScrollables = getNonScrollableFrontLayers(true, layersChanged);
1661 bool selectionCacheable = nonScrollables.empty(); 1661 bool selectionCacheable = nonScrollables.empty();
1662 bool haveSelections = m_manager && !m_manager->getSelections().empty(); 1662 bool haveSelections = m_manager && !m_manager->getSelections().empty();
1663 bool selectionDrawn = false;
1664 1663
1665 // If all the non-scrollable layers are non-opaque, then we draw 1664 // If all the non-scrollable layers are non-opaque, then we draw
1666 // the selection rectangle behind them and cache it. If any are 1665 // the selection rectangle behind them and cache it. If any are
1667 // opaque, however, we can't cache. 1666 // opaque, however, we can't cache.
1668 // 1667 //
1730 repaintCache = true; 1729 repaintCache = true;
1731 } 1730 }
1732 1731
1733 } else if (m_cacheCentreFrame != m_centreFrame) { 1732 } else if (m_cacheCentreFrame != m_centreFrame) {
1734 1733
1735 long dx = 1734 int dx =
1736 getXForFrame(m_cacheCentreFrame) - 1735 getXForFrame(m_cacheCentreFrame) -
1737 getXForFrame(m_centreFrame); 1736 getXForFrame(m_centreFrame);
1738 1737
1739 if (dx > -width() && dx < width()) { 1738 if (dx > -width() && dx < width()) {
1740 #ifdef PIXMAP_COPY_TO_SELF 1739 #ifdef PIXMAP_COPY_TO_SELF
1822 } 1821 }
1823 1822
1824 if (haveSelections && selectionCacheable) { 1823 if (haveSelections && selectionCacheable) {
1825 drawSelections(paint); 1824 drawSelections(paint);
1826 m_selectionCached = repaintCache; 1825 m_selectionCached = repaintCache;
1827 selectionDrawn = true;
1828 } 1826 }
1829 1827
1830 paint.end(); 1828 paint.end();
1831 1829
1832 if (repaintCache) { 1830 if (repaintCache) {
1871 paint.end(); 1869 paint.end();
1872 1870
1873 bool showPlayPointer = true; 1871 bool showPlayPointer = true;
1874 if (m_followPlay == PlaybackScrollContinuous) { 1872 if (m_followPlay == PlaybackScrollContinuous) {
1875 showPlayPointer = false; 1873 showPlayPointer = false;
1876 } else if (long(m_playPointerFrame) <= getStartFrame() || 1874 } else if (m_playPointerFrame <= getStartFrame() ||
1877 m_playPointerFrame >= getEndFrame()) { 1875 m_playPointerFrame >= getEndFrame()) {
1878 showPlayPointer = false; 1876 showPlayPointer = false;
1879 } else if (m_manager && !m_manager->isPlaying()) { 1877 } else if (m_manager && !m_manager->isPlaying()) {
1880 if (m_playPointerFrame == getCentreFrame() && 1878 if (m_playPointerFrame == getCentreFrame() &&
1881 m_manager->shouldShowCentreLine() && 1879 m_manager->shouldShowCentreLine() &&
1935 } 1933 }
1936 1934
1937 int sampleRate = getModelsSampleRate(); 1935 int sampleRate = getModelsSampleRate();
1938 1936
1939 QPoint localPos; 1937 QPoint localPos;
1940 long illuminateFrame = -1; 1938 int illuminateFrame = -1;
1941 bool closeToLeft, closeToRight; 1939 bool closeToLeft, closeToRight;
1942 1940
1943 if (shouldIlluminateLocalSelection(localPos, closeToLeft, closeToRight)) { 1941 if (shouldIlluminateLocalSelection(localPos, closeToLeft, closeToRight)) {
1944 illuminateFrame = getFrameForX(localPos.x()); 1942 illuminateFrame = getFrameForX(localPos.x());
1945 } 1943 }
2291 2289
2292 paint.restore(); 2290 paint.restore();
2293 } 2291 }
2294 2292
2295 bool 2293 bool
2296 View::render(QPainter &paint, int xorigin, size_t f0, size_t f1) 2294 View::render(QPainter &paint, int xorigin, int f0, int f1)
2297 { 2295 {
2298 size_t x0 = f0 / m_zoomLevel; 2296 int x0 = f0 / m_zoomLevel;
2299 size_t x1 = f1 / m_zoomLevel; 2297 int x1 = f1 / m_zoomLevel;
2300 2298
2301 size_t w = x1 - x0; 2299 int w = x1 - x0;
2302 2300
2303 size_t origCentreFrame = m_centreFrame; 2301 int origCentreFrame = m_centreFrame;
2304 2302
2305 bool someLayersIncomplete = false; 2303 bool someLayersIncomplete = false;
2306 2304
2307 for (LayerList::iterator i = m_layers.begin(); 2305 for (LayerList::iterator i = m_layers.begin();
2308 i != m_layers.end(); ++i) { 2306 i != m_layers.end(); ++i) {
2346 } 2344 }
2347 2345
2348 QProgressDialog progress(tr("Rendering image..."), 2346 QProgressDialog progress(tr("Rendering image..."),
2349 tr("Cancel"), 0, w / width(), this); 2347 tr("Cancel"), 0, w / width(), this);
2350 2348
2351 for (size_t x = 0; x < w; x += width()) { 2349 for (int x = 0; x < w; x += width()) {
2352 2350
2353 progress.setValue(x / width()); 2351 progress.setValue(x / width());
2354 qApp->processEvents(); 2352 qApp->processEvents();
2355 if (progress.wasCanceled()) { 2353 if (progress.wasCanceled()) {
2356 m_centreFrame = origCentreFrame; 2354 m_centreFrame = origCentreFrame;
2398 } 2396 }
2399 2397
2400 QImage * 2398 QImage *
2401 View::toNewImage() 2399 View::toNewImage()
2402 { 2400 {
2403 size_t f0 = getModelsStartFrame(); 2401 int f0 = getModelsStartFrame();
2404 size_t f1 = getModelsEndFrame(); 2402 int f1 = getModelsEndFrame();
2405 2403
2406 return toNewImage(f0, f1); 2404 return toNewImage(f0, f1);
2407 } 2405 }
2408 2406
2409 QImage * 2407 QImage *
2410 View::toNewImage(size_t f0, size_t f1) 2408 View::toNewImage(int f0, int f1)
2411 { 2409 {
2412 size_t x0 = f0 / getZoomLevel(); 2410 int x0 = f0 / getZoomLevel();
2413 size_t x1 = f1 / getZoomLevel(); 2411 int x1 = f1 / getZoomLevel();
2414 2412
2415 QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32); 2413 QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32);
2416 2414
2417 QPainter *paint = new QPainter(image); 2415 QPainter *paint = new QPainter(image);
2418 if (!render(*paint, 0, f0, f1)) { 2416 if (!render(*paint, 0, f0, f1)) {
2426 } 2424 }
2427 2425
2428 QSize 2426 QSize
2429 View::getImageSize() 2427 View::getImageSize()
2430 { 2428 {
2431 size_t f0 = getModelsStartFrame(); 2429 int f0 = getModelsStartFrame();
2432 size_t f1 = getModelsEndFrame(); 2430 int f1 = getModelsEndFrame();
2433 2431
2434 return getImageSize(f0, f1); 2432 return getImageSize(f0, f1);
2435 } 2433 }
2436 2434
2437 QSize 2435 QSize
2438 View::getImageSize(size_t f0, size_t f1) 2436 View::getImageSize(int f0, int f1)
2439 { 2437 {
2440 size_t x0 = f0 / getZoomLevel(); 2438 int x0 = f0 / getZoomLevel();
2441 size_t x1 = f1 / getZoomLevel(); 2439 int x1 = f1 / getZoomLevel();
2442 2440
2443 return QSize(x1 - x0, height()); 2441 return QSize(x1 - x0, height());
2444 } 2442 }
2445 2443
2446 void 2444 void
2462 .arg(m_followZoom) 2460 .arg(m_followZoom)
2463 .arg(m_followPlay == PlaybackScrollContinuous ? "scroll" : 2461 .arg(m_followPlay == PlaybackScrollContinuous ? "scroll" :
2464 m_followPlay == PlaybackScrollPage ? "page" : "ignore") 2462 m_followPlay == PlaybackScrollPage ? "page" : "ignore")
2465 .arg(extraAttributes); 2463 .arg(extraAttributes);
2466 2464
2467 for (size_t i = 0; i < m_layers.size(); ++i) { 2465 for (int i = 0; i < (int)m_layers.size(); ++i) {
2468 bool visible = !m_layers[i]->isLayerDormant(this); 2466 bool visible = !m_layers[i]->isLayerDormant(this);
2469 m_layers[i]->toBriefXml(stream, indent + " ", 2467 m_layers[i]->toBriefXml(stream, indent + " ",
2470 QString("visible=\"%1\"") 2468 QString("visible=\"%1\"")
2471 .arg(visible ? "true" : "false")); 2469 .arg(visible ? "true" : "false"));
2472 } 2470 }