Skip to content

Commit

Permalink
Trigger new EditPercussionShortcut flow from Customize kit dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
mathesoncalum committed Jan 24, 2025
1 parent 4f86f03 commit 6e4ba68
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 122 deletions.
3 changes: 2 additions & 1 deletion src/framework/ui/view/interactiveprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ QWindow* InteractiveProvider::topWindow() const
return mainWin;
}

if (!last.window->parent()) {
// TODO/HACK: last.window doesn't seem to have a parent when the top window is a widget....
if (!last.window->parent() && !topWindowIsWidget()) {
ASSERT_X("Window must have a parent!");
}

Expand Down
98 changes: 31 additions & 67 deletions src/palette/view/widgets/customizekitdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "engraving/dom/stem.h"
#include "engraving/dom/utils.h"

#include "notation/utilities/percussionutilities.h"

#include "draw/types/geometry.h"

#include <QMessageBox>
Expand All @@ -51,7 +53,6 @@ using namespace mu::notation;
using namespace mu::engraving;

static const QString CUSTOMIZE_KIT_DIALOG_NAME("CustomizeKitDialog");
static const std::string_view POSSIBLE_SHORTCUTS("ABCDEFG");

enum Column : char {
PITCH, NOTE, SHORTCUT, NAME
Expand Down Expand Up @@ -185,7 +186,7 @@ CustomizeKitDialog::CustomizeKitDialog(QWidget* parent)
connect(staffLine, &QSpinBox::valueChanged, this, &CustomizeKitDialog::valueChanged);
connect(voice, &QComboBox::currentIndexChanged, this, &CustomizeKitDialog::valueChanged);
connect(stemDirection, &QComboBox::currentIndexChanged, this, &CustomizeKitDialog::valueChanged);
connect(shortcut, &QComboBox::currentIndexChanged, this, &CustomizeKitDialog::shortcutChanged);
connect(shortcut, &QPushButton::clicked, this, &CustomizeKitDialog::defineShortcut);
connect(loadButton, &QPushButton::clicked, this, &CustomizeKitDialog::load);
connect(saveButton, &QPushButton::clicked, this, &CustomizeKitDialog::save);
pitchList->setColumnWidth(0, 40);
Expand Down Expand Up @@ -308,8 +309,7 @@ void CustomizeKitDialog::loadPitchesList()
if (m_editedDrumset.shortcut(i) == 0) {
item->setText(Column::SHORTCUT, "");
} else {
QString s(QChar(m_editedDrumset.shortcut(i)));
item->setText(Column::SHORTCUT, s);
item->setText(Column::SHORTCUT, QChar(m_editedDrumset.shortcut(i)));
}
item->setText(Column::NAME, m_editedDrumset.translatedName(i));
item->setData(Column::PITCH, Qt::UserRole, i);
Expand Down Expand Up @@ -354,49 +354,6 @@ void CustomizeKitDialog::nameChanged(const QString& n)
setEnabledPitchControls(!n.isEmpty());
}

//---------------------------------------------------------
// shortcutChanged
//---------------------------------------------------------

void CustomizeKitDialog::shortcutChanged()
{
QTreeWidgetItem* item = pitchList->currentItem();
if (!item) {
return;
}

int pitch = item->data(Column::PITCH, Qt::UserRole).toInt();
int index = shortcut->currentIndex();
bool invalidIndex = index < 0 || index >= static_cast<int>(POSSIBLE_SHORTCUTS.size());
int sc;

if (invalidIndex) {
sc = 0;
} else {
sc = POSSIBLE_SHORTCUTS[index];
}

if (QString(QChar(m_editedDrumset.drum(pitch).shortcut)) != shortcut->currentText()) {
//
// remove conflicting shortcuts
//
for (int i = 0; i < DRUM_INSTRUMENTS; ++i) {
if (i == pitch) {
continue;
}
if (m_editedDrumset.drum(i).shortcut == sc) {
m_editedDrumset.drum(i).shortcut = 0;
}
}
m_editedDrumset.drum(pitch).shortcut = sc;
if (invalidIndex) {
item->setText(Column::SHORTCUT, "");
} else {
item->setText(Column::SHORTCUT, shortcut->currentText());
}
}
}

//---------------------------------------------------------
// bboxClicked
//---------------------------------------------------------
Expand Down Expand Up @@ -496,14 +453,11 @@ void CustomizeKitDialog::itemChanged(QTreeWidgetItem* current, QTreeWidgetItem*

m_editedDrumset.drum(pitch).line = staffLine->value();
m_editedDrumset.drum(pitch).voice = voice->currentIndex();
int index = shortcut->currentIndex();

if (index < 0 || index >= static_cast<int>(POSSIBLE_SHORTCUTS.size())) {
m_editedDrumset.drum(pitch).shortcut = 0;
} else {
m_editedDrumset.drum(pitch).shortcut = POSSIBLE_SHORTCUTS[index];
}
m_editedDrumset.drum(pitch).line = staffLine->value();
m_editedDrumset.drum(pitch).voice = voice->currentIndex();
m_editedDrumset.drum(pitch).stemDirection = DirectionV(stemDirection->currentIndex());

previous->setText(Column::NAME, m_editedDrumset.translatedName(pitch));
}
if (current == 0) {
Expand All @@ -529,11 +483,9 @@ void CustomizeKitDialog::itemChanged(QTreeWidgetItem* current, QTreeWidgetItem*
noteHead->setCurrentIndex(noteHead->findData(int(nh)));
fillNoteheadsComboboxes(isCustomGroup, pitch);

if (m_editedDrumset.shortcut(pitch) == 0) {
shortcut->setCurrentIndex(7);
} else {
shortcut->setCurrentIndex(m_editedDrumset.shortcut(pitch) - 'A');
}
const bool hasShortcut = m_editedDrumset.shortcut(pitch) != '\0';
const QString shortcutText = hasShortcut ? QChar(m_editedDrumset.shortcut(pitch)) : muse::qtrc("shortcuts", "None");
shortcut->setText(shortcutText);

staffLine->blockSignals(false);
voice->blockSignals(false);
Expand Down Expand Up @@ -574,16 +526,10 @@ void CustomizeKitDialog::valueChanged()
setCustomNoteheadsGUIEnabled(false);
}

m_editedDrumset.drum(pitch).line = staffLine->value();
m_editedDrumset.drum(pitch).voice = voice->currentIndex();
m_editedDrumset.drum(pitch).line = staffLine->value();
m_editedDrumset.drum(pitch).voice = voice->currentIndex();
m_editedDrumset.drum(pitch).stemDirection = DirectionV(stemDirection->currentIndex());
if (QString(QChar(m_editedDrumset.drum(pitch).shortcut)) != shortcut->currentText()) {
if (shortcut->currentText().isEmpty()) {
m_editedDrumset.drum(pitch).shortcut = 0;
} else {
m_editedDrumset.drum(pitch).shortcut = shortcut->currentText().at(0).toLatin1();
}
}

updateExample();

m_notation->parts()->replaceDrumset(m_instrumentKey, m_editedDrumset);
Expand Down Expand Up @@ -716,3 +662,21 @@ void CustomizeKitDialog::customQuarterChanged(int)
{
updateExample();
}

void CustomizeKitDialog::defineShortcut()
{
QTreeWidgetItem* item = pitchList->currentItem();
if (!item) {
return;
}

const int originPitch = item->data(Column::PITCH, Qt::UserRole).toInt();
PercussionUtilities::editPercussionShortcut(m_editedDrumset, originPitch);

const QString editedShortcutText = QChar(m_editedDrumset.shortcut(originPitch));
shortcut->setText(!editedShortcutText.isEmpty() ? editedShortcutText : muse::qtrc("shortcuts", "None"));
item->setText(Column::SHORTCUT, !editedShortcutText.isEmpty() ? editedShortcutText : QString());
// TODO: Update the item of the conflict shortcut too

valueChanged();
}
3 changes: 2 additions & 1 deletion src/palette/view/widgets/customizekitdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ private slots:
void bboxClicked(QAbstractButton* button);
void itemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
void nameChanged(const QString&);
void shortcutChanged();
void valueChanged();
void load();
void save();
void customGboxToggled(bool);
void customQuarterChanged(int);

void defineShortcut();

private:
void apply();
void cancel();
Expand Down
60 changes: 7 additions & 53 deletions src/palette/view/widgets/customizekitdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -309,59 +309,6 @@
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>shortcut</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="shortcut">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<item>
<property name="text">
<string notr="true">A</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">B</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">C</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">D</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">E</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">F</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">G</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">--</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0">
Expand Down Expand Up @@ -402,6 +349,13 @@
</item>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="shortcut">
<property name="text">
<string>None</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit 6e4ba68

Please sign in to comment.