void MainWindow::on_all_table_customContextMenuRequested(const QPoint &pos) { QModelIndex index = ui->all_table->indexAt(pos); if(!index.isValid()) return; book_name = ui->all_table->selectedItems()[0]->text().toStdString(); selected_row = ui->all_table->selectedItems()[0]; QMenu* menu = new QMenu(this); QAction* action = 0; if(DB::db()->user()->get_library()->is_in_library(book_name)) { cerr << "1" << endl; if(!DB::db()->user()->get_library()->is_in_starred(book_name)) { action = new QAction("Like this", this); menu->addAction(action); connect(action,SIGNAL(triggered()),this,SLOT(like())); } vector<Shelf*> shelves = DB::db()->user()->get_library()->get_shelves(); int count = 0; for(int i = 0; i < shelves.size(); i++) { if(shelves[i]->get_name() == "default") continue; if(shelves[i]->has_book(book_name)) continue; count++; } if(count > 0) { action = new QAction("Add to Shelf", this); menu->addAction(action); connect(action,SIGNAL(triggered()),this,SLOT(add_to_shelf())); } } else { action = new QAction("Add To Library",this); menu->addAction(action); connect(action,SIGNAL(triggered()),this,SLOT(add_to_library())); } menu->popup(ui->all_table->viewport()->mapToGlobal(pos)); }
//----------------------------------------------------------------------------- void qtSqueezedLabel::contextMenuEvent(QContextMenuEvent* e) { if (this->contextMenuPolicy() == Qt::DefaultContextMenu) { QMenu* menu = new QMenu(this); menu->setAttribute(Qt::WA_DeleteOnClose); QAction* action = menu->addAction("&Copy Full Text"); action->setEnabled(!this->fullText().isEmpty()); connect(action, SIGNAL(triggered()), this, SLOT(copy())); menu->popup(e->globalPos()); e->accept(); return; } QLabel::contextMenuEvent(e); }
void QgsBrowserDockWidget::showContextMenu( const QPoint & pt ) { QModelIndex idx = mBrowserView->indexAt( pt ); QgsDataItem* item = mModel->dataItem( idx ); if ( !item ) return; QMenu* menu = new QMenu( this ); if ( item->type() == QgsDataItem::Directory ) { QSettings settings; QStringList favDirs = settings.value( "/browser/favourites" ).toStringList(); bool inFavDirs = favDirs.contains( item->path() ); if ( item->parent() != NULL && !inFavDirs ) { // only non-root directories can be added as favourites menu->addAction( tr( "Add as a favourite" ), this, SLOT( addFavourite() ) ); } else if ( inFavDirs ) { // only favourites can be removed menu->addAction( tr( "Remove favourite" ), this, SLOT( removeFavourite() ) ); } } QList<QAction*> actions = item->actions(); if ( !actions.isEmpty() ) { if ( !menu->actions().isEmpty() ) menu->addSeparator(); // add action to the menu menu->addActions( actions ); } if ( menu->actions().count() == 0 ) { delete menu; return; } menu->popup( mBrowserView->mapToGlobal( pt ) ); }
void WorkspaceWidget::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::RightButton) { Ogre::LogManager::getSingleton().logMessage("Right mouse button clicked."); QPoint cursorPos = event->pos(); QTreeWidgetItem *selItem = this->itemAt(cursorPos); if(selItem) { QString itemType = selItem->text(1); Ogre::LogManager::getSingleton().logMessage("Item type: " + itemType.toStdString()); } QMenu *contextMenu = new QMenu(this); contextMenu->addAction(actionNewMaterial); contextMenu->popup(QWidget::mapToGlobal(cursorPos)); return; } QTreeWidget::mousePressEvent(event); }
void MembersDialog::listContextMenu( const QPoint& pos ) { QModelIndex index = m_list->indexAt( pos ); if ( index.isValid() ) { m_list->selectionModel()->setCurrentIndex( index, QItemSelectionModel::Current ); m_list->selectionModel()->select( index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows ); } QString menuName; if ( index.isValid() ) menuName = "menuMember"; else menuName = "menuNull"; QMenu* menu = builder()->contextMenu( menuName ); if ( menu ) menu->popup( m_list->viewport()->mapToGlobal( pos ) ); }
void ListView::showPopup(QTreeWidgetItem *item, QPoint p) { if (item == NULL) return; ProcessMenuParam *mp = getMenu(item); if (mp == NULL) return; if (p.isNull()){ QRect rc = visualItemRect(item); p = QPoint(rc.x() + rc.width() / 2, rc.y() + rc.height() / 2); p = viewport()->mapToGlobal(p); } mp->key = 0; Event eMenu(EventProcessMenu, mp); QMenu *menu = (QMenu*)eMenu.process(); if (menu){ setCurrentItem(item); menu->popup(p); } }
void tst_QMenu::widgetActionFocus() { //test if the focus is correctly handled with a QWidgetAction QMenu m; QListWidget *l = new QListWidget(&m); for (int i = 1; i<3 ; i++) l->addItem(QString("item%1").arg(i)); QWidgetAction *wa = new QWidgetAction(&m); wa->setDefaultWidget(l); m.addAction(wa); m.setActiveAction(wa); l->setFocus(); //to ensure it has primarily the focus QAction *menuitem1=m.addAction("menuitem1"); QAction *menuitem2=m.addAction("menuitem2"); m.popup(QPoint()); QVERIFY(m.isVisible()); QVERIFY(l->hasFocus()); QVERIFY(l->currentItem()); QCOMPARE(l->currentItem()->text(), QString("item1")); QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down); QVERIFY(l->currentItem()); QCOMPARE(l->currentItem()->text(), QString("item2")); QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down); QVERIFY(m.hasFocus()); QCOMPARE(m.activeAction(), menuitem1); QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down); QVERIFY(m.hasFocus()); QCOMPARE(m.activeAction(), menuitem2); QTest::keyClick(QApplication::focusWidget(), Qt::Key_Up); QVERIFY(m.hasFocus()); QCOMPARE(m.activeAction(), menuitem1); QTest::keyClick(QApplication::focusWidget(), Qt::Key_Up); QVERIFY(l->hasFocus()); QCOMPARE(m.activeAction(), (QAction *)wa); }
/** * @brief Shows a popup menu with actions related to the selected item. * @param event The event to handle. */ void DialogsTreeView::contextMenuEvent(QContextMenuEvent *event) { if (model == nullptr) { return; } QMenu* menu = new QMenu(this); menu->addAction(create_action); QString id = model->get_selected_id(); if (model->prefix_exists(id)) { menu->addSeparator(); menu->addAction(set_id_action); menu->addAction(duplicate_action); menu->addSeparator(); menu->addAction(delete_action); } menu->popup(viewport()->mapToGlobal(event->pos()) + QPoint(1, 1)); }
/*!\reimp */ void QLabel::contextMenuEvent(QContextMenuEvent *ev) { #ifdef QT_NO_CONTEXTMENU Q_UNUSED(ev); #else Q_D(QLabel); if (!d->isTextLabel) { ev->ignore(); return; } QMenu *menu = d->createStandardContextMenu(ev->pos()); if (!menu) { ev->ignore(); return; } ev->accept(); menu->setAttribute(Qt::WA_DeleteOnClose); menu->popup(ev->globalPos()); #endif }
void ListView::contextMenuEvent(QContextMenuEvent* e) { unsigned long id; void *param; ListViewItem* item = itemAt(e->pos()); if (item == NULL) return; if (!getMenu(item, id, param)) return; EventMenuProcess eMenu(id, param); eMenu.process(); QMenu *menu = eMenu.menu(); if (menu) { setCurrentItem(item); menu->popup(e->globalPos()); } }
void ResourcesBrowser::showBookmarksPopupMenu( const QPoint& pos ) { QListWidgetItem* clickedItem = m_bookmarks->itemAt( pos ); if ( !clickedItem ) { // no item was clicked - ignore return; } // create the menu QMenu* popupMenu = new QMenu( this ); { QAction* removeBookmarkAction = new RemoveBookmarkAction( QIcon( m_iconsDir + "removeBookmark.png" ), "Remove", this, m_bookmarks, clickedItem ); connect( removeBookmarkAction, SIGNAL( triggered() ), this, SLOT( removeBookmark() ) ); popupMenu->addAction( removeBookmarkAction ); } // display the menu popupMenu->popup( mapToGlobal( pos ) ); }
void ResTable::createPopupMenu(const QPoint& pos) { LOGDEB(("ResTable::createPopupMenu: m_detaildocnum %d\n", m_detaildocnum)); if (m_detaildocnum >= 0 && m_model) { int opts = m_ismainres? ResultPopup::isMain : 0; int selsz = tableView->selectionModel()->selectedRows().size(); if (selsz == 1) { opts |= ResultPopup::showSaveOne; } else if (selsz > 1 && !m_ismainres) { // We don't show save multiple for the main list because not all // docs are necessary subdocs and multisave only works with those. opts |= ResultPopup::showSaveSel; } QMenu *popup = ResultPopup::create(this, opts, m_model->getDocSource(), m_detaildoc); popup->popup(mapToGlobal(pos)); } }
void Path_button::directory_ready(File_info_list files) { if (!menu_pending) return; QMenu* menu = new QMenu(); if (go_parent_visible) { menu->addAction("Go to parent", this, SLOT(action_go_parent_triggered())); menu->addSeparator(); } foreach(File_info i, files) { if (i.is_folder()) { QAction* a = menu->addAction(i.name, this, SLOT(menu_action_triggered())); if (i.uri == uri) { a->setEnabled(false); } a->setData(i.uri); menu->addAction(a); } } menu->popup(menu_point); menu_pending = false; }
/** * @brief Shows a popup menu with actions related to the selected item. * @param event The event to handle. */ void SpriteTreeView::contextMenuEvent(QContextMenuEvent *event) { if (model == nullptr) { return; } QMenu* menu = new QMenu(this); menu->addAction(create_animation_action); SpriteModel::Index index = model->get_selected_index(); if (index.is_valid()) { menu->addAction(create_direction_action); menu->addSeparator(); menu->addAction(rename_animation_action); menu->addAction(duplicate_action); menu->addSeparator(); menu->addAction(delete_action); } menu->popup(viewport()->mapToGlobal(event->pos()) + QPoint(1, 1)); }
void USBLinkTreeWidget::customContextMenuRequested(QPoint pos) { QMenu *menu = new QMenu(this); QAction *action_delete = new QAction(tr("Delete"), menu); context_menu_item = this->itemAt(pos); if(context_menu_item == nullptr || context_menu_item->data(0, Qt::UserRole).toBool() == true) { // Is a directory QWidgetAction *action_new_folder = new QWidgetAction(menu); QLineEdit *line_new_folder = new QLineEdit(nullptr); line_new_folder->setPlaceholderText(tr("New folder")); action_new_folder->setDefaultWidget(line_new_folder); connect(line_new_folder, &QLineEdit::returnPressed, this, &USBLinkTreeWidget::newFolder); // FIXME: Can this delete line_new_folder while in use by newFolder? connect(line_new_folder, &QLineEdit::returnPressed, menu, &QMenu::close); menu->addAction(action_new_folder); if(context_menu_item == nullptr || context_menu_item->childCount() > 0) { // Non-empty directory action_delete->setDisabled(true); } } else { // Is not a directory QAction *action_download = new QAction(tr("Download"), menu); connect(action_download, &QAction::triggered, this, &USBLinkTreeWidget::downloadEntry); menu->addAction(action_download); } connect(action_delete, &QAction::triggered, this, &USBLinkTreeWidget::deleteEntry); menu->addAction(action_delete); menu->popup(this->viewport()->mapToGlobal(pos)); }
void ProjectTree::showContextMenu(ProjectTreeWidget *focus, const QPoint &globalPos, Node *node) { QMenu *contextMenu = nullptr; Project *project = projectForNode(node); emit s_instance->aboutToShowContextMenu(project, node); if (!node) { contextMenu = Core::ActionManager::actionContainer(Constants::M_SESSIONCONTEXT)->menu(); } else { switch (node->nodeType()) { case NodeType::Project: { if ((node->parentFolderNode() && node->parentFolderNode()->asContainerNode()) || node->asContainerNode()) contextMenu = Core::ActionManager::actionContainer(Constants::M_PROJECTCONTEXT)->menu(); else contextMenu = Core::ActionManager::actionContainer(Constants::M_SUBPROJECTCONTEXT)->menu(); break; } case NodeType::VirtualFolder: case NodeType::Folder: contextMenu = Core::ActionManager::actionContainer(Constants::M_FOLDERCONTEXT)->menu(); break; case NodeType::File: contextMenu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT)->menu(); break; default: qWarning("ProjectExplorerPlugin::showContextMenu - Missing handler for node type"); } } if (contextMenu && contextMenu->actions().count() > 0) { contextMenu->popup(globalPos); s_instance->m_focusForContextMenu = focus; connect(contextMenu, &QMenu::aboutToHide, s_instance, &ProjectTree::hideContextMenu, Qt::ConnectionType(Qt::UniqueConnection | Qt::QueuedConnection)); } }
void ListView::showPopup(ListViewItem *item, QPoint p) { unsigned long id; void *param; if (item == NULL) return; if (!getMenu(item, id, param)) return; if (p.isNull()){ QRect rc = visualItemRect(item); p = QPoint(rc.x() + rc.width() / 2, rc.y() + rc.height() / 2); p = viewport()->mapToGlobal(p); } EventMenuProcess eMenu(id, param); eMenu.process(); QMenu *menu = eMenu.menu(); if (menu){ setCurrentItem(item); menu->popup(p); } }
void FileSystemWidget::treeViewContextMenuRequested(const QPoint &pos) { QModelIndex index = m_tree->indexAt(pos); if (!index.isValid()) { return; } FileNode *node = m_model->nodeFromIndex(index); if (!node) { return; } m_contextInfo = node->fileInfo(); m_contextIndex = index; QMenu *contextMenu = 0; if (node->isDir()) { contextMenu = m_folderMenu; } else { contextMenu = m_fileMenu; } if (contextMenu && contextMenu->actions().count() > 0) { contextMenu->popup(m_tree->mapToGlobal(pos)); } }
void WebSearchBar::contextMenuEvent(QContextMenuEvent* event) { Q_UNUSED(event) QMenu* menu = createContextMenu(); menu->setAttribute(Qt::WA_DeleteOnClose); menu->addSeparator(); QAction* act = menu->addAction(tr("Show suggestions")); act->setCheckable(true); act->setChecked(qzSettings->showSearchSuggestions); connect(act, SIGNAL(triggered(bool)), this, SLOT(enableSearchSuggestions(bool))); QAction* instantSearch = menu->addAction(tr("Search when engine changed")); instantSearch->setCheckable(true); instantSearch->setChecked(qzSettings->searchOnEngineChange); connect(instantSearch, SIGNAL(triggered(bool)), this, SLOT(instantSearchChanged(bool))); // Prevent choosing first option with double rightclick QPoint pos = event->globalPos(); pos.setY(pos.y() + 1); menu->popup(pos); }
void MyQComboBox::showPopup() { QRect desk = popupGeometry(QApplication::desktop()->screenNumber(this)); QPoint popupPoint = mapToGlobal(QPoint(0, 0)); const int dateFrameHeight = _menu->sizeHint().height(); if (popupPoint.y() + height() + dateFrameHeight > desk.bottom()) { popupPoint.setY(popupPoint.y() - dateFrameHeight); } else { popupPoint.setY(popupPoint.y() + height()); } const int dateFrameWidth = _menu->sizeHint().width(); if (popupPoint.x() + dateFrameWidth > desk.right()) { popupPoint.setX(desk.right() - dateFrameWidth); } if (popupPoint.x() < desk.left()) { popupPoint.setX(desk.left()); } if (popupPoint.y() < desk.top()) { popupPoint.setY(desk.top()); } _menu->popup(popupPoint); }
void ResTable::createHeaderPopupMenu(const QPoint& pos) { LOGDEB(("ResTable::createHeaderPopupMenu(%d, %d)\n", pos.x(), pos.y())); QHeaderView *header = tableView->horizontalHeader(); if (!header || !m_model) return; m_popcolumn = header->logicalIndexAt(pos); if (m_popcolumn < 0) return; const map<string, QString>& allfields = m_model->getAllFields(); const vector<string>& fields = m_model->getFields(); QMenu *popup = new QMenu(this); popup->addAction(tr("&Reset sort"), this, SLOT(resetSort())); popup->addSeparator(); popup->addAction(tr("&Save as CSV"), this, SLOT(saveAsCSV())); popup->addSeparator(); popup->addAction(tr("&Delete column"), this, SLOT(deleteColumn())); popup->addSeparator(); QAction *act; for (map<string, QString>::const_iterator it = allfields.begin(); it != allfields.end(); it++) { if (std::find(fields.begin(), fields.end(), it->first) != fields.end()) continue; act = new QAction(tr("Add \"%1\" column").arg(it->second), popup); act->setData(QString::fromUtf8(it->first.c_str())); connect(act, SIGNAL(triggered(bool)), this , SLOT(addColumn())); popup->addAction(act); } popup->popup(mapToGlobal(pos)); }
void QtSE::fsProjectTreeContextMenu( QPoint point ) { activeProjectItem = (CProjectTreeItem*)fsProjectTree->itemAt( point ); if( activeProjectItem ) { QMenu *menu = new QMenu(); menu->setAttribute( Qt::WA_DeleteOnClose , true ); switch( activeProjectItem->getPartType() ) { case CProjectTreeItem::dir: { //activeFilePath.clear(); //activeProjectItem->getRelativePath( activeFilePath ); //activeFilePath.prepend( projectPath.getPath( true ) ); menu->addAction( "Add Folder" , this , SLOT(addFolder()) ); menu->addSeparator(); menu->addAction( "Add Stage" , this , SLOT(addStage()) ); menu->addAction( "Add Framebuffer" , this , SLOT(addFramebuffer()) ); menu->addAction( "Add Shader" , this , SLOT(addShader()) ); menu->addAction( "Add Model" , this , SLOT(addModel()) ); menu->addAction( "Add Texture" , this , SLOT(addTexture()) ); menu->addSeparator(); menu->addAction( "Delete Folder" , this , SLOT(deleteItem()) ); break; } default: delete menu; return; } menu->popup( QCursor::pos() , NULL ); } }
void DataWindow::customContextMenuRequested(QPoint pos) { //obtain index where index was clicked //QModelIndex index = m_pRawTableView->indexAt(pos); //get selected items QModelIndexList selected = ui->m_tableView_rawTableView->selectionModel()->selectedIndexes(); //create custom context menu and actions QMenu *menu = new QMenu(this); //**************** Marking **************** QMenu *markingSubMenu = new QMenu("Mark channels",menu); QAction* doMarkChBad = markingSubMenu->addAction(tr("Mark as bad")); connect(doMarkChBad,&QAction::triggered, [=](){ m_pRawModel->markChBad(selected,1); }); QAction* doMarkChGood = markingSubMenu->addAction(tr("Mark as good")); connect(doMarkChGood,&QAction::triggered, [=](){ m_pRawModel->markChBad(selected,0); }); //**************** FilterOperators **************** //selected channels QMenu *filtOpSubMenu = new QMenu("Apply FilterOperator to selected channel",menu); QMutableMapIterator<QString,QSharedPointer<MNEOperator> > it(m_pRawModel->m_Operators); while(it.hasNext()) { it.next(); QAction* doApplyFilter = filtOpSubMenu->addAction(tr("%1").arg(it.key())); connect(doApplyFilter,&QAction::triggered, [=](){ m_pRawModel->applyOperator(selected,it.value()); }); } //all channels QMenu *filtOpAllSubMenu = new QMenu("Apply FilterOperator to all channels",menu); it.toFront(); while(it.hasNext()) { it.next(); QAction* doApplyFilter = filtOpAllSubMenu->addAction(tr("%1").arg(it.key())); connect(doApplyFilter,&QAction::triggered, [=](){ m_pRawModel->applyOperator(QModelIndexList(),it.value()); }); } //undoing filtering QMenu *undoFiltOpSubMenu = new QMenu("Undo filtering",menu); QMenu *undoFiltOpSelSubMenu = new QMenu("to selected channels",undoFiltOpSubMenu); //undo certain FilterOperators to selected channels it.toFront(); while(it.hasNext()) { it.next(); QAction* undoApplyFilter = undoFiltOpSelSubMenu->addAction(tr("%1").arg(it.key())); connect(undoApplyFilter,&QAction::triggered, [=](){ m_pRawModel->undoFilter(selected,it.value()); }); } undoFiltOpSubMenu->addMenu(undoFiltOpSelSubMenu); //undo all filterting to selected channels QAction* undoApplyFilterSel = undoFiltOpSubMenu->addAction(tr("Undo FilterOperators to selected channels")); connect(undoApplyFilterSel,&QAction::triggered, [=](){ m_pRawModel->undoFilter(selected); }); //undo all filtering to all channels QAction* undoApplyFilterAll = undoFiltOpSubMenu->addAction(tr("Undo FilterOperators to all channels")); connect(undoApplyFilterAll,&QAction::triggered, [=](){ m_pRawModel->undoFilter(); }); //add everything to main contextmenu menu->addMenu(markingSubMenu); menu->addMenu(filtOpSubMenu); menu->addMenu(filtOpAllSubMenu); menu->addMenu(undoFiltOpSubMenu); //show context menu menu->popup(ui->m_tableView_rawTableView->viewport()->mapToGlobal(pos)); }
void Tray::onActivated() { QMenu * menu = new WindowMenu(&d->mNmModel); menu->setAttribute(Qt::WA_DeleteOnClose); menu->popup(QCursor::pos()); }
void PlacesView::contextMenuEvent(QContextMenuEvent* event) { QModelIndex index = indexAt(event->pos()); if(index.isValid() && index.parent().isValid()) { if(index.column() != 0) // the real item is at column 0 index = index.sibling(index.row(), 0); // Do not take the ownership of the menu since // it will be deleted with deleteLater() upon hidden. // This is possibly related to #145 - https://github.com/lxde/pcmanfm-qt/issues/145 QMenu* menu = new QMenu(); QAction* action; PlacesModelItem* item = static_cast<PlacesModelItem*>(model_->itemFromIndex(index)); if(item->type() != PlacesModelItem::Mount && (item->type() != PlacesModelItem::Volume || static_cast<PlacesModelVolumeItem*>(item)->isMounted())) { action = new PlacesModel::ItemAction(item->index(), tr("Open in New Tab"), menu); connect(action, &QAction::triggered, this, &PlacesView::onOpenNewTab); menu->addAction(action); action = new PlacesModel::ItemAction(item->index(), tr("Open in New Window"), menu); connect(action, &QAction::triggered, this, &PlacesView::onOpenNewWindow); menu->addAction(action); } switch(item->type()) { case PlacesModelItem::Places: { FmPath* path = item->path(); if(path && fm_path_equal(fm_path_get_trash(), path)) { action = new PlacesModel::ItemAction(item->index(), tr("Empty Trash"), menu); connect(action, &QAction::triggered, this, &PlacesView::onEmptyTrash); menu->addAction(action); } break; } case PlacesModelItem::Bookmark: { // create context menu for bookmark item if(item->index().row() > 0) { action = new PlacesModel::ItemAction(item->index(), tr("Move Bookmark Up"), menu); connect(action, &QAction::triggered, this, &PlacesView::onMoveBookmarkUp); menu->addAction(action); } if(item->index().row() < model_->rowCount()) { action = new PlacesModel::ItemAction(item->index(), tr("Move Bookmark Down"), menu); connect(action, &QAction::triggered, this, &PlacesView::onMoveBookmarkDown); menu->addAction(action); } action = new PlacesModel::ItemAction(item->index(), tr("Rename Bookmark"), menu); connect(action, &QAction::triggered, this, &PlacesView::onRenameBookmark); menu->addAction(action); action = new PlacesModel::ItemAction(item->index(), tr("Remove Bookmark"), menu); connect(action, &QAction::triggered, this, &PlacesView::onDeleteBookmark); menu->addAction(action); break; } case PlacesModelItem::Volume: { PlacesModelVolumeItem* volumeItem = static_cast<PlacesModelVolumeItem*>(item); if(volumeItem->isMounted()) { action = new PlacesModel::ItemAction(item->index(), tr("Unmount"), menu); connect(action, &QAction::triggered, this, &PlacesView::onUnmountVolume); } else { action = new PlacesModel::ItemAction(item->index(), tr("Mount"), menu); connect(action, &QAction::triggered, this, &PlacesView::onMountVolume); } menu->addAction(action); if(volumeItem->canEject()) { action = new PlacesModel::ItemAction(item->index(), tr("Eject"), menu); connect(action, &QAction::triggered, this, &PlacesView::onEjectVolume); menu->addAction(action); } break; } case PlacesModelItem::Mount: { action = new PlacesModel::ItemAction(item->index(), tr("Unmount"), menu); connect(action, &QAction::triggered, this, &PlacesView::onUnmountMount); menu->addAction(action); break; } } if(menu->actions().size()) { menu->popup(mapToGlobal(event->pos())); connect(menu, &QMenu::aboutToHide, menu, &QMenu::deleteLater); } else { menu->deleteLater(); } } }
void ListView::headerContextMenu( const QPoint& pos ) { QMenu* menu = builder()->contextMenu( "menuHeader" ); if ( menu ) menu->popup( m_list->header()->mapToGlobal( pos ) ); }
void QgsWelcomePage::showContextMenuForProjects( QPoint point ) { QModelIndex index = mRecentProjectsListView->indexAt( point ); if ( !index.isValid() ) return; bool pin = mModel->data( index, QgsWelcomePageItemsModel::PinRole ).toBool(); QString path = mModel->data( index, QgsWelcomePageItemsModel::PathRole ).toString(); if ( path.isEmpty() ) return; bool enabled = mModel->flags( index ) & Qt::ItemIsEnabled; QMenu *menu = new QMenu( this ); if ( enabled ) { if ( !pin ) { QAction *pinAction = new QAction( tr( "Pin to List" ), menu ); connect( pinAction, &QAction::triggered, this, [this, index] { mModel->pinProject( index ); emit projectPinned( index.row() ); } ); menu->addAction( pinAction ); } else { QAction *pinAction = new QAction( tr( "Unpin from List" ), menu ); connect( pinAction, &QAction::triggered, this, [this, index] { mModel->unpinProject( index ); emit projectUnpinned( index.row() ); } ); menu->addAction( pinAction ); } QAction *openFolderAction = new QAction( tr( "Open Directory…" ), menu ); connect( openFolderAction, &QAction::triggered, this, [path] { QFileInfo fi( path ); QString folder = fi.path(); QDesktopServices::openUrl( QUrl::fromLocalFile( folder ) ); } ); menu->addAction( openFolderAction ); } else { QAction *rescanAction = new QAction( tr( "Refresh" ), menu ); connect( rescanAction, &QAction::triggered, this, [this, index] { mModel->recheckProject( index ); } ); menu->addAction( rescanAction ); } QAction *removeProjectAction = new QAction( tr( "Remove from List" ), menu ); connect( removeProjectAction, &QAction::triggered, this, [this, index] { mModel->removeProject( index ); emit projectRemoved( index.row() ); } ); menu->addAction( removeProjectAction ); menu->popup( mapToGlobal( point ) ); }
bool ItemDelegate::eventFilter(QObject *object, QEvent *event) { if (object->objectName() == "editor") { QPlainTextEdit *editor = qobject_cast<QPlainTextEdit*>(object); if (editor == NULL) return false; QEvent::Type type = event->type(); if ( type == QEvent::KeyPress ) { QKeyEvent *keyevent = static_cast<QKeyEvent *>(event); switch ( keyevent->key() ) { case Qt::Key_Enter: case Qt::Key_Return: // Commit data on Ctrl+Return or Enter? if (m_saveOnReturnKey) { if (keyevent->modifiers() == Qt::ControlModifier) { editor->insertPlainText("\n"); return true; } else if (keyevent->modifiers() != Qt::NoModifier) { return false; } } else { if (keyevent->modifiers() != Qt::ControlModifier) return false; } emit commitData(editor); emit closeEditor(editor); return true; case Qt::Key_S: // Commit data on Ctrl+S. if (keyevent->modifiers() != Qt::ControlModifier) return false; emit commitData(editor); emit closeEditor(editor); return true; case Qt::Key_F2: // Commit data on F2. emit commitData(editor); emit closeEditor(editor); return true; case Qt::Key_Escape: // Close editor without committing data. emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache); return true; default: return false; } } else if ( type == QEvent::ContextMenu ) { QAction *act; QMenu *menu = editor->createStandardContextMenu(); connect( menu, SIGNAL(aboutToHide()), menu, SLOT(deleteLater()) ); menu->setParent(editor); act = menu->addAction( tr("&Save Item") ); act->setShortcut( QKeySequence(tr("F2, Ctrl+Enter")) ); connect( act, SIGNAL(triggered()), this, SLOT(editorSave()) ); act = menu->addAction( tr("Cancel Editing") ); act->setShortcut( QKeySequence(tr("Escape")) ); connect( act, SIGNAL(triggered()), this, SLOT(editorCancel()) ); QContextMenuEvent *menuEvent = static_cast<QContextMenuEvent *>(event); menu->popup( menuEvent->globalPos() ); } } else { // resize event for items if (event->type() == QEvent::Resize) { QResizeEvent *resize = static_cast<QResizeEvent *>(event); ItemWidget *item = dynamic_cast<ItemWidget *>(object); if (item != NULL) { item->widget()->resize(resize->size()); onItemChanged(item); return true; } } } return false; }
void QgsWelcomePage::showContextMenuForProjects( QPoint point ) { QModelIndex index = mRecentProjectsListView->indexAt( point ); if ( !index.isValid() ) return; bool pin = mModel->data( index, QgsWelcomePageItemsModel::PinRole ).toBool(); QString path = mModel->data( index, QgsWelcomePageItemsModel::PathRole ).toString(); if ( path.isEmpty() ) return; bool enabled = mModel->flags( index ) & Qt::ItemIsEnabled; QMenu *menu = new QMenu( this ); if ( enabled ) { if ( !pin ) { QAction *pinAction = new QAction( tr( "Pin to List" ), menu ); connect( pinAction, &QAction::triggered, this, [this, index] { mModel->pinProject( index ); emit projectPinned( index.row() ); } ); menu->addAction( pinAction ); } else { QAction *pinAction = new QAction( tr( "Unpin from List" ), menu ); connect( pinAction, &QAction::triggered, this, [this, index] { mModel->unpinProject( index ); emit projectUnpinned( index.row() ); } ); menu->addAction( pinAction ); } QAction *openFolderAction = new QAction( tr( "Open Directory…" ), menu ); connect( openFolderAction, &QAction::triggered, this, [path] { QgsGui::instance()->nativePlatformInterface()->openFileExplorerAndSelectFile( path ); } ); menu->addAction( openFolderAction ); } else { QAction *rescanAction = new QAction( tr( "Refresh" ), menu ); connect( rescanAction, &QAction::triggered, this, [this, index] { mModel->recheckProject( index ); } ); menu->addAction( rescanAction ); // add an entry to open the closest existing path to the original project file location // to help users re-find moved/renamed projects! const QString closestPath = QgsFileUtils::findClosestExistingPath( path ); QAction *openFolderAction = new QAction( tr( "Open “%1”…" ).arg( QDir::toNativeSeparators( closestPath ) ), menu ); connect( openFolderAction, &QAction::triggered, this, [closestPath] { QDesktopServices::openUrl( QUrl::fromLocalFile( closestPath ) ); } ); menu->addAction( openFolderAction ); } QAction *removeProjectAction = new QAction( tr( "Remove from List" ), menu ); connect( removeProjectAction, &QAction::triggered, this, [this, index] { mModel->removeProject( index ); emit projectRemoved( index.row() ); } ); menu->addAction( removeProjectAction ); menu->popup( mapToGlobal( point ) ); }
void QMenuProto::popup(const QPoint &p, QAction *atAction) { QMenu *item = qscriptvalue_cast<QMenu*>(thisObject()); if (item) item->popup(p, atAction); }