From 118cd4a03ea2c58df6e9d30233011eb6a5ec8547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matev=C5=BE=20Jekovec?= Date: Mon, 26 Dec 2022 18:00:40 +0100 Subject: [PATCH] UI: Use double click to enter lyrics/chord mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Single click selects syllable, chord, text or bookmark. Double click shows the edit text widget. Show · symbol for syllables and chords with no value set for easier selection. --- src/layout/drawablechordname.cpp | 4 ++-- src/layout/drawablemuselement.cpp | 4 +++- src/layout/drawablemuselement.h | 2 ++ src/layout/drawablesyllable.cpp | 19 ++++++++++++++----- src/ui/mainwin.cpp | 24 +++++++++++++++++------- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/layout/drawablechordname.cpp b/src/layout/drawablechordname.cpp index fe3df37e..10897d1b 100644 --- a/src/layout/drawablechordname.cpp +++ b/src/layout/drawablechordname.cpp @@ -1,5 +1,5 @@ /*! - Copyright (c) 2019, Matevž Jekovec, Canorus development team + Copyright (c) 2019-2022, Matevž Jekovec, Canorus development team All Rights Reserved. See AUTHORS for a complete list of authors. Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE.GPL for details. @@ -86,7 +86,7 @@ QString CADrawableChordName::drawableDiatonicPitch() { QString chordPitch = CADiatonicPitch::diatonicPitchToString(chordName()->diatonicPitch()); if (chordPitch.isEmpty()) { - return ""; + return CADrawableMusElement::EMPTY_PLACEHOLDER; } chordPitch = chordPitch[0].toUpper(); // chord-style pitch is upper case diff --git a/src/layout/drawablemuselement.cpp b/src/layout/drawablemuselement.cpp index e9d121b6..e9d97a54 100644 --- a/src/layout/drawablemuselement.cpp +++ b/src/layout/drawablemuselement.cpp @@ -1,5 +1,5 @@ /*! - Copyright (c) 2006-2009, Matevž Jekovec, Canorus development team + Copyright (c) 2006-2022, Matevž Jekovec, Canorus development team All Rights Reserved. See AUTHORS for a complete list of authors. Licensed under the GNU GENERAL PUBLIC LICENSE. See COPYING for details. @@ -7,6 +7,8 @@ #include "layout/drawablemuselement.h" +const QString CADrawableMusElement::EMPTY_PLACEHOLDER = "·"; + CADrawableMusElement::CADrawableMusElement(CAMusElement* m, CADrawableContext* drawableContext, double x, double y) : CADrawable(x, y) { diff --git a/src/layout/drawablemuselement.h b/src/layout/drawablemuselement.h index d84d4a94..2c24ebae 100644 --- a/src/layout/drawablemuselement.h +++ b/src/layout/drawablemuselement.h @@ -43,6 +43,8 @@ class CADrawableMusElement : public CADrawable { virtual CADrawable* clone() { return clone(nullptr); } virtual CADrawableMusElement* clone(CADrawableContext* newContext = nullptr) = 0; + static const QString EMPTY_PLACEHOLDER; + protected: void setDrawableMusElementType(CADrawableMusElementType t) { _drawableMusElementType = t; } diff --git a/src/layout/drawablesyllable.cpp b/src/layout/drawablesyllable.cpp index b4954f81..215688ff 100644 --- a/src/layout/drawablesyllable.cpp +++ b/src/layout/drawablesyllable.cpp @@ -1,5 +1,5 @@ /*! - Copyright (c) 2007, Matevž Jekovec, Canorus development team + Copyright (c) 2007-2022, Matevž Jekovec, Canorus development team All Rights Reserved. See AUTHORS for a complete list of authors. Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE.GPL for details. @@ -46,18 +46,27 @@ void CADrawableSyllable::draw(QPainter* p, const CADrawSettings s) QFont font("Century Schoolbook L"); font.setPixelSize(qRound(DEFAULT_TEXT_SIZE * s.z)); p->setFont(font); - p->drawText(s.x, s.y + qRound(height() * s.z), textToDrawableText(syllable()->text())); + + QString text = syllable()->text(); + // Show "space" dot when selected, if empty and not part of hyphen/melisma. + if (text.isEmpty() && !syllable()->hyphenStart() && !syllable()->melismaStart()) { + text = CADrawableMusElement::EMPTY_PLACEHOLDER; + } + // Strip melisma. + text = textToDrawableText(text); + + p->drawText(s.x, s.y + qRound(height() * s.z), text); #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) - int textWidth = QFontMetrics(font).horizontalAdvance(textToDrawableText(syllable()->text())); + int textWidth = QFontMetrics(font).horizontalAdvance(text); #else - int textWidth = QFontMetrics(font).width(textToDrawableText(syllable()->text())); + int textWidth = QFontMetrics(font).width(text); #endif if (syllable()->hyphenStart() && (width() * s.z - textWidth) > qRound(DEFAULT_DASH_LENGTH * s.z)) { p->drawLine(qRound(s.x + width() * s.z * 0.5 + 0.5 * textWidth - 0.5 * s.z * DEFAULT_DASH_LENGTH), s.y + qRound(height() * s.z * 0.7), qRound(s.x + width() * s.z * 0.5 + 0.5 * textWidth + 0.5 * s.z * DEFAULT_DASH_LENGTH), s.y + qRound(height() * s.z * 0.7)); } else if (syllable()->melismaStart() && (width() * s.z - textWidth) > qRound(DEFAULT_DASH_LENGTH * s.z)) { - p->drawLine(s.x + textWidth, s.y + qRound(height() * s.z), + p->drawLine(s.x + textWidth + (!text.isEmpty()?1.5*s.z:0), s.y + qRound(height() * s.z), qRound(s.x + width() * s.z), s.y + qRound(height() * s.z)); } } diff --git a/src/ui/mainwin.cpp b/src/ui/mainwin.cpp index 9a3c526d..71c7f59b 100644 --- a/src/ui/mainwin.cpp +++ b/src/ui/mainwin.cpp @@ -1,5 +1,5 @@ /*! - Copyright (c) 2006-2020, Reinhard Katzmann, Matevž Jekovec, Canorus development team + Copyright (c) 2006-2022, Reinhard Katzmann, Matevž Jekovec, Canorus development team All Rights Reserved. See AUTHORS for a complete list of authors. Licensed under the GNU GENERAL PUBLIC LICENSE. See COPYING for details. @@ -2028,8 +2028,22 @@ void CAMainWin::scoreViewMouseMove(QMouseEvent* e, QPoint coords) void CAMainWin::scoreViewDoubleClick(QMouseEvent*, const QPoint) { if (mode() == EditMode) { - static_cast(sender())->selectAllCurBar(); - static_cast(sender())->repaint(); + CAScoreView* c = static_cast(sender()); + CADrawableMusElement* dElt = nullptr; + CAMusElement* elt = nullptr; + + if (c->selection().size() == 1) { + dElt = c->selection().front(); + elt = dElt->musElement(); + } + + if (elt && (elt->musElementType() == CAMusElement::Syllable || elt->musElementType() == CAMusElement::ChordName || (elt->musElementType() == CAMusElement::Mark && (static_cast(elt)->markType() == CAMark::Text || static_cast(elt)->markType() == CAMark::BookMark)))) { + c->createTextEdit(dElt); + } else { + c->selectAllCurBar(); + } + + c->repaint(); } } @@ -2101,10 +2115,6 @@ void CAMainWin::scoreViewMouseRelease(QMouseEvent* e, QPoint coords) dElt = v->selection().front(); elt = dElt->musElement(); } - - if (elt && (elt->musElementType() == CAMusElement::Syllable || elt->musElementType() == CAMusElement::ChordName || (elt->musElementType() == CAMusElement::Mark && (static_cast(elt)->markType() == CAMark::Text || static_cast(elt)->markType() == CAMark::BookMark)))) { - v->createTextEdit(dElt); - } } v->repaint(); }