From b13e71162d74abe27bf701e05008bf47a364acdb Mon Sep 17 00:00:00 2001 From: nowrep Date: Tue, 19 Jul 2011 22:04:08 +0200 Subject: [PATCH] Added Show source of selection feature. However, in Qt 4.8 beta it is buggy, so it is disabled until it will be fixed --- src/app/qupzilla.cpp | 4 ++-- src/app/qupzilla.h | 2 +- src/other/sourceviewer.cpp | 10 +++++++--- src/other/sourceviewer.h | 2 +- src/webview/webview.cpp | 18 ++++++++++++++---- src/webview/webview.h | 1 + 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp index c3c26deee..8ee752d21 100644 --- a/src/app/qupzilla.cpp +++ b/src/app/qupzilla.cpp @@ -911,9 +911,9 @@ void QupZilla::showPreferences() prefs->show(); } -void QupZilla::showSource() +void QupZilla::showSource(const QString &selectedHtml) { - SourceViewer* source = new SourceViewer(weView()->page()); + SourceViewer* source = new SourceViewer(weView()->page(), selectedHtml); source->show(); } diff --git a/src/app/qupzilla.h b/src/app/qupzilla.h index 2fec050a0..048f7f7c5 100644 --- a/src/app/qupzilla.h +++ b/src/app/qupzilla.h @@ -127,7 +127,7 @@ public slots: void loadActionUrl(); void bookmarkPage(); void loadAddress(QUrl url) { weView()->load(url); locationBar()->setText(url.toEncoded()); } - void showSource(); + void showSource(const QString& selectedHtml = ""); void showPageInfo(); void receiveMessage(MainApplication::MessageType mes, bool state); diff --git a/src/other/sourceviewer.cpp b/src/other/sourceviewer.cpp index 81a96d050..41a3e1751 100644 --- a/src/other/sourceviewer.cpp +++ b/src/other/sourceviewer.cpp @@ -20,8 +20,8 @@ #include "htmlhighlighter.h" #include "sourceviewersearch.h" -SourceViewer::SourceViewer(QWebPage* page, QWidget* parent) : - QWidget(parent) +SourceViewer::SourceViewer(QWebPage* page, const QString &selectedHtml) : + QWidget(0) ,m_page(page) { setAttribute(Qt::WA_DeleteOnClose); @@ -94,6 +94,10 @@ SourceViewer::SourceViewer(QWebPage* page, QWidget* parent) : const QRect screen = QApplication::desktop()->screenGeometry(); const QRect &size = QWidget::geometry(); QWidget::move( (screen.width()-size.width())/2, (screen.height()-size.height())/2 ); + + //Highlight selectedHtml + if (!selectedHtml.isEmpty()) + m_sourceEdit->find(selectedHtml, QTextDocument::FindWholeWords); } void SourceViewer::save() @@ -117,7 +121,7 @@ void SourceViewer::save() void SourceViewer::findText() { if (m_layout->count() > 2) { - SourceViewerSearch* search= qobject_cast( m_layout->itemAt(1)->widget() ); + SourceViewerSearch* search = qobject_cast( m_layout->itemAt(1)->widget() ); search->activateLineEdit(); return; } diff --git a/src/other/sourceviewer.h b/src/other/sourceviewer.h index 613760413..906286f84 100644 --- a/src/other/sourceviewer.h +++ b/src/other/sourceviewer.h @@ -38,7 +38,7 @@ class SourceViewer : public QWidget { Q_OBJECT public: - explicit SourceViewer(QWebPage* page, QWidget* parent = 0); + explicit SourceViewer(QWebPage* page, const QString &selectedHtml); QTextEdit* sourceEdit() { return m_sourceEdit; } signals: diff --git a/src/webview/webview.cpp b/src/webview/webview.cpp index 3e0ebe529..befc56d0c 100644 --- a/src/webview/webview.cpp +++ b/src/webview/webview.cpp @@ -468,7 +468,7 @@ void WebView::contextMenuEvent(QContextMenuEvent* event) menu->addAction(tr("Send link..."), this, SLOT(sendLinkByMail()))->setData(r.linkUrl()); menu->addAction(QIcon::fromTheme("edit-copy"), tr("&Copy link address"), this, SLOT(copyLinkToClipboard()))->setData(r.linkUrl()); menu->addSeparator(); - if (!page()->selectedText().isEmpty()) + if (!selectedText().isEmpty()) menu->addAction(pageAction(QWebPage::Copy)); } @@ -483,7 +483,7 @@ void WebView::contextMenuEvent(QContextMenuEvent* event) menu->addAction(tr("Send image..."), this, SLOT(sendLinkByMail()))->setData(r.linkUrl()); menu->addSeparator(); //menu->addAction(tr("Block image"), this, SLOT(blockImage()))->setData(r.imageUrl().toString()); - if (!page()->selectedText().isEmpty()) + if (!selectedText().isEmpty()) menu->addAction(pageAction(QWebPage::Copy)); } @@ -534,7 +534,7 @@ void WebView::contextMenuEvent(QContextMenuEvent* event) menu->addAction(tr("Send page..."), this, SLOT(sendLinkByMail()))->setData(url()); menu->addSeparator(); menu->addAction(QIcon::fromTheme("edit-select-all"), tr("Select &all"), this, SLOT(selectAll())); - if (!page()->selectedText().isEmpty()) + if (!selectedText().isEmpty()) menu->addAction(pageAction(QWebPage::Copy)); menu->addSeparator(); @@ -545,13 +545,18 @@ void WebView::contextMenuEvent(QContextMenuEvent* event) mApp->plugins()->populateWebViewMenu(menu, this, r); - if (!page()->selectedText().isEmpty()) { + if (!selectedText().isEmpty()) { menu->addSeparator(); QString selectedText = page()->selectedText(); selectedText.truncate(20); menu->addAction(QIcon(":icons/menu/google.png"), tr("Search \"%1 ..\" on &Google").arg(selectedText), this, SLOT(searchOnGoogle()))->setData(page()->selectedText()); } +#if QT_VERSION == 0x040800 +// if (!selectedHtml().isEmpty()) +// menu->addAction(tr("Show source of selection"), this, SLOT(showSourceOfSelection())); +#endif + if (!menu->isEmpty()) { //Prevent choosing first option with double rightclick QPoint pos = QCursor::pos(); @@ -635,6 +640,11 @@ void WebView::showSource() p_QupZilla->showSource(); } +void WebView::showSourceOfSelection() +{ + p_QupZilla->showSource(selectedHtml()); +} + void WebView::downloadLinkToDisk() { if (QAction* action = qobject_cast(sender())) { diff --git a/src/webview/webview.h b/src/webview/webview.h index 0448224af..16476be49 100644 --- a/src/webview/webview.h +++ b/src/webview/webview.h @@ -101,6 +101,7 @@ private slots: void sendLinkByMail(); void bookmarkLink(); void showSource(); + void showSourceOfSelection(); void showSiteInfo(); void getFocus(const QUrl &urla); void showInspector();