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 CustomWebView::contextMenuEvent (QGraphicsSceneContextMenuEvent *e) { QPointer<QMenu> menu (new QMenu ()); QWebHitTestResult r = page ()-> mainFrame ()->hitTestContent (e->pos ().toPoint ()); IHookProxy_ptr proxy (new Util::DefaultHookProxy ()); emit hookWebViewContextMenu (proxy, this, e, r, menu, WVSStart); if (!r.linkUrl ().isEmpty ()) { QUrl url = r.linkUrl (); QString text = r.linkText (); if (XmlSettingsManager::Instance ()-> property ("TryToDetectRSSLinks").toBool ()) { bool hasAtom = text.contains ("Atom"); bool hasRSS = text.contains ("RSS"); if (hasAtom || hasRSS) { LeechCraft::Entity e; if (hasAtom) { e.Additional_ ["UserVisibleName"] = "Atom"; e.Mime_ = "application/atom+xml"; } else { e.Additional_ ["UserVisibleName"] = "RSS"; e.Mime_ = "application/rss+xml"; } e.Entity_ = url; e.Parameters_ = LeechCraft::FromUserInitiated | LeechCraft::OnlyHandle; bool ch = false; emit couldHandle (e, &ch); if (ch) { QList<QVariant> datalist; datalist << url << e.Mime_; menu->addAction (tr ("Subscribe"), this, SLOT (subscribeToLink ()))->setData (datalist); menu->addSeparator (); } } } menu->addAction (tr ("Open &here"), this, SLOT (openLinkHere ()))->setData (url); menu->addAction (tr ("Open in new &tab"), this, SLOT (openLinkInNewTab ()))->setData (url); menu->addSeparator (); menu->addAction (tr ("&Save link..."), this, SLOT (saveLink ())); QList<QVariant> datalist; datalist << url << text; menu->addAction (tr ("&Bookmark link..."), this, SLOT (bookmarkLink ()))->setData (datalist); menu->addSeparator (); if (!page ()->selectedText ().isEmpty ()) menu->addAction (pageAction (QWebPage::Copy)); menu->addAction (tr ("&Copy link"), this, SLOT (copyLink ())); if (page ()->settings ()->testAttribute (QWebSettings::DeveloperExtrasEnabled)) menu->addAction (pageAction (QWebPage::InspectElement)); } else if (page ()->selectedText ().contains (UrlInText)) { menu->addAction (tr ("Open as link"), this, SLOT (openLinkInNewTab ()))-> setData (page ()->selectedText ()); } emit hookWebViewContextMenu (proxy, this, e, r, menu, WVSAfterLink); if (!r.imageUrl ().isEmpty ()) { if (!menu->isEmpty ()) menu->addSeparator (); menu->addAction (tr ("Open image here"), this, SLOT (openImageHere ()))->setData (r.imageUrl ()); menu->addAction (tr ("Open image in new tab"), this, SLOT (openImageInNewTab ())); menu->addSeparator (); menu->addAction (tr ("Save image..."), this, SLOT (saveImage ())); QAction *spx = menu->addAction (tr ("Save pixmap..."), this, SLOT (savePixmap ())); spx->setToolTip (tr ("Saves the rendered pixmap without redownloading.")); spx->setProperty ("Poshuku/OrigPX", r.pixmap ()); spx->setProperty ("Poshuku/OrigURL", r.imageUrl ()); menu->addAction (tr ("Copy image"), this, SLOT (copyImage ())); menu->addAction (tr ("Copy image location"), this, SLOT (copyImageLocation ()))->setData (r.imageUrl ()); } emit hookWebViewContextMenu (proxy, this, e, r, menu, WVSAfterImage); bool hasSelected = !page ()->selectedText ().isEmpty (); if (hasSelected) { if (!menu->isEmpty ()) menu->addSeparator (); menu->addAction (pageAction (QWebPage::Copy)); } if (r.isContentEditable ()) menu->addAction (pageAction (QWebPage::Paste)); if (hasSelected) { Browser_->Find_->setData (page ()->selectedText ()); menu->addAction (Browser_->Find_); menu->addAction (tr ("Search..."), this, SLOT (searchSelectedText ())); } emit hookWebViewContextMenu (proxy, this, e, r, menu, WVSAfterSelectedText); if (menu->isEmpty ()) menu = page ()->createStandardContextMenu (); if (!menu->isEmpty ()) menu->addSeparator (); menu->addAction (Browser_->Add2Favorites_); menu->addSeparator (); menu->addAction (Browser_->Print_); menu->addAction (Browser_->PrintPreview_); menu->addSeparator (); menu->addAction (Browser_->ViewSources_); menu->addAction (Browser_->SavePage_); menu->addSeparator (); menu->addAction (pageAction (QWebPage::ReloadAndBypassCache)); menu->addAction (Browser_->ReloadPeriodically_); menu->addAction (Browser_->NotifyWhenFinished_); menu->addSeparator (); menu->addAction (Browser_->ChangeEncoding_->menuAction ()); emit hookWebViewContextMenu (proxy, this, e, r, menu, WVSAfterFinish); if (!menu->isEmpty ()) menu->exec (Browser_->GetGraphicsView ()->viewport ()-> mapToGlobal (e->pos ().toPoint ())); else QGraphicsWebView::contextMenuEvent (e); if (menu) delete menu; }
void WebView::contextMenuEvent(QContextMenuEvent *event) { // do not display the context menu if gesture was previously invoked if (m_gestureTime.isValid() && !m_gestureTime.isNull()) { int secs = m_gestureTime.secsTo(QDateTime::currentDateTime()); if (secs >= 0 && secs <=1) return; } QMenu menu(this); QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); m_hitResult = r; if (!r.linkUrl().isEmpty()) { MenuCommands cmds; QAction* newwin = new QAction(pageAction(QWebPage::OpenLinkInNewWindow)->text(), this); connect(newwin, SIGNAL(triggered()), this, SLOT(openLinkInNewWin())); menu.addAction(newwin); QAction* newtab = new QAction(cmds.OpenNewTabTitle(), this); newtab->setShortcuts(cmds.OpenNewTabShortcuts()); connect(newtab, SIGNAL(triggered()), this, SLOT(openLinkInNewTab())); menu.addAction(newtab); menu.addSeparator(); menu.addAction(pageAction(QWebPage::DownloadLinkToDisk)); menu.addSeparator(); menu.addAction(pageAction(QWebPage::CopyLinkToClipboard)); { QAction* copyadr = new QAction(cmds.CopyAddrTitle(), this); connect(copyadr, SIGNAL(triggered()), this, SLOT(copyMailtoAddress())); menu.addAction( copyadr ); } if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) { QAction* inspect = new QAction(cmds.InspectTitle(), this); //inspect->setShortcuts(cmds.InspectShortcuts()); connect(inspect, SIGNAL(triggered()), this, SLOT(slotInspectElement())); menu.addAction(inspect); } } if (!r.imageUrl().isEmpty()) { if (!menu.isEmpty()) menu.addSeparator(); menu.addAction( pageAction(QWebPage::DownloadImageToDisk)); menu.addAction( pageAction(QWebPage::CopyImageToClipboard)); QAction* newwin = new QAction(pageAction(QWebPage::OpenImageInNewWindow)->text(), this); connect(newwin, SIGNAL(triggered()), this, SLOT(openImageInNewWin())); menu.addAction(newwin); MenuCommands cmds; QAction* newtab = new QAction(cmds.OpenNewTabTitle(), this); newtab->setShortcuts(cmds.OpenNewTabShortcuts()); connect(newtab, SIGNAL(triggered()), this, SLOT(openImageInNewTab())); menu.addAction( newtab ); menu.addSeparator(); QAction* adblock = new QAction(cmds.OpenAdBlockTitle(), this); adblock->setShortcuts(cmds.OpenAdBlockShortcuts()); connect(adblock, SIGNAL(triggered()), this, SLOT(adBlock())); adblock->setToolTip(r.imageUrl().toString()); menu.addAction( adblock ); } if (!menu.isEmpty()) { menu.exec(mapToGlobal(event->pos())); return; } QWebView::contextMenuEvent(event); }