| 1174 | } |
| 1175 | |
| 1176 | void |
| 1177 | AbstractMenu::build_detached (const std::string &name, QFrame *mbar) |
| 1178 | { |
| 1179 | // Clean up the menu bar before rebuilding |
| 1180 | if (mbar->layout ()) { |
| 1181 | delete mbar->layout (); |
| 1182 | } |
| 1183 | QObjectList children = mbar->children (); |
| 1184 | for (QObjectList::const_iterator c = children.begin (); c != children.end (); ++c) { |
| 1185 | if (dynamic_cast<QToolButton *> (*c)) { |
| 1186 | delete *c; |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | QHBoxLayout *menu_layout = new QHBoxLayout (mbar); |
| 1191 | menu_layout->setContentsMargins (0, 0, 0, 0); |
| 1192 | mbar->setLayout (menu_layout); |
| 1193 | |
| 1194 | AbstractMenuItem *item = find_item_exact ("@@" + name); |
| 1195 | tl_assert (item != 0); |
| 1196 | |
| 1197 | for (std::list<AbstractMenuItem>::iterator c = item->children.begin (); c != item->children.end (); ++c) { |
| 1198 | |
| 1199 | if (c->has_submenu ()) { |
| 1200 | |
| 1201 | QToolButton *menu_button = new QToolButton (mbar); |
| 1202 | menu_layout->addWidget (menu_button); |
| 1203 | menu_button->setAutoRaise (true); |
| 1204 | menu_button->setPopupMode (QToolButton::MenuButtonPopup); |
| 1205 | menu_button->setText (tl::to_qstring (c->action ()->get_title ())); |
| 1206 | |
| 1207 | if (c->menu () == 0) { |
| 1208 | c->set_menu (new QMenu (mp_dispatcher->menu_parent_widget ()), true); |
| 1209 | } |
| 1210 | |
| 1211 | menu_button->setMenu (c->menu ()); |
| 1212 | build (c->menu (), c->children); |
| 1213 | |
| 1214 | } else { |
| 1215 | |
| 1216 | QAction *action = c->action ()->qaction (); |
| 1217 | |
| 1218 | QToolButton *menu_button = new QToolButton (mbar); |
| 1219 | menu_layout->addWidget (menu_button); |
| 1220 | menu_button->setAutoRaise (true); |
| 1221 | menu_button->setDefaultAction (action); |
| 1222 | |
| 1223 | } |
| 1224 | |
| 1225 | } |
| 1226 | |
| 1227 | menu_layout->addStretch (1); |
| 1228 | } |
| 1229 | |
| 1230 | static QAction *insert_action_after (QWidget *widget, QAction *after, QAction *action) |
| 1231 | { |