comparison layer/FlexiNoteLayer.cpp @ 650:12d570c27d85 tonioni

split drag delete
author matthiasm
date Sun, 16 Jun 2013 00:16:37 +0100
parents f61a54364d1d
children
comparison
equal deleted inserted replaced
648:f61a54364d1d 650:12d570c27d85
468 p = *i; 468 p = *i;
469 } 469 }
470 } 470 }
471 471
472 return true; 472 return true;
473 }
474
475 bool
476 FlexiNoteLayer::getLeftNeighbour(View *v, FlexiNote note, FlexiNote &leftNeighbour) const {
477 // MM: this is necessary (I think) to restrict the movement of notes to the left
478 if (!m_model) return false;
479
480 FlexiNoteModel::PointList onPoints = m_model->getPoints(0, note.frame - 1);
481 if (!onPoints.empty())
482 {
483 leftNeighbour = *onPoints.end();
484 return true;
485 }
486 return false;
487 }
488
489 bool
490 FlexiNoteLayer::getRightNeighbour(View *v, FlexiNote note, FlexiNote &rightNeighbour) const {
491 // MM: this is necessary (I think) to restrict the movement of notes to the right
492 if (!m_model) return false;
493
494 FlexiNoteModel::PointList onPoints = m_model->getPoints(note.frame + note.duration);
495 if (!onPoints.empty())
496 {
497 rightNeighbour = *onPoints.begin();
498 return true;
499 }
500 return false;
473 } 501 }
474 502
475 QString 503 QString
476 FlexiNoteLayer::getFeatureDescription(View *v, QPoint &pos) const 504 FlexiNoteLayer::getFeatureDescription(View *v, QPoint &pos) const
477 { 505 {
1017 m_editingCommand = 0; 1045 m_editingCommand = 0;
1018 m_editing = false; 1046 m_editing = false;
1019 } 1047 }
1020 1048
1021 void 1049 void
1022 FlexiNoteLayer::splitStart(View *v, QMouseEvent *e) 1050 FlexiNoteLayer::multiStart(View *v, QMouseEvent *e)
1023 { 1051 {
1024 // GF: note splitting starts (!! remove printing soon) 1052 std::cerr << "multiStart" << std::endl;
1025 std::cerr << "splitStart" << std::endl;
1026 if (!m_model) return; 1053 if (!m_model) return;
1027 1054
1055 if (m_editingCommand) {
1056 finish(m_editingCommand);
1057 m_editingCommand = 0;
1058 }
1059
1028 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; 1060 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
1029 // m_originalPoint = m_editingPoint; 1061 bool closeToLeft = false, closeToRight = false, closeToTop = false, closeToBottom = false;
1030 // 1062 getRelativeMousePosition(v, m_editingPoint, e->x(), e->y(), closeToLeft, closeToRight, closeToTop, closeToBottom);
1031 // m_dragPointX = v->getXForFrame(m_editingPoint.frame); 1063
1032 // m_dragPointY = getYForValue(v, m_editingPoint.value); 1064 std::cerr << closeToLeft << " " << closeToRight << " " << closeToTop << " " << closeToBottom << std::endl;
1033 1065
1034 if (m_editingCommand) { 1066 if (closeToLeft)
1035 finish(m_editingCommand); 1067 {
1036 m_editingCommand = 0; 1068 std::cerr << "... move left boundary" << std::endl;
1037 } 1069
1038 1070 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
1039 m_editing = true; 1071 m_originalPoint = m_editingPoint;
1040 m_dragStartX = e->x(); 1072
1041 m_dragStartY = e->y(); 1073 m_editing = true;
1042 1074 m_multiEditMode = MoveLeftBoundary;
1043 } 1075 m_dragStartX = e->x();
1044 1076 m_dragStartY = e->y();
1045 void 1077
1046 FlexiNoteLayer::splitEnd(View *v, QMouseEvent *e) 1078 } else if (closeToTop)
1079 {
1080 // MM: note delete starts
1081 std::cerr << "... delete" << std::endl;
1082 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
1083 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand
1084 (m_model, tr("Edit Point"));
1085 command->deletePoint(m_editingPoint);
1086 finish(command);
1087 m_editing = false;
1088 m_editingPoint = 0;
1089
1090 } else if (closeToBottom)
1091 {
1092 // GF: note splitting starts (!! remove printing soon)
1093 std::cerr << "... split" << std::endl;
1094 m_editing = true;
1095 m_multiEditMode = Split;
1096 m_dragStartX = e->x();
1097 m_dragStartY = e->y();
1098 }
1099 return;
1100 }
1101
1102
1103 void
1104 FlexiNoteLayer::multiDrag(View *v, QMouseEvent *e)
1047 { 1105 {
1048 // GF: note splitting ends. (!! remove printing soon) 1106 // GF: note splitting ends. (!! remove printing soon)
1049 std::cerr << "splitEnd" << std::endl; 1107 std::cerr << "multiDrag" << std::endl;
1050 if (!m_model || !m_editing) return; 1108 if (!m_model || !m_editing) return;
1051 1109
1052 int xdist = e->x() - m_dragStartX; 1110 switch (m_multiEditMode)
1053 int ydist = e->y() - m_dragStartY; 1111 {
1054 if (xdist != 0 || ydist != 0) { 1112 case MoveLeftBoundary :
1055 std::cerr << "mouse moved" << std::endl; 1113 {
1056 return; 1114 long frame = v->getFrameForX(e->x());
1057 } 1115 long duration = m_originalPoint.duration - (frame - m_originalPoint.frame);
1058 1116
1059 // MM simpler declaration 1117 if (!m_editingCommand) {
1060 FlexiNote note(0); 1118 m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
1061 if (!getPointToDrag(v, e->x(), e->y(), note)) return; 1119 tr("Drag Point"));
1062 1120 }
1063 long frame = v->getFrameForX(e->x()); 1121
1064 1122 m_editingCommand->deletePoint(m_editingPoint);
1065 int gap = 0; // MM: I prefer a gap of 0, but we can decide later 1123 m_editingPoint.frame = frame;
1066 1124 m_editingPoint.duration = duration;
1067 // MM: changed this a bit, to make it slightly clearer 1125 m_editingCommand->addPoint(m_editingPoint);
1068 FlexiNote newNote1(note.frame, note.value, 1126
1069 frame - note.frame - gap, 1127 }
1070 note.level, note.label); 1128 default : return;
1071 1129 }
1072 FlexiNote newNote2(frame, note.value, 1130 return;
1073 note.duration - newNote1.duration, 1131 }
1074 note.level, note.label); 1132
1075 1133 void
1076 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand 1134 FlexiNoteLayer::multiEnd(View *v, QMouseEvent *e)
1077 (m_model, tr("Edit Point")); 1135 {
1078 command->deletePoint(note); 1136 // GF: note splitting ends. (!! remove printing soon)
1079 command->addPoint(newNote1); 1137 std::cerr << "multiEnd" << std::endl;
1080 command->addPoint(newNote2); 1138 if (!m_model || !m_editing) return;
1081 finish(command); 1139 m_editing = false;
1082 1140
1083 } 1141 switch (m_multiEditMode)
1142 {
1143 case MoveLeftBoundary :
1144 {
1145 std::cerr << "... move left boundary" << std::endl;
1146
1147
1148 if (m_editingCommand) {
1149
1150 QString newName = m_editingCommand->getName();
1151
1152 if (m_editingPoint.frame != m_originalPoint.frame) {
1153 newName = tr("Relocate Point");
1154 }
1155
1156 m_editingCommand->setName(newName);
1157 finish(m_editingCommand);
1158 }
1159
1160 m_editingCommand = 0;
1161 m_editing = false;
1162
1163 }
1164 case Split :
1165 {
1166
1167 // MM simpler declaration
1168 FlexiNote note(0);
1169 if (!getNoteToEdit(v, m_dragStartX, m_dragStartY, note)) return;
1170
1171 long frame = v->getFrameForX(e->x());
1172
1173 int gap = 100; // MM: I prefer a gap of 0, but we can decide later
1174
1175 // MM: changed this a bit, to make it slightly clearer
1176 FlexiNote newNote1(note.frame, note.value,
1177 frame - note.frame - gap,
1178 note.level, note.label);
1179
1180 FlexiNote newNote2(frame, note.value,
1181 note.duration - newNote1.duration,
1182 note.level, note.label);
1183 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand
1184 (m_model, tr("Edit Point"));
1185
1186 command->deletePoint(note);
1187 command->addPoint(newNote1);
1188 command->addPoint(newNote2);
1189 finish(command);
1190 }
1191 }
1192
1193 return;
1194 }
1195
1196 // void
1197 // FlexiNoteLayer::moveBoundaryStart(View *v, QMouseEvent *e)
1198 // {
1199 // }
1200 //
1201 // void
1202 // FlexiNoteLayer::moveBoundaryEnd(View *v, QMouseEvent *e)
1203 // {
1204 // }
1084 1205
1085 void 1206 void
1086 FlexiNoteLayer::mouseMoveEvent(View *v, QMouseEvent *e) 1207 FlexiNoteLayer::mouseMoveEvent(View *v, QMouseEvent *e)
1087 { 1208 {
1088 // GF: context sensitive cursors 1209 // GF: context sensitive cursors