From 4548f4098b44ae6ce281b4325fb8dfb5f6a44d25 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 13 Dec 2010 17:53:46 +0100 Subject: GCI Task by Furkan Uzumcu: Context Menu Improvements This commit changed context menu by adding Find/Print actions there and letting users opening URL-like text in new tab/window --- src/webview.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/webview.cpp b/src/webview.cpp index e90b8da5..9e9203d6 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -143,6 +143,11 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) KMenu menu(this); QAction *a; + if(result.pixmap().isNull()) + { + a = mainwindow->actionByName(KStandardAction::name(KStandardAction::Find)); + menu.addAction(a); + } KAction *inspectAction = new KAction(KIcon("layer-visible-on"), i18n("Inspect Element"), this); connect(inspectAction, SIGNAL(triggered(bool)), this, SLOT(inspect())); @@ -181,6 +186,34 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) else a->setText(i18n("Copy")); menu.addAction(a); + if(selectedText().contains('.') && selectedText().indexOf('.') < selectedText().length() && !selectedText().trimmed().contains(" ")) + { + QString text = selectedText(); + text = text.trimmed(); + KUrl urlLikeText(text); + if(urlLikeText.isValid()) + { + QString truncatedUrl = text; + const int maxTextSize = 18; + if (truncatedUrl.length() > maxTextSize) + { + const int truncateSize = 15; + truncatedUrl.truncate(truncateSize); + truncatedUrl += QL1S("..."); + } + //open selected text url in a new tab + QAction * const openInNewTabAction = new KAction(KIcon("tab-new"), i18n("Open '%1' in New Tab", truncatedUrl), this); + openInNewTabAction->setData(urlLikeText); + connect(openInNewTabAction, SIGNAL(triggered(bool)), this, SLOT(openLinkInNewTab())); + menu.addAction(openInNewTabAction); + //open selected text url in a new window + QAction * const openInNewWindowAction = new KAction(KIcon("window-new"), i18n("Open '%1' in New Window", truncatedUrl), this); + openInNewWindowAction->setData(urlLikeText); + connect(openInNewWindowAction, SIGNAL(triggered(bool)), this, SLOT(openLinkInNewWindow())); + menu.addAction(openInNewWindowAction); + menu.addSeparator(); + } + } } // is content editable? Add PASTE @@ -188,7 +221,8 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) { menu.addAction(pageAction(KWebPage::Paste)); } - + a = mainwindow->actionByName(KStandardAction::name(KStandardAction::Print)); + menu.addAction(a); // is content selected? Add SEARCH actions if (result.isContentSelected()) { -- cgit v1.2.1