Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
void WebView::contextMenuEvent(QContextMenuEvent *event)
{
    QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
    if (!r.linkUrl().isEmpty()) {
        QMenu menu(this);
        menu.addAction(pageAction(QWebPage::OpenLink));

        // building a custom signal for external browser action
        QSignalMapper* signalMapper = new QSignalMapper (this);
        signalMapper->setProperty("url", QVariant(r.linkUrl()));
        connect(signalMapper, SIGNAL(mapped(int)),
                this, SLOT(triggerContextMenuAction(int)));

        QAction* extAction = menu.addAction(tr("Open in External Browser"));
        connect (extAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
        signalMapper->setMapping(extAction, QWebPage::OpenLink);

        QAction* newAction = menu.addAction(tr("Open in new window"));
        connect (newAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
        signalMapper->setMapping(newAction, QWebPage::OpenLinkInNewWindow);

        menu.addAction(pageAction(QWebPage::DownloadLinkToDisk));
        menu.addAction(pageAction(QWebPage::CopyLinkToClipboard));
        menu.exec(mapToGlobal(event->pos()));
        return;
    }
Ejemplo n.º 3
0
QString ViewWindow::anchorAt(const QPoint & pos)
{
	QWebHitTestResult res = page()->currentFrame()->hitTestContent( pos );

	if ( !res.linkUrl().isValid() )
		return QString::null;

	return  res.linkUrl().path();
}
Ejemplo n.º 4
0
void WebView::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::MidButton) {
        QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
        if (!r.linkUrl().isEmpty()) {
            openLinkInNewWindow(r.linkUrl());
            return;
        }
    }
    QWebView::mousePressEvent(event);
}
Ejemplo n.º 5
0
static QMenu* createContextMenu(QWebPage* page, QPoint position)
{
    QMenu* menu = page->createStandardContextMenu();

    QWebHitTestResult r = page->mainFrame()->hitTestContent(position);

    if (!r.linkUrl().isEmpty()) {
        WebPage* webPage = qobject_cast<WebPage*>(page);
        QAction* newTabAction = menu->addAction("Open in Default &Browser", webPage, SLOT(openUrlInDefaultBrowser()));
        newTabAction->setData(r.linkUrl());
        menu->insertAction(menu->actions().at(2), newTabAction);
    }
    return menu;
}
Ejemplo n.º 6
0
    virtual void contextMenuEvent(QContextMenuEvent* event)
    {
        QMenu* menu = page()->createStandardContextMenu();

        QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());

        if (!r.linkUrl().isEmpty()) {
            QAction* newTabAction = menu->addAction(tr("Open in Default &Browser"), this, SLOT(openUrlInDefaultBrowser()));
            newTabAction->setData(r.linkUrl());
            menu->insertAction(menu->actions().at(2), newTabAction);
        }

        menu->exec(mapToGlobal(event->pos()));
        delete menu;
    }
Ejemplo n.º 7
0
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));
}
Ejemplo n.º 8
0
void SearchPage::showBrowserContextMenu(const QPoint &pos) {
    const QWebHitTestResult result = m_browser->page()->mainFrame()->hitTestContent(pos);
    const QString url = result.linkUrl().toString();

    if (url.isEmpty()) {
        return;
    }

    QMenu menu(this);
    QAction *copyAction = menu.addAction(QIcon::fromTheme("edit-copy"), tr("&Copy URL"));
    QAction *addAction = menu.addAction(QIcon::fromTheme("list-add"), tr("&Add URL"));
    QAction *retrieveAction = menu.addAction(QIcon::fromTheme("folder-remote"), tr("&Retrieve URLs"));
    QAction *downloadAction = menu.addAction(QIcon::fromTheme("download"), tr("Retrieve &download requests"));
    QAction *action = menu.exec(m_browser->mapToGlobal(pos));
    
    if (!action) {
        return;
    }
    
    if (action == copyAction) {
        copyUrl(url);
    }
    else if (action == addAction) {
        addUrl(url);
    }
    else if (action == retrieveAction) {
        retrieveUrls(url);
    }
    else if (action == downloadAction) {
        fetchDownloadRequests(url);
    }
}
Ejemplo n.º 9
0
void CopyTitle::populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &r)
{
    m_view = view;

    if (!r.linkUrl().isEmpty() || r.isContentEditable()) {
        return;
    }

    QString title;
    if (!r.imageUrl().isEmpty()) {
        QString m_userFileName = r.imageUrl().toString().trimmed();
        int pos = m_userFileName.lastIndexOf(QLatin1Char('/'));
        if (pos != -1) {
            int size = m_userFileName.size();
            title = m_userFileName.right(size - pos - 1);
        }
        else {
            title += "image";
        }
    }

    else {
        title = view->title();
    }

    menu->addAction(QIcon::fromTheme("edit-copy"), !r.imageUrl().isEmpty() ? tr("Copy Image Name") : tr("Copy Page Title"), this, SLOT(copyPageTitle()))->setData(title);
}
Ejemplo n.º 10
0
QWebView *MyTextBrowser::createWindow(QWebPage::WebWindowType type)
{
  QWebHitTestResult r = page()->mainFrame()->hitTestContent(pressPos);
  if(!r.linkUrl().isEmpty() && type == QWebPage::WebBrowserWindow) 
  {
    QString cmd = opt.newwindow;
    if(cmd.isEmpty()) cmd = "pvbrowser";
    cmd += " \"";
    cmd += r.linkUrl().toString();;
    cmd += "\"";
#ifdef PVUNIX
    //cmd += " &";
    int ret = system(cmd.toUtf8());
#endif
#ifdef PVWIN32
    int ret = mysystem(cmd.toUtf8());
#endif
    if(ret < 0) printf("ERROR system(%s)", (const char *) cmd.toUtf8());
  }
  return NULL;
}
Ejemplo n.º 11
0
void webview::contextMenuEvent(QContextMenuEvent * event)
{
    QMenu * menu = new QMenu();
    menu->setVisible(true);
    QWebHitTestResult element = this->page()->mainFrame()->hitTestContent(event->pos());
    if(!element.linkUrl().isEmpty())
    {
        QAction * newtab = this->pageAction(QWebPage::OpenLinkInNewWindow);
        newtab->setText(tr("open link in new tab"));
        menu->addAction(newtab);
        menu->addAction(this->pageAction(QWebPage::DownloadLinkToDisk));
        menu->addAction(this->pageAction(QWebPage::CopyLinkToClipboard));
    }
    if(!element.imageUrl().isEmpty())
    {
        menu->addAction(this->pageAction(QWebPage::DownloadImageToDisk));
        menu->addAction(this->pageAction(QWebPage::CopyImageToClipboard));
        menu->addAction(this->pageAction(QWebPage::CopyImageUrlToClipboard));
        QAction * newimage = this->pageAction(QWebPage::OpenImageInNewWindow);
        newimage->setText(tr("open image in new tab"));
        menu->addAction(newimage);
    }
    if(!page()->selectedText().isEmpty())
    {
        menu->addAction(this->pageAction(QWebPage::Copy));
        menu->addAction(this->pageAction(QWebPage::Cut));
        menu->addAction(this->pageAction(QWebPage::Paste));
        menu->addAction(this->pageAction(QWebPage::Undo));
        menu->addAction(this->pageAction(QWebPage::Redo));
        menu->addAction(this->pageAction(QWebPage::SelectAll));
    }
    if(element.element().tagName().toLower() == "input" && element.element().attribute(QLatin1String("type")).toLower() == "text")
    {
        menu->addAction(this->pageAction(QWebPage::SelectAll));
        menu->addAction(this->pageAction(QWebPage::Paste));
        menu->addAction(this->pageAction(QWebPage::SetTextDirectionLeftToRight));
        menu->addAction(this->pageAction(QWebPage::SetTextDirectionRightToLeft));
        menu->addAction(this->pageAction(QWebPage::SetTextDirectionDefault));
        menu->addAction(this->pageAction(QWebPage::MoveToNextWord));
    }
    if(!element.isNull())
    {
        menu->addAction(this->pageAction(QWebPage::Back));
        menu->addAction(this->pageAction(QWebPage::Forward));
        menu->addAction(this->pageAction(QWebPage::Reload));
        menu->addAction(this->pageAction(QWebPage::Stop));
        menu->addAction(this->pageAction(QWebPage::InspectElement));
    }
    menu->exec(event->globalPos());
}
Ejemplo n.º 12
0
void WebView::contextMenuEvent(QContextMenuEvent* event)
{
    QSettings settings;
    return;
    if(settings.value("disableDebug").toBool()) {
        return;
    }

    QMenu* menu = m_page->createStandardContextMenu();

    QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());

    if (!r.linkUrl().isEmpty()) {
        QAction* newTabAction = menu->addAction(tr("Test Menu"));
        newTabAction->setData(r.linkUrl());
        menu->insertAction(menu->actions().at(2), newTabAction);
    }
    for(int i=0; i< menu->actions().size(); i++) {
        QAction *qa = menu->actions().at(i);
    }

    menu->exec(mapToGlobal(event->pos()));
    delete menu;
}
Ejemplo n.º 13
0
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));
  }
}
Ejemplo n.º 14
0
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);
}
Ejemplo n.º 15
0
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);
    }
}
Ejemplo n.º 16
0
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);
}
Ejemplo n.º 17
0
void TestPlugin::populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &r)
{
    // Called from WebView when creating context menu

    m_view = view;

    QString title;
    if (!r.imageUrl().isEmpty()) {
        title += " on image";
    }

    if (!r.linkUrl().isEmpty()) {
        title += " on link";
    }

    if (r.isContentEditable()) {
        title += " on input";
    }

    menu->addAction(tr("My first plugin action") + title, this, SLOT(actionSlot()));
}
Ejemplo n.º 18
0
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);
}
Ejemplo n.º 19
0
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);
}
Ejemplo n.º 20
0
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);
}
Ejemplo n.º 21
0
void MainWindow::editorContextMenuRequested ( const QPoint & pos ) {
    QString guid = getCurrentNoteGuid();
    if (guid == "main")
        return;

    QWebHitTestResult element = ui->editor->page()->mainFrame()->hitTestContent(pos);

    if (element.isNull())
        return;

    QStringList classes = allClasses(element.element());
    if (classes.contains("pdfarea"))
        return;

    QMenu * menu = new QMenu(ui->editor);

    menu->addAction(ui->editor->pageAction(QWebPage::SelectAll));

    if (element.isContentSelected()) {

        if (!menu->isEmpty())
            menu->addSeparator();

        menu->addAction(ui->editor->pageAction(QWebPage::Copy));

        if (element.isContentEditable()) {
            menu->addAction(ui->editor->pageAction(QWebPage::Cut));
            menu->addAction(ui->editor->pageAction(QWebPage::Paste));
            menu->addSeparator();

            menu->addAction(ui->editor->pageAction(QWebPage::ToggleBold));
            menu->addAction(ui->editor->pageAction(QWebPage::ToggleItalic));
            menu->addAction(ui->editor->pageAction(QWebPage::ToggleUnderline));
        }
    }

    if(!element.imageUrl().isEmpty() && (element.imageUrl().scheme() != "qrc")) {

        if (!menu->isEmpty())
            menu->addSeparator();

        menu->addAction(ui->editor->pageAction(QWebPage::DownloadImageToDisk));
        menu->addAction(ui->editor->pageAction(QWebPage::CopyImageToClipboard));

        if (element.imageUrl().scheme() == "http" || element.imageUrl().scheme() == "https")
            menu->addAction(ui->editor->pageAction(QWebPage::CopyImageUrlToClipboard));

        QAction * openImage = new QAction(this);
        openImage->setText("Open Image");
        openImage->setObjectName("openImage");
        menu->addAction(openImage);

        if (JS("editMode").toBool()) {
            menu->addSeparator();

            QAction * deleteImage = new QAction(this);
            deleteImage->setText("Delete Image");
            deleteImage->setObjectName("deleteImage");
            deleteImage->setIcon(QIcon::fromTheme("edit-delete"));
            menu->addAction(deleteImage);

            if (element.imageUrl().scheme() != "resource") {
                QAction * saveLocally = new QAction(this);
                saveLocally->setText("Save Locally");
                saveLocally->setObjectName("saveLocally");
                menu->addAction(saveLocally);
            }
        }
    }

    if (!element.linkUrl().isEmpty()) {
        if (!menu->isEmpty())
            menu->addSeparator();

        menu->addAction(ui->editor->pageAction(QWebPage::CopyLinkToClipboard));

        if (element.isContentEditable()) {
            QAction * deleteURL = new QAction(this);
            deleteURL->setText("Remove Link");
            deleteURL->setObjectName("deleteURL");
            menu->addAction(deleteURL);
        }
    }

    if (element.isContentEditable() && !element.isContentSelected() && element.imageUrl().isEmpty()) {
        Speller *speller = Speller::GetInstance();
        if (speller->initialized()) {

            QHash<QString, QString> languages = speller->availableLanguages();
            if (!languages.isEmpty()) {

                if (!menu->isEmpty())
                    menu->addSeparator();                

                QAction* act = menu->addAction(tr("Check &Spelling"));
                act->setCheckable(true);
                act->setChecked(speller->isEnabled());
                connect(act, SIGNAL(triggered(bool)), speller, SLOT(setEnabled(bool)));

                if (speller->isEnabled()) {
                    QString word = JS(QString("getSpellingWord(%1,%2);").arg(pos.x()).arg(pos.y())).toString();
                    if (!word.isEmpty() && speller->isMisspelled(word)) {
                        QStringList wordsList = speller->suggest(word);

                        QFont boldFont = menu->font();
                        boldFont.setBold(true);

                        QActionGroup *suggestGroup = new QActionGroup(menu);

                        QString suggest;
                        foreach(suggest, wordsList) {
                            QAction* act = menu->addAction(suggest);
                            act->setFont(boldFont);
                            act->setData(suggest);
                            suggestGroup->addAction(act);
                        }
                        connect(suggestGroup, SIGNAL(triggered(QAction*)), this, SLOT(replaceWord(QAction*)));
                    }
Ejemplo n.º 22
0
	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;
	}
Ejemplo n.º 23
0
bool QtWebKitWebWidget::eventFilter(QObject *object, QEvent *event)
{
	if (object == m_webView)
	{
		if (event->type() == QEvent::Resize)
		{
			emit progressBarGeometryChanged();
		}
		else if (event->type() == QEvent::ToolTip && m_isLinkHovered)
		{
			event->accept();

			return true;
		}
		else if (event->type() == QEvent::MouseButtonPress)
		{
			QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);

			if (mouseEvent->button() == Qt::MiddleButton)
			{
				QWebHitTestResult result = m_webView->page()->mainFrame()->hitTestContent(mouseEvent->pos());

				if (result.linkUrl().isValid())
				{
					emit requestedOpenUrl(result.linkUrl(), true, false);

					event->accept();

					return true;
				}
			}

			if (mouseEvent->button() == Qt::BackButton)
			{
				triggerAction(GoBackAction);

				event->accept();

				return true;
			}

			if (mouseEvent->button() == Qt::ForwardButton)
			{
				triggerAction(GoForwardAction);

				event->accept();

				return true;
			}
		}
		else if (event->type() == QEvent::MouseButtonDblClick && SettingsManager::getValue(QLatin1String("Browser/ShowSelectionContextMenuOnDoubleClick")).toBool())
		{
			QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);

			if (mouseEvent && mouseEvent->button() == Qt::LeftButton)
			{
				QTimer::singleShot(250, this, SLOT(showContextMenu()));
			}
		}
		else if (event->type() == QEvent::Wheel)
		{
			QWheelEvent *wheelEvent = static_cast<QWheelEvent*>(event);

			if (wheelEvent->modifiers() & Qt::CTRL || wheelEvent->buttons() & Qt::LeftButton)
			{
				setZoom(getZoom() + (wheelEvent->delta() / 16));

				event->accept();

				return true;
			}

		}
	}

	return QObject::eventFilter(object, event);
}
Ejemplo n.º 24
0
void Videoner_Handler::populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &r)
{
    m_view = view;
    if (m_pageyt) {
        QRegExp rx1("v=([^&]+)|youtu.be/([^&]+)|y2u.be/([^&]+)|youtube.com/embed/([^&]+)");
        QString videoId1;

        rx1.indexIn(r.linkUrl().toString());
        for (int i = 1; i < 4; ++i) {
            if (!rx1.cap(i).isEmpty()) {
                videoId1 = rx1.cap(i);
                break;
            }
        }
        if (videoId1.isEmpty()) {
            rx1.indexIn(view->url().toString());
            for (int i = 1; i < 4; ++i) {
                if (!rx1.cap(i).isEmpty()) {
                    videoId1 = rx1.cap(i);
                    break;
                }
            }
        }
        if (!videoId1.isEmpty()) {
            QString videoPage1;
            videoPage1 = "http://www.youtube.com/watch?v=" + videoId1;
            menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, (m_sepyth ? SLOT(startExternalHandlerYt()) : SLOT(startExternalHandler())))->setData(videoPage1);
        }
    }
    if (m_pagevm) {
        QRegExp rx2("://vimeo.com/([^d]{8})");
        QString videoId2;

        rx2.indexIn(r.linkUrl().toString());
        for (int i = 1; i < 4; ++i) {
            if (!rx2.cap(i).isEmpty()) {
                videoId2 = rx2.cap(i);
                break;
            }
        }
        if (videoId2.isEmpty()) {
            rx2.indexIn(view->url().toString());
            for (int i = 1; i < 4; ++i) {
                if (!rx2.cap(i).isEmpty()) {
                    videoId2 = rx2.cap(i);
                    break;
                }
            }
        }
        if (!videoId2.isEmpty()) {
            QString videoPage2;
            videoPage2 = "http://vimeo.com/" + videoId2;
            menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, SLOT(startExternalHandler()))->setData(videoPage2);
        }
    }
    if (m_pagell) {
        QRegExp rx3("www.liveleak.com/view?i=([a-z0-9]{3})_([^&]+)");
        QString videoId3;

        rx3.indexIn(r.linkUrl().toString());
        for (int i = 1; i < 4; ++i) {
            if (!rx3.cap(i).isEmpty()) {
                videoId3 = rx3.cap(i);
                break;
            }
        }
        if (videoId3.isEmpty()) {
            rx3.indexIn(view->url().toString());
            for (int i = 1; i < 4; ++i) {
                if (!rx3.cap(i).isEmpty()) {
                    videoId3 = rx3.cap(i);
                    break;
                }
            }
        }
        if (!videoId3.isEmpty()) {
            QString videoPage3;
            videoPage3 = "http://www.liveleak.com/view?i=" + videoId3;
            menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, SLOT(startExternalHandler()))->setData(videoPage3);
        }
    }
    if (m_pagemc) {
        QRegExp rx4("www.metacafe.com/watch/([^d]+)/([^&]+)");
        QString videoId4;

        rx4.indexIn(r.linkUrl().toString());
        for (int i = 1; i < 4; ++i) {
            if (!rx4.cap(i).isEmpty()) {
                videoId4 = rx4.cap(i);
                break;
            }
        }
        if (videoId4.isEmpty()) {
            rx4.indexIn(view->url().toString());
            for (int i = 1; i < 4; ++i) {
                if (!rx4.cap(i).isEmpty()) {
                    videoId4 = rx4.cap(i);
                    break;
                }
            }
        }
        if (!videoId4.isEmpty()) {
            QString videoPage4;
            videoPage4 = "http://www.metacafe.com/watch/" + videoId4;
            menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, SLOT(startExternalHandler()))->setData(videoPage4);
        }
    }
    if (m_pagedm) {
        QRegExp rx5("dailymotion.com/video/([a-z0-9]+_[^&]+)");
        QString videoId5;

        rx5.indexIn(r.linkUrl().toString());
        for (int i = 1; i < 4; ++i) {
            if (!rx5.cap(i).isEmpty()) {
                videoId5 = rx5.cap(i);
                break;
            }
        }
        if (videoId5.isEmpty()) {
            rx5.indexIn(view->url().toString());
            for (int i = 1; i < 4; ++i) {
                if (!rx5.cap(i).isEmpty()) {
                    videoId5 = rx5.cap(i);
                    break;
                }
            }
        }
        if (!videoId5.isEmpty()) {
            QString videoPage5;
            videoPage5 = "http://www.dailymotion.com/video/" + videoId5;
            menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, SLOT(startExternalHandler()))->setData(videoPage5);
        }
    }
    if (m_pagebr) {
        QRegExp rx6("www.break.com/video/([^&]+)");
        QString videoId6;

        rx6.indexIn(r.linkUrl().toString());
        for (int i = 1; i < 4; ++i) {
            if (!rx6.cap(i).isEmpty()) {
                videoId6 = rx6.cap(i);
                break;
            }
        }
        if (videoId6.isEmpty()) {
            rx6.indexIn(view->url().toString());
            for (int i = 1; i < 4; ++i) {
                if (!rx6.cap(i).isEmpty()) {
                    videoId6 = rx6.cap(i);
                    break;
                }
            }
        }
        if (!videoId6.isEmpty()) {
            QString videoPage6;
            videoPage6 = "www.break.com/video/" + videoId6;
            menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, SLOT(startExternalHandler()))->setData(videoPage6);
        }
    }
    if (m_pagehu) {
        QRegExp rx7("www.hulu.com/watch/([^d]+)");
        QString videoId7;

        rx7.indexIn(r.linkUrl().toString());
        for (int i = 1; i < 4; ++i) {
            if (!rx7.cap(i).isEmpty()) {
                videoId7 = rx7.cap(i);
                break;
            }
        }
        if (videoId7.isEmpty()) {
            rx7.indexIn(view->url().toString());
            for (int i = 1; i < 4; ++i) {
                if (!rx7.cap(i).isEmpty()) {
                    videoId7 = rx7.cap(i);
                    break;
                }
            }
        }
        if (!videoId7.isEmpty()) {
            QString videoPage7;
            videoPage7 = "http://www.hulu.com/watch/" + videoId7;
            menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, SLOT(startExternalHandler()))->setData(videoPage7);
        }
    }
    if (m_medel) {
        if (r.element().tagName().toLower() == QLatin1String("video")
           || r.element().tagName().toLower() == QLatin1String("audio")) {
            QUrl mediaLink = r.element().evaluateJavaScript("this.currentSrc").toUrl();
            menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, (m_sepmedel ? SLOT(startExternalHandlerMed()) : SLOT(startExternalHandler())))->setData(mediaLink);
        }
    }
}
Ejemplo n.º 25
0
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);
}
Ejemplo n.º 26
0
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);
}