From ab811c363c14b3441c93096957da9e5f66da6080 Mon Sep 17 00:00:00 2001 From: Zithia Satazaki Date: Tue, 29 Mar 2022 15:58:16 -0400 Subject: [PATCH] negate selection --- notes | 2 +- xybrid/ui/patterneditoritemdelegate.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/notes b/notes index 864fe1a..46101db 100644 --- a/notes +++ b/notes @@ -45,7 +45,7 @@ TODO { - fix strut not working except to overwrite another param - add negate function to param columns - multi select negate + - multi select negate revert-to-saved menu action diff --git a/xybrid/ui/patterneditoritemdelegate.cpp b/xybrid/ui/patterneditoritemdelegate.cpp index ab12269..84c2dc6 100644 --- a/xybrid/ui/patterneditoritemdelegate.cpp +++ b/xybrid/ui/patterneditoritemdelegate.cpp @@ -238,6 +238,30 @@ bool PatternEditorItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *m return cc->commit("delete selection"); } + if (k == Qt::Key_Minus) { + dc->cancel(); + SelectionBounds s(sel); + auto cc = (new CompositeCommand())->reserve((1 + s.y2 - s.y1) * (1 + s.ch2 - s.ch1)); + + for (int c = s.ch1; c <= s.ch2; c++) { + if (c == s.ch2 && s.x2 < 2) continue; // no params selected here + for (int r = s.y1; r <= s.y2; r++) { + auto dc = new PatternDeltaCommand(p, c, r-1); + //auto min = c == s.ch1 ? std::max(0, s.x1 - 2) : 0; + //auto max = c == s.ch2 ? s.x2 - 2 : PatternEditorModel::paramSoftCap; + + for (auto i = 0; i < static_cast(dc->row.numParams()); i++) { + if (s.paramSelected(c, i)) { + auto& pr = dc->row.param(i); + if (pr[0] != ' ') pr[1] *= -1; + } + } + cc->compose(dc); + } + } + + return cc->commit("negate selection"); + } // for all other commands, reset selection to cursor and defer sm->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);