From 1dd0cfaa4a83b68d9d16253523f2acf12f7a9a57 Mon Sep 17 00:00:00 2001 From: Cameron White Date: Sun, 17 Jan 2021 11:40:08 -0500 Subject: [PATCH] Implement the new editing style for alterations of pace. This is similar to the changes in 56e5ba8 for tempo markers. Bug: #23, #192, #220 --- source/app/powertabeditor.cpp | 44 ++++++++++++++++------- source/app/powertabeditor.h | 2 +- source/dialogs/alterationofpacedialog.cpp | 10 +++++- source/dialogs/alterationofpacedialog.h | 3 +- source/painters/scoreclickevent.h | 1 + source/painters/systemrenderer.cpp | 4 ++- 6 files changed, 47 insertions(+), 17 deletions(-) diff --git a/source/app/powertabeditor.cpp b/source/app/powertabeditor.cpp index ef011fa0b..588abe3e8 100644 --- a/source/app/powertabeditor.cpp +++ b/source/app/powertabeditor.cpp @@ -776,6 +776,10 @@ void PowerTabEditor::removeSelectedItem() editTempoMarker(/* remove */ true); break; + case ScoreItem::AlterationOfPace: + editAlterationOfPace(/* remove */ true); + break; + case ScoreItem::RehearsalSign: editRehearsalSign(/* remove */ true); break; @@ -1335,33 +1339,43 @@ void PowerTabEditor::editTempoMarker(bool remove) myTempoMarkerCommand->setChecked(false); } -void PowerTabEditor::editAlterationOfPace() +void PowerTabEditor::editAlterationOfPace(bool remove) { const ScoreLocation &location = getLocation(); const TempoMarker *marker = ScoreUtils::findByPosition( location.getSystem().getTempoMarkers(), location.getPositionIndex()); - if (marker) + if (remove) { + Q_ASSERT(marker); Q_ASSERT(marker->getMarkerType() == TempoMarker::AlterationOfPace); myUndoManager->push(new RemoveTempoMarker(location), location.getSystemIndex()); + return; } - else + + AlterationOfPaceDialog dialog(this, marker); + if (dialog.exec() == QDialog::Accepted) { - AlterationOfPaceDialog dialog(this); - if (dialog.exec() == QDialog::Accepted) - { - TempoMarker marker(location.getPositionIndex()); - marker.setMarkerType(TempoMarker::AlterationOfPace); - marker.setAlterationOfPace(dialog.getAlterationOfPaceType()); + TempoMarker new_marker(location.getPositionIndex()); + new_marker.setMarkerType(TempoMarker::AlterationOfPace); + new_marker.setAlterationOfPace(dialog.getAlterationOfPaceType()); - myUndoManager->push(new AddTempoMarker(location, marker), + if (marker) + { + myUndoManager->beginMacro(tr("Edit Alteration of Pace")); + myUndoManager->push(new RemoveTempoMarker(location), location.getSystemIndex()); } - else - myAlterationOfPaceCommand->setChecked(false); + + myUndoManager->push(new AddTempoMarker(location, new_marker), + location.getSystemIndex()); + + if (marker) + myUndoManager->endMacro(); } + else + myAlterationOfPaceCommand->setChecked(false); } void PowerTabEditor::insertStandardBarline() @@ -2508,7 +2522,7 @@ void PowerTabEditor::createCommands() "MusicSymbols.AlterationOfPace", QKeySequence(), this); myAlterationOfPaceCommand->setCheckable(true); connect(myAlterationOfPaceCommand, &QAction::triggered, this, - &PowerTabEditor::editAlterationOfPace); + [=]() { editAlterationOfPace(); }); myKeySignatureCommand = new Command(tr("Edit Key Signature..."), "MusicSymbols.EditKeySignature", @@ -3375,6 +3389,9 @@ void PowerTabEditor::setupNewTab() case ScoreItem::TempoMarker: editTempoMarker(); break; + case ScoreItem::AlterationOfPace: + editAlterationOfPace(); + break; case ScoreItem::RehearsalSign: editRehearsalSign(); break; @@ -3476,6 +3493,7 @@ canDeleteItem(ScoreItem item) { switch (item) { + case ScoreItem::AlterationOfPace: case ScoreItem::AlternateEnding: case ScoreItem::PlayerChange: case ScoreItem::RehearsalSign: diff --git a/source/app/powertabeditor.h b/source/app/powertabeditor.h index f824547c1..ed68f6986 100644 --- a/source/app/powertabeditor.h +++ b/source/app/powertabeditor.h @@ -210,7 +210,7 @@ private slots: /// Adds or removes a tempo marker at the current position. void editTempoMarker(bool remove = false); /// Adds or removes an accel/rit symbol at the current position. - void editAlterationOfPace(); + void editAlterationOfPace(bool remove = false); /// Edits the key signature at the caret's current location. void editKeySignature(); /// Edits the time signature at the caret's current location. diff --git a/source/dialogs/alterationofpacedialog.cpp b/source/dialogs/alterationofpacedialog.cpp index 41e29bec4..e11ad4b47 100644 --- a/source/dialogs/alterationofpacedialog.cpp +++ b/source/dialogs/alterationofpacedialog.cpp @@ -18,7 +18,8 @@ #include "alterationofpacedialog.h" #include "ui_alterationofpacedialog.h" -AlterationOfPaceDialog::AlterationOfPaceDialog(QWidget *parent) +AlterationOfPaceDialog::AlterationOfPaceDialog( + QWidget *parent, const TempoMarker *current_marker) : QDialog(parent), ui(new Ui::AlterationOfPaceDialog) { ui->setupUi(this); @@ -30,6 +31,13 @@ AlterationOfPaceDialog::AlterationOfPaceDialog(QWidget *parent) TempoMarker::Accelerando); ui->typeComboBox->addItem(QStringLiteral("Ritardando (rit.)"), TempoMarker::Ritardando); + + if (current_marker) + { + ui->typeComboBox->setCurrentIndex( + current_marker->getAlterationOfPace() == TempoMarker::Ritardando + ? 1 : 0); + } } AlterationOfPaceDialog::~AlterationOfPaceDialog() diff --git a/source/dialogs/alterationofpacedialog.h b/source/dialogs/alterationofpacedialog.h index 3fe9ab0d9..3e531bca0 100644 --- a/source/dialogs/alterationofpacedialog.h +++ b/source/dialogs/alterationofpacedialog.h @@ -30,7 +30,8 @@ class AlterationOfPaceDialog : public QDialog Q_OBJECT public: - explicit AlterationOfPaceDialog(QWidget *parent); + explicit AlterationOfPaceDialog(QWidget *parent, + const TempoMarker *current_marker); ~AlterationOfPaceDialog(); TempoMarker::AlterationOfPaceType getAlterationOfPaceType() const; diff --git a/source/painters/scoreclickevent.h b/source/painters/scoreclickevent.h index 37f43d0bf..bd92a5e91 100644 --- a/source/painters/scoreclickevent.h +++ b/source/painters/scoreclickevent.h @@ -25,6 +25,7 @@ class ConstScoreLocation; /// Item types that can be clicked. enum class ScoreItem { + AlterationOfPace, AlternateEnding, Barline, Clef, diff --git a/source/painters/systemrenderer.cpp b/source/painters/systemrenderer.cpp index ce8fe7329..6446b6b8b 100644 --- a/source/painters/systemrenderer.cpp +++ b/source/painters/systemrenderer.cpp @@ -632,7 +632,9 @@ SystemRenderer::drawTempoMarkers(const ConstScoreLocation &location, auto group = new ClickableGroup( QObject::tr("Double-click to edit tempo marker."), myScoreArea->getClickEvent(), marker_location, - ScoreItem::TempoMarker); + tempo.getMarkerType() == TempoMarker::AlterationOfPace + ? ScoreItem::AlterationOfPace + : ScoreItem::TempoMarker); QFont font = myPlainTextFont; if (tempo.getMarkerType() == TempoMarker::AlterationOfPace)