Skip to content

Commit 02526d1

Browse files
committed
fixed #27362: reselecting range should seek playback
1 parent 14d1dee commit 02526d1

File tree

2 files changed

+73
-10
lines changed

2 files changed

+73
-10
lines changed

src/notation/tests/notationviewinputcontroller_tests.cpp

+60-1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ class NotationViewInputControllerTests : public ::testing::Test
151151
}
152152
break;
153153
}
154+
case ElementType::MEASURE:
155+
return chord->segment()->measure();
154156
default:
155157
break;
156158
}
@@ -553,6 +555,63 @@ TEST_F(NotationViewInputControllerTests, Mouse_Press_Range_Start_Play_From_First
553555
m_controller->mousePressEvent(make_mousePressEvent(Qt::LeftButton, Qt::ShiftModifier, QPoint(100, 100)));
554556
}
555557

558+
/**
559+
* @brief Mouse_Press_On_Selected_Selected_Range
560+
* @details User pressed left mouse button on already selected range
561+
* The selection shouldn't be changed, but the first measure in the range should be seeked
562+
*/
563+
TEST_F(NotationViewInputControllerTests, Mouse_Press_On_Already_Selected_Range)
564+
{
565+
//! [GIVEN] There is a test score
566+
engraving::MasterScore* score = engraving::ScoreRW::readScore(TEST_SCORE_PATH);
567+
568+
//! [GIVEN] Previous selected measure
569+
INotationInteraction::HitElementContext oldContext = hitContext(score, { ElementType::MEASURE });
570+
571+
//! [GIVEN] User selected measure that is already selected
572+
INotationInteraction::HitElementContext newContext = oldContext;
573+
newContext.element->setSelected(true);
574+
575+
std::vector<EngravingItem*> selectedElements {
576+
newContext.element
577+
};
578+
579+
EXPECT_CALL(*m_interaction, hitElement(_, _))
580+
.WillOnce(Return(newContext.element));
581+
582+
EXPECT_CALL(*m_interaction, hitStaff(_))
583+
.WillOnce(Return(newContext.element->staff()));
584+
585+
//! [GIVEN] The new hit element context with new measure will be set
586+
EXPECT_CALL(*m_interaction, setHitElementContext(newContext))
587+
.Times(1);
588+
589+
EXPECT_CALL(*m_interaction, hitElementContext())
590+
.Times(2)
591+
.WillOnce(ReturnRef(oldContext))
592+
.WillOnce(ReturnRef(oldContext));
593+
594+
//! [GIVEN] There is a range selection
595+
ON_CALL(*m_selection, isRange())
596+
.WillByDefault(Return(true));
597+
ON_CALL(*m_selectionRange, containsPoint(_))
598+
.WillByDefault(Return(true));
599+
600+
EXPECT_CALL(*m_selection, elements())
601+
.WillOnce(ReturnRef(selectedElements));
602+
603+
//! [THEN] We should seek measure from the range
604+
EXPECT_CALL(*m_playbackController, seekElement(newContext.element))
605+
.Times(1);
606+
607+
//! [THEN] No selection change
608+
EXPECT_CALL(*m_interaction, select(_, _, _))
609+
.Times(0);
610+
611+
//! [WHEN] User pressed left mouse button
612+
m_controller->mousePressEvent(make_mousePressEvent(Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)));
613+
}
614+
556615
/**
557616
* @brief Mouse_Press_On_Already_Selected_Element
558617
* @details User pressed on already selected note
@@ -614,7 +673,7 @@ TEST_F(NotationViewInputControllerTests, Mouse_Press_On_Already_Selected_Element
614673
/**
615674
* @brief Mouse_Press_On_Range
616675
* @details User pressed selected new measure with ShiftModifier
617-
* The new meausure should be selected, shouldn't be played, previous meausure should be seeked
676+
* The new measure should be selected, shouldn't be played, previous measure should be seeked
618677
*/
619678
TEST_F(NotationViewInputControllerTests, Mouse_Press_On_Range)
620679
{

src/notation/view/notationviewinputcontroller.cpp

+13-9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include "engraving/dom/drumset.h"
3535
#include "engraving/dom/shadownote.h"
3636

37+
#include "defer.h"
38+
3739
using namespace mu;
3840
using namespace mu::notation;
3941
using namespace mu::engraving;
@@ -612,6 +614,13 @@ void NotationViewInputController::mousePressEvent(QMouseEvent* event)
612614
EngravingItem* hitElement = nullptr;
613615
staff_idx_t hitStaffIndex = muse::nidx;
614616

617+
DEFER {
618+
EngravingItem* playbackStartElement = resolveStartPlayableElement();
619+
if (playbackStartElement) {
620+
playbackController()->seekElement(playbackStartElement);
621+
}
622+
};
623+
615624
if (!m_readonly) {
616625
m_prevHitElement = hitElementContext().element;
617626

@@ -645,10 +654,6 @@ void NotationViewInputController::mousePressEvent(QMouseEvent* event)
645654
}
646655

647656
if (playbackController()->isPlaying()) {
648-
if (seekAllowed(hitElement)) {
649-
playbackController()->seekElement(hitElement);
650-
}
651-
652657
return;
653658
}
654659

@@ -725,11 +730,6 @@ void NotationViewInputController::mousePressEvent(QMouseEvent* event)
725730
}
726731
}
727732

728-
EngravingItem* playbackStartElement = resolveStartPlayableElement();
729-
if (playbackStartElement) {
730-
playbackController()->seekElement(playbackStartElement);
731-
}
732-
733733
if (button == Qt::LeftButton) {
734734
handleLeftClick(ctx);
735735
} else if (button == Qt::RightButton) {
@@ -1394,6 +1394,10 @@ EngravingItem* NotationViewInputController::resolveStartPlayableElement() const
13941394
{
13951395
EngravingItem* hitElement = hitElementContext().element;
13961396

1397+
if (playbackController()->isPlaying()) {
1398+
return hitElement;
1399+
}
1400+
13971401
INotationSelectionPtr selection = viewInteraction()->selection();
13981402
if (!selection->isRange()) {
13991403
return hitElement;

0 commit comments

Comments
 (0)