Allow drag and drop reordering of macros

This commit is contained in:
WarmUpTill 2022-02-23 21:29:50 +01:00 committed by WarmUpTill
parent 83df1ab658
commit 88dff37776
3 changed files with 35 additions and 0 deletions

View File

@ -584,6 +584,15 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>

View File

@ -154,6 +154,7 @@ public slots:
void MoveMacroConditionUp(int idx);
void MoveMacroConditionDown(int idx);
void HighlightMatchedMacros();
void MacroDragDropReorder(QModelIndex, int, int, QModelIndex, int);
void on_screenRegionSwitches_currentRowChanged(int idx);
void on_showFrame_clicked();

View File

@ -384,6 +384,25 @@ void AdvSceneSwitcher::on_macros_currentRowChanged(int idx)
}
}
void AdvSceneSwitcher::MacroDragDropReorder(QModelIndex, int from, int,
QModelIndex, int to)
{
std::lock_guard<std::mutex> lock(switcher->m);
if (from > to) {
std::rotate(switcher->macros.rend() - from - 1,
switcher->macros.rend() - from,
switcher->macros.rend() - to);
} else {
std::rotate(switcher->macros.begin() + from,
switcher->macros.begin() + from + 1,
switcher->macros.begin() + to);
}
for (auto &m : switcher->macros) {
m->ResolveMacroRef();
}
}
void AdvSceneSwitcher::setupMacroTab()
{
const QSignalBlocker signalBlocker(ui->macros);
@ -401,6 +420,12 @@ void AdvSceneSwitcher::setupMacroTab()
ui->macroHelp->setVisible(false);
}
connect(ui->macros->model(),
SIGNAL(rowsMoved(QModelIndex, int, int, QModelIndex, int)),
this,
SLOT(MacroDragDropReorder(QModelIndex, int, int, QModelIndex,
int)));
delete conditionsList;
conditionsList = new MacroSegmentList(this);
conditionsList->SetHelpMsg(