]> git.sesse.net Git - nageru/commitdiff
Make it possible to put checkboxes on theme menu entries.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 19 Jul 2019 11:54:17 +0000 (13:54 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 19 Jul 2019 11:54:17 +0000 (13:54 +0200)
nageru/mainwindow.cpp
nageru/theme.cpp
nageru/theme.h

index f33c57d6b2d24f6343c9bab2b04464e6ed489e8f..73362229ce35e8efc70f9cf5dcfe4c25a6e73037 100644 (file)
@@ -910,6 +910,12 @@ void MainWindow::fill_menu_from_theme_menu(const vector<unique_ptr<Theme::MenuEn
                }
 
                QAction *action = menu->addAction(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);
                });
index ec8f43191aefb0f31d3bef4aae0e7c1b588cba81..ce3d2d6d55c917f6fdc0afba77c1cec348428ca2 100644 (file)
@@ -1412,6 +1412,8 @@ void Theme::register_globals()
        const vector<pair<string, int>> num_constants = {
                { "VIDEO_FORMAT_BGRA", bmusb::PixelFormat_8BitBGRA },
                { "VIDEO_FORMAT_YCBCR", bmusb::PixelFormat_8BitYCbCrPlanar },
+               { "CHECKABLE", MenuEntry::CHECKABLE },
+               { "CHECKED", MenuEntry::CHECKED },
        };
        const vector<pair<string, string>> str_constants = {
                { "THEME_PATH", theme_path },
@@ -1802,6 +1804,13 @@ unique_ptr<Theme::MenuEntry> 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<unique_ptr<Theme::MenuEntry>> submenu = create_recursive_theme_menu(L);
@@ -1810,7 +1819,7 @@ unique_ptr<Theme::MenuEntry> 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;
 }
index 22a9ff7d3423a4e203c9fc688be2f4f354306ca5..b4e8d8c406bcd612637eb662882d04798a115f2d 100644 (file)
@@ -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<std::unique_ptr<MenuEntry>> 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.