comparison base/View.cpp @ 9:73d85d19919f

* Add play-selection and looping modes. Looping seems to work OK, but the plain play-selection is miscalculating current frame number to feed back to the GUI. * Cache selection rectanges wherever possible in View::paintEvent.
author Chris Cannam
date Tue, 24 Jan 2006 16:20:58 +0000
parents 214054a0d8b8
children ec6886f0e673
comparison
equal deleted inserted replaced
8:214054a0d8b8 9:73d85d19919f
38 m_lightBackground(true), 38 m_lightBackground(true),
39 m_showProgress(showProgress), 39 m_showProgress(showProgress),
40 m_cache(0), 40 m_cache(0),
41 m_cacheCentreFrame(0), 41 m_cacheCentreFrame(0),
42 m_cacheZoomLevel(1024), 42 m_cacheZoomLevel(1024),
43 m_selectionCached(false),
43 m_deleting(false), 44 m_deleting(false),
44 m_haveSelectedLayer(false), 45 m_haveSelectedLayer(false),
45 m_manager(0) 46 m_manager(0)
46 { 47 {
47 // QWidget::setAttribute(Qt::WA_PaintOnScreen); 48 // QWidget::setAttribute(Qt::WA_PaintOnScreen);
313 m_manager->disconnect(this, SLOT(viewManagerZoomLevelChanged(void *, unsigned long, bool))); 314 m_manager->disconnect(this, SLOT(viewManagerZoomLevelChanged(void *, unsigned long, bool)));
314 disconnect(m_manager, SIGNAL(centreFrameChanged(void *, unsigned long, bool))); 315 disconnect(m_manager, SIGNAL(centreFrameChanged(void *, unsigned long, bool)));
315 disconnect(m_manager, SIGNAL(zoomLevelChanged(void *, unsigned long, bool))); 316 disconnect(m_manager, SIGNAL(zoomLevelChanged(void *, unsigned long, bool)));
316 disconnect(m_manager, SIGNAL(toolModeChanged())); 317 disconnect(m_manager, SIGNAL(toolModeChanged()));
317 disconnect(m_manager, SIGNAL(selectionChanged())); 318 disconnect(m_manager, SIGNAL(selectionChanged()));
319 disconnect(m_manager, SIGNAL(inProgressSelectionChanged()));
318 } 320 }
319 321
320 m_manager = manager; 322 m_manager = manager;
321 if (m_followPan) setCentreFrame(m_manager->getGlobalCentreFrame(), false); 323 if (m_followPan) setCentreFrame(m_manager->getGlobalCentreFrame(), false);
322 if (m_followZoom) setZoomLevel(m_manager->getGlobalZoom()); 324 if (m_followZoom) setZoomLevel(m_manager->getGlobalZoom());
328 connect(m_manager, SIGNAL(zoomLevelChanged(void *, unsigned long, bool)), 330 connect(m_manager, SIGNAL(zoomLevelChanged(void *, unsigned long, bool)),
329 this, SLOT(viewManagerZoomLevelChanged(void *, unsigned long, bool))); 331 this, SLOT(viewManagerZoomLevelChanged(void *, unsigned long, bool)));
330 connect(m_manager, SIGNAL(toolModeChanged()), 332 connect(m_manager, SIGNAL(toolModeChanged()),
331 this, SLOT(toolModeChanged())); 333 this, SLOT(toolModeChanged()));
332 connect(m_manager, SIGNAL(selectionChanged()), 334 connect(m_manager, SIGNAL(selectionChanged()),
333 this, SLOT(update())); 335 this, SLOT(selectionChanged()));
336 connect(m_manager, SIGNAL(inProgressSelectionChanged()),
337 this, SLOT(selectionChanged()));
334 338
335 connect(this, SIGNAL(centreFrameChanged(void *, unsigned long, bool)), 339 connect(this, SIGNAL(centreFrameChanged(void *, unsigned long, bool)),
336 m_manager, SIGNAL(centreFrameChanged(void *, unsigned long, bool))); 340 m_manager, SIGNAL(centreFrameChanged(void *, unsigned long, bool)));
337 connect(this, SIGNAL(zoomLevelChanged(void *, unsigned long, bool)), 341 connect(this, SIGNAL(zoomLevelChanged(void *, unsigned long, bool)),
338 m_manager, SIGNAL(zoomLevelChanged(void *, unsigned long, bool))); 342 m_manager, SIGNAL(zoomLevelChanged(void *, unsigned long, bool)));
525 if (m_manager && (sender() == m_manager)) { 529 if (m_manager && (sender() == m_manager)) {
526 setZoomLevel(z); 530 setZoomLevel(z);
527 if (p == this) repaint(); 531 if (p == this) repaint();
528 } 532 }
529 } 533 }
534 }
535
536 void
537 View::selectionChanged()
538 {
539 if (m_selectionCached) {
540 delete m_cache;
541 m_cache = 0;
542 m_selectionCached = false;
543 }
544 update();
530 } 545 }
531 546
532 size_t 547 size_t
533 View::getModelsStartFrame() const 548 View::getModelsStartFrame() const
534 { 549 {
797 // are, we should store only those in the cache 812 // are, we should store only those in the cache
798 813
799 bool layersChanged = false; 814 bool layersChanged = false;
800 LayerList scrollables = getScrollableBackLayers(layersChanged); 815 LayerList scrollables = getScrollableBackLayers(layersChanged);
801 LayerList nonScrollables = getNonScrollableFrontLayers(layersChanged); 816 LayerList nonScrollables = getNonScrollableFrontLayers(layersChanged);
817 bool selectionCacheable = nonScrollables.empty();
818 bool haveSelections = m_manager && !m_manager->getSelections().empty();
819 bool selectionDrawn = false;
802 820
803 #ifdef DEBUG_VIEW_WIDGET_PAINT 821 #ifdef DEBUG_VIEW_WIDGET_PAINT
804 std::cerr << "View(" << this << ")::paintEvent: have " << scrollables.size() 822 std::cerr << "View(" << this << ")::paintEvent: have " << scrollables.size()
805 << " scrollable back layers and " << nonScrollables.size() 823 << " scrollable back layers and " << nonScrollables.size()
806 << " non-scrollable front layers" << std::endl; 824 << " non-scrollable front layers" << std::endl;
807 #endif 825 std::cerr << "haveSelections " << haveSelections << ", selectionCacheable "
808 826 << selectionCacheable << ", m_selectionCached " << m_selectionCached << std::endl;
809 if (layersChanged || scrollables.empty()) { 827 #endif
828
829 if (layersChanged || scrollables.empty() ||
830 (haveSelections && (selectionCacheable != m_selectionCached))) {
810 delete m_cache; 831 delete m_cache;
811 m_cache = 0; 832 m_cache = 0;
833 m_selectionCached = false;
812 } 834 }
813 835
814 if (!scrollables.empty()) { 836 if (!scrollables.empty()) {
815 if (!m_cache || 837 if (!m_cache ||
816 m_cacheZoomLevel != m_zoomLevel || 838 m_cacheZoomLevel != m_zoomLevel ||
922 paint.setRenderHint(QPainter::Antialiasing, false); 944 paint.setRenderHint(QPainter::Antialiasing, false);
923 paint.save(); 945 paint.save();
924 (*i)->paint(paint, cacheRect); 946 (*i)->paint(paint, cacheRect);
925 paint.restore(); 947 paint.restore();
926 } 948 }
949
950 if (haveSelections && selectionCacheable) {
951 drawSelections(paint);
952 m_selectionCached = repaintCache;
953 selectionDrawn = true;
954 }
927 955
928 paint.end(); 956 paint.end();
929 957
930 if (repaintCache) { 958 if (repaintCache) {
931 cacheRect |= (e ? e->rect() : rect()); 959 cacheRect |= (e ? e->rect() : rect());
960 988
961 for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) { 989 for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) {
962 (*i)->paint(paint, nonCacheRect); 990 (*i)->paint(paint, nonCacheRect);
963 } 991 }
964 992
993 paint.end();
994
995 paint.begin(this);
996 if (e) paint.setClipRect(e->rect());
997 if (!m_selectionCached) {
998 drawSelections(paint);
999 }
1000 paint.end();
1001
1002 if (m_followPlay != PlaybackScrollContinuous) {
1003
1004 paint.begin(this);
1005
1006 if (long(m_playPointerFrame) > getStartFrame() &&
1007 m_playPointerFrame < getEndFrame()) {
1008
1009 int playx = (long(m_playPointerFrame) - getStartFrame()) /
1010 m_zoomLevel;
1011
1012 paint.setPen(Qt::black);
1013 paint.drawLine(playx - 1, 0, playx - 1, height() - 1);
1014 paint.drawLine(playx + 1, 0, playx + 1, height() - 1);
1015 paint.drawPoint(playx, 0);
1016 paint.drawPoint(playx, height() - 1);
1017 paint.setPen(Qt::white);
1018 paint.drawLine(playx, 1, playx, height() - 2);
1019 }
1020
1021 paint.end();
1022 }
1023
1024 QFrame::paintEvent(e);
1025 }
1026
1027 void
1028 View::drawSelections(QPainter &paint)
1029 {
965 ViewManager::SelectionList selections; 1030 ViewManager::SelectionList selections;
966 1031
967 if (m_manager) { 1032 if (m_manager) {
968 selections = m_manager->getSelections(); 1033 selections = m_manager->getSelections();
969 if (m_manager->haveInProgressSelection()) { 1034 if (m_manager->haveInProgressSelection()) {
973 if (exclusive) selections.clear(); 1038 if (exclusive) selections.clear();
974 selections.insert(inProgressSelection); 1039 selections.insert(inProgressSelection);
975 } 1040 }
976 } 1041 }
977 1042
1043 paint.save();
978 paint.setPen(QColor(150, 150, 255)); 1044 paint.setPen(QColor(150, 150, 255));
979 paint.setBrush(QColor(150, 150, 255, 80)); 1045 paint.setBrush(QColor(150, 150, 255, 80));
980 1046
981 for (ViewManager::SelectionList::iterator i = selections.begin(); 1047 for (ViewManager::SelectionList::iterator i = selections.begin();
982 i != selections.end(); ++i) { 1048 i != selections.end(); ++i) {
993 1059
994 if (p0 == -1 && p1 == -1) continue; 1060 if (p0 == -1 && p1 == -1) continue;
995 1061
996 if (p1 > width()) p1 = width() + 1; 1062 if (p1 > width()) p1 = width() + 1;
997 1063
1064 #ifdef DEBUG_VIEW_WIDGET_PAINT
1065 std::cerr << "View::drawSelections: " << p0 << ",-1 [" << (p1-p0) << "x" << (height()+1) << "]" << std::endl;
1066 #endif
1067
998 paint.drawRect(p0, -1, p1 - p0, height() + 1); 1068 paint.drawRect(p0, -1, p1 - p0, height() + 1);
999 } 1069 }
1000 1070
1001 paint.end(); 1071 paint.restore();
1002
1003 if (m_followPlay != PlaybackScrollContinuous) {
1004
1005 paint.begin(this);
1006
1007 if (long(m_playPointerFrame) > getStartFrame() &&
1008 m_playPointerFrame < getEndFrame()) {
1009
1010 int playx = (long(m_playPointerFrame) - getStartFrame()) /
1011 m_zoomLevel;
1012
1013 paint.setPen(Qt::black);
1014 paint.drawLine(playx - 1, 0, playx - 1, height() - 1);
1015 paint.drawLine(playx + 1, 0, playx + 1, height() - 1);
1016 paint.drawPoint(playx, 0);
1017 paint.drawPoint(playx, height() - 1);
1018 paint.setPen(Qt::white);
1019 paint.drawLine(playx, 1, playx, height() - 2);
1020 }
1021
1022 paint.end();
1023 }
1024
1025 QFrame::paintEvent(e);
1026 } 1072 }
1027 1073
1028 QString 1074 QString
1029 View::toXmlString(QString indent, QString extraAttributes) const 1075 View::toXmlString(QString indent, QString extraAttributes) const
1030 { 1076 {