void WebView::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = new QMenu(this); QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); if (!r.linkUrl().isEmpty()) { menu->addAction(tr("Open in New &Window"), this, SLOT(openLinkInNewWindow())); menu->addAction(tr("Open in New &Tab"), this, SLOT(openLinkInNewTab())); menu->addSeparator(); menu->addAction(tr("Save Lin&k"), this, SLOT(downloadLinkToDisk())); menu->addAction(tr("&Bookmark This Link"), this, SLOT(bookmarkLink()))->setData(r.linkUrl().toString()); menu->addSeparator(); menu->addAction(tr("&Copy Link Location"), this, SLOT(copyLinkToClipboard())); if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) menu->addAction(pageAction(QWebPage::InspectElement)); } if (!r.imageUrl().isEmpty()) { if (!menu->isEmpty()) menu->addSeparator(); menu->addAction(tr("Open Image in New &Window"), this, SLOT(openImageInNewWindow())); menu->addAction(tr("Open Image in New &Tab"), this, SLOT(openImageInNewTab())); menu->addSeparator(); menu->addAction(tr("&Save Image"), this, SLOT(downloadImageToDisk())); menu->addAction(tr("&Copy Image"), this, SLOT(copyImageToClipboard())); menu->addAction(tr("C&opy Image Location"), this, SLOT(copyImageLocationToClipboard()))->setData(r.imageUrl().toString()); } #ifdef WEBKIT_TRUNK // i.e. Qt 4.5, but not in Qt 4.5 yet if (menu->isEmpty()) menu = page()->createStandardContextMenu(); #endif if (!menu->isEmpty()) { if (m_page->mainWindow()->menuBar()->isHidden()) { menu->addSeparator(); menu->addAction(m_page->mainWindow()->showMenuBarAction()); } menu->exec(mapToGlobal(event->pos())); delete menu; return; } delete menu; QWebView::contextMenuEvent(event); }
void WebView::contextMenuEvent(QContextMenuEvent *event) { QMenu menu(this); QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); if (!r.linkUrl().isEmpty()) { menu.addAction(tr("Open in New &Window"), this, SLOT(openLinkInNewWindow())); menu.addAction(tr("Open in New &Tab"), this, SLOT(openLinkInNewTab())); menu.addSeparator(); menu.addAction(tr("Save Lin&k"), this, SLOT(downloadLinkToDisk())); menu.addAction(tr("&Bookmark This Link"), this, SLOT(bookmarkLink()))->setData(r.linkUrl().toString()); menu.addSeparator(); menu.addAction(tr("&Copy Link Location"), this, SLOT(copyLinkToClipboard())); if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) menu.addAction(pageAction(QWebPage::InspectElement)); } if (!r.imageUrl().isEmpty()) { if (!menu.isEmpty()) menu.addSeparator(); menu.addAction(tr("Open Image in New &Window"), this, SLOT(openImageInNewWindow())); menu.addAction(tr("Open Image in New &Tab"), this, SLOT(openImageInNewTab())); menu.addSeparator(); menu.addAction(tr("&Save Image"), this, SLOT(downloadImageToDisk())); menu.addAction(tr("&Copy Image"), this, SLOT(copyImageToClipboard())); menu.addAction(tr("C&opy Image Location"), this, SLOT(copyImageLocationToClipboard()))->setData(r.imageUrl().toString()); } if (!menu.isEmpty()) { menu.exec(mapToGlobal(event->pos())); return; } QWebView::contextMenuEvent(event); }
void WebView::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = new QMenu(this); QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); if (!r.linkUrl().isEmpty()) { QAction *newWindowAction = menu->addAction(tr("Open in New &Window"), this, SLOT(openActionUrlInNewWindow())); newWindowAction->setData(r.linkUrl()); QAction *newTabAction = menu->addAction(tr("Open in New &Tab"), this, SLOT(openActionUrlInNewTab())); newTabAction->setData(r.linkUrl()); menu->addSeparator(); menu->addAction(tr("Save Lin&k"), this, SLOT(downloadLinkToDisk())); menu->addAction(tr("&Bookmark This Link"), this, SLOT(bookmarkLink()))->setData(r.linkUrl()); menu->addSeparator(); if (!page()->selectedText().isEmpty()) menu->addAction(pageAction(QWebPage::Copy)); menu->addAction(tr("&Copy Link Location"), this, SLOT(copyLinkToClipboard())); } if (!r.imageUrl().isEmpty()) { if (!menu->isEmpty()) menu->addSeparator(); QAction *newWindowAction = menu->addAction(tr("Open Image in New &Window"), this, SLOT(openActionUrlInNewWindow())); newWindowAction->setData(r.imageUrl()); QAction *newTabAction = menu->addAction(tr("Open Image in New &Tab"), this, SLOT(openActionUrlInNewTab())); newTabAction->setData(r.imageUrl()); menu->addSeparator(); menu->addAction(tr("&Save Image"), this, SLOT(downloadImageToDisk())); menu->addAction(tr("&Copy Image"), this, SLOT(copyImageToClipboard())); menu->addAction(tr("C&opy Image Location"), this, SLOT(copyImageLocationToClipboard()))->setData(r.imageUrl().toString()); menu->addSeparator(); menu->addAction(tr("Block Image"), this, SLOT(blockImage()))->setData(r.imageUrl().toString()); } if (!page()->selectedText().isEmpty()) { if (menu->isEmpty()) { menu->addAction(pageAction(QWebPage::Copy)); } else { menu->addSeparator(); } QMenu *searchMenu = menu->addMenu(tr("Search with...")); QList<QString> list = ToolbarSearch::openSearchManager()->allEnginesNames(); for (int i = 0; i < list.count(); ++i) { QString name = list.at(i); OpenSearchEngine *engine = ToolbarSearch::openSearchManager()->engine(name); QAction *action = new OpenSearchEngineAction(engine, searchMenu); searchMenu->addAction(action); action->setData(name); } connect(searchMenu, SIGNAL(triggered(QAction *)), this, SLOT(searchRequested(QAction *))); } QWebElement element = r.element(); if (!element.isNull() && element.tagName().toLower() == QLatin1String("input") && element.attribute(QLatin1String("type"), QLatin1String("text")) == QLatin1String("text")) { if (menu->isEmpty()) { menu->addAction(pageAction(QWebPage::Copy)); } else { menu->addSeparator(); } QVariant variant; variant.setValue(element); menu->addAction(tr("Add to the toolbar search"), this, SLOT(addSearchEngine()))->setData(variant); } if (menu->isEmpty()) { delete menu; menu = page()->createStandardContextMenu(); } else { if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) menu->addAction(pageAction(QWebPage::InspectElement)); } if (!menu->isEmpty()) { if (BrowserMainWindow::parentWindow(tabWidget())->menuBar()->isHidden()) { menu->addSeparator(); menu->addAction(BrowserMainWindow::parentWindow(tabWidget())->showMenuBarAction()); } menu->exec(mapToGlobal(event->pos())); delete menu; return; } delete menu; QWebView::contextMenuEvent(event); }