Mercurial > hg > svgui
comparison layer/TimeInstantLayer.cpp @ 1266:a34a2a25907c
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | ee01a4062747 |
children | 61418c112281 |
comparison
equal
deleted
inserted
replaced
1265:6e724c81f18f | 1266:a34a2a25907c |
---|---|
99 int *min, int *max, int *deflt) const | 99 int *min, int *max, int *deflt) const |
100 { | 100 { |
101 int val = 0; | 101 int val = 0; |
102 | 102 |
103 if (name == "Plot Type") { | 103 if (name == "Plot Type") { |
104 | 104 |
105 if (min) *min = 0; | 105 if (min) *min = 0; |
106 if (max) *max = 1; | 106 if (max) *max = 1; |
107 if (deflt) *deflt = 0; | 107 if (deflt) *deflt = 0; |
108 | 108 |
109 val = int(m_plotStyle); | 109 val = int(m_plotStyle); |
110 | 110 |
111 } else { | 111 } else { |
112 | 112 |
113 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); | 113 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); |
114 } | 114 } |
115 | 115 |
116 return val; | 116 return val; |
117 } | 117 } |
118 | 118 |
119 QString | 119 QString |
120 TimeInstantLayer::getPropertyValueLabel(const PropertyName &name, | 120 TimeInstantLayer::getPropertyValueLabel(const PropertyName &name, |
121 int value) const | 121 int value) const |
122 { | 122 { |
123 if (name == "Plot Type") { | 123 if (name == "Plot Type") { |
124 switch (value) { | 124 switch (value) { |
125 default: | 125 default: |
126 case 0: return tr("Instants"); | 126 case 0: return tr("Instants"); |
127 case 1: return tr("Segmentation"); | 127 case 1: return tr("Segmentation"); |
128 } | 128 } |
129 } | 129 } |
130 return SingleColourLayer::getPropertyValueLabel(name, value); | 130 return SingleColourLayer::getPropertyValueLabel(name, value); |
131 } | 131 } |
132 | 132 |
133 void | 133 void |
134 TimeInstantLayer::setProperty(const PropertyName &name, int value) | 134 TimeInstantLayer::setProperty(const PropertyName &name, int value) |
135 { | 135 { |
136 if (name == "Plot Type") { | 136 if (name == "Plot Type") { |
137 setPlotStyle(PlotStyle(value)); | 137 setPlotStyle(PlotStyle(value)); |
138 } else { | 138 } else { |
139 SingleColourLayer::setProperty(name, value); | 139 SingleColourLayer::setProperty(name, value); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
165 if (!m_model) return SparseOneDimensionalModel::PointList(); | 165 if (!m_model) return SparseOneDimensionalModel::PointList(); |
166 | 166 |
167 sv_frame_t frame = v->getFrameForX(x); | 167 sv_frame_t frame = v->getFrameForX(x); |
168 | 168 |
169 SparseOneDimensionalModel::PointList onPoints = | 169 SparseOneDimensionalModel::PointList onPoints = |
170 m_model->getPoints(frame); | 170 m_model->getPoints(frame); |
171 | 171 |
172 if (!onPoints.empty()) { | 172 if (!onPoints.empty()) { |
173 return onPoints; | 173 return onPoints; |
174 } | 174 } |
175 | 175 |
176 SparseOneDimensionalModel::PointList prevPoints = | 176 SparseOneDimensionalModel::PointList prevPoints = |
177 m_model->getPreviousPoints(frame); | 177 m_model->getPreviousPoints(frame); |
178 SparseOneDimensionalModel::PointList nextPoints = | 178 SparseOneDimensionalModel::PointList nextPoints = |
179 m_model->getNextPoints(frame); | 179 m_model->getNextPoints(frame); |
180 | 180 |
181 SparseOneDimensionalModel::PointList usePoints = prevPoints; | 181 SparseOneDimensionalModel::PointList usePoints = prevPoints; |
182 | 182 |
183 if (prevPoints.empty()) { | 183 if (prevPoints.empty()) { |
184 usePoints = nextPoints; | 184 usePoints = nextPoints; |
185 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() && | 185 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() && |
186 !(nextPoints.begin()->frame > v->getEndFrame())) { | 186 !(nextPoints.begin()->frame > v->getEndFrame())) { |
187 usePoints = nextPoints; | 187 usePoints = nextPoints; |
188 } else if (nextPoints.begin()->frame - frame < | 188 } else if (nextPoints.begin()->frame - frame < |
189 frame - prevPoints.begin()->frame) { | 189 frame - prevPoints.begin()->frame) { |
190 usePoints = nextPoints; | 190 usePoints = nextPoints; |
191 } | 191 } |
192 | 192 |
193 if (!usePoints.empty()) { | 193 if (!usePoints.empty()) { |
194 int fuzz = 2; | 194 int fuzz = 2; |
195 int px = v->getXForFrame(usePoints.begin()->frame); | 195 int px = v->getXForFrame(usePoints.begin()->frame); |
196 if ((px > x && px - x > fuzz) || | 196 if ((px > x && px - x > fuzz) || |
197 (px < x && x - px > fuzz + 1)) { | 197 (px < x && x - px > fuzz + 1)) { |
198 usePoints.clear(); | 198 usePoints.clear(); |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 return usePoints; | 202 return usePoints; |
203 } | 203 } |
204 | 204 |
222 if (!m_model || !m_model->getSampleRate()) return ""; | 222 if (!m_model || !m_model->getSampleRate()) return ""; |
223 | 223 |
224 SparseOneDimensionalModel::PointList points = getLocalPoints(v, x); | 224 SparseOneDimensionalModel::PointList points = getLocalPoints(v, x); |
225 | 225 |
226 if (points.empty()) { | 226 if (points.empty()) { |
227 if (!m_model->isReady()) { | 227 if (!m_model->isReady()) { |
228 return tr("In progress"); | 228 return tr("In progress"); |
229 } else { | 229 } else { |
230 return tr("No local points"); | 230 return tr("No local points"); |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 sv_frame_t useFrame = points.begin()->frame; | 234 sv_frame_t useFrame = points.begin()->frame; |
235 | 235 |
236 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); | 236 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); |
237 | 237 |
238 QString text; | 238 QString text; |
239 | 239 |
240 if (points.begin()->label == "") { | 240 if (points.begin()->label == "") { |
241 text = QString(tr("Time:\t%1\nNo label")) | 241 text = QString(tr("Time:\t%1\nNo label")) |
242 .arg(rt.toText(true).c_str()); | 242 .arg(rt.toText(true).c_str()); |
243 } else { | 243 } else { |
244 text = QString(tr("Time:\t%1\nLabel:\t%2")) | 244 text = QString(tr("Time:\t%1\nLabel:\t%2")) |
245 .arg(rt.toText(true).c_str()) | 245 .arg(rt.toText(true).c_str()) |
246 .arg(points.begin()->label); | 246 .arg(points.begin()->label); |
247 } | 247 } |
248 | 248 |
249 pos = QPoint(v->getXForFrame(useFrame), pos.y()); | 249 pos = QPoint(v->getXForFrame(useFrame), pos.y()); |
250 return text; | 250 return text; |
251 } | 251 } |
252 | 252 |
253 bool | 253 bool |
254 TimeInstantLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, | 254 TimeInstantLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, |
255 int &resolution, | 255 int &resolution, |
256 SnapType snap) const | 256 SnapType snap) const |
257 { | 257 { |
258 if (!m_model) { | 258 if (!m_model) { |
259 return Layer::snapToFeatureFrame(v, frame, resolution, snap); | 259 return Layer::snapToFeatureFrame(v, frame, resolution, snap); |
260 } | 260 } |
261 | 261 |
262 resolution = m_model->getResolution(); | 262 resolution = m_model->getResolution(); |
263 SparseOneDimensionalModel::PointList points; | 263 SparseOneDimensionalModel::PointList points; |
264 | 264 |
265 if (snap == SnapNeighbouring) { | 265 if (snap == SnapNeighbouring) { |
266 | 266 |
267 points = getLocalPoints(v, v->getXForFrame(frame)); | 267 points = getLocalPoints(v, v->getXForFrame(frame)); |
268 if (points.empty()) return false; | 268 if (points.empty()) return false; |
269 frame = points.begin()->frame; | 269 frame = points.begin()->frame; |
270 return true; | 270 return true; |
271 } | 271 } |
272 | 272 |
273 points = m_model->getPoints(frame, frame); | 273 points = m_model->getPoints(frame, frame); |
274 sv_frame_t snapped = frame; | 274 sv_frame_t snapped = frame; |
275 bool found = false; | 275 bool found = false; |
276 | 276 |
277 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin(); | 277 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin(); |
278 i != points.end(); ++i) { | 278 i != points.end(); ++i) { |
279 | 279 |
280 if (snap == SnapRight) { | 280 if (snap == SnapRight) { |
281 | 281 |
282 if (i->frame >= frame) { | 282 if (i->frame >= frame) { |
283 snapped = i->frame; | 283 snapped = i->frame; |
284 found = true; | 284 found = true; |
285 break; | 285 break; |
286 } | 286 } |
287 | 287 |
288 } else if (snap == SnapLeft) { | 288 } else if (snap == SnapLeft) { |
289 | 289 |
290 if (i->frame <= frame) { | 290 if (i->frame <= frame) { |
291 snapped = i->frame; | 291 snapped = i->frame; |
292 found = true; // don't break, as the next may be better | 292 found = true; // don't break, as the next may be better |
293 } else { | 293 } else { |
294 break; | 294 break; |
295 } | 295 } |
296 | 296 |
297 } else { // nearest | 297 } else { // nearest |
298 | 298 |
299 SparseOneDimensionalModel::PointList::const_iterator j = i; | 299 SparseOneDimensionalModel::PointList::const_iterator j = i; |
300 ++j; | 300 ++j; |
301 | 301 |
302 if (j == points.end()) { | 302 if (j == points.end()) { |
303 | 303 |
304 snapped = i->frame; | 304 snapped = i->frame; |
305 found = true; | 305 found = true; |
306 break; | 306 break; |
307 | 307 |
308 } else if (j->frame >= frame) { | 308 } else if (j->frame >= frame) { |
309 | 309 |
310 if (j->frame - frame < frame - i->frame) { | 310 if (j->frame - frame < frame - i->frame) { |
311 snapped = j->frame; | 311 snapped = j->frame; |
312 } else { | 312 } else { |
313 snapped = i->frame; | 313 snapped = i->frame; |
314 } | 314 } |
315 found = true; | 315 found = true; |
316 break; | 316 break; |
317 } | 317 } |
318 } | 318 } |
319 } | 319 } |
320 | 320 |
321 frame = snapped; | 321 frame = snapped; |
322 return found; | 322 return found; |
323 } | 323 } |
333 | 333 |
334 sv_frame_t frame0 = v->getFrameForX(x0); | 334 sv_frame_t frame0 = v->getFrameForX(x0); |
335 sv_frame_t frame1 = v->getFrameForX(x1); | 335 sv_frame_t frame1 = v->getFrameForX(x1); |
336 | 336 |
337 SparseOneDimensionalModel::PointList points(m_model->getPoints | 337 SparseOneDimensionalModel::PointList points(m_model->getPoints |
338 (frame0, frame1)); | 338 (frame0, frame1)); |
339 | 339 |
340 bool odd = false; | 340 bool odd = false; |
341 if (m_plotStyle == PlotSegmentation && !points.empty()) { | 341 if (m_plotStyle == PlotSegmentation && !points.empty()) { |
342 int index = m_model->getIndexOf(*points.begin()); | 342 int index = m_model->getIndexOf(*points.begin()); |
343 odd = ((index % 2) == 1); | 343 odd = ((index % 2) == 1); |
344 } | 344 } |
345 | 345 |
346 paint.setPen(getBaseQColor()); | 346 paint.setPen(getBaseQColor()); |
347 | 347 |
348 QColor brushColour(getBaseQColor()); | 348 QColor brushColour(getBaseQColor()); |
349 brushColour.setAlpha(100); | 349 brushColour.setAlpha(100); |
350 paint.setBrush(brushColour); | 350 paint.setBrush(brushColour); |
351 | 351 |
352 QColor oddBrushColour(brushColour); | 352 QColor oddBrushColour(brushColour); |
353 if (m_plotStyle == PlotSegmentation) { | 353 if (m_plotStyle == PlotSegmentation) { |
354 if (getBaseQColor() == Qt::black) { | 354 if (getBaseQColor() == Qt::black) { |
355 oddBrushColour = Qt::gray; | 355 oddBrushColour = Qt::gray; |
356 } else if (getBaseQColor() == Qt::darkRed) { | 356 } else if (getBaseQColor() == Qt::darkRed) { |
357 oddBrushColour = Qt::red; | 357 oddBrushColour = Qt::red; |
358 } else if (getBaseQColor() == Qt::darkBlue) { | 358 } else if (getBaseQColor() == Qt::darkBlue) { |
359 oddBrushColour = Qt::blue; | 359 oddBrushColour = Qt::blue; |
360 } else if (getBaseQColor() == Qt::darkGreen) { | 360 } else if (getBaseQColor() == Qt::darkGreen) { |
361 oddBrushColour = Qt::green; | 361 oddBrushColour = Qt::green; |
362 } else { | 362 } else { |
363 oddBrushColour = oddBrushColour.light(150); | 363 oddBrushColour = oddBrushColour.light(150); |
364 } | 364 } |
365 oddBrushColour.setAlpha(100); | 365 oddBrushColour.setAlpha(100); |
366 } | 366 } |
367 | 367 |
368 // SVDEBUG << "TimeInstantLayer::paint: resolution is " | 368 // SVDEBUG << "TimeInstantLayer::paint: resolution is " |
369 // << m_model->getResolution() << " frames" << endl; | 369 // << m_model->getResolution() << " frames" << endl; |
370 | 370 |
371 QPoint localPos; | 371 QPoint localPos; |
372 sv_frame_t illuminateFrame = -1; | 372 sv_frame_t illuminateFrame = -1; |
373 | 373 |
374 if (v->shouldIlluminateLocalFeatures(this, localPos)) { | 374 if (v->shouldIlluminateLocalFeatures(this, localPos)) { |
375 SparseOneDimensionalModel::PointList localPoints = | 375 SparseOneDimensionalModel::PointList localPoints = |
376 getLocalPoints(v, localPos.x()); | 376 getLocalPoints(v, localPos.x()); |
377 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; | 377 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; |
378 } | 378 } |
379 | 379 |
380 int prevX = -1; | 380 int prevX = -1; |
381 int textY = v->getTextLabelHeight(this, paint); | 381 int textY = v->getTextLabelHeight(this, paint); |
382 | 382 |
383 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin(); | 383 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin(); |
384 i != points.end(); ++i) { | 384 i != points.end(); ++i) { |
385 | 385 |
386 const SparseOneDimensionalModel::Point &p(*i); | 386 const SparseOneDimensionalModel::Point &p(*i); |
387 SparseOneDimensionalModel::PointList::const_iterator j = i; | 387 SparseOneDimensionalModel::PointList::const_iterator j = i; |
388 ++j; | 388 ++j; |
389 | 389 |
390 int x = v->getXForFrame(p.frame); | 390 int x = v->getXForFrame(p.frame); |
391 if (x == prevX && m_plotStyle == PlotInstants && | 391 if (x == prevX && m_plotStyle == PlotInstants && |
392 p.frame != illuminateFrame) continue; | 392 p.frame != illuminateFrame) continue; |
393 | 393 |
394 int iw = v->getXForFrame(p.frame + m_model->getResolution()) - x; | 394 int iw = v->getXForFrame(p.frame + m_model->getResolution()) - x; |
395 if (iw < 2) { | 395 if (iw < 2) { |
396 if (iw < 1) { | 396 if (iw < 1) { |
397 iw = 2; | 397 iw = 2; |
398 if (j != points.end()) { | 398 if (j != points.end()) { |
399 int nx = v->getXForFrame(j->frame); | 399 int nx = v->getXForFrame(j->frame); |
400 if (nx < x + 3) iw = 1; | 400 if (nx < x + 3) iw = 1; |
401 } | 401 } |
402 } else { | 402 } else { |
403 iw = 2; | 403 iw = 2; |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
407 if (p.frame == illuminateFrame) { | 407 if (p.frame == illuminateFrame) { |
408 paint.setPen(getForegroundQColor(v->getView())); | 408 paint.setPen(getForegroundQColor(v->getView())); |
409 } else { | 409 } else { |
410 paint.setPen(brushColour); | 410 paint.setPen(brushColour); |
411 } | 411 } |
412 | 412 |
413 if (m_plotStyle == PlotInstants) { | 413 if (m_plotStyle == PlotInstants) { |
414 if (iw > 1) { | 414 if (iw > 1) { |
415 paint.drawRect(x, 0, iw - 1, v->getPaintHeight() - 1); | 415 paint.drawRect(x, 0, iw - 1, v->getPaintHeight() - 1); |
416 } else { | 416 } else { |
417 paint.drawLine(x, 0, x, v->getPaintHeight() - 1); | 417 paint.drawLine(x, 0, x, v->getPaintHeight() - 1); |
418 } | 418 } |
419 } else { | 419 } else { |
420 | 420 |
421 if (odd) paint.setBrush(oddBrushColour); | 421 if (odd) paint.setBrush(oddBrushColour); |
422 else paint.setBrush(brushColour); | 422 else paint.setBrush(brushColour); |
423 | 423 |
424 int nx; | 424 int nx; |
425 | 425 |
426 if (j != points.end()) { | 426 if (j != points.end()) { |
427 const SparseOneDimensionalModel::Point &q(*j); | 427 const SparseOneDimensionalModel::Point &q(*j); |
428 nx = v->getXForFrame(q.frame); | 428 nx = v->getXForFrame(q.frame); |
429 } else { | 429 } else { |
430 nx = v->getXForFrame(m_model->getEndFrame()); | 430 nx = v->getXForFrame(m_model->getEndFrame()); |
431 } | 431 } |
432 | 432 |
433 if (nx >= x) { | 433 if (nx >= x) { |
434 | 434 |
435 if (illuminateFrame != p.frame && | 435 if (illuminateFrame != p.frame && |
436 (nx < x + 5 || x >= v->getPaintWidth() - 1)) { | 436 (nx < x + 5 || x >= v->getPaintWidth() - 1)) { |
437 paint.setPen(Qt::NoPen); | 437 paint.setPen(Qt::NoPen); |
438 } | 438 } |
439 | 439 |
440 paint.drawRect(x, -1, nx - x, v->getPaintHeight() + 1); | 440 paint.drawRect(x, -1, nx - x, v->getPaintHeight() + 1); |
441 } | 441 } |
442 | 442 |
443 odd = !odd; | 443 odd = !odd; |
444 } | 444 } |
445 | 445 |
446 paint.setPen(getBaseQColor()); | 446 paint.setPen(getBaseQColor()); |
447 | 447 |
448 if (p.label != "") { | 448 if (p.label != "") { |
449 | 449 |
450 // only draw if there's enough room from here to the next point | 450 // only draw if there's enough room from here to the next point |
451 | 451 |
452 int lw = paint.fontMetrics().width(p.label); | 452 int lw = paint.fontMetrics().width(p.label); |
453 bool good = true; | 453 bool good = true; |
454 | 454 |
455 if (j != points.end()) { | 455 if (j != points.end()) { |
456 int nx = v->getXForFrame(j->frame); | 456 int nx = v->getXForFrame(j->frame); |
457 if (nx >= x && nx - x - iw - 3 <= lw) good = false; | 457 if (nx >= x && nx - x - iw - 3 <= lw) good = false; |
458 } | 458 } |
459 | 459 |
460 if (good) { | 460 if (good) { |
461 PaintAssistant::drawVisibleText(v, paint, x + iw + 2, textY, p.label, PaintAssistant::OutlinedText); | 461 PaintAssistant::drawVisibleText(v, paint, x + iw + 2, textY, p.label, PaintAssistant::OutlinedText); |
462 // paint.drawText(x + iw + 2, textY, p.label); | 462 // paint.drawText(x + iw + 2, textY, p.label); |
463 } | 463 } |
464 } | 464 } |
465 | 465 |
466 prevX = x; | 466 prevX = x; |
467 } | 467 } |
468 } | 468 } |
469 | 469 |
470 void | 470 void |
471 TimeInstantLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) | 471 TimeInstantLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) |
482 | 482 |
483 m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point")); | 483 m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point")); |
484 | 484 |
485 if (m_editingCommand) finish(m_editingCommand); | 485 if (m_editingCommand) finish(m_editingCommand); |
486 m_editingCommand = new SparseOneDimensionalModel::EditCommand(m_model, | 486 m_editingCommand = new SparseOneDimensionalModel::EditCommand(m_model, |
487 tr("Draw Point")); | 487 tr("Draw Point")); |
488 m_editingCommand->addPoint(m_editingPoint); | 488 m_editingCommand->addPoint(m_editingPoint); |
489 | 489 |
490 m_editing = true; | 490 m_editing = true; |
491 } | 491 } |
492 | 492 |
513 #ifdef DEBUG_TIME_INSTANT_LAYER | 513 #ifdef DEBUG_TIME_INSTANT_LAYER |
514 cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << endl; | 514 cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << endl; |
515 #endif | 515 #endif |
516 if (!m_model || !m_editing) return; | 516 if (!m_model || !m_editing) return; |
517 QString newName = tr("Add Point at %1 s") | 517 QString newName = tr("Add Point at %1 s") |
518 .arg(RealTime::frame2RealTime(m_editingPoint.frame, | 518 .arg(RealTime::frame2RealTime(m_editingPoint.frame, |
519 m_model->getSampleRate()) | 519 m_model->getSampleRate()) |
520 .toText(false).c_str()); | 520 .toText(false).c_str()); |
521 m_editingCommand->setName(newName); | 521 m_editingCommand->setName(newName); |
522 finish(m_editingCommand); | 522 finish(m_editingCommand); |
523 m_editingCommand = 0; | 523 m_editingCommand = 0; |
524 m_editing = false; | 524 m_editing = false; |
525 } | 525 } |
533 if (points.empty()) return; | 533 if (points.empty()) return; |
534 | 534 |
535 m_editingPoint = *points.begin(); | 535 m_editingPoint = *points.begin(); |
536 | 536 |
537 if (m_editingCommand) { | 537 if (m_editingCommand) { |
538 finish(m_editingCommand); | 538 finish(m_editingCommand); |
539 m_editingCommand = 0; | 539 m_editingCommand = 0; |
540 } | 540 } |
541 | 541 |
542 m_editing = true; | 542 m_editing = true; |
543 } | 543 } |
544 | 544 |
581 if (points.empty()) return; | 581 if (points.empty()) return; |
582 | 582 |
583 m_editingPoint = *points.begin(); | 583 m_editingPoint = *points.begin(); |
584 | 584 |
585 if (m_editingCommand) { | 585 if (m_editingCommand) { |
586 finish(m_editingCommand); | 586 finish(m_editingCommand); |
587 m_editingCommand = 0; | 587 m_editingCommand = 0; |
588 } | 588 } |
589 | 589 |
590 m_editing = true; | 590 m_editing = true; |
591 } | 591 } |
592 | 592 |
602 sv_frame_t frame = v->getFrameForX(e->x()); | 602 sv_frame_t frame = v->getFrameForX(e->x()); |
603 if (frame < 0) frame = 0; | 603 if (frame < 0) frame = 0; |
604 frame = frame / m_model->getResolution() * m_model->getResolution(); | 604 frame = frame / m_model->getResolution() * m_model->getResolution(); |
605 | 605 |
606 if (!m_editingCommand) { | 606 if (!m_editingCommand) { |
607 m_editingCommand = new SparseOneDimensionalModel::EditCommand(m_model, | 607 m_editingCommand = new SparseOneDimensionalModel::EditCommand(m_model, |
608 tr("Drag Point")); | 608 tr("Drag Point")); |
609 } | 609 } |
610 | 610 |
611 m_editingCommand->deletePoint(m_editingPoint); | 611 m_editingCommand->deletePoint(m_editingPoint); |
612 m_editingPoint.frame = frame; | 612 m_editingPoint.frame = frame; |
613 m_editingCommand->addPoint(m_editingPoint); | 613 m_editingCommand->addPoint(m_editingPoint); |
619 #ifdef DEBUG_TIME_INSTANT_LAYER | 619 #ifdef DEBUG_TIME_INSTANT_LAYER |
620 cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << endl; | 620 cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << endl; |
621 #endif | 621 #endif |
622 if (!m_model || !m_editing) return; | 622 if (!m_model || !m_editing) return; |
623 if (m_editingCommand) { | 623 if (m_editingCommand) { |
624 QString newName = tr("Move Point to %1 s") | 624 QString newName = tr("Move Point to %1 s") |
625 .arg(RealTime::frame2RealTime(m_editingPoint.frame, | 625 .arg(RealTime::frame2RealTime(m_editingPoint.frame, |
626 m_model->getSampleRate()) | 626 m_model->getSampleRate()) |
627 .toText(false).c_str()); | 627 .toText(false).c_str()); |
628 m_editingCommand->setName(newName); | 628 m_editingCommand->setName(newName); |
629 finish(m_editingCommand); | 629 finish(m_editingCommand); |
630 } | 630 } |
631 m_editingCommand = 0; | 631 m_editingCommand = 0; |
632 m_editing = false; | 632 m_editing = false; |
633 } | 633 } |
634 | 634 |
671 TimeInstantLayer::moveSelection(Selection s, sv_frame_t newStartFrame) | 671 TimeInstantLayer::moveSelection(Selection s, sv_frame_t newStartFrame) |
672 { | 672 { |
673 if (!m_model) return; | 673 if (!m_model) return; |
674 | 674 |
675 SparseOneDimensionalModel::EditCommand *command = | 675 SparseOneDimensionalModel::EditCommand *command = |
676 new SparseOneDimensionalModel::EditCommand(m_model, | 676 new SparseOneDimensionalModel::EditCommand(m_model, |
677 tr("Drag Selection")); | 677 tr("Drag Selection")); |
678 | 678 |
679 SparseOneDimensionalModel::PointList points = | 679 SparseOneDimensionalModel::PointList points = |
680 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 680 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
681 | 681 |
682 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); | 682 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); |
683 i != points.end(); ++i) { | 683 i != points.end(); ++i) { |
684 | 684 |
685 if (s.contains(i->frame)) { | 685 if (s.contains(i->frame)) { |
686 SparseOneDimensionalModel::Point newPoint(*i); | 686 SparseOneDimensionalModel::Point newPoint(*i); |
687 newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); | 687 newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); |
688 command->deletePoint(*i); | 688 command->deletePoint(*i); |
689 command->addPoint(newPoint); | 689 command->addPoint(newPoint); |
690 } | 690 } |
691 } | 691 } |
692 | 692 |
693 finish(command); | 693 finish(command); |
694 } | 694 } |
695 | 695 |
697 TimeInstantLayer::resizeSelection(Selection s, Selection newSize) | 697 TimeInstantLayer::resizeSelection(Selection s, Selection newSize) |
698 { | 698 { |
699 if (!m_model) return; | 699 if (!m_model) return; |
700 | 700 |
701 SparseOneDimensionalModel::EditCommand *command = | 701 SparseOneDimensionalModel::EditCommand *command = |
702 new SparseOneDimensionalModel::EditCommand(m_model, | 702 new SparseOneDimensionalModel::EditCommand(m_model, |
703 tr("Resize Selection")); | 703 tr("Resize Selection")); |
704 | 704 |
705 SparseOneDimensionalModel::PointList points = | 705 SparseOneDimensionalModel::PointList points = |
706 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 706 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
707 | 707 |
708 double ratio = | 708 double ratio = |
709 double(newSize.getEndFrame() - newSize.getStartFrame()) / | 709 double(newSize.getEndFrame() - newSize.getStartFrame()) / |
710 double(s.getEndFrame() - s.getStartFrame()); | 710 double(s.getEndFrame() - s.getStartFrame()); |
711 | 711 |
712 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); | 712 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); |
713 i != points.end(); ++i) { | 713 i != points.end(); ++i) { |
714 | 714 |
715 if (s.contains(i->frame)) { | 715 if (s.contains(i->frame)) { |
716 | 716 |
717 double target = double(i->frame); | 717 double target = double(i->frame); |
718 target = double(newSize.getStartFrame()) + | 718 target = double(newSize.getStartFrame()) + |
719 target - double(s.getStartFrame()) * ratio; | 719 target - double(s.getStartFrame()) * ratio; |
720 | 720 |
721 SparseOneDimensionalModel::Point newPoint(*i); | 721 SparseOneDimensionalModel::Point newPoint(*i); |
722 newPoint.frame = lrint(target); | 722 newPoint.frame = lrint(target); |
723 command->deletePoint(*i); | 723 command->deletePoint(*i); |
724 command->addPoint(newPoint); | 724 command->addPoint(newPoint); |
725 } | 725 } |
726 } | 726 } |
727 | 727 |
728 finish(command); | 728 finish(command); |
729 } | 729 } |
730 | 730 |
732 TimeInstantLayer::deleteSelection(Selection s) | 732 TimeInstantLayer::deleteSelection(Selection s) |
733 { | 733 { |
734 if (!m_model) return; | 734 if (!m_model) return; |
735 | 735 |
736 SparseOneDimensionalModel::EditCommand *command = | 736 SparseOneDimensionalModel::EditCommand *command = |
737 new SparseOneDimensionalModel::EditCommand(m_model, | 737 new SparseOneDimensionalModel::EditCommand(m_model, |
738 tr("Delete Selection")); | 738 tr("Delete Selection")); |
739 | 739 |
740 SparseOneDimensionalModel::PointList points = | 740 SparseOneDimensionalModel::PointList points = |
741 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 741 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
742 | 742 |
743 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); | 743 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); |
744 i != points.end(); ++i) { | 744 i != points.end(); ++i) { |
745 if (s.contains(i->frame)) command->deletePoint(*i); | 745 if (s.contains(i->frame)) command->deletePoint(*i); |
746 } | 746 } |
747 | 747 |
748 finish(command); | 748 finish(command); |
749 } | 749 } |
750 | 750 |
752 TimeInstantLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) | 752 TimeInstantLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) |
753 { | 753 { |
754 if (!m_model) return; | 754 if (!m_model) return; |
755 | 755 |
756 SparseOneDimensionalModel::PointList points = | 756 SparseOneDimensionalModel::PointList points = |
757 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 757 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
758 | 758 |
759 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); | 759 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); |
760 i != points.end(); ++i) { | 760 i != points.end(); ++i) { |
761 if (s.contains(i->frame)) { | 761 if (s.contains(i->frame)) { |
762 Clipboard::Point point(i->frame, i->label); | 762 Clipboard::Point point(i->frame, i->label); |
763 point.setReferenceFrame(alignToReference(v, i->frame)); | 763 point.setReferenceFrame(alignToReference(v, i->frame)); |
764 to.addPoint(point); | 764 to.addPoint(point); |
765 } | 765 } |
766 } | 766 } |
791 realign = true; | 791 realign = true; |
792 } | 792 } |
793 } | 793 } |
794 | 794 |
795 SparseOneDimensionalModel::EditCommand *command = | 795 SparseOneDimensionalModel::EditCommand *command = |
796 new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste")); | 796 new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste")); |
797 | 797 |
798 for (Clipboard::PointList::const_iterator i = points.begin(); | 798 for (Clipboard::PointList::const_iterator i = points.begin(); |
799 i != points.end(); ++i) { | 799 i != points.end(); ++i) { |
800 | 800 |
801 if (!i->haveFrame()) continue; | 801 if (!i->haveFrame()) continue; |
859 { | 859 { |
860 SingleColourLayer::setProperties(attributes); | 860 SingleColourLayer::setProperties(attributes); |
861 | 861 |
862 bool ok; | 862 bool ok; |
863 PlotStyle style = (PlotStyle) | 863 PlotStyle style = (PlotStyle) |
864 attributes.value("plotStyle").toInt(&ok); | 864 attributes.value("plotStyle").toInt(&ok); |
865 if (ok) setPlotStyle(style); | 865 if (ok) setPlotStyle(style); |
866 } | 866 } |
867 | 867 |