void tab::contextMenuRequest(QPoint pos) { clickPos = pos; QMenu menu; QWebHitTestResult r = webView->page()->mainFrame()->hitTestContent(pos); if(!r.linkUrl().isEmpty()) { menu.addAction(tr("Open in New Tab"), this, SLOT(openLinkInNewTab())); menu.addAction(webView->pageAction(QWebPage::DownloadLinkToDisk)); menu.addAction(webView->pageAction(QWebPage::CopyLinkToClipboard)); } if(!r.imageUrl().isEmpty()) { menu.addSeparator(); menu.addAction(webView->pageAction(QWebPage::DownloadImageToDisk)); menu.addAction(webView->pageAction(QWebPage::CopyImageToClipboard)); menu.addAction(webView->pageAction(QWebPage::CopyImageUrlToClipboard)); } menu.addSeparator(); menu.addAction(webView->pageAction(QWebPage::InspectElement)); menu.exec(webView->mapToGlobal(pos)); }
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) { QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); if (!r.linkUrl().isEmpty()) { QMenu menu(this); menu.addAction(pageAction(QWebPage::OpenLinkInNewWindow)); menu.addAction(tr("Open in New Tab"), this, SLOT(openLinkInNewTab())); menu.addSeparator(); menu.addAction(pageAction(QWebPage::DownloadLinkToDisk)); // Add link to bookmarks... menu.addSeparator(); menu.addAction(pageAction(QWebPage::CopyLinkToClipboard)); if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) menu.addAction(pageAction(QWebPage::InspectElement)); menu.exec(mapToGlobal(event->pos())); return; } QWebView::contextMenuEvent(event); }
void HelpViewer::mouseReleaseEvent(QMouseEvent *e) { if (e->button() == Qt::XButton1) { QTextBrowser::backward(); return; } if (e->button() == Qt::XButton2) { QTextBrowser::forward(); return; } controlPressed = e->modifiers() & Qt::ControlModifier; if ((controlPressed && hasAnchorAt(e->pos())) || (e->button() == Qt::MidButton && hasAnchorAt(e->pos()))) { openLinkInNewTab(); return; } QTextBrowser::mouseReleaseEvent(e); }
void HelpViewer::contextMenuEvent(QContextMenuEvent *e) { QMenu menu(QLatin1String(""), 0); QUrl link; QAction *copyAnchorAction = 0; if (hasAnchorAt(e->pos())) { link = anchorAt(e->pos()); if (link.isRelative()) link = source().resolved(link); copyAnchorAction = menu.addAction(tr("Copy &Link Location")); copyAnchorAction->setEnabled(!link.isEmpty() && link.isValid()); menu.addAction(tr("Open Link in New Tab\tCtrl+LMB"), this, SLOT(openLinkInNewTab())); menu.addSeparator(); } menu.addActions(parentWidget->globalActions()); QAction *action = menu.exec(e->globalPos()); if (action == copyAnchorAction) QApplication::clipboard()->setText(link.toString()); }
void WebView::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = new QMenu(this); QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); if (!r.linkUrl().isEmpty()) { qDebug() << "Normal Click"; menu->addAction(pageAction(QWebPage::OpenLinkInNewWindow)); menu->addAction(tr("Open in New Tab"), this, SLOT(openLinkInNewTab())); menu->addSeparator(); menu->addAction(pageAction(QWebPage::DownloadLinkToDisk)); // Add link to bookmarks... menu->addSeparator(); menu->addAction(pageAction(QWebPage::CopyLinkToClipboard)); menu->addAction(tr("Block Image"), this, SLOT(blockImage()))->setData(r.imageUrl().toString()); if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) menu->addAction(pageAction(QWebPage::InspectElement)); menu->exec(mapToGlobal(event->pos())); return; } delete menu; QWebView::contextMenuEvent(event); }
void HistoryView::contextMenuEvent(QContextMenuEvent* event) { const QModelIndex index = indexAt(event->pos()); if (!index.isValid() || index.data(HistoryModel::IsTopLevelRole).toBool()) { return; } m_clickedIndex = index; QMenu menu; menu.addAction(tr("Open link in current tab"), this, SLOT(openLinkInCurrentTab())); menu.addAction(tr("Open link in new tab"), this, SLOT(openLinkInNewTab())); menu.addSeparator(); menu.addAction(tr("Copy title"), this, SLOT(copyTitle())); menu.addAction(tr("Copy address"), this, SLOT(copyAddress())); menu.addSeparator(); menu.addAction(tr("Remove"), this, SLOT(removeItems())); // Prevent choosing first option with double rightclick QPoint pos = viewport()->mapToGlobal(event->pos()); QPoint p(pos.x(), pos.y() + 1); menu.exec(p); }
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 HelpViewer::openLinkInNewTab(const QString &link) { lastAnchor = link; openLinkInNewTab(); }
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); }