51 /* UI_MENU_CHECKITEM_LIST */ add_menuitem_list_widget, |
51 /* UI_MENU_CHECKITEM_LIST */ add_menuitem_list_widget, |
52 /* UI_MENU_RADIOITEM_LIST */ add_menuitem_list_widget, |
52 /* UI_MENU_RADIOITEM_LIST */ add_menuitem_list_widget, |
53 /* UI_MENU_SEPARATOR */ add_menuseparator_widget |
53 /* UI_MENU_SEPARATOR */ add_menuseparator_widget |
54 }; |
54 }; |
55 |
55 |
|
56 /* |
|
57 * create all menu child items |
|
58 */ |
56 static void add_menu_items(QMenu *parent, int i, UiMenu *menu, UiObject *obj) { |
59 static void add_menu_items(QMenu *parent, int i, UiMenu *menu, UiObject *obj) { |
57 UiMenuItemI *it = menu->items_begin; |
60 UiMenuItemI *it = menu->items_begin; |
58 int index = 0; |
61 int index = 0; |
59 while(it) { |
62 while(it) { |
60 createMenuItem[it->type](parent, index, it, obj); |
63 createMenuItem[it->type](parent, index, it, obj); |
67 UiMenu *m = (UiMenu*)item; |
70 UiMenu *m = (UiMenu*)item; |
68 QMenu *menu = parent->addMenu(m->label); |
71 QMenu *menu = parent->addMenu(m->label); |
69 add_menu_items(menu, i, m, obj); |
72 add_menu_items(menu, i, m, obj); |
70 } |
73 } |
71 |
74 |
|
75 static UiAction* create_action( |
|
76 UiObject *obj, |
|
77 const char *icon, |
|
78 const char *label, |
|
79 ui_callback callback, |
|
80 void *userdata, |
|
81 int *states) |
|
82 { |
|
83 QString str = QString::fromUtf8(label); |
|
84 UiAction *action = new UiAction(obj, str, callback, userdata); |
|
85 if(icon) { |
|
86 action->setIcon(QIcon::fromTheme(icon)); |
|
87 action->setIconVisibleInMenu(true); |
|
88 } |
|
89 |
|
90 if(states) { |
|
91 size_t nstates = uic_group_array_size(states); |
|
92 uic_add_group_widget_i(obj->ctx, action, (ui_enablefunc)ui_action_enable, states, nstates); |
|
93 action->setEnabled(false); |
|
94 } |
|
95 |
|
96 return action; |
|
97 } |
|
98 |
72 void add_menuitem_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) { |
99 void add_menuitem_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) { |
73 UiMenuItem *it = (UiMenuItem*)item; |
100 UiMenuItem *it = (UiMenuItem*)item; |
74 QString str = QString::fromUtf8(it->label); |
101 UiAction *action = create_action(obj, it->icon, it->label, it->callback, it->userdata, it->groups); |
75 UiAction *action = new UiAction(obj, str, it->callback, it->userdata); |
|
76 action->setIcon(QIcon::fromTheme(it->icon)); |
|
77 action->setIconVisibleInMenu(true); |
|
78 parent->addAction(action); |
102 parent->addAction(action); |
79 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger())); |
103 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger())); |
80 } |
104 } |
81 |
105 |
82 void add_menuseparator_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) { |
106 void add_menuseparator_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) { |
83 parent->addSeparator(); |
107 parent->addSeparator(); |
84 } |
108 } |
85 |
109 |
86 void add_checkitem_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) { |
110 void add_checkitem_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) { |
|
111 UiMenuCheckItem *it = (UiMenuCheckItem*)item; |
87 |
112 |
|
113 UiAction *action = create_action(obj, it->icon, it->label, it->callback, it->userdata, it->groups); |
|
114 parent->addAction(action); |
|
115 action->setCheckable(true); |
|
116 action->prepare_event = ui_checkableaction_prepare_event; |
|
117 |
|
118 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, NULL, it->varname, UI_VAR_INTEGER); |
|
119 if(var) { |
|
120 UiInteger *value = (UiInteger*)var->value; |
|
121 value->obj = action; |
|
122 value->get = ui_checkableaction_get; |
|
123 value->set = ui_checkableaction_set; |
|
124 |
|
125 action->setChecked((bool)value->value); |
|
126 } |
88 } |
127 } |
89 |
128 |
90 void add_radioitem_widget(QMenu *parent, int index, UiMenuItemI *item, UiObject *obj) { |
129 void add_radioitem_widget(QMenu *parent, int index, UiMenuItemI *item, UiObject *obj) { |
91 |
130 |
92 } |
131 } |