1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* menu.h
* Copyright 2014 William Pitcock
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions, and the following disclaimer in the documentation
* provided with the distribution.
*
* This software is provided "as is" and without any warranty, express or
* implied. In no event shall the authors be liable for any damages arising from
* the use of this software.
*/
#include "libaudqt.h"
#ifndef LIBAUDQT_MENU_H
#define LIBAUDQT_MENU_H
#include <libaudcore/objects.h>
class QAction;
class QMenu;
class QMenuBar;
class QWidget;
enum class AudMenuID;
namespace audqt {
typedef void (* MenuFunc) ();
struct MenuItemText {
const char * name;
const char * icon;
const char * shortcut;
};
struct MenuItemConfig {
const char * sect;
const char * name;
const char * hook;
};
struct MenuItem {
MenuItemText text;
void (* func) ();
/* for toggle items */
MenuItemConfig cfg;
/* for submenus */
ArrayRef<MenuItem> items;
/* for custom submenus */
QMenu * (* submenu) ();
/* for separators */
bool sep;
};
constexpr MenuItem MenuCommand (MenuItemText text, MenuFunc func)
{ return {text, func}; }
constexpr MenuItem MenuToggle (MenuItemText text, MenuItemConfig cfg, MenuFunc func = nullptr)
{ return {text, func, cfg}; }
constexpr MenuItem MenuSub (MenuItemText text, ArrayRef<MenuItem> items)
{ return {text, nullptr, {}, items}; }
constexpr MenuItem MenuSub (MenuItemText text, QMenu * (* submenu) ())
{ return {text, nullptr, {}, nullptr, submenu}; }
constexpr MenuItem MenuSep ()
{ return {{}, nullptr, {}, nullptr, nullptr, true}; }
/* menu.cc */
QAction * menu_action (const MenuItem & menu_item, const char * domain, QWidget * parent = nullptr);
QMenu * menu_build (ArrayRef<MenuItem> menu_items, const char * domain, QWidget * parent = nullptr);
QMenuBar * menubar_build (ArrayRef<MenuItem> menu_items, const char * domain, QWidget * parent = nullptr);
#ifdef PACKAGE
static inline QMenu * menu_build (ArrayRef<MenuItem> menu_items, QWidget * parent = nullptr)
{ return menu_build (menu_items, PACKAGE, parent); }
static inline QMenuBar * menubar_build (ArrayRef<MenuItem> menu_items, QWidget * parent = nullptr)
{ return menubar_build (menu_items, PACKAGE, parent); }
#endif
/* plugin-menu.cc */
QMenu * menu_get_by_id (AudMenuID id);
void menu_add (AudMenuID id, MenuFunc func, const char * name, const char * icon);
void menu_remove (AudMenuID id, MenuFunc func);
} // namespace audqt
#endif
|