提交 3486c0b3 编写于 作者: J jp9000

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.
上级 da8547c1
......@@ -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);
......
......@@ -401,6 +401,7 @@ private:
void CreateProgramDisplay();
void CreateProgramOptions();
int TransitionCount();
int AddTransitionBeforeSeparator(const QString &name,
obs_source_t *source);
void AddQuickTransitionId(int id);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册