WWidget *FormWidgets::wPopupMenu() { WContainerWidget *result = new WContainerWidget(); topic("WPopupMenu", "WPopupMenuItem", result); addText(tr("formwidgets-WPopupMenu"), result); WPopupMenu *popup = new WPopupMenu(); popup->setAutoHide(true, 1000); popup->addItem("icons/house.png", "Build a house"); popup->addItem("Roof included")->setCheckable(true); popup->addItem("Add a door")->setDisabled(true); popup->addSeparator(); popup->addItem("Add a window"); WPopupMenu *subMenu = new WPopupMenu(); subMenu->addItem("Add a chair"); subMenu->addItem("Add a table"); popup->addMenu("Add furniture", subMenu); popup->aboutToHide().connect(boost::bind(&FormWidgets::popupAction, this, popup)); WLabel* clickMe = new WLabel("Clicking here will show a popup menu.", result); clickMe->setStyleClass("popupmenuLabel"); clickMe->clicked().connect(popup, &WPopupMenu::popup); return result; }
/*! \brief Show a popup for a folder item. */ void showPopup(const WModelIndex& item, const WMouseEvent& event) { if (event.button() == WMouseEvent::RightButton) { // Select the item, it was not yet selected. if (!folderView_->isSelected(item)) folderView_->select(item); if (!popup_) { popup_ = new WPopupMenu(); popup_->addItem("icons/folder_new.gif", "Create a New Folder"); popup_->addItem("Rename this Folder")->setCheckable(true); popup_->addItem("Delete this Folder"); popup_->addSeparator(); popup_->addItem("Folder Details"); popup_->addSeparator(); popup_->addItem("Application Inventory"); popup_->addItem("Hardware Inventory"); popup_->addSeparator(); WPopupMenu *subMenu = new WPopupMenu(); subMenu->addItem("Sub Item 1"); subMenu->addItem("Sub Item 2"); popup_->addMenu("File Deployments", subMenu); /* * This is one method of executing a popup, which does not block a * thread for a reentrant event loop, and thus scales. * * Alternatively you could call WPopupMenu::exec(), which returns * the result, but while waiting for it, blocks the thread. */ popup_->aboutToHide().connect(this, &TreeViewDragDrop::popupAction); } if (popup_->isHidden()) popup_->popup(event); else popup_->hide(); } }