0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 04:42:18 +02:00

UI: Fix selecting correct transition when deleting

When deleting a transition, it would sometimes select the one that
replaces it, which could be the separator.  This would cause undefined
behavior.  This fixes it so that it selects either the one that replaces
it (if a valid one replaces it), or the transition at the bottom of the
known list and not the separator.
This commit is contained in:
jp9000 2020-10-06 08:49:58 -07:00
parent da8547c112
commit 3486c0b363
2 changed files with 23 additions and 6 deletions

View File

@ -102,11 +102,9 @@ void OBSBasic::InitDefaultTransitions()
ui->transitions->blockSignals(false);
}
int OBSBasic::AddTransitionBeforeSeparator(const QString &name,
obs_source_t *source)
int OBSBasic::TransitionCount()
{
int idx = -1;
int idx = 0;
for (int i = 0; i < ui->transitions->count(); i++) {
QVariant v = ui->transitions->itemData(i);
if (!v.toString().isEmpty()) {
@ -115,11 +113,21 @@ int OBSBasic::AddTransitionBeforeSeparator(const QString &name,
}
}
/* should always have at least fade and cut due to them being
* defaults */
assert(idx != 0);
return idx - 1; /* remove separator from equation */
}
int OBSBasic::AddTransitionBeforeSeparator(const QString &name,
obs_source_t *source)
{
int idx = TransitionCount();
ui->transitions->blockSignals(true);
ui->transitions->insertItem(idx - 1, name,
ui->transitions->insertItem(idx, name,
QVariant::fromValue(OBSSource(source)));
ui->transitions->blockSignals(false);
return idx - 1;
return idx;
}
void OBSBasic::AddQuickTransitionHotkey(QuickTransition *qt)
@ -577,7 +585,15 @@ void OBSBasic::on_transitionRemove_clicked()
}
}
ui->transitions->blockSignals(true);
ui->transitions->removeItem(idx);
ui->transitions->setCurrentIndex(-1);
ui->transitions->blockSignals(false);
int bottomIdx = TransitionCount() - 1;
if (idx > bottomIdx)
idx = bottomIdx;
ui->transitions->setCurrentIndex(idx);
if (api)
api->on_event(OBS_FRONTEND_EVENT_TRANSITION_LIST_CHANGED);

View File

@ -401,6 +401,7 @@ private:
void CreateProgramDisplay();
void CreateProgramOptions();
int TransitionCount();
int AddTransitionBeforeSeparator(const QString &name,
obs_source_t *source);
void AddQuickTransitionId(int id);