Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds clickable sources in list, fixes memory leak in parent scenes popup menu. #52

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 32 additions & 34 deletions src/quick-access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ QMenu *QuickAccessItem::_CreateSceneMenu()
});
wa->setDefaultWidget(t);
popup->addAction(wa);

popup->setStyleSheet("QMenu { menu-scrollable: 1; }");
auto getActionAfter = [](QMenu *menu, const QString &name) {
QList<QAction *> actions = menu->actions();

Expand All @@ -315,6 +315,15 @@ QMenu *QuickAccessItem::_CreateSceneMenu()
QWidgetAction *popupItem = new QWidgetAction(this);
QWidget *itemWidget = new QuickAccessSceneItem(this, sceneItem);
popupItem->setDefaultWidget(itemWidget);
popupItem->setParent(pop);

connect(popupItem, &QWidgetAction::triggered, this,
[this, name]() {
obs_source_t *sceneClicked =
obs_get_source_by_name(name);
obs_frontend_set_current_scene(sceneClicked);
obs_source_release(sceneClicked);
});

QAction *after = getActionAfter(pop, qname);
pop->insertAction(after, popupItem);
Expand All @@ -324,6 +333,16 @@ QMenu *QuickAccessItem::_CreateSceneMenu()
addSource(popup, src);
}

connect(popup, &QMenu::hovered, this, [popup](QAction *act) {
QList<QWidgetAction *> menuActions =
popup->findChildren<QWidgetAction *>();
for (auto menuAction : menuActions) {
auto widget = static_cast<QuickAccessSceneItem *>(
menuAction->defaultWidget());
widget->setHighlight(menuAction == act);
}
});

return popup;
}

Expand Down Expand Up @@ -351,6 +370,7 @@ void QuickAccessItem::on_actionScenes_triggered()
}
_getSceneItems();
_AddScenePopupMenu(QCursor::pos());
obs_source_release(source);
}

void QuickAccessItem::SwitchToScene()
Expand Down Expand Up @@ -1281,7 +1301,7 @@ QuickAccessSceneItem::QuickAccessSceneItem(QWidget *parent,

setAttribute(Qt::WA_TranslucentBackground);
setMouseTracking(true);
setStyleSheet("background: none");
//setStyleSheet("background: none");

QIcon icon;

Expand Down Expand Up @@ -1349,34 +1369,6 @@ QuickAccessSceneItem::QuickAccessSceneItem(QWidget *parent,
}

auto setItemVisible = [this](bool val) {
//obs_scene_t *scene = obs_sceneitem_get_scene(_sceneItem);
//obs_source_t *scenesource = obs_scene_get_source(scene);
//int64_t id = obs_sceneitem_get_id(_sceneItem);
//const char *name = obs_source_get_name(scenesource);
//const char *uuid = obs_source_get_uuid(scenesource);
//obs_source_t *source = obs_sceneitem_get_source(_sceneItem);

//auto undo_redo = [](const std::string &uuid, int64_t id,
// bool val) {
// auto s = obs_get_source_by_uuid(uuid.c_str());
// obs_scene_t *sc = obs_group_or_scene_from_source(s);
// obs_sceneitem_t *si =
// obs_scene_find_sceneitem_by_id(sc, id);
// if (si)
// obs_sceneitem_set_visible(si, val);
//};

//QString str = QTStr(val ? "Undo.ShowSceneItem"
// : "Undo.HideSceneItem");

//OBSBasic *main = OBSBasic::Get();
//main->undo_s.add_action(
// str.arg(obs_source_get_name(source), name),
// std::bind(undo_redo, std::placeholders::_1, id, !val),
// std::bind(undo_redo, std::placeholders::_1, id, val),
// uuid, uuid);

//QSignalBlocker sourcesSignalBlocker(this);
obs_sceneitem_set_visible(_sceneItem, val);
};
connect(_vis, &QAbstractButton::clicked, setItemVisible);
Expand All @@ -1392,11 +1384,17 @@ void QuickAccessSceneItem::on_actionTransform_triggered()
obs_frontend_open_sceneitem_edit_transform(_sceneItem);
}

void QuickAccessSceneItem::mouseReleaseEvent(QMouseEvent *e)
//void QuickAccessSceneItem::mouseReleaseEvent(QMouseEvent *e)
//{
// // This is to suppress mouse event propegating down
// // to QMenu.
// UNUSED_PARAMETER(e);
//}

void QuickAccessSceneItem::setHighlight(bool h)
{
// This is to suppress mouse event propegating down
// to QMenu.
UNUSED_PARAMETER(e);
setBackgroundRole(h ? QPalette::Highlight : QPalette::Window);
setAutoFillBackground(h);
}

bool AddSourceToWidget(void *data, obs_source_t *source)
Expand Down
3 changes: 2 additions & 1 deletion src/quick-access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class QuickAccessSceneItem : public QWidget {
public:
QuickAccessSceneItem(QWidget *parent, obs_sceneitem_t *sceneItem);
~QuickAccessSceneItem();
void mouseReleaseEvent(QMouseEvent *e) override;
void setHighlight(bool h);
//void mouseReleaseEvent(QMouseEvent *e) override;

private:
obs_sceneitem_t *_sceneItem = nullptr;
Expand Down