From 2e1b69c339862fb9b8147bf0ac07d87ca4810d4e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 19 Jul 2019 13:54:17 +0200 Subject: [PATCH] Make it possible to put checkboxes on theme menu entries. --- nageru/mainwindow.cpp | 6 ++++++ nageru/theme.cpp | 11 ++++++++++- nageru/theme.h | 8 ++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/nageru/mainwindow.cpp b/nageru/mainwindow.cpp index f33c57d..7336222 100644 --- a/nageru/mainwindow.cpp +++ b/nageru/mainwindow.cpp @@ -910,6 +910,12 @@ void MainWindow::fill_menu_from_theme_menu(const vectoraddAction(QString::fromStdString(entry->text)); + if (entry->entry.flags == Theme::MenuEntry::CHECKABLE) { + action->setCheckable(true); + } else if (entry->entry.flags == Theme::MenuEntry::CHECKED) { + action->setCheckable(true); + action->setChecked(true); + } connect(action, &QAction::triggered, [lua_ref = entry->entry.lua_ref] { global_mixer->theme_menu_entry_clicked(lua_ref); }); diff --git a/nageru/theme.cpp b/nageru/theme.cpp index ec8f431..ce3d2d6 100644 --- a/nageru/theme.cpp +++ b/nageru/theme.cpp @@ -1412,6 +1412,8 @@ void Theme::register_globals() const vector> num_constants = { { "VIDEO_FORMAT_BGRA", bmusb::PixelFormat_8BitBGRA }, { "VIDEO_FORMAT_YCBCR", bmusb::PixelFormat_8BitYCbCrPlanar }, + { "CHECKABLE", MenuEntry::CHECKABLE }, + { "CHECKED", MenuEntry::CHECKED }, }; const vector> str_constants = { { "THEME_PATH", theme_path }, @@ -1802,6 +1804,13 @@ unique_ptr create_theme_menu_entry(lua_State *L, int index) const string text = checkstdstring(L, -1); lua_pop(L, 1); + unsigned flags = 0; + if (lua_objlen(L, -1) > 2) { + lua_rawgeti(L, -1, 3); + flags = luaL_checknumber(L, -1); + lua_pop(L, 1); + } + lua_rawgeti(L, index, 2); if (lua_istable(L, -1)) { vector> submenu = create_recursive_theme_menu(L); @@ -1810,7 +1819,7 @@ unique_ptr create_theme_menu_entry(lua_State *L, int index) } else { luaL_checktype(L, -1, LUA_TFUNCTION); int ref = luaL_ref(L, LUA_REGISTRYINDEX); - entry.reset(new Theme::MenuEntry{ text, L, ref }); + entry.reset(new Theme::MenuEntry{ text, L, ref, flags }); } return entry; } diff --git a/nageru/theme.h b/nageru/theme.h index 22a9ff7..b4e8d8c 100644 --- a/nageru/theme.h +++ b/nageru/theme.h @@ -149,12 +149,15 @@ public: #endif struct MenuEntry { - MenuEntry(const std::string &text, lua_State *L, int lua_ref) - : text(text), is_submenu(false), entry{L, lua_ref} {} + MenuEntry(const std::string &text, lua_State *L, int lua_ref, unsigned flags) + : text(text), is_submenu(false), entry{L, lua_ref, flags} {} MenuEntry(const std::string &text, std::vector> submenu) : text(text), is_submenu(true), submenu(std::move(submenu)) {} ~MenuEntry(); + static constexpr unsigned CHECKABLE = 1; + static constexpr unsigned CHECKED = 2; + std::string text; bool is_submenu; @@ -163,6 +166,7 @@ public: struct { lua_State *L; int lua_ref; + unsigned flags; } entry; // is_submenu = true. -- 2.39.2