Skip to content

Commit

Permalink
fix #272632 Crash when advancing lyric
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Jun 11, 2018
1 parent ba8039e commit 5c651e3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion libmscore/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2403,7 +2403,7 @@ void TextBase::editCopy(EditData& ed)
// cursor
//---------------------------------------------------------

TextCursor* TextBase::cursor(EditData& ed)
TextCursor* TextBase::cursor(const EditData& ed)
{
TextEditData* ted = static_cast<TextEditData*>(ed.getData(this));
return &ted->cursor;
Expand Down
2 changes: 1 addition & 1 deletion libmscore/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class TextBase : public Element {

void editInsertText(TextCursor*, const QString&);

TextCursor* cursor(EditData&);
TextCursor* cursor(const EditData&);
const TextBlock& textBlock(int line) const { return _layout[line]; }
TextBlock& textBlock(int line) { return _layout[line]; }
QList<TextBlock>& textBlockList() { return _layout; }
Expand Down
2 changes: 1 addition & 1 deletion libmscore/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void TextBase::startEdit(EditData& ed)
{
ed.grips = 0;
TextEditData* ted = new TextEditData(this);
ted->e = this;
ted->e = this;
ted->cursor.setRow(0);
ted->cursor.setColumn(0);
ted->cursor.clearSelection();
Expand Down
6 changes: 2 additions & 4 deletions mscore/editlyrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ namespace Ms {

bool ScoreView::editKeyLyrics(QKeyEvent* ev)
{
editData.key = ev->key();
editData.modifiers = ev->modifiers();
editData.s = ev->text();
Q_ASSERT(editData.element->isLyrics());

switch (editData.key) {
case Qt::Key_Space:
Expand Down Expand Up @@ -157,7 +155,7 @@ void ScoreView::lyricsTab(bool back, bool end, bool moveOnly)
// search next chord
while ((nextSegment = nextSegment->next1(SegmentType::ChordRest))) {
Element* el = nextSegment->element(track);
if (el && el->type() == ElementType::CHORD)
if (el && el->isChord())
break;
}
}
Expand Down
6 changes: 2 additions & 4 deletions mscore/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool ScoreView::event(QEvent* event)
if (event->type() == QEvent::KeyPress && editData.element) {
QKeyEvent* ke = static_cast<QKeyEvent*>(event);
if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
if (editData.element->isText())
if (editData.element->isTextBase())
return true;
bool rv = true;
if (ke->key() == Qt::Key_Tab) {
Expand Down Expand Up @@ -494,10 +494,8 @@ void ScoreView::mouseDoubleClickEvent(QMouseEvent* me)
if (state == ViewState::NORMAL) {
QPointF p = toLogical(me->pos());
Element* e = elementNear(p);
if (e && e->isEditable()) {
if (e && e->isEditable())
startEditMode(e);
changeState(ViewState::EDIT);
}
}
}

Expand Down
13 changes: 7 additions & 6 deletions mscore/scoreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,9 @@ void ScoreView::cmd(const char* s)
editSwap();
}
else if (cmd == "lyrics") {
_score->startCmd();
Lyrics* lyrics = _score->addLyrics();
_score->endCmd();
if (lyrics) {
startEditMode(lyrics);
return;
Expand Down Expand Up @@ -2598,7 +2600,7 @@ void ScoreView::deselectAll()
void ScoreView::editInputTransition(QInputMethodEvent* ie)
{
if (editData.element->isText()) {
toText(editData.element)->inputTransition(ie);
toText(editData.element)->inputTransition(editData, ie);
QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle);
}
}
Expand All @@ -2610,12 +2612,12 @@ void ScoreView::editInputTransition(QInputMethodEvent* ie)

QVariant ScoreView::inputMethodQuery(Qt::InputMethodQuery query) const
{
#if 0 // TODO
// if editing a text object, place the InputMethod popup window just below the text
if ((query & Qt::ImCursorRectangle) && editData.element && editData.element->isText()) {
if ((query & Qt::ImCursorRectangle) && editData.element && editData.element->isTextBase()) {
Text* text = toText(editData.element);
if (text->cursor()) {
QRectF cursorRect = toPhysical(text->cursorRect().translated(text->canvasPos()));
if (editMode()) {
TextCursor* cursor = text->cursor(editData);
QRectF cursorRect = toPhysical(cursor->cursorRect().translated(text->canvasPos()));
cursorRect.setWidth(1.0); // InputMethod doesn't display properly if width left at 0
cursorRect.setHeight(cursorRect.height() + 5.0); // add a little margin under the cursor
qDebug("cursorRect: [%3f,%3f,%3f,%3f]", cursorRect.x(), cursorRect.y(), cursorRect.width(), cursorRect.height());
Expand All @@ -2624,7 +2626,6 @@ QVariant ScoreView::inputMethodQuery(Qt::InputMethodQuery query) const
else
return QVariant(toPhysical(text->canvasBoundingRect()));
}
#endif
return QWidget::inputMethodQuery(query); // fall back to QWidget's version as default
}

Expand Down
4 changes: 2 additions & 2 deletions mscore/shortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1907,8 +1907,8 @@ Shortcut Shortcut::_sc[] = {
QT_TRANSLATE_NOOP("action","Add lyrics"),
0,
Icons::Invalid_ICON,
Qt::WindowShortcut,
ShortcutFlags::A_CMD
Qt::WindowShortcut
// ,ShortcutFlags::A_CMD
},
{
MsWidget::SCORE_TAB,
Expand Down

0 comments on commit 5c651e3

Please sign in to comment.