fix lyrics editing, context menu

This commit is contained in:
Werner Schweer 2017-05-03 10:31:11 +02:00
parent 4d3f951d7e
commit f02a489bf8
6 changed files with 59 additions and 87 deletions

View file

@ -294,8 +294,8 @@ class Text : public Element {
qreal lineHeight() const;
virtual qreal baseLine() const override;
bool empty() const { return _text.isEmpty(); }
void clear() { _text.clear(); }
bool empty() const { return xmlText().isEmpty(); }
void clear() { setXmlText(QString()); }
bool layoutToParentWidth() const { return _layoutToParentWidth; }
void setLayoutToParentWidth(bool v) { _layoutToParentWidth = v; }

View file

@ -90,7 +90,7 @@ void ScoreView::startEditMode(Element* e)
return;
}
editData.element = e;
startEdit();
changeState(ViewState::EDIT);
}
//---------------------------------------------------------
@ -104,7 +104,7 @@ void ScoreView::startEdit(Element* element, Grip startGrip)
return;
}
editData.element = element;
startEdit();
changeState(ViewState::EDIT);
if (startGrip != Grip::NO_GRIP)
editData.curGrip = startGrip;
}
@ -127,7 +127,6 @@ void ScoreView::startEdit()
updateGrips();
_score->update();
setCursor(QCursor(Qt::ArrowCursor));
printf("====start edit %d\n", int(state));
}
//---------------------------------------------------------

View file

@ -82,7 +82,7 @@ void ScoreView::lyricsUpDown(bool up, bool end)
void ScoreView::lyricsTab(bool back, bool end, bool moveOnly)
{
Lyrics* lyrics = (Lyrics*)editData.element;
Lyrics* lyrics = toLyrics(editData.element);
int track = lyrics->track();
Segment* segment = lyrics->segment();
int verse = lyrics->no();
@ -108,6 +108,7 @@ void ScoreView::lyricsTab(bool back, bool end, bool moveOnly)
if (nextSegment == 0)
return;
printf("lyricsTab: endEdit\n");
endEdit();
// look for the lyrics we are moving from; may be the current lyrics or a previous one
@ -136,7 +137,7 @@ void ScoreView::lyricsTab(bool back, bool end, bool moveOnly)
if (!_toLyrics) {
_toLyrics = new Lyrics(_score);
_toLyrics->setTrack(track);
ChordRest* cr = static_cast<ChordRest*>(nextSegment->element(track));
ChordRest* cr = toChordRest(nextSegment->element(track));
_toLyrics->setParent(cr);
_toLyrics->setNo(verse);
_toLyrics->setPlacement(placement);
@ -145,7 +146,6 @@ void ScoreView::lyricsTab(bool back, bool end, bool moveOnly)
}
_score->startCmd();
if (fromLyrics && !moveOnly) {
switch (_toLyrics->syllabic()) {
// as we arrived at toLyrics by a [Space], it can be the beginning
@ -162,7 +162,7 @@ void ScoreView::lyricsTab(bool back, bool end, bool moveOnly)
}
// as we moved away from fromLyrics by a [Space], it can be
// the end of a multi-syllable, but cannot have syllabic dashes after
switch(fromLyrics->syllabic()) {
switch (fromLyrics->syllabic()) {
case Lyrics::Syllabic::SINGLE:
case Lyrics::Syllabic::END:
break;
@ -177,12 +177,12 @@ void ScoreView::lyricsTab(bool back, bool end, bool moveOnly)
fromLyrics->undoChangeProperty(P_ID::LYRIC_TICKS, 0);
}
printf("lyricsTab: newLyrics %d\n", newLyrics);
if (newLyrics)
_score->undoAddElement(_toLyrics);
_score->select(_toLyrics, SelectType::SINGLE, 0);
startEdit(_toLyrics, Grip::NO_GRIP);
mscore->changeState(mscoreState());
adjustCanvasPosition(_toLyrics, false);
@ -196,7 +196,7 @@ void ScoreView::lyricsTab(bool back, bool end, bool moveOnly)
cursor->movePosition(QTextCursor::Start, QTextCursor::KeepAnchor);
}
_score->setLayoutAll();
_score->update();
_score->endCmd();
}
//---------------------------------------------------------
@ -473,8 +473,10 @@ void ScoreView::lyricsEndEdit()
Lyrics* lyrics = toLyrics(editData.element);
// if no text, just remove this lyrics
if (lyrics->empty())
if (lyrics->empty()) {
qDebug("lyrics empty: remove");
lyrics->parent()->remove(lyrics);
}
// if not empty, make sure this new lyrics does not fall in the middle
// of an existing melisma from a previous lyrics; in case, shorten it
else {

View file

@ -209,7 +209,8 @@ void ScoreView::focusOutEvent(QFocusEvent* event)
void ScoreView::mouseMoveEvent(QMouseEvent* me)
{
printf("mouseMoveEvent\n");
if (!me->button())
return;
switch (state) {
case ViewState::NORMAL:
if (!editData.element && (me->modifiers() & Qt::ShiftModifier))
@ -353,6 +354,8 @@ void ScoreView::mousePressEvent(QMouseEvent* ev)
switch (state) {
case ViewState::NORMAL:
if (ev->button() == Qt::RightButton) // context menu?
break;
editData.element = e;
mousePressEventNormal(ev);
break;
@ -368,8 +371,7 @@ void ScoreView::mousePressEvent(QMouseEvent* ev)
break;
case ViewState::NOTE_ENTRY:
if (ev->type() == QEvent::MouseButtonPress)
noteEntryButton(ev);
noteEntryButton(ev);
break;
case ViewState::EDIT:
@ -391,7 +393,7 @@ void ScoreView::mousePressEvent(QMouseEvent* ev)
break;
default:
printf("mousePressEvent in state %d\n", int(state));
qDebug("mousePressEvent in state %d", int(state));
break;
}
}
@ -429,7 +431,6 @@ void ScoreView::keyPressEvent(QKeyEvent* ev)
qDebug("keyPressEvent key 0x%02x(%c) mod 0x%04x <%s> nativeKey 0x%02x scancode %d",
editData.key, editData.key, int(editData.modifiers), qPrintable(editData.s), ev->nativeVirtualKey(), ev->nativeScanCode());
if (editData.element->isLyrics()) {
if (editKeyLyrics(ev)) {
ev->accept();
@ -437,49 +438,18 @@ void ScoreView::keyPressEvent(QKeyEvent* ev)
}
}
else if (editData.element->isHarmony()) {
/*
if (editData.key == Qt::Key_Tab || editData.key == Qt::Key_Backtab) {
harmonyTab(editData.key == Qt::Key_Backtab ? true : (editData.modifiers & Qt::ShiftModifier));
ev->accept();
return;
}
*/
if (editData.key == Qt::Key_Space && !(editData.modifiers & CONTROL_MODIFIER)) {
harmonyBeatsTab(true, editData.modifiers & Qt::ShiftModifier);
ev->accept();
return;
}
/*
if (editData.key == Qt::Key_Semicolon || editData.key == Qt::Key_Colon) {
harmonyBeatsTab(false, editData.key == Qt::Key_Colon);
ev->accept();
return;
}
if (editData.key >= Qt::Key_1 && editData.key <= Qt::Key_9 && (modifiers & CONTROL_MODIFIER)) {
int ticks = (MScore::division >> 4) << (editData.key - Qt::Key_1);
harmonyTicksTab(ticks);
ev->accept();
return;
}
*/
}
else if (editData.element->type() == ElementType::FIGURED_BASS) {
else if (editData.element->isFiguredBass()) {
int found = false;
if (editData.key == Qt::Key_Space && !(editData.modifiers & CONTROL_MODIFIER)) {
figuredBassTab(false, editData.modifiers & Qt::ShiftModifier);
found = true;
}
/*
if (editData.key == Qt::Key_Tab || editData.key == Qt::Key_Backtab) {
figuredBassTab(true, editData.key == Qt::Key_Backtab ? true : (editData.modifiers & Qt::ShiftModifier) );
found = true;
}
if (editData.key >= Qt::Key_1 && editData.key <= Qt::Key_9 && (editData.modifiers & CONTROL_MODIFIER)) {
int ticks = (MScore::division >> 4) << (editData.key - Qt::Key_1);
figuredBassTicksTab(ticks);
found = true;
}
*/
if (found) {
ev->accept();
return;
@ -601,6 +571,43 @@ void ScoreView::keyReleaseEvent(QKeyEvent* ev)
}
}
//---------------------------------------------------------
// contextPopup
//---------------------------------------------------------
void ScoreView::contextMenuEvent(QContextMenuEvent* ev)
{
QPoint gp = ev->globalPos();
editData.startMove = toLogical(ev->pos());
Element* e = elementNear(editData.startMove);
if (e) {
if (!e->selected()) {
// bool control = (ev->modifiers() & Qt::ControlModifier) ? true : false;
// _score->select(e, control ? SelectType::ADD : SelectType::SINGLE, 0);
// editData.element = e;
// select(ev);
}
if (seq)
seq->stopNotes(); // stop now because we dont get a mouseRelease event
objectPopup(gp, e);
}
else {
int staffIdx;
Measure* m = _score->pos2measure(editData.startMove, &staffIdx, 0, 0, 0);
if (m && m->staffLines(staffIdx)->abbox().contains(editData.startMove))
measurePopup(gp, m);
else {
QMenu* popup = new QMenu();
popup->addAction(getAction("edit-style"));
popup->addAction(getAction("page-settings"));
popup->addAction(getAction("load-style"));
_score->update();
popup->popup(gp);
}
}
ev->accept();
}
//---------------------------------------------------------
// escapeCmd
//---------------------------------------------------------

View file

@ -1718,8 +1718,6 @@ void ScoreView::cmd(const QAction* a)
editSwap();
}
else if (cmd == "lyrics") {
// if (noteEntryMode()) // force out of entry mode
//TODO:state sm->postEvent(new CommandEvent("note-input"));
Lyrics* lyrics = _score->addLyrics();
if (lyrics) {
startEditMode(lyrics);
@ -2485,42 +2483,6 @@ void ScoreView::endNoteEntry()
_score->update();
}
//---------------------------------------------------------
// contextPopup
//---------------------------------------------------------
void ScoreView::contextPopup(QContextMenuEvent* ev)
{
QPoint gp = ev->globalPos();
editData.startMove = toLogical(ev->pos());
Element* e = elementNear(editData.startMove);
if (e) {
if (!e->selected()) {
// bool control = (ev->modifiers() & Qt::ControlModifier) ? true : false;
// _score->select(e, control ? SelectType::ADD : SelectType::SINGLE, 0);
editData.element = e;
//TODO? select(ev);
}
ElementType type = e->type();
if (seq)
seq->stopNotes(); // stop now because we dont get a mouseRelease event
if (type == ElementType::MEASURE)
measurePopup(gp, static_cast<Measure*>(e));
else {
objectPopup(gp, e);
}
}
else {
QMenu* popup = new QMenu();
popup->addAction(getAction("edit-style"));
popup->addAction(getAction("page-settings"));
popup->addAction(getAction("load-style"));
_score->update();
popup->popup(gp);
}
}
//---------------------------------------------------------
// dragScoreView
//---------------------------------------------------------

View file

@ -176,6 +176,8 @@ class ScoreView : public QWidget, public MuseScoreView {
virtual void keyPressEvent(QKeyEvent*) override;
virtual void keyReleaseEvent(QKeyEvent*) override;
virtual void contextMenuEvent(QContextMenuEvent*) override;
void mousePressEventNormal(QMouseEvent*);
void escapeCmd();