|
38 | 38 |
|
39 | 39 | #include "log.h" |
40 | 40 |
|
41 | | -using namespace mu; |
| 41 | +using namespace muse::draw; |
42 | 42 | using namespace mu::engraving; |
43 | 43 |
|
44 | 44 | namespace mu::engraving { |
@@ -532,6 +532,39 @@ TranslatableString Dynamic::subtypeUserName() const |
532 | 532 | } |
533 | 533 | } |
534 | 534 |
|
| 535 | +void Dynamic::editDrag(EditData& ed) |
| 536 | +{ |
| 537 | + const bool hasLeftGrip = this->hasLeftGrip(); |
| 538 | + const bool hasRightGrip = this->hasRightGrip(); |
| 539 | + |
| 540 | + // Right grip (when two grips/when single grip) |
| 541 | + if ((int(ed.curGrip) == 1 && hasLeftGrip && hasRightGrip) || (int(ed.curGrip) == 0 && !hasLeftGrip && hasRightGrip)) { |
| 542 | + m_rightDragOffset += ed.evtDelta.x(); |
| 543 | + if (m_rightDragOffset < 0) { |
| 544 | + m_rightDragOffset = 0; |
| 545 | + } |
| 546 | + return; |
| 547 | + } |
| 548 | + |
| 549 | + // Left grip (when two grips or single grip) |
| 550 | + if (int(ed.curGrip) == 0 && hasLeftGrip) { |
| 551 | + m_leftDragOffset += ed.evtDelta.x(); |
| 552 | + if (m_leftDragOffset > 0) { |
| 553 | + m_leftDragOffset = 0; |
| 554 | + } |
| 555 | + return; |
| 556 | + } |
| 557 | + |
| 558 | + TextBase::editDrag(ed); |
| 559 | +} |
| 560 | + |
| 561 | +void Dynamic::endEditDrag(EditData& ed) |
| 562 | +{ |
| 563 | + m_leftDragOffset = m_rightDragOffset = 0.0; |
| 564 | + |
| 565 | + TextBase::endEditDrag(ed); |
| 566 | +} |
| 567 | + |
535 | 568 | //--------------------------------------------------------- |
536 | 569 | // reset |
537 | 570 | //--------------------------------------------------------- |
@@ -717,3 +750,115 @@ String Dynamic::screenReaderInfo() const |
717 | 750 | return String(u"%1: %2").arg(EngravingItem::accessibleInfo(), s); |
718 | 751 | } |
719 | 752 | } |
| 753 | + |
| 754 | +//--------------------------------------------------------- |
| 755 | +// drawEditMode |
| 756 | +//--------------------------------------------------------- |
| 757 | + |
| 758 | +void Dynamic::drawEditMode(Painter* p, EditData& ed, double currentViewScaling) |
| 759 | +{ |
| 760 | + if (ed.editTextualProperties) { |
| 761 | + TextBase::drawEditMode(p, ed, currentViewScaling); |
| 762 | + } else { |
| 763 | + EngravingItem::drawEditMode(p, ed, currentViewScaling); |
| 764 | + } |
| 765 | +} |
| 766 | + |
| 767 | +//--------------------------------------------------------- |
| 768 | +// hasLeftHairpin |
| 769 | +//--------------------------------------------------------- |
| 770 | + |
| 771 | +bool Dynamic::hasLeftGrip() const |
| 772 | +{ |
| 773 | + if (segment()->tick().isZero()) { |
| 774 | + return false; // Don't show the left grip for the leftmost dynamic with tick zero |
| 775 | + } |
| 776 | + return m_leftHairpin == nullptr; |
| 777 | +} |
| 778 | + |
| 779 | +//--------------------------------------------------------- |
| 780 | +// hasRightHairpin |
| 781 | +//--------------------------------------------------------- |
| 782 | + |
| 783 | +bool Dynamic::hasRightGrip() const |
| 784 | +{ |
| 785 | + return m_rightHairpin == nullptr; |
| 786 | +} |
| 787 | + |
| 788 | +//--------------------------------------------------------- |
| 789 | +// findAdjacentHairpins |
| 790 | +//--------------------------------------------------------- |
| 791 | + |
| 792 | +void Dynamic::findAdjacentHairpins() |
| 793 | +{ |
| 794 | + m_leftHairpin = nullptr; |
| 795 | + m_rightHairpin = nullptr; |
| 796 | + |
| 797 | + const Fraction tick = segment()->tick(); |
| 798 | + const int intTick = tick.ticks(); |
| 799 | + |
| 800 | + const auto& spanners = score()->spannerMap().findOverlapping(intTick - 1, intTick + 1); |
| 801 | + for (auto i : spanners) { |
| 802 | + Spanner* sp = i.value; |
| 803 | + if (sp->track() == track() && sp->isHairpin()) { |
| 804 | + Hairpin* hp = toHairpin(sp); |
| 805 | + if (hp->tick() == tick) { |
| 806 | + m_rightHairpin = hp; |
| 807 | + } else if (hp->tick2() == tick) { |
| 808 | + m_leftHairpin = hp; |
| 809 | + } |
| 810 | + } |
| 811 | + } |
| 812 | +} |
| 813 | + |
| 814 | +//--------------------------------------------------------- |
| 815 | +// gripsCount |
| 816 | +//--------------------------------------------------------- |
| 817 | + |
| 818 | +int Dynamic::gripsCount() const |
| 819 | +{ |
| 820 | + if (empty()) { |
| 821 | + return 0; |
| 822 | + } |
| 823 | + |
| 824 | + const bool hasLeftGrip = this->hasLeftGrip(); |
| 825 | + const bool hasRightGrip = this->hasRightGrip(); |
| 826 | + |
| 827 | + if (hasLeftGrip && hasRightGrip) { |
| 828 | + return 2; |
| 829 | + } else if (hasLeftGrip || hasRightGrip) { |
| 830 | + return 1; |
| 831 | + } else { |
| 832 | + return 0; |
| 833 | + } |
| 834 | +} |
| 835 | + |
| 836 | +//--------------------------------------------------------- |
| 837 | +// gripsPositions |
| 838 | +//--------------------------------------------------------- |
| 839 | + |
| 840 | +std::vector<PointF> Dynamic::gripsPositions(const EditData&) const |
| 841 | +{ |
| 842 | + const LayoutData* ldata = this->ldata(); |
| 843 | + const PointF pp(pagePos()); |
| 844 | + double md = score()->style().styleS(Sid::hairpinMinDistance).val() * spatium(); // Minimum distance between dynamic and grip |
| 845 | + |
| 846 | + // Calculated by subtracting the y-value of the dynamic's pagePos from the y-value of hairpin's Grip::START position in HairpinSegment::gripsPositions |
| 847 | + const double GRIP_VERTICAL_OFFSET = -11.408; |
| 848 | + |
| 849 | + PointF leftOffset(-ldata->bbox().width() / 2 - md + m_leftDragOffset, GRIP_VERTICAL_OFFSET); |
| 850 | + PointF rightOffset(ldata->bbox().width() / 2 + md + m_rightDragOffset, GRIP_VERTICAL_OFFSET); |
| 851 | + |
| 852 | + const bool hasLeftGrip = this->hasLeftGrip(); |
| 853 | + const bool hasRightGrip = this->hasRightGrip(); |
| 854 | + |
| 855 | + if (hasLeftGrip && hasRightGrip) { |
| 856 | + return { pp + leftOffset, pp + rightOffset }; |
| 857 | + } else if (hasLeftGrip) { |
| 858 | + return { pp + leftOffset }; |
| 859 | + } else if (hasRightGrip) { |
| 860 | + return { pp + rightOffset }; |
| 861 | + } else { |
| 862 | + return {}; |
| 863 | + } |
| 864 | +} |
0 commit comments