Mercurial > hg > svgui
comparison layer/TextLayer.cpp @ 36:c28ebb4ba4de
* Improvements to text layer editing, and implement file I/O for it
* Start some fixes to spectrogram frequency computation
author | Chris Cannam |
---|---|
date | Mon, 20 Feb 2006 17:23:40 +0000 |
parents | 10ba9276a315 |
children | 78515b1e29eb |
comparison
equal
deleted
inserted
replaced
35:10ba9276a315 | 36:c28ebb4ba4de |
---|---|
16 | 16 |
17 #include "model/TextModel.h" | 17 #include "model/TextModel.h" |
18 | 18 |
19 #include <QPainter> | 19 #include <QPainter> |
20 #include <QMouseEvent> | 20 #include <QMouseEvent> |
21 #include <QInputDialog> | |
21 | 22 |
22 #include <iostream> | 23 #include <iostream> |
23 #include <cmath> | 24 #include <cmath> |
24 | 25 |
25 TextLayer::TextLayer(View *w) : | 26 TextLayer::TextLayer(View *w) : |
45 this, SIGNAL(modelChanged(size_t, size_t))); | 46 this, SIGNAL(modelChanged(size_t, size_t))); |
46 | 47 |
47 connect(m_model, SIGNAL(completionChanged()), | 48 connect(m_model, SIGNAL(completionChanged()), |
48 this, SIGNAL(modelCompletionChanged())); | 49 this, SIGNAL(modelCompletionChanged())); |
49 | 50 |
50 std::cerr << "TextLayer::setModel(" << model << ")" << std::endl; | 51 // std::cerr << "TextLayer::setModel(" << model << ")" << std::endl; |
51 | 52 |
52 emit modelReplaced(); | 53 emit modelReplaced(); |
53 } | 54 } |
54 | 55 |
55 Layer::PropertyList | 56 Layer::PropertyList |
327 | 328 |
328 TextModel::PointList points(m_model->getPoints(frame0, frame1)); | 329 TextModel::PointList points(m_model->getPoints(frame0, frame1)); |
329 if (points.empty()) return; | 330 if (points.empty()) return; |
330 | 331 |
331 QColor brushColour(m_colour); | 332 QColor brushColour(m_colour); |
332 brushColour.setAlpha(80); | 333 |
333 paint.setBrush(brushColour); | 334 int h, s, v; |
334 | 335 brushColour.getHsv(&h, &s, &v); |
336 brushColour.setHsv(h, s, 255, 100); | |
337 | |
338 QColor penColour; | |
335 if (m_view->hasLightBackground()) { | 339 if (m_view->hasLightBackground()) { |
336 paint.setPen(Qt::black); | 340 penColour = Qt::black; |
337 } else { | 341 } else { |
338 paint.setPen(Qt::white); | 342 penColour = Qt::white; |
339 } | 343 } |
340 | 344 |
341 // std::cerr << "TextLayer::paint: resolution is " | 345 // std::cerr << "TextLayer::paint: resolution is " |
342 // << m_model->getResolution() << " frames" << std::endl; | 346 // << m_model->getResolution() << " frames" << std::endl; |
343 | 347 |
363 | 367 |
364 int x = getXForFrame(p.frame); | 368 int x = getXForFrame(p.frame); |
365 int y = getYForHeight(p.height); | 369 int y = getYForHeight(p.height); |
366 | 370 |
367 if (illuminateFrame == p.frame) { | 371 if (illuminateFrame == p.frame) { |
368 /* | 372 paint.setBrush(penColour); |
369 //!!! aside from the problem of choosing a colour, it'd be | 373 if (m_view->hasLightBackground()) { |
370 //better to save the highlighted rects and draw them at | 374 paint.setPen(Qt::white); |
371 //the end perhaps | 375 } else { |
372 | 376 paint.setPen(Qt::black); |
373 //!!! not equipped to illuminate the right section in line | 377 } |
374 //or curve mode | 378 } else { |
375 | 379 paint.setPen(penColour); |
376 if (m_plotStyle != PlotCurve && | 380 paint.setBrush(brushColour); |
377 m_plotStyle != PlotLines) { | |
378 paint.setPen(Qt::black);//!!! | |
379 if (m_plotStyle != PlotSegmentation) { | |
380 paint.setBrush(Qt::black);//!!! | |
381 } | |
382 } | |
383 */ | |
384 } | 381 } |
385 | 382 |
386 QString label = p.label; | 383 QString label = p.label; |
387 if (label == "") { | 384 if (label == "") { |
388 label = tr("<no text>"); | 385 label = tr("<no text>"); |
426 } | 423 } |
427 | 424 |
428 void | 425 void |
429 TextLayer::drawStart(QMouseEvent *e) | 426 TextLayer::drawStart(QMouseEvent *e) |
430 { | 427 { |
431 std::cerr << "TextLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl; | 428 // std::cerr << "TextLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl; |
432 | 429 |
433 if (!m_model) { | 430 if (!m_model) { |
434 std::cerr << "TextLayer::drawStart: no model" << std::endl; | 431 std::cerr << "TextLayer::drawStart: no model" << std::endl; |
435 return; | 432 return; |
436 } | 433 } |
452 } | 449 } |
453 | 450 |
454 void | 451 void |
455 TextLayer::drawDrag(QMouseEvent *e) | 452 TextLayer::drawDrag(QMouseEvent *e) |
456 { | 453 { |
457 std::cerr << "TextLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl; | 454 // std::cerr << "TextLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl; |
458 | 455 |
459 if (!m_model || !m_editing) return; | 456 if (!m_model || !m_editing) return; |
460 | 457 |
461 long frame = getFrameForX(e->x()); | 458 long frame = getFrameForX(e->x()); |
462 if (frame < 0) frame = 0; | 459 if (frame < 0) frame = 0; |
471 } | 468 } |
472 | 469 |
473 void | 470 void |
474 TextLayer::drawEnd(QMouseEvent *e) | 471 TextLayer::drawEnd(QMouseEvent *e) |
475 { | 472 { |
476 std::cerr << "TextLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl; | 473 // std::cerr << "TextLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl; |
477 if (!m_model || !m_editing) return; | 474 if (!m_model || !m_editing) return; |
475 | |
476 bool ok = false; | |
477 QString label = QInputDialog::getText(m_view, tr("Enter label"), | |
478 tr("Please enter a new label:"), | |
479 QLineEdit::Normal, "", &ok); | |
480 | |
481 if (ok) { | |
482 TextModel::RelabelCommand *command = | |
483 new TextModel::RelabelCommand(m_model, m_editingPoint, label); | |
484 m_editingCommand->addCommand(command); | |
485 } | |
486 | |
478 m_editingCommand->finish(); | 487 m_editingCommand->finish(); |
479 m_editingCommand = 0; | 488 m_editingCommand = 0; |
480 m_editing = false; | 489 m_editing = false; |
481 } | 490 } |
482 | 491 |
483 void | 492 void |
484 TextLayer::editStart(QMouseEvent *e) | 493 TextLayer::editStart(QMouseEvent *e) |
485 { | 494 { |
486 std::cerr << "TextLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; | 495 // std::cerr << "TextLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; |
487 | 496 |
488 if (!m_model) return; | 497 if (!m_model) return; |
489 | 498 |
490 TextModel::PointList points = getLocalPoints(e->x(), e->y()); | 499 TextModel::PointList points = getLocalPoints(e->x(), e->y()); |
491 if (points.empty()) return; | 500 if (points.empty()) return; |
492 | 501 |
502 m_editOrigin = e->pos(); | |
493 m_editingPoint = *points.begin(); | 503 m_editingPoint = *points.begin(); |
494 m_originalPoint = m_editingPoint; | 504 m_originalPoint = m_editingPoint; |
495 | 505 |
496 if (m_editingCommand) { | 506 if (m_editingCommand) { |
497 m_editingCommand->finish(); | 507 m_editingCommand->finish(); |
504 void | 514 void |
505 TextLayer::editDrag(QMouseEvent *e) | 515 TextLayer::editDrag(QMouseEvent *e) |
506 { | 516 { |
507 if (!m_model || !m_editing) return; | 517 if (!m_model || !m_editing) return; |
508 | 518 |
509 long frame = getFrameForX(e->x()); | 519 long frameDiff = getFrameForX(e->x()) - getFrameForX(m_editOrigin.x()); |
520 float heightDiff = getHeightForY(e->y()) - getHeightForY(m_editOrigin.y()); | |
521 | |
522 long frame = m_originalPoint.frame + frameDiff; | |
523 float height = m_originalPoint.height + heightDiff; | |
524 | |
525 // long frame = getFrameForX(e->x()); | |
510 if (frame < 0) frame = 0; | 526 if (frame < 0) frame = 0; |
511 frame = frame / m_model->getResolution() * m_model->getResolution(); | 527 frame = (frame / m_model->getResolution()) * m_model->getResolution(); |
512 | 528 |
513 float height = getHeightForY(e->y()); | 529 // float height = getHeightForY(e->y()); |
514 | 530 |
515 if (!m_editingCommand) { | 531 if (!m_editingCommand) { |
516 m_editingCommand = new TextModel::EditCommand(m_model, tr("Drag Label")); | 532 m_editingCommand = new TextModel::EditCommand(m_model, tr("Drag Label")); |
517 } | 533 } |
518 | 534 |
523 } | 539 } |
524 | 540 |
525 void | 541 void |
526 TextLayer::editEnd(QMouseEvent *e) | 542 TextLayer::editEnd(QMouseEvent *e) |
527 { | 543 { |
528 std::cerr << "TextLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; | 544 // std::cerr << "TextLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; |
529 if (!m_model || !m_editing) return; | 545 if (!m_model || !m_editing) return; |
530 | 546 |
531 if (m_editingCommand) { | 547 if (m_editingCommand) { |
532 | 548 |
533 QString newName = m_editingCommand->getName(); | 549 QString newName = m_editingCommand->getName(); |
534 | 550 |
535 if (m_editingPoint.frame != m_originalPoint.frame) { | 551 if (m_editingPoint.frame != m_originalPoint.frame) { |
536 if (m_editingPoint.height != m_originalPoint.height) { | 552 if (m_editingPoint.height != m_originalPoint.height) { |
537 newName = tr("Move Label"); | 553 newName = tr("Move Label"); |
538 } else { | 554 } else { |
539 newName = tr("Relocate Label"); | 555 newName = tr("Move Label Horizontally"); |
540 } | 556 } |
541 } else { | 557 } else { |
542 newName = tr("Change Point Height"); | 558 newName = tr("Move Label Vertically"); |
543 } | 559 } |
544 | 560 |
545 m_editingCommand->setName(newName); | 561 m_editingCommand->setName(newName); |
546 m_editingCommand->finish(); | 562 m_editingCommand->finish(); |
547 } | 563 } |
548 | 564 |
549 m_editingCommand = 0; | 565 m_editingCommand = 0; |
550 m_editing = false; | 566 m_editing = false; |
551 } | 567 } |
568 | |
569 void | |
570 TextLayer::editOpen(QMouseEvent *e) | |
571 { | |
572 std::cerr << "TextLayer::editOpen" << std::endl; | |
573 | |
574 if (!m_model) return; | |
575 | |
576 TextModel::PointList points = getLocalPoints(e->x(), e->y()); | |
577 if (points.empty()) return; | |
578 | |
579 QString label = points.begin()->label; | |
580 | |
581 bool ok = false; | |
582 label = QInputDialog::getText(m_view, tr("Enter label"), | |
583 tr("Please enter a new label:"), | |
584 QLineEdit::Normal, label, &ok); | |
585 if (ok && label != points.begin()->label) { | |
586 TextModel::RelabelCommand *command = | |
587 new TextModel::RelabelCommand(m_model, *points.begin(), label); | |
588 CommandHistory::getInstance()->addCommand(command, true); | |
589 } | |
590 } | |
552 | 591 |
553 QString | 592 QString |
554 TextLayer::toXmlString(QString indent, QString extraAttributes) const | 593 TextLayer::toXmlString(QString indent, QString extraAttributes) const |
555 { | 594 { |
556 return Layer::toXmlString(indent, extraAttributes + | 595 return Layer::toXmlString(indent, extraAttributes + |