122 value->get = ui_checkableaction_get; |
122 value->get = ui_checkableaction_get; |
123 value->set = ui_checkableaction_set; |
123 value->set = ui_checkableaction_set; |
124 |
124 |
125 action->setChecked((bool)value->value); |
125 action->setChecked((bool)value->value); |
126 } |
126 } |
|
127 action->var = var; |
127 } |
128 } |
128 |
129 |
129 void add_radioitem_widget(QMenu *parent, int index, UiMenuItemI *item, UiObject *obj) { |
130 void add_radioitem_widget(QMenu *parent, int index, UiMenuItemI *item, UiObject *obj) { |
130 |
131 UiMenuRadioItem *it = (UiMenuRadioItem*)item; |
131 } |
132 |
132 |
133 UiAction *action = create_action(obj, it->icon, it->label, it->callback, it->userdata, it->groups); |
133 void add_checkitemnv_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) { |
134 parent->addAction(action); |
134 |
135 action->setCheckable(true); |
|
136 action->prepare_event = ui_actiongroup_prepare_event; |
|
137 |
|
138 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, NULL, it->varname, UI_VAR_INTEGER); |
|
139 if(var) { |
|
140 UiInteger *value = (UiInteger*)var->value; |
|
141 QActionGroup *group = (QActionGroup*)value->obj; |
|
142 if(!group) { |
|
143 group = new QActionGroup(parent); |
|
144 value->obj = group; |
|
145 } |
|
146 group->addAction(action); |
|
147 value->get = ui_actiongroup_get; |
|
148 value->set = ui_actiongroup_set; |
|
149 if(value->value != 0) { |
|
150 ui_actiongroup_set(value, value->value); |
|
151 } |
|
152 } |
|
153 action->var; |
|
154 } |
|
155 |
|
156 void ui_actiongroup_prepare_event(UiEvent *event, UiAction *action) { |
|
157 if(action->var) { |
|
158 UiInteger *value = (UiInteger*)action->var->value; |
|
159 event->eventdata = value; |
|
160 event->intval = value->get(value); |
|
161 } |
|
162 } |
|
163 |
|
164 int64_t ui_actiongroup_get(UiInteger *value) { |
|
165 QActionGroup *group = (QActionGroup*)value->obj; |
|
166 auto actions = group->actions(); |
|
167 int i = 1; |
|
168 foreach(const QAction *action, actions) { |
|
169 if(action->isChecked()) { |
|
170 value->value = i; |
|
171 break; |
|
172 } |
|
173 i++; |
|
174 } |
|
175 return value->value; |
|
176 } |
|
177 |
|
178 void ui_actiongroup_set(UiInteger *value, int64_t i) { |
|
179 QActionGroup *group = (QActionGroup*)value->obj; |
|
180 auto actions = group->actions(); |
|
181 if(i > 0) { |
|
182 if(i-1 < actions.size()) { |
|
183 actions[i]->setEnabled(true); |
|
184 } |
|
185 value->value = i; |
|
186 } else { |
|
187 foreach(QAction *action, actions) { |
|
188 action->setEnabled(false); |
|
189 } |
|
190 value->value = 0; |
|
191 } |
135 } |
192 } |
136 |
193 |
137 void add_menuitem_list_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) { |
194 void add_menuitem_list_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) { |
138 |
195 |
139 } |
196 } |