Skip to content

Commit fa8cf4a

Browse files
committed
Show segment highlighting on all hovered staves in case of multi-staff selection
1 parent bb5bada commit fa8cf4a

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/engraving/dom/anchors.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,11 @@ TimeTickAnchor::TimeTickAnchor(Segment* parent)
161161
TimeTickAnchor::DrawRegion TimeTickAnchor::drawRegion() const
162162
{
163163
const ShowAnchors& showAnchors = score()->showAnchors();
164-
Fraction thisTick = segment()->tick();
164+
const staff_idx_t thisStaffIdx = staffIdx();
165+
const Fraction thisTick = segment()->tick();
165166

166-
bool trackOutOfRange = staffIdx() != showAnchors.staffIdx;
167-
bool tickOutOfRange = thisTick < showAnchors.startTickExtendedRegion || thisTick >= showAnchors.endTickExtendedRegion;
167+
const bool trackOutOfRange = thisStaffIdx < showAnchors.staffIdx || thisStaffIdx >= showAnchors.endStaffIdx;
168+
const bool tickOutOfRange = thisTick < showAnchors.startTickExtendedRegion || thisTick >= showAnchors.endTickExtendedRegion;
168169
if (trackOutOfRange || tickOutOfRange) {
169170
return DrawRegion::OUT_OF_RANGE;
170171
}

src/engraving/dom/score.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ struct ShowAnchors {
217217
ShowAnchors() = default;
218218
ShowAnchors(voice_idx_t vIdx, staff_idx_t stfIdx, const Fraction& sTickMain, const Fraction& eTickMain,
219219
const Fraction& sTickExt, const Fraction& eTickExt)
220-
: voiceIdx(vIdx), staffIdx(stfIdx), startTickMainRegion(sTickMain), endTickMainRegion(eTickMain),
220+
: voiceIdx(vIdx), staffIdx(stfIdx), endStaffIdx(stfIdx + 1), startTickMainRegion(sTickMain), endTickMainRegion(eTickMain),
221+
startTickExtendedRegion(sTickExt), endTickExtendedRegion(eTickExt) {}
222+
ShowAnchors(voice_idx_t vIdx, staff_idx_t stfIdx, staff_idx_t endStfIdx, const Fraction& sTickMain, const Fraction& eTickMain,
223+
const Fraction& sTickExt, const Fraction& eTickExt)
224+
: voiceIdx(vIdx), staffIdx(stfIdx), endStaffIdx(endStfIdx), startTickMainRegion(sTickMain), endTickMainRegion(eTickMain),
221225
startTickExtendedRegion(sTickExt), endTickExtendedRegion(eTickExt) {}
222226

223227
void reset()
@@ -232,6 +236,7 @@ struct ShowAnchors {
232236

233237
voice_idx_t voiceIdx = muse::nidx;
234238
staff_idx_t staffIdx = muse::nidx;
239+
staff_idx_t endStaffIdx = muse::nidx;
235240
Fraction startTickMainRegion = Fraction(-1, 1);
236241
Fraction endTickMainRegion = Fraction(-1, 1);
237242
Fraction startTickExtendedRegion = Fraction(-1, 1);

src/notation/internal/notationinteraction.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,8 @@ bool NotationInteraction::isDropSingleAccepted(const PointF& pos, Qt::KeyboardMo
15071507
return false;
15081508
}
15091509

1510-
static void dropRangePosition(Score* score, const PointF& pos, Fraction tickLength, staff_idx_t* staffIdx, Segment** segment)
1510+
static void dropRangePosition(Score* score, const PointF& pos, Fraction tickLength, staff_idx_t numStaves, staff_idx_t* staffIdx,
1511+
Segment** segment)
15111512
{
15121513
IF_ASSERT_FAILED(score && staffIdx && segment) {
15131514
return;
@@ -1544,12 +1545,16 @@ static void dropRangePosition(Score* score, const PointF& pos, Fraction tickLeng
15441545
return;
15451546
}
15461547

1548+
const staff_idx_t endStaffIdx = std::min(*staffIdx + numStaves, score->nstaves());
1549+
15471550
// Add time tick anchors throughout these measures
15481551
for (MeasureBase* mb = startMeasure; mb && mb->tick() <= endMeasure->tick(); mb = mb->next()) {
15491552
if (!mb->isMeasure()) {
15501553
continue;
15511554
}
1552-
EditTimeTickAnchors::updateAnchors(toMeasure(mb), *staffIdx);
1555+
for (staff_idx_t i = 0; i < endStaffIdx; ++i) {
1556+
EditTimeTickAnchors::updateAnchors(toMeasure(mb), i);
1557+
}
15531558
}
15541559

15551560
// Get precise location using the newly created time tick anchors
@@ -1561,7 +1566,7 @@ static void dropRangePosition(Score* score, const PointF& pos, Fraction tickLeng
15611566
startTick = (*segment)->tick();
15621567
endTick = startTick + tickLength;
15631568

1564-
score->setShowAnchors(ShowAnchors(0, *staffIdx, startTick, endTick,
1569+
score->setShowAnchors(ShowAnchors(0, *staffIdx, *staffIdx + numStaves, startTick, endTick,
15651570
startMeasure->tick(), endMeasure->endTick()));
15661571

15671572
// Invalidate BSP tree of affected pages
@@ -1597,7 +1602,7 @@ bool NotationInteraction::isDropRangeAccepted(const PointF& pos)
15971602
staff_idx_t staffIdx = muse::nidx;
15981603
Segment* segment = nullptr;
15991604

1600-
dropRangePosition(score(), pos, rdd.tickLength, &staffIdx, &segment);
1605+
dropRangePosition(score(), pos, rdd.tickLength, rdd.numStaves, &staffIdx, &segment);
16011606
if (staffIdx == muse::nidx || !segment) {
16021607
return false;
16031608
}
@@ -1621,7 +1626,7 @@ bool NotationInteraction::isDropRangeAccepted(const PointF& pos)
16211626
return false;
16221627
}
16231628

1624-
const staff_idx_t endStaffIdx = staffIdx + rdd.numStaves;
1629+
const staff_idx_t endStaffIdx = std::min(staffIdx + rdd.numStaves, score()->nstaves());
16251630

16261631
rdd.dropRects = ScoreRangeUtilities::boundingArea(score(),
16271632
segment, endSegment,
@@ -1899,7 +1904,7 @@ bool NotationInteraction::dropRange(const QByteArray& data, const PointF& pos, b
18991904
staff_idx_t staffIdx = muse::nidx;
19001905
Segment* segment = nullptr;
19011906

1902-
dropRangePosition(score(), pos, rdd.tickLength, &staffIdx, &segment);
1907+
dropRangePosition(score(), pos, rdd.tickLength, rdd.numStaves, &staffIdx, &segment);
19031908
if (staffIdx == muse::nidx || !segment) {
19041909
return false;
19051910
}

0 commit comments

Comments
 (0)