diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index 3cd02cc39..3fa751a9b 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -709,6 +709,10 @@ void OBSBasic::AddScene(OBSSource source) OBSBasic::SceneItemAdded, this); signal_handler_connect(handler, "item_remove", OBSBasic::SceneItemRemoved, this); + signal_handler_connect(handler, "item_select", + OBSBasic::SceneItemSelected, this); + signal_handler_connect(handler, "item_deselect", + OBSBasic::SceneItemDeselected, this); signal_handler_connect(handler, "item_move_up", OBSBasic::SceneItemMoveUp, this); signal_handler_connect(handler, "item_move_down", @@ -815,6 +819,36 @@ void OBSBasic::RenameSources(QString newName, QString prevName) } } +void OBSBasic::SelectSceneItem(OBSScene scene, OBSSceneItem item, bool select) +{ + if (scene != GetCurrentScene()) + return; + + for (int i = 0; i < ui->sources->count(); i++) { + QListWidgetItem *witem = ui->sources->item(i); + QVariant data = witem->data(Qt::UserRole); + if (!data.canConvert()) + continue; + + if (item != data.value()) + continue; + + if (select && witem->isSelected()) + break; + + if (!select && !witem->isSelected()) + break; + + QItemSelectionModel::SelectionFlags model = select ? + QItemSelectionModel::Select : + QItemSelectionModel::Deselect; + model |= QItemSelectionModel::Current; + + ui->sources->setCurrentItem(witem, model); + break; + } +} + void OBSBasic::MoveSceneItem(OBSSceneItem item, obs_order_movement movement) { OBSScene scene = obs_sceneitem_get_scene(item); @@ -1057,6 +1091,30 @@ void OBSBasic::SceneItemRemoved(void *data, calldata_t *params) Q_ARG(OBSSceneItem, OBSSceneItem(item))); } +void OBSBasic::SceneItemSelected(void *data, calldata_t *params) +{ + OBSBasic *window = static_cast(data); + + obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene"); + obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item"); + + QMetaObject::invokeMethod(window, "SelectSceneItem", + Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item), + Q_ARG(bool, true)); +} + +void OBSBasic::SceneItemDeselected(void *data, calldata_t *params) +{ + OBSBasic *window = static_cast(data); + + obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene"); + obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item"); + + QMetaObject::invokeMethod(window, "SelectSceneItem", + Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item), + Q_ARG(bool, false)); +} + void OBSBasic::SourceAdded(void *data, calldata_t *params) { OBSBasic *window = static_cast(data); diff --git a/obs/window-basic-main.hpp b/obs/window-basic-main.hpp index 5707e691a..824ea002b 100644 --- a/obs/window-basic-main.hpp +++ b/obs/window-basic-main.hpp @@ -161,6 +161,7 @@ private slots: void UpdateSceneSelection(OBSSource source); void RenameSources(QString newName, QString prevName); + void SelectSceneItem(OBSScene scene, OBSSceneItem item, bool select); void MoveSceneItem(OBSSceneItem item, obs_order_movement movement); void ActivateAudioSource(OBSSource source); @@ -173,6 +174,8 @@ private: /* OBS Callbacks */ static void SceneItemAdded(void *data, calldata_t *params); static void SceneItemRemoved(void *data, calldata_t *params); + static void SceneItemSelected(void *data, calldata_t *params); + static void SceneItemDeselected(void *data, calldata_t *params); static void SourceAdded(void *data, calldata_t *params); static void SourceRemoved(void *data, calldata_t *params); static void SourceActivated(void *data, calldata_t *params);