void WebView::contextMenuEvent(QContextMenuEvent* event) { if (isLoading_) return; QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); QMenu *menu; if (!r.linkUrl().isEmpty()) { if (r.linkUrl().scheme() == "addnick") { event->ignore(); return; } menu = URLObject::getInstance()->createPopupMenu(r.linkUrl().toEncoded()); //menu->addAction(pageAction(QWebPage::CopyLinkToClipboard)); } else { menu = new QMenu(this); if (!page()->selectedText().isEmpty()) { menu->addAction(pageAction(QWebPage::Copy)); } else { if (!menu->isEmpty()) { menu->addSeparator(); } menu->addAction(pageAction(QWebPage::SelectAll)); } if (settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) { menu->addAction(pageAction(QWebPage::InspectElement)); } } menu->addAction(pageAction(QWebPage::Reload)); menu->exec(mapToGlobal(event->pos())); event->accept(); delete menu; }
HelpWidget::HelpWidget(QHelpEngine *pHelpEngine, const QUrl &pHomePage, QWidget *pParent) : QWebView(pParent), CommonWidget(pParent), mHelpEngine(pHelpEngine), mHomePage(pHomePage), mZoomLevel(-1) // This will ensure that mZoomLevel gets initialised by our // first call to setZoomLevel { // Add a small margin to the widget, so that no visual trace of the border // drawn by drawBorderIfDocked is left when scrolling setStyleSheet("QWebView {" " margin: 1px;" "}"); // Note: not sure why, but no matter how many pixels are specified for the // margin, no margin actually exists, but it addresses the issue with // the border drawn by drawBorderIfDocked, so... // Use our own help page and help network access manager classes setPage(new HelpPage(this)); page()->setNetworkAccessManager(new HelpNetworkAccessManager(pHelpEngine, this)); // Prevent objects from being dropped on us // Note: by default, QWebView allows for objects to be dropped on itself, // so... setAcceptDrops(false); // Prevent the widget from taking over the scrolling of other widgets setFocusPolicy(Qt::NoFocus); // Set our initial zoom level to the default value // Note: to set mZoomLevel directly is not good enough since one of the // things setZoomLevel does is to set our zoom factor, so... setZoomLevel(DefaultZoomLevel); // Some connections connect(this, SIGNAL(urlChanged(const QUrl &)), this, SLOT(urlChanged(const QUrl &))); connect(page(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); connect(pageAction(QWebPage::Back), SIGNAL(changed()), this, SLOT(documentChanged())); connect(pageAction(QWebPage::Forward), SIGNAL(changed()), this, SLOT(documentChanged())); // Go to the home page goToHomePage(); }
//Page context menu void AWebView::contextMenuEvent(QContextMenuEvent *event) { QMenu menu(this); menu.addAction(pageAction(QWebPage::Back)); menu.addAction(pageAction(QWebPage::Forward)); menu.addAction(pageAction(QWebPage::Reload)); menu.exec(mapToGlobal(event->pos())); return; }
void SimplePartWidget::buildContextMenu(const QPoint &point, QMenu &menu) const { menu.addAction(m_findAction); auto a = pageAction(QWebPage::Copy); a->setIcon(UiUtils::loadIcon(QStringLiteral("edit-copy"))); menu.addAction(a); a = pageAction(QWebPage::SelectAll); a->setIcon(UiUtils::loadIcon(QStringLiteral("edit-select-all"))); menu.addAction(a); if (!page()->mainFrame()->hitTestContent(point).linkUrl().isEmpty()) { menu.addSeparator(); a = pageAction(QWebPage::CopyLinkToClipboard); a->setIcon(UiUtils::loadIcon(QStringLiteral("edit-copy"))); menu.addAction(a); } menu.addSeparator(); menu.addAction(m_savePart); menu.addAction(m_saveMessage); if (!page()->mainFrame()->hitTestContent(point).imageUrl().isEmpty()) { a = pageAction(QWebPage::DownloadImageToDisk); a->setIcon(UiUtils::loadIcon(QStringLiteral("download"))); menu.addAction(a); } menu.addSeparator(); QMenu *colorSchemeMenu = menu.addMenu(UiUtils::loadIcon(QStringLiteral("colorneg")), tr("Color scheme")); QActionGroup *ag = new QActionGroup(colorSchemeMenu); for (auto item: supportedColorSchemes()) { QAction *a = colorSchemeMenu->addAction(item.second); connect(a, &QAction::triggered, this, [this, item](){ const_cast<SimplePartWidget*>(this)->setColorScheme(item.first); }); a->setCheckable(true); if (item.first == m_colorScheme) { a->setChecked(true); } a->setActionGroup(ag); } auto zoomMenu = menu.addMenu(UiUtils::loadIcon(QStringLiteral("zoom")), tr("Zoom")); if (m_messageView) { zoomMenu->addAction(m_messageView->m_zoomIn); zoomMenu->addAction(m_messageView->m_zoomOut); zoomMenu->addAction(m_messageView->m_zoomOriginal); } else { auto zoomIn = zoomMenu->addAction(UiUtils::loadIcon(QStringLiteral("zoom-in")), tr("Zoom In")); zoomIn->setShortcut(QKeySequence::ZoomIn); connect(zoomIn, &QAction::triggered, this, &SimplePartWidget::zoomIn); auto zoomOut = zoomMenu->addAction(UiUtils::loadIcon(QStringLiteral("zoom-out")), tr("Zoom Out")); zoomOut->setShortcut(QKeySequence::ZoomOut); connect(zoomOut, &QAction::triggered, this, &SimplePartWidget::zoomOut); auto zoomOriginal = zoomMenu->addAction(UiUtils::loadIcon(QStringLiteral("zoom-original")), tr("Original Size")); connect(zoomOriginal, &QAction::triggered, this, &SimplePartWidget::zoomOriginal); } }
void HelpViewer::actionChanged() { QAction *a = qobject_cast<QAction *>(sender()); if (a == pageAction(QWebPage::Copy)) emit copyAvailable(a->isEnabled()); else if (a == pageAction(QWebPage::Back)) emit backwardAvailable(a->isEnabled()); else if (a == pageAction(QWebPage::Forward)) emit forwardAvailable(a->isEnabled()); }
void HelpWindowWidget::documentChanged() { // A new help document has been selected, resulting in the previous or next // help document becoming either available or not QAction *action = qobject_cast<QAction *>(sender()); if (action == pageAction(QWebPage::Back)) emit backEnabled(action->isEnabled()); else if (action == pageAction(QWebPage::Forward)) emit forwardEnabled(action->isEnabled()); }
void GlaucaWebView::contextMenuEvent(QContextMenuEvent *event){ QWebHitTestResult result=page()->mainFrame()->hitTestContent(event->pos()); QMenu menu(this); if(result.isContentSelected()){ menu.addAction(pageAction(QWebPage::Copy)); menu.addAction("Search \""+this->selectedText()+"\"",this,SIGNAL(searchRequest(this->selectedText()))); menu.addAction("Add selected items to local wiki",this,SLOT(addSelectedToWiki())); menu.addSeparator(); } if(!result.linkUrl().isEmpty()){ menu.addAction("Open Link in new tab",this,SIGNAL(urlChanged(result.linkUrl()))); menu.addAction(pageAction(QWebPage::DownloadLinkToDisk)); menu.addAction(pageAction(QWebPage::CopyLinkToClipboard)); menu.addSeparator(); } if(!result.imageUrl().isEmpty()){ menu.addAction(pageAction(QWebPage::CopyImageToClipboard)); menu.addSeparator(); } menu.addAction(pageAction(QWebPage::Back)); menu.addAction(pageAction(QWebPage::Forward)); menu.addAction(pageAction(QWebPage::Reload)); menu.addAction(pageAction(QWebPage::Stop)); menu.addSeparator(); menu.addAction("Add page to local WIKI",this,SLOT(addPageToWiki())); menu.addAction("View Page Source",this,SLOT(viewPageSource())); menu.exec(mapToGlobal(event->pos())); }
void ChannelsView::contextMenu(QMenu *menu, const QWebHitTestResult &result) { menu->addSeparator(); const QUrl url = result.linkUrl(); if (url.scheme() == LS("chat") && url.host() == LS("channel")) ChannelMenu::bind(menu, ChatUrls::channel(url), IChannelMenu::ChatViewScope); menu->addSeparator(); if (!result.isContentEditable()) { menu->removeAction(pageAction(QWebPage::SelectAll)); menu->addAction(pageAction(QWebPage::SelectAll)); } }
void AWebView::keyPressEvent (QKeyEvent* event) { if (event->matches(QKeySequence::Copy) == true) pageAction(QWebPage::Copy)->trigger(); else QWebView::keyPressEvent(event); }
TinyWebBrowser::TinyWebBrowser( QWidget* parent ) : QWebView( parent ), d( 0 ) { connect( this, SIGNAL(statusBarMessage(QString)), this, SIGNAL(statusMessage(QString)) ); page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); connect( this, SIGNAL(linkClicked(QUrl)), this, SLOT(openExternalLink(QUrl)) ); connect( this, SIGNAL(titleChanged(QString)), this, SLOT(setWindowTitle(QString)) ); pageAction( QWebPage::OpenLinkInNewWindow )->setEnabled( false ); pageAction( QWebPage::OpenLinkInNewWindow )->setVisible( false ); }
void CustomWebView::keyReleaseEvent (QKeyEvent *event) { bool handled = false; if (event->matches (QKeySequence::Copy)) { pageAction (QWebPage::Copy)->trigger (); /* TODO const QString& text = selectedText (); if (!text.isEmpty ()) { QApplication::clipboard ()->setText (text, QClipboard::Clipboard); handled = true; } */ } else if (event->key () == Qt::Key_F6) Browser_->focusLineEdit (); else if (event->modifiers () == Qt::SHIFT && (event->key () == Qt::Key_PageUp || event->key () == Qt::Key_PageDown)) { ScrollDelta_ += event->key () == Qt::Key_PageUp ? -0.1 : 0.1; if (!ScrollTimer_->isActive ()) ScrollTimer_->start (30); } else if (event->modifiers () == Qt::SHIFT && event->key () == Qt::Key_Plus) { ScrollDelta_ = 0; ScrollTimer_->stop (); } if (!handled) QGraphicsWebView::keyReleaseEvent (event); }
// ------------------------------------------ // csWebView // ------------------------------------------ csWebView::csWebView(QWidget *parent) :QWebView(parent) { // ------------------------------ // define additional actions // ------------------------------ sendToClientAct = new QAction(tr("&Send to CGLX"), this); // ------------------------------ // reproduce default context menu // for images on the web // ------------------------------ connect(pageAction ( QWebPage::DownloadImageToDisk ), SIGNAL(triggered()), this, SLOT(DownloadImg())); connect(pageAction ( QWebPage::OpenImageInNewWindow ), SIGNAL(triggered()), this, SLOT(OpenImg())); connect(pageAction ( QWebPage::CopyImageToClipboard ), SIGNAL(triggered()), this, SLOT(CopyImg())); connect(sendToClientAct, SIGNAL(triggered()), this, SLOT(SendToCGLX())); }
HelpViewer::HelpViewer(QHelpEngine *engine, CentralWidget *parent) : QWebView(parent) , helpEngine(engine) , parentWidget(parent) , loadFinished(false) { setAcceptDrops(false); setPage(new HelpPage(parent, helpEngine, this)); page()->setNetworkAccessManager(new HelpNetworkAccessManager(engine, this)); QAction* action = pageAction(QWebPage::OpenLinkInNewWindow); action->setText(tr("Open Link in New Tab")); if (!parent) action->setVisible(false); pageAction(QWebPage::DownloadLinkToDisk)->setVisible(false); pageAction(QWebPage::DownloadImageToDisk)->setVisible(false); pageAction(QWebPage::OpenImageInNewWindow)->setVisible(false); connect(pageAction(QWebPage::Copy), SIGNAL(changed()), this, SLOT(actionChanged())); connect(pageAction(QWebPage::Back), SIGNAL(changed()), this, SLOT(actionChanged())); connect(pageAction(QWebPage::Forward), SIGNAL(changed()), this, SLOT(actionChanged())); connect(page(), SIGNAL(linkHovered(QString,QString,QString)), this, SIGNAL(highlighted(QString))); connect(this, SIGNAL(urlChanged(QUrl)), this, SIGNAL(sourceChanged(QUrl))); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(setLoadFinished(bool))); }
void HelpBrowser::setHelpEngine(QHelpEngine* helpEngine) { mpHelpEngine = helpEngine; setPage(new HelpPage((QWidget*)parent(), helpEngine, this)); page()->setNetworkAccessManager(new HelpNetworkAccessManager(helpEngine, this)); QAction* action = pageAction(QWebPage::OpenLinkInNewWindow); action->setText(tr("Open Link in New Tab")); if (!parent()) action->setVisible(false); pageAction(QWebPage::DownloadLinkToDisk)->setVisible(false); pageAction(QWebPage::DownloadImageToDisk)->setVisible(false); pageAction(QWebPage::OpenImageInNewWindow)->setVisible(false); }
void lmcMessageLog::createContextMenu(void) { QAction* action = pageAction(QWebPage::Copy); action->setShortcut(QKeySequence::Copy); addAction(action); action = pageAction(QWebPage::CopyLinkToClipboard); addAction(action); action = pageAction(QWebPage::SelectAll); action->setShortcut(QKeySequence::SelectAll); addAction(action); contextMenu = new QMenu(this); copyAction = contextMenu->addAction("&Copy", this, SLOT(copyAction_triggered()), QKeySequence::Copy); copyLinkAction = contextMenu->addAction("&Copy Link", this, SLOT(copyLinkAction_triggered())); contextMenu->addSeparator(); selectAllAction = contextMenu->addAction("Select &All", this, SLOT(selectAllAction_triggered()), QKeySequence::SelectAll); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint))); setContextMenuPolicy(Qt::CustomContextMenu); }
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 WebView::contextMenuEvent(QContextMenuEvent* event) { if (isLoading_) return; #ifdef WEBENGINE #if QT_VERSION >= QT_VERSION_CHECK(5,7,0) QWebEngineContextMenuData r = page()->contextMenuData(); #else struct CMData { QUrl linkUrl() { return QUrl(); } // just a stub. TODO invent something }; CMData r; #endif #else QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); #endif QMenu *menu; if (!r.linkUrl().isEmpty()) { if (r.linkUrl().scheme() == "addnick") { event->ignore(); return; } menu = URLObject::getInstance()->createPopupMenu(r.linkUrl().toEncoded()); //menu->addAction(pageAction(QWebPage::CopyLinkToClipboard)); } else { menu = new QMenu(this); if (!page()->selectedText().isEmpty()) { #ifdef WEBENGINE menu->addAction(pageAction(QWebEnginePage::Copy)); } else { if (!menu->isEmpty()) { menu->addSeparator(); } menu->addAction(pageAction(QWebEnginePage::SelectAll)); } menu->addAction(pageAction(QWebEnginePage::InspectElement)); } menu->addAction(pageAction(QWebEnginePage::Reload)); #else menu->addAction(pageAction(QWebPage::Copy)); } else {
void WebView::contextMenuEvent ( QContextMenuEvent * event ) { QMenu menu; QPoint pos = event->pos(); QWebHitTestResult hitTest = page()->mainFrame()->hitTestContent( pos ); if (!hitTest.linkElement().isNull()) { menu.addAction( pageAction(QWebPage::CopyLinkToClipboard) ); menu.addSeparator(); } if (hitTest.isContentEditable() || hitTest.isContentSelected()) { menu.addAction( pageAction(QWebPage::Copy) ); if (hitTest.isContentEditable()) menu.addAction( pageAction(QWebPage::Paste) ); menu.addSeparator(); } menu.addAction( pageAction(QWebPage::Back) ); menu.addAction( pageAction(QWebPage::Forward) ); menu.addAction( pageAction(QWebPage::Reload) ); menu.exec( event->globalPos() ); }
void ChatView::contextMenu(QMenu *menu, const QWebHitTestResult &result) { menu->addSeparator(); const QUrl url = result.linkUrl(); if (url.scheme() == LS("chat") && url.host() == LS("channel")) Hooks::ChannelMenu::bind(menu, ChatUrls::channel(url), Hooks::ChatViewScope); else Hooks::ChannelMenu::bind(menu, ChatClient::channels()->get(m_id), Hooks::ChatViewScope); menu->addSeparator(); QMenu *display = menu->addMenu(SCHAT_ICON(Gear), tr("Display")); display->addAction(m_seconds); display->addAction(m_service); developerMenu(display); display->removeAction(pageAction(QWebPage::Reload)); menu->addAction(m_autoscroll); menu->addSeparator(); ClientChannel channel = ChatClient::channels()->get(id()); if (channel && channel->data().value(LS("page")) == 1) menu->addAction(m_reload); else menu->addAction(m_clear); if (!result.isContentEditable()) { menu->removeAction(pageAction(QWebPage::SelectAll)); menu->addAction(pageAction(QWebPage::SelectAll)); } menu->removeAction(pageAction(QWebPage::Reload)); menu->removeAction(pageAction(QWebPage::InspectElement)); connect(menu, SIGNAL(triggered(QAction*)), SLOT(menuTriggered(QAction*))); ChatViewHooks::contextMenu(this, menu, result); }
HelpWindowWidget::HelpWindowWidget(QHelpEngine *pHelpEngine, const QUrl &pHomePage, QWidget *pParent) : OpenCOR::WebViewerWidget::WebViewerWidget(pParent), Core::CommonWidget(), mHelpEngine(pHelpEngine), mHomePage(pHomePage), mZoomLevel(-1) // This will ensure that mZoomLevel gets initialised by our // first call to setZoomLevel { // Use our own help page and help network access manager classes setPage(new HelpWindowPage(this)); page()->setNetworkAccessManager(new HelpWindowNetworkAccessManager(pHelpEngine, this)); // Set our initial zoom level to the default value // Note: to set mZoomLevel directly is not good enough since one of the // things setZoomLevel does is to set our zoom factor... setZoomLevel(DefaultZoomLevel); // Some connections connect(this, SIGNAL(urlChanged(const QUrl &)), this, SLOT(urlChanged(const QUrl &))); connect(page(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); connect(pageAction(QWebPage::Back), SIGNAL(changed()), this, SLOT(documentChanged())); connect(pageAction(QWebPage::Forward), SIGNAL(changed()), this, SLOT(documentChanged())); // Go to the home page goToHomePage(); }
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 HelpWidget::documentChanged() { // A new help document has been selected, resulting in the previous or next // help document becoming either available or not QAction *action = qobject_cast<QAction *>(sender()); if (action) { // The QObject casting was successful, so we can carry on if (action == pageAction(QWebPage::Back)) { // The current action is to tell us whether the previous help // document is available, so send a signal to let the user know // about it emit backEnabled(action->isEnabled()); } else if (action == pageAction(QWebPage::Forward)) { // The current action is to tell us whether the next help document // is available, so send a signal to let the user know about it emit forwardEnabled(action->isEnabled()); } } }
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 AdiumThemeView::contextMenuEvent(QContextMenuEvent *event) { QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); QUrl url = r.linkUrl(); if (!url.isEmpty()) { // save current link url in openLinkAction m_openLinkAction->setData(url); QMenu menu(this); menu.addAction(m_openLinkAction); menu.addAction(pageAction(QWebPage::CopyLinkToClipboard)); menu.exec(mapToGlobal(event->pos())); } else { QWebView::contextMenuEvent(event); } }
void CustomWebView::mousePressEvent (QGraphicsSceneMouseEvent *e) { qobject_cast<CustomWebPage*> (page ())->SetButtons (e->buttons ()); qobject_cast<CustomWebPage*> (page ())->SetModifiers (e->modifiers ()); const bool mBack = e->button () == Qt::XButton1; const bool mForward = e->button () == Qt::XButton2; if (mBack || mForward) { pageAction (mBack ? QWebPage::Back : QWebPage::Forward)->trigger (); e->accept (); return; } QGraphicsWebView::mousePressEvent (e); }
AdiumThemeView::AdiumThemeView(QWidget *parent) : QWebView(parent), // check iconPath docs for minus sign in -KIconLoader::SizeLarge m_defaultAvatar(KIconLoader::global()->iconPath(QLatin1String("im-user"),-KIconLoader::SizeLarge)), m_displayHeader(true) { //blocks QWebView functionality which allows you to change page by dragging a URL onto it. setAcceptDrops(false); // don't let QWebView handle the links, we do page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); QAction *defaultOpenLinkAction = pageAction(QWebPage::OpenLink); m_openLinkAction = new KAction(defaultOpenLinkAction->text(), this); connect(m_openLinkAction, SIGNAL(triggered()), this, SLOT(onOpenLinkActionTriggered())); connect(this, SIGNAL(linkClicked(QUrl)), this, SLOT(onLinkClicked(QUrl))); }
void AWebView::contextMenuEvent (QContextMenuEvent* event) { QString selected = page()->selectedText(); if (selected.length() == 0 || LinkHovered == true) QWebView::contextMenuEvent(event); else { // Странно, но если делать m_menu переменной класса и задать все нужные свойства в конструкторе, // то возникает AV :\ разбираться с причинами лениво, ибо не так уж и накладно создавать каждый раз QMenu* m_menu = new QMenu(this); m_menu->addAction(pageAction(QWebPage::Copy)); m_menu->addSeparator(); QAction* yandex = m_menu->addAction(QString::fromUtf8("Яндекс")); yandex->setIcon(QIcon(":/icons/yandex.ico")); QAction* wikipedia = m_menu->addAction(QString::fromUtf8("Википедия")); wikipedia->setIcon(QIcon(":/icons/wikipedia.ico")); QAction* google = m_menu->addAction(QString::fromUtf8("Google")); google->setIcon(QIcon(":/icons/google.ico")); QAction* google_translate = m_menu->addAction(QString::fromUtf8("Google Переводчик")); google_translate->setIcon(QIcon(":/icons/google.translate.ico")); QAction* rsdn = m_menu->addAction(QString::fromUtf8("RSDN")); rsdn->setIcon(QIcon(":/icons/rsdn16.png")); connect(yandex, SIGNAL(triggered()), this, SLOT(menu_yandex_triggered())); connect(wikipedia, SIGNAL(triggered()), this, SLOT(menu_wikipedia_triggered())); connect(google, SIGNAL(triggered()), this, SLOT(menu_google_triggered())); connect(google_translate, SIGNAL(triggered()), this, SLOT(menu_google_translate_triggered())); connect(rsdn, SIGNAL(triggered()), this, SLOT(menu_rsdn_triggered())); m_menu->exec(event->globalPos()); delete m_menu; } }
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); }
HelpWebView::HelpWebView(IEditorSite::Pointer editorSite, QWidget *parent, qreal zoom) : QWebView(parent) //, parentWidget(parent) , m_LoadFinished(false) , m_HelpEngine(HelpPluginActivator::getInstance()->getQHelpEngine()) { setAcceptDrops(false); setPage(new HelpPage(editorSite, parent)); page()->setNetworkAccessManager(new HelpNetworkAccessManager(this)); QAction* action = pageAction(QWebPage::OpenLinkInNewWindow); action->setText(tr("Open Link in New Tab")); if (!parent) action->setVisible(false); pageAction(QWebPage::DownloadLinkToDisk)->setVisible(false); pageAction(QWebPage::DownloadImageToDisk)->setVisible(false); pageAction(QWebPage::OpenImageInNewWindow)->setVisible(false); connect(pageAction(QWebPage::Copy), SIGNAL(changed()), this, SLOT(actionChanged())); connect(pageAction(QWebPage::Back), SIGNAL(changed()), this, SLOT(actionChanged())); connect(pageAction(QWebPage::Forward), SIGNAL(changed()), this, SLOT(actionChanged())); connect(page(), SIGNAL(linkHovered(QString,QString,QString)), this, SIGNAL(highlighted(QString))); connect(this, SIGNAL(urlChanged(QUrl)), this, SIGNAL(sourceChanged(QUrl))); connect(this, SIGNAL(loadStarted()), this, SLOT(setLoadStarted())); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(setLoadFinished(bool))); connect(page(), SIGNAL(printRequested(QWebFrame*)), this, SIGNAL(printRequested())); setFont(viewerFont()); setTextSizeMultiplier(zoom == 0.0 ? 1.0 : zoom); }
void WebView::copyImageToClipboard() { pageAction(QWebPage::CopyImageToClipboard)->trigger(); }