Skip to content

Commit

Permalink
fix #274925: Unable to select text in Chord Symbol
Browse files Browse the repository at this point in the history
Add correect placement for _layout field in Harmony class
Make layoutInvalid private as it was before #3914

rebase after master
  • Loading branch information
handrok committed Nov 10, 2018
1 parent 32c4c4c commit 5cec75a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
23 changes: 19 additions & 4 deletions libmscore/harmony.cpp
Expand Up @@ -707,8 +707,9 @@ void Harmony::startEdit(EditData& ed)
if (!textList.empty())
setXmlText(harmonyName());

layoutInvalid = false;
_needAutoplace = false;
TextBase::startEdit(ed);
_needAutoplace = true;
}

//---------------------------------------------------------
Expand Down Expand Up @@ -738,8 +739,10 @@ bool Harmony::edit(EditData& ed)
void Harmony::endEdit(EditData& ed)
{
TextBase::endEdit(ed);
if (isLayoutInvalid())
layout();
_needAutoplace = false;
layout();
_needAutoplace = true;

if (links()) {
for (ScoreElement* e : *links()) {
if (e == this)
Expand Down Expand Up @@ -1056,7 +1059,8 @@ void Harmony::layout()
if (hasFrame())
layoutFrame();

// autoplaceSegmentElement(styleP(Sid::minHarmonyDistance));
// if (_needAutoplace)
// autoplaceSegmentElement(styleP(Sid::minHarmonyDistance));
}

//---------------------------------------------------------
Expand All @@ -1072,6 +1076,17 @@ void Harmony::calculateBoundingRect()
for (const TextSegment* ts : textList)
bb |= ts->tightBoundingRect().translated(ts->x, ts->y);
setbbox(bb);
for (int i = 0; i < rows(); ++i) {
TextBlock& t = textBlockList()[i];

// when MS switch to editing Harmony MS draws text defined by textBlockList().
// When MS switches back to normal state it draws text from textList
// To correct placement of text in editing we need to layout textBlockList() elements
t.layout(this);
for (auto& s : t.fragments()) {
s.pos = { 0, 0 };
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions libmscore/harmony.h
Expand Up @@ -79,6 +79,7 @@ class Harmony final : public TextBase {
QList<TextSegment*> textList; // rendered chord

bool _leftParen, _rightParen; // include opening and/or closing parenthesis
bool _needAutoplace {true}; //in some cases we don't need call autoplaceSegmentElement, see startEdit()

mutable QRectF _tbbox;

Expand Down
3 changes: 1 addition & 2 deletions libmscore/textbase.h
Expand Up @@ -225,6 +225,7 @@ class TextBase : public Element {
QString _text;
QList<TextBlock> _layout;
bool textInvalid { true };
bool layoutInvalid { true };
Tid _tid; // text style id

QString preEdit; // move to EditData?
Expand All @@ -238,8 +239,6 @@ class TextBase : public Element {
virtual int getPropertyFlagsIdx(Pid id) const override;

protected:
bool layoutInvalid { true };

QColor textColor() const;
QRectF frame; // calculated in layout()
void layoutFrame();
Expand Down

0 comments on commit 5cec75a

Please sign in to comment.