diff options
-rw-r--r-- | src/mainwindow.cpp | 13 | ||||
-rw-r--r-- | src/mainwindow.h | 1 | ||||
-rw-r--r-- | src/webview.cpp | 177 |
3 files changed, 82 insertions, 109 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 40ecfb81..31a47033 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -561,19 +561,6 @@ void MainWindow::slotFileOpen() } -// void MainWindow::slotFilePrintPreview() -// { -// if (!currentTab()) -// return; -// -// QPrinter printer; -// QPrintPreviewDialog previewdlg(&printer, this); -// connect(&previewdlg, SIGNAL(paintRequested(QPrinter *)), -// currentTab(), SLOT(print(QPrinter *))); -// previewdlg.exec(); -// } - - void MainWindow::printRequested(QWebFrame *frame) { if (!currentTab()) diff --git a/src/mainwindow.h b/src/mainwindow.h index d248b067..fe4d3089 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -125,7 +125,6 @@ private slots: // File Menu slots void slotFileOpen(); -// void slotFilePrintPreview(); void slotFileSaveAs(); void slotViewPageSource(); diff --git a/src/webview.cpp b/src/webview.cpp index 6cf6afbf..85e0e996 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -110,6 +110,7 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) KMenu menu(this); QAction *a; + // is a link? if (!result.linkUrl().isEmpty()) { // link actions @@ -125,84 +126,40 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) a = pageAction(QWebPage::CopyLinkToClipboard); a->setIcon(KIcon("edit-copy")); menu.addAction(a); - - if (!result.pixmap().isNull()) - { - menu.addSeparator(); - - // TODO Add "View Image" && remove copy_this_image action - a = pageAction(QWebPage::DownloadImageToDisk); - a->setIcon(KIcon("document-save")); - menu.addAction(a); - - a = pageAction(QWebPage::CopyImageToClipboard); - a->setIcon(KIcon("edit-copy")); - menu.addAction(a); - } } - else if (result.isContentEditable() && result.isContentSelected()) + + // is content editable && selected? Add CUT + if (result.isContentEditable() && result.isContentSelected()) { // actions for text selected in field a = pageAction(QWebPage::Cut); a->setIcon(KIcon("edit-cut")); a->setShortcut(KStandardShortcut::cut().primary()); menu.addAction(a); - + } + + // is content selected) Add COPY + if(result.isContentSelected()) + { a = pageAction(QWebPage::Copy); a->setIcon(KIcon("edit-copy")); a->setShortcut(KStandardShortcut::copy().primary()); menu.addAction(a); - - a = pageAction(QWebPage::Paste); - a->setIcon(KIcon("edit-paste")); - a->setShortcut(KStandardShortcut::paste().primary()); - menu.addAction(a); - - menu.addSeparator(); - - KConfig config("kuriikwsfilterrc"); //Share with konqueror - KConfigGroup cg = config.group("General"); - QStringList favoriteEngines; - favoriteEngines << "wikipedia" << "google"; //defaults - favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines); - QString keywordDelimiter = cg.readEntry("KeywordDelimiter", ":"); - KService::Ptr service; - KUriFilterData data; - foreach (const QString &engine, favoriteEngines) - { - service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine)); - const QString searchProviderPrefix = *(service->property("Keys").toStringList().begin()) + keywordDelimiter; - data.setData(searchProviderPrefix + "some keyword"); - a = new KAction(i18n("Search with ")+service->name(), this); - a->setIcon(Application::icon(KUrl(data.uri()))); - a->setData(searchProviderPrefix); - connect(a, SIGNAL(triggered(bool)), this, SLOT(slotSearch())); - menu.addAction(a); - } - - - // TODO Add translate, show translation } - else if (result.isContentEditable()) + + // is content editable? Add PASTE + if(result.isContentEditable()) { - // actions for a not selected field or a void field - // WARNING: why it doesn't automatically select a field? - // Why the paste action is disabled? - a = pageAction(QWebPage::Paste); a->setIcon(KIcon("edit-paste")); a->setShortcut(KStandardShortcut::paste().primary()); menu.addAction(a); } - else if (result.isContentSelected()) - { - // actions for text selected in page - a = pageAction(QWebPage::Copy); - a->setIcon(KIcon("edit-copy")); - a->setShortcut(KStandardShortcut::copy().primary()); - menu.addAction(a); - - menu.addSeparator(); + + // is content selected? Add SEARCH actions + if(result.isContentSelected()) + { + KActionMenu *searchMenu = new KActionMenu(i18n("Search with..."), this); KConfig config("kuriikwsfilterrc"); //Share with konqueror KConfigGroup cg = config.group("General"); @@ -212,21 +169,28 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) QString keywordDelimiter = cg.readEntry("KeywordDelimiter", ":"); KService::Ptr service; KUriFilterData data; + foreach (const QString &engine, favoriteEngines) { - service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine)); - const QString searchProviderPrefix = *(service->property("Keys").toStringList().begin()) + keywordDelimiter; - data.setData(searchProviderPrefix + "some keyword"); - a = new KAction(i18n("Search with %1", service->name()), this); - a->setIcon(Application::icon(KUrl(data.uri()))); - a->setData(searchProviderPrefix); - connect(a, SIGNAL(triggered(bool)), this, SLOT(slotSearch())); - menu.addAction(a); + if(!engine.isNull()) + { + service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine)); + const QString searchProviderPrefix = *(service->property("Keys").toStringList().begin()) + keywordDelimiter; + data.setData(searchProviderPrefix + "some keyword"); + a = new KAction(service->name(), this); + a->setIcon(Application::icon(KUrl(data.uri()))); + a->setData(searchProviderPrefix); + connect(a, SIGNAL(triggered(bool)), this, SLOT(slotSearch())); + searchMenu->addAction(a); + } } - - // TODO Add translate, show translation + menu.addAction(searchMenu); + menu.addSeparator(); + // TODO Add translate, show translation } - else if (!result.pixmap().isNull()) + + // is an image? + if (!result.pixmap().isNull()) { menu.addSeparator(); @@ -238,37 +202,54 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) a = pageAction(QWebPage::CopyImageToClipboard); a->setIcon(KIcon("edit-copy")); menu.addAction(a); + + menu.addSeparator(); } - else - { - //page actions - menu.addAction(mainwindow->actionByName("new_tab")); - - if(mainwindow->isFullScreen()) - { - menu.addAction(mainwindow->actionByName("fullscreen")); - } + // last (but not less) actions.. + if(result.linkUrl().isEmpty()) + { + // page action + menu.addAction(mainwindow->actionByName("new_tab")); menu.addSeparator(); + } + + QWebHistory *history = page()->history(); + if(history->canGoBack()) + { + a = pageAction(QWebPage::Back); + a->setIcon(KIcon("go-previous")); + menu.addAction(a); + } + + if(history->canGoForward()) + { + a = pageAction(QWebPage::Forward); + a->setIcon(KIcon("go-next")); + menu.addAction(a); + } - menu.addAction(mainwindow->actionByName("history_back")); - menu.addAction(mainwindow->actionByName("history_forward")); - menu.addAction(mainwindow->actionByName("view_redisplay")); - - KActionMenu *frameMenu = new KActionMenu(i18n("Frame"), this); + menu.addAction(mainwindow->actionByName("view_redisplay")); + + KActionMenu *frameMenu = new KActionMenu(i18n("Current Frame"), this); - a = pageAction(QWebPage::OpenFrameInNewWindow); - a->setText(i18n("Open in new tab")); - a->setIcon(KIcon("view-right-new")); - frameMenu->addAction(a); - - a = new KAction( KIcon("document-print-frame"), i18n("Print frame"), this); - connect(a, SIGNAL(triggered()), this, SLOT(printFrame())); - frameMenu->addAction(a); - menu.addAction(frameMenu); - + a = pageAction(QWebPage::OpenFrameInNewWindow); + a->setText(i18n("Open in new tab")); + a->setIcon(KIcon("view-right-new")); + frameMenu->addAction(a); + + a = new KAction( KIcon("document-print-frame"), i18n("Print frame"), this); + connect(a, SIGNAL(triggered()), this, SLOT(printFrame())); + frameMenu->addAction(a); + menu.addAction(frameMenu); + + // empty space actions + if(result.linkUrl().isEmpty()) + { menu.addSeparator(); + menu.addAction(mainwindow->actionByName(KStandardAction::name(KStandardAction::SaveAs))); + menu.addAction(mainwindow->actionByName("page_source")); QAction *addBookmarkAction = Application::bookmarkProvider()->actionByName("rekonq_add_bookmark"); menu.addAction(addBookmarkAction); @@ -282,6 +263,12 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) } } + if(mainwindow->isFullScreen()) + { + menu.addSeparator(); + menu.addAction(mainwindow->actionByName("fullscreen")); + } + menu.exec(mapToGlobal(event->pos())); } |