ui/qt/menu.cpp

changeset 1109
1dd32226aa9f
parent 989
cd1ccc0d3d05
equal deleted inserted replaced
1108:2c8ab8c17da7 1109:1dd32226aa9f
69 UiMenu *m = (UiMenu*)item; 69 UiMenu *m = (UiMenu*)item;
70 QMenu *menu = parent->addMenu(m->label); 70 QMenu *menu = parent->addMenu(m->label);
71 add_menu_items(menu, i, m, obj); 71 add_menu_items(menu, i, m, obj);
72 } 72 }
73 73
74 static UiAction* create_action( 74 static UiQAction* create_action(
75 UiObject *obj, 75 UiObject *obj,
76 const char *icon, 76 const char *icon,
77 const char *label, 77 const char *label,
78 ui_callback callback, 78 ui_callback callback,
79 void *userdata, 79 void *userdata,
80 int *states) 80 int *states)
81 { 81 {
82 QString str = QString::fromUtf8(label); 82 QString str = QString::fromUtf8(label);
83 UiAction *action = new UiAction(obj, str, callback, userdata); 83 UiQAction *action = new UiQAction(obj, str, callback, userdata);
84 if(icon) { 84 if(icon) {
85 action->setIcon(QIcon::fromTheme(icon)); 85 action->setIcon(QIcon::fromTheme(icon));
86 action->setIconVisibleInMenu(true); 86 action->setIconVisibleInMenu(true);
87 } 87 }
88 88
95 return action; 95 return action;
96 } 96 }
97 97
98 void add_menuitem_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) { 98 void add_menuitem_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) {
99 UiMenuItem *it = (UiMenuItem*)item; 99 UiMenuItem *it = (UiMenuItem*)item;
100 UiAction *action = create_action(obj, it->icon, it->label, it->callback, it->userdata, it->states); 100 UiQAction *action = create_action(obj, it->icon, it->label, it->callback, it->userdata, it->states);
101 parent->addAction(action); 101 parent->addAction(action);
102 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger())); 102 QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger()));
103 } 103 }
104 104
105 void add_menuseparator_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) { 105 void add_menuseparator_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) {
107 } 107 }
108 108
109 void add_checkitem_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) { 109 void add_checkitem_widget(QMenu *parent, int i, UiMenuItemI *item, UiObject *obj) {
110 UiMenuCheckItem *it = (UiMenuCheckItem*)item; 110 UiMenuCheckItem *it = (UiMenuCheckItem*)item;
111 111
112 UiAction *action = create_action(obj, it->icon, it->label, it->callback, it->userdata, it->states); 112 UiQAction *action = create_action(obj, it->icon, it->label, it->callback, it->userdata, it->states);
113 parent->addAction(action); 113 parent->addAction(action);
114 action->setCheckable(true); 114 action->setCheckable(true);
115 action->prepare_event = ui_checkableaction_prepare_event; 115 action->prepare_event = ui_checkableaction_prepare_event;
116 116
117 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, NULL, it->varname, UI_VAR_INTEGER); 117 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, NULL, it->varname, UI_VAR_INTEGER);
127 } 127 }
128 128
129 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) {
130 UiMenuRadioItem *it = (UiMenuRadioItem*)item; 130 UiMenuRadioItem *it = (UiMenuRadioItem*)item;
131 131
132 UiAction *action = create_action(obj, it->icon, it->label, it->callback, it->userdata, it->states); 132 UiQAction *action = create_action(obj, it->icon, it->label, it->callback, it->userdata, it->states);
133 parent->addAction(action); 133 parent->addAction(action);
134 action->setCheckable(true); 134 action->setCheckable(true);
135 action->prepare_event = ui_actiongroup_prepare_event; 135 action->prepare_event = ui_actiongroup_prepare_event;
136 136
137 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, NULL, it->varname, UI_VAR_INTEGER); 137 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, NULL, it->varname, UI_VAR_INTEGER);
150 } 150 }
151 } 151 }
152 action->var; 152 action->var;
153 } 153 }
154 154
155 void ui_actiongroup_prepare_event(UiEvent *event, UiAction *action) { 155 void ui_actiongroup_prepare_event(UiEvent *event, UiQAction *action) {
156 if(action->var) { 156 if(action->var) {
157 UiInteger *value = (UiInteger*)action->var->value; 157 UiInteger *value = (UiInteger*)action->var->value;
158 event->eventdata = value; 158 event->eventdata = value;
159 event->eventdatatype = UI_EVENT_DATA_INTEGER_VALUE; 159 event->eventdatatype = UI_EVENT_DATA_INTEGER_VALUE;
160 event->intval = value->get(value); 160 event->intval = value->get(value);
212 } 212 }
213 ls = (UiMenu*)ls->item.next; 213 ls = (UiMenu*)ls->item.next;
214 } 214 }
215 } 215 }
216 216
217 void ui_checkableaction_prepare_event(UiEvent *event, UiAction *action) { 217 void ui_checkableaction_prepare_event(UiEvent *event, UiQAction *action) {
218 if(action->var) { 218 if(action->var) {
219 event->eventdata = action->var->value; 219 event->eventdata = action->var->value;
220 event->eventdatatype = UI_EVENT_DATA_INTEGER_VALUE; 220 event->eventdatatype = UI_EVENT_DATA_INTEGER_VALUE;
221 } 221 }
222 event->intval = action->isChecked(); 222 event->intval = action->isChecked();
223 } 223 }
224 224
225 int64_t ui_checkableaction_get(UiInteger *value) { 225 int64_t ui_checkableaction_get(UiInteger *value) {
226 UiAction *action= (UiAction*)value->obj; 226 UiQAction *action= (UiQAction*)value->obj;
227 value->value = action->isChecked(); 227 value->value = action->isChecked();
228 return value->value; 228 return value->value;
229 } 229 }
230 230
231 void ui_checkableaction_set(UiInteger *value, int64_t i) { 231 void ui_checkableaction_set(UiInteger *value, int64_t i) {
232 UiAction *action = (UiAction*)value->obj; 232 UiQAction *action = (UiQAction*)value->obj;
233 value->value = i; 233 value->value = i;
234 if(i != 0) { 234 if(i != 0) {
235 action->setChecked((bool)i); 235 action->setChecked((bool)i);
236 } 236 }
237 } 237 }

mercurial