summaryrefslogtreecommitdiff
path: root/src/webview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webview.cpp')
-rw-r--r--src/webview.cpp112
1 files changed, 65 insertions, 47 deletions
diff --git a/src/webview.cpp b/src/webview.cpp
index 7cae61cf..2e97c486 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -35,7 +35,7 @@
#include <QMessageBox>
#include <QMouseEvent>
#include <QWebHitTestResult>
-#include <QUiLoader>
+//#include <QUiLoader>
#include <QBuffer>
@@ -45,11 +45,11 @@ WebPage::WebPage(QObject *parent)
, m_pressedButtons(Qt::NoButton)
, m_openInNewTab(false)
{
- setNetworkAccessManager(BrowserApplication::networkAccessManager());
- connect(this, SIGNAL(unsupportedContent(QNetworkReply *)),
- this, SLOT(handleUnsupportedContent(QNetworkReply *)));
+ setNetworkAccessManager( BrowserApplication::networkAccessManager() );
+ connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(handleUnsupportedContent(QNetworkReply *)));
}
+
BrowserMainWindow *WebPage::mainWindow()
{
QObject *w = this->parent();
@@ -61,24 +61,28 @@ BrowserMainWindow *WebPage::mainWindow()
return BrowserApplication::instance()->mainWindow();
}
+
bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
{
// ctrl open in new tab
// ctrl-shift open in new tab and select
// ctrl-alt open in new window
- if (type == QWebPage::NavigationTypeLinkClicked
- && (m_keyboardModifiers & Qt::ControlModifier
- || m_pressedButtons == Qt::MidButton)) {
+ if ( type == QWebPage::NavigationTypeLinkClicked && (m_keyboardModifiers & Qt::ControlModifier
+ || m_pressedButtons == Qt::MidButton) )
+ {
bool newWindow = (m_keyboardModifiers & Qt::AltModifier);
WebView *webView;
- if (newWindow) {
+ if (newWindow)
+ {
BrowserApplication::instance()->newMainWindow();
BrowserMainWindow *newMainWindow = BrowserApplication::instance()->mainWindow();
webView = newMainWindow->currentTab();
newMainWindow->raise();
newMainWindow->activateWindow();
webView->setFocus();
- } else {
+ }
+ else
+ {
bool selectNewTab = (m_keyboardModifiers & Qt::ShiftModifier);
webView = mainWindow()->tabWidget()->newTab(selectNewTab);
}
@@ -87,19 +91,22 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r
m_pressedButtons = Qt::NoButton;
return false;
}
- if (frame == mainFrame()) {
+ if ( frame == mainFrame() )
+ {
m_loadingUrl = request.url();
emit loadingUrl(m_loadingUrl);
}
return QWebPage::acceptNavigationRequest(frame, request, type);
}
+
QWebPage *WebPage::createWindow(QWebPage::WebWindowType type)
{
Q_UNUSED(type);
if (m_keyboardModifiers & Qt::ControlModifier || m_pressedButtons == Qt::MidButton)
m_openInNewTab = true;
- if (m_openInNewTab) {
+ if (m_openInNewTab)
+ {
m_openInNewTab = false;
return mainWindow()->tabWidget()->newTab()->page();
}
@@ -108,20 +115,11 @@ QWebPage *WebPage::createWindow(QWebPage::WebWindowType type)
return mainWindow->currentTab()->page();
}
-// #if !defined(QT_NO_UITOOLS)
-// QObject *WebPage::createPlugin(const QString &classId, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues)
-// {
-// Q_UNUSED(url);
-// Q_UNUSED(paramNames);
-// Q_UNUSED(paramValues);
-// QUiLoader loader;
-// return loader.createWidget(classId, view());
-// }
-// #endif // !defined(QT_NO_UITOOLS)
void WebPage::handleUnsupportedContent(QNetworkReply *reply)
{
- if (reply->error() == QNetworkReply::NoError) {
+ if (reply->error() == QNetworkReply::NoError)
+ {
BrowserApplication::downloadManager()->handleUnsupportedContent(reply);
return;
}
@@ -140,16 +138,19 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply)
imageBuffer.open(QBuffer::ReadWrite);
QIcon icon = view()->style()->standardIcon(QStyle::SP_MessageBoxWarning, 0, view());
QPixmap pixmap = icon.pixmap(QSize(32,32));
- if (pixmap.save(&imageBuffer, "PNG")) {
+ if (pixmap.save(&imageBuffer, "PNG"))
+ {
html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"),
QString(QLatin1String(imageBuffer.buffer().toBase64())));
}
QList<QWebFrame*> frames;
frames.append(mainFrame());
- while (!frames.isEmpty()) {
+ while (!frames.isEmpty())
+ {
QWebFrame *frame = frames.takeFirst();
- if (frame->url() == reply->url()) {
+ if (frame->url() == reply->url())
+ {
frame->setHtml(html, reply->url());
return;
}
@@ -157,36 +158,37 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply)
foreach(QWebFrame *frame, children)
frames.append(frame);
}
- if (m_loadingUrl == reply->url()) {
+ if (m_loadingUrl == reply->url())
+ {
mainFrame()->setHtml(html, reply->url());
}
}
+// ------------------------------------------------------------------------------------------------------------------------------------------------------
+
+
WebView::WebView(QWidget* parent)
: QWebView(parent)
, m_progress(0)
, m_page(new WebPage(this))
{
setPage(m_page);
- connect(page(), SIGNAL(statusBarMessage(const QString&)),
- SLOT(setStatusBarText(const QString&)));
- connect(this, SIGNAL(loadProgress(int)),
- this, SLOT(setProgress(int)));
- connect(this, SIGNAL(loadFinished(bool)),
- this, SLOT(loadFinished()));
- connect(page(), SIGNAL(loadingUrl(const QUrl&)),
- this, SIGNAL(urlChanged(const QUrl &)));
- connect(page(), SIGNAL(downloadRequested(const QNetworkRequest &)),
- this, SLOT(downloadRequested(const QNetworkRequest &)));
+ connect(page(), SIGNAL(statusBarMessage(const QString&)), this, SLOT(setStatusBarText(const QString&)));
+ connect(this, SIGNAL(loadProgress(int)), this, SLOT(setProgress(int)));
+ connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished()));
+ connect(page(), SIGNAL(loadingUrl(const QUrl&)), this, SIGNAL(urlChanged(const QUrl &)));
+ connect(page(), SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(downloadRequested(const QNetworkRequest &)));
page()->setForwardUnsupportedContent(true);
}
+
void WebView::contextMenuEvent(QContextMenuEvent *event)
{
QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
- if (!r.linkUrl().isEmpty()) {
+ if (!r.linkUrl().isEmpty())
+ {
QMenu menu(this);
menu.addAction(pageAction(QWebPage::OpenLinkInNewWindow));
menu.addAction(i18n("Open in New Tab"), this, SLOT(openLinkInNewTab()));
@@ -203,9 +205,11 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
QWebView::contextMenuEvent(event);
}
+
void WebView::wheelEvent(QWheelEvent *event)
{
- if (QApplication::keyboardModifiers() & Qt::ControlModifier) {
+ if (QApplication::keyboardModifiers() & Qt::ControlModifier)
+ {
int numDegrees = event->delta() / 8;
int numSteps = numDegrees / 15;
setTextSizeMultiplier(textSizeMultiplier() + numSteps * 0.1);
@@ -215,46 +219,55 @@ void WebView::wheelEvent(QWheelEvent *event)
QWebView::wheelEvent(event);
}
+
void WebView::openLinkInNewTab()
{
m_page->m_openInNewTab = true;
pageAction(QWebPage::OpenLinkInNewWindow)->trigger();
}
+
void WebView::setProgress(int progress)
{
m_progress = progress;
}
+
void WebView::loadFinished()
{
- if (100 != m_progress) {
+ if (m_progress != 100)
+ {
qWarning() << "Recieved finished signal while progress is still:" << progress()
<< "Url:" << url();
}
m_progress = 0;
}
-void WebView::loadUrl(const QUrl &url)
+
+void WebView::loadUrl(const KUrl &url)
{
m_initialUrl = url;
load(url);
}
+
QString WebView::lastStatusBarText() const
{
return m_statusBarText;
}
-QUrl WebView::url() const
+
+KUrl WebView::url() const
{
- QUrl url = QWebView::url();
- if (!url.isEmpty())
+ KUrl url = QWebView::url();
+ if ( !url.isEmpty() )
+ {
return url;
-
+ }
return m_initialUrl;
}
+
void WebView::mousePressEvent(QMouseEvent *event)
{
m_page->m_pressedButtons = event->buttons();
@@ -262,22 +275,27 @@ void WebView::mousePressEvent(QMouseEvent *event)
QWebView::mousePressEvent(event);
}
+
void WebView::mouseReleaseEvent(QMouseEvent *event)
{
QWebView::mouseReleaseEvent(event);
- if (!event->isAccepted() && (m_page->m_pressedButtons & Qt::MidButton)) {
- QUrl url(QApplication::clipboard()->text(QClipboard::Selection));
- if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty()) {
+ if (!event->isAccepted() && (m_page->m_pressedButtons & Qt::MidButton))
+ {
+ KUrl url( QApplication::clipboard()->text(QClipboard::Selection) );
+ if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty())
+ {
setUrl(url);
}
}
}
+
void WebView::setStatusBarText(const QString &string)
{
m_statusBarText = string;
}
+
void WebView::downloadRequested(const QNetworkRequest &request)
{
BrowserApplication::downloadManager()->download(request);