Mercurial > hg > svgui
comparison layer/NoteLayer.cpp @ 550:d666f5f8b154
* Make a better job of picking the proper point to drag, edit, delete etc
in note and region layers
* Some work to do with region dragging, but this still needs more thought
author | Chris Cannam |
---|---|
date | Mon, 28 Sep 2009 12:29:12 +0000 |
parents | 1dd2cddc32eb |
children | c2ba2796cbee |
comparison
equal
deleted
inserted
replaced
549:e6122e4999a3 | 550:d666f5f8b154 |
---|---|
402 } | 402 } |
403 | 403 |
404 return usePoints; | 404 return usePoints; |
405 } | 405 } |
406 | 406 |
407 bool | |
408 NoteLayer::getPointToDrag(View *v, int x, int y, NoteModel::Point &p) const | |
409 { | |
410 if (!m_model) return false; | |
411 | |
412 long frame = v->getFrameForX(x); | |
413 | |
414 NoteModel::PointList onPoints = m_model->getPoints(frame); | |
415 if (onPoints.empty()) return false; | |
416 | |
417 std::cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << std::endl; | |
418 | |
419 int nearestDistance = -1; | |
420 | |
421 for (NoteModel::PointList::const_iterator i = onPoints.begin(); | |
422 i != onPoints.end(); ++i) { | |
423 | |
424 int distance = getYForValue(v, (*i).value) - y; | |
425 if (distance < 0) distance = -distance; | |
426 if (nearestDistance == -1 || distance < nearestDistance) { | |
427 nearestDistance = distance; | |
428 p = *i; | |
429 } | |
430 } | |
431 | |
432 return true; | |
433 } | |
434 | |
407 QString | 435 QString |
408 NoteLayer::getFeatureDescription(View *v, QPoint &pos) const | 436 NoteLayer::getFeatureDescription(View *v, QPoint &pos) const |
409 { | 437 { |
410 int x = pos.x(); | 438 int x = pos.x(); |
411 | 439 |
816 void | 844 void |
817 NoteLayer::eraseStart(View *v, QMouseEvent *e) | 845 NoteLayer::eraseStart(View *v, QMouseEvent *e) |
818 { | 846 { |
819 if (!m_model) return; | 847 if (!m_model) return; |
820 | 848 |
821 NoteModel::PointList points = getLocalPoints(v, e->x()); | 849 // NoteModel::PointList points = getLocalPoints(v, e->x()); |
822 if (points.empty()) return; | 850 // if (points.empty()) return; |
823 | 851 |
824 m_editingPoint = *points.begin(); | 852 // m_editingPoint = *points.begin(); |
853 | |
854 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; | |
825 | 855 |
826 if (m_editingCommand) { | 856 if (m_editingCommand) { |
827 finish(m_editingCommand); | 857 finish(m_editingCommand); |
828 m_editingCommand = 0; | 858 m_editingCommand = 0; |
829 } | 859 } |
841 { | 871 { |
842 if (!m_model || !m_editing) return; | 872 if (!m_model || !m_editing) return; |
843 | 873 |
844 m_editing = false; | 874 m_editing = false; |
845 | 875 |
876 /* | |
846 NoteModel::PointList points = getLocalPoints(v, e->x()); | 877 NoteModel::PointList points = getLocalPoints(v, e->x()); |
847 if (points.empty()) return; | 878 if (points.empty()) return; |
848 if (points.begin()->frame != m_editingPoint.frame || | 879 if (points.begin()->frame != m_editingPoint.frame || |
849 points.begin()->value != m_editingPoint.value) return; | 880 points.begin()->value != m_editingPoint.value) return; |
850 | 881 */ |
851 m_editingCommand = new NoteModel::EditCommand | 882 |
852 (m_model, tr("Erase Point")); | 883 NoteModel::Point p(0); |
884 if (!getPointToDrag(v, e->x(), e->y(), p)) return; | |
885 if (p.frame != m_editingPoint.frame || p.value != m_editingPoint.value) return; | |
886 | |
887 m_editingCommand = new NoteModel::EditCommand(m_model, tr("Erase Point")); | |
853 | 888 |
854 m_editingCommand->deletePoint(m_editingPoint); | 889 m_editingCommand->deletePoint(m_editingPoint); |
855 | 890 |
856 finish(m_editingCommand); | 891 finish(m_editingCommand); |
857 m_editingCommand = 0; | 892 m_editingCommand = 0; |
863 { | 898 { |
864 // std::cerr << "NoteLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; | 899 // std::cerr << "NoteLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; |
865 | 900 |
866 if (!m_model) return; | 901 if (!m_model) return; |
867 | 902 |
903 /* | |
868 NoteModel::PointList points = getLocalPoints(v, e->x()); | 904 NoteModel::PointList points = getLocalPoints(v, e->x()); |
869 if (points.empty()) return; | 905 if (points.empty()) return; |
870 | 906 |
871 m_editingPoint = *points.begin(); | 907 m_editingPoint = *points.begin(); |
908 */ | |
909 | |
910 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; | |
872 m_originalPoint = m_editingPoint; | 911 m_originalPoint = m_editingPoint; |
873 | 912 |
874 if (m_editingCommand) { | 913 if (m_editingCommand) { |
875 finish(m_editingCommand); | 914 finish(m_editingCommand); |
876 m_editingCommand = 0; | 915 m_editingCommand = 0; |
933 | 972 |
934 bool | 973 bool |
935 NoteLayer::editOpen(View *v, QMouseEvent *e) | 974 NoteLayer::editOpen(View *v, QMouseEvent *e) |
936 { | 975 { |
937 if (!m_model) return false; | 976 if (!m_model) return false; |
938 | 977 /* |
939 NoteModel::PointList points = getLocalPoints(v, e->x()); | 978 NoteModel::PointList points = getLocalPoints(v, e->x()); |
940 if (points.empty()) return false; | 979 if (points.empty()) return false; |
941 | 980 */ |
942 NoteModel::Point note = *points.begin(); | 981 |
982 NoteModel::Point note(0); | |
983 if (!getPointToDrag(v, e->x(), e->y(), note)) return false; | |
984 | |
985 // NoteModel::Point note = *points.begin(); | |
943 | 986 |
944 ItemEditDialog *dialog = new ItemEditDialog | 987 ItemEditDialog *dialog = new ItemEditDialog |
945 (m_model->getSampleRate(), | 988 (m_model->getSampleRate(), |
946 ItemEditDialog::ShowTime | | 989 ItemEditDialog::ShowTime | |
947 ItemEditDialog::ShowDuration | | 990 ItemEditDialog::ShowDuration | |