2015-08-30 23:46:15 -04:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-03-24 05:29:35 -04:00
|
|
|
** Copyright (C) 2015-2016 Oleg Shparber
|
2015-08-30 23:46:15 -04:00
|
|
|
** Copyright (C) 2013-2014 Jerzy Kozera
|
2016-04-17 03:07:48 -04:00
|
|
|
** Contact: https://go.zealdocs.org/l/contact
|
2015-08-30 23:46:15 -04:00
|
|
|
**
|
|
|
|
|
** This file is part of Zeal.
|
|
|
|
|
**
|
|
|
|
|
** Zeal is free software: you can redistribute it and/or modify
|
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
** (at your option) any later version.
|
|
|
|
|
**
|
|
|
|
|
** Zeal is distributed in the hope that it will be useful,
|
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
|
**
|
|
|
|
|
** You should have received a copy of the GNU General Public License
|
2016-05-01 22:13:18 -04:00
|
|
|
** along with Zeal. If not, see <https://www.gnu.org/licenses/>.
|
2015-08-30 23:46:15 -04:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2015-03-22 23:20:01 -07:00
|
|
|
#include "webview.h"
|
2015-01-04 18:02:35 -08:00
|
|
|
|
2014-10-03 17:12:34 +02:00
|
|
|
#include "../mainwindow.h"
|
|
|
|
|
|
2015-01-09 10:56:19 -08:00
|
|
|
#include <QApplication>
|
2015-01-06 23:41:03 -08:00
|
|
|
#include <QWheelEvent>
|
|
|
|
|
|
2015-09-19 00:07:00 -04:00
|
|
|
#ifndef USE_WEBENGINE
|
|
|
|
|
#include <QWebFrame>
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-03-22 23:20:01 -07:00
|
|
|
WebView::WebView(QWidget *parent) :
|
2015-01-06 23:15:17 -08:00
|
|
|
QWebView(parent)
|
2015-01-05 08:40:08 -08:00
|
|
|
{
|
|
|
|
|
}
|
2014-10-03 17:12:34 +02:00
|
|
|
|
2015-03-22 23:20:01 -07:00
|
|
|
int WebView::zealZoomFactor() const
|
2015-01-06 23:15:17 -08:00
|
|
|
{
|
|
|
|
|
return m_zoomFactor;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-22 23:20:01 -07:00
|
|
|
void WebView::setZealZoomFactor(int zf)
|
2015-01-06 23:15:17 -08:00
|
|
|
{
|
|
|
|
|
m_zoomFactor = zf;
|
|
|
|
|
updateZoomFactor();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-22 23:20:01 -07:00
|
|
|
QWebView *WebView::createWindow(QWebPage::WebWindowType type)
|
2015-01-05 08:40:08 -08:00
|
|
|
{
|
2014-10-03 17:12:34 +02:00
|
|
|
Q_UNUSED(type)
|
|
|
|
|
|
|
|
|
|
MainWindow *mw = qobject_cast<MainWindow *>(qApp->activeWindow());
|
|
|
|
|
mw->createTab();
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2014-11-20 15:09:25 +08:00
|
|
|
|
2015-05-11 13:02:57 -07:00
|
|
|
void WebView::mousePressEvent(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
switch (event->button()) {
|
|
|
|
|
case Qt::BackButton:
|
|
|
|
|
back();
|
|
|
|
|
event->accept();
|
|
|
|
|
break;
|
|
|
|
|
case Qt::ForwardButton:
|
|
|
|
|
forward();
|
|
|
|
|
event->accept();
|
|
|
|
|
break;
|
2015-09-19 00:07:00 -04:00
|
|
|
#ifndef USE_WEBENGINE
|
|
|
|
|
case Qt::LeftButton:
|
|
|
|
|
if (!(event->modifiers() & Qt::ControlModifier || event->modifiers() & Qt::ShiftModifier))
|
|
|
|
|
break;
|
|
|
|
|
case Qt::MiddleButton:
|
|
|
|
|
m_clickedLink = clickedLink(event->pos());
|
|
|
|
|
if (m_clickedLink.isValid())
|
|
|
|
|
event->accept();
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2015-05-11 13:02:57 -07:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWebView::mousePressEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-19 00:07:00 -04:00
|
|
|
#ifndef USE_WEBENGINE
|
|
|
|
|
void WebView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
switch (event->button()) {
|
|
|
|
|
case Qt::LeftButton:
|
|
|
|
|
if (!(event->modifiers() & Qt::ControlModifier || event->modifiers() & Qt::ShiftModifier))
|
|
|
|
|
break;
|
|
|
|
|
case Qt::MiddleButton:
|
|
|
|
|
if (m_clickedLink == clickedLink(event->pos()) && m_clickedLink.isValid()) {
|
|
|
|
|
QWebView *webView = createWindow(QWebPage::WebBrowserWindow);
|
2016-09-22 02:20:26 -04:00
|
|
|
webView->load(m_clickedLink);
|
2015-09-19 00:07:00 -04:00
|
|
|
event->accept();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
QWebView::mouseReleaseEvent(event);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-03-22 23:20:01 -07:00
|
|
|
void WebView::wheelEvent(QWheelEvent *event)
|
2015-01-05 08:40:08 -08:00
|
|
|
{
|
2014-11-21 21:32:28 +01:00
|
|
|
if (event->modifiers() & Qt::ControlModifier) {
|
2015-01-06 23:15:17 -08:00
|
|
|
m_zoomFactor += event->delta() / 120;
|
2014-11-21 21:32:28 +01:00
|
|
|
updateZoomFactor();
|
|
|
|
|
} else {
|
2014-11-20 15:09:25 +08:00
|
|
|
QWebView::wheelEvent(event);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-06 23:15:17 -08:00
|
|
|
|
2015-09-19 00:07:00 -04:00
|
|
|
#ifndef USE_WEBENGINE
|
|
|
|
|
QUrl WebView::clickedLink(const QPoint &pos) const
|
|
|
|
|
{
|
|
|
|
|
QWebFrame *frame = page()->frameAt(pos);
|
|
|
|
|
if (!frame)
|
|
|
|
|
return QUrl();
|
|
|
|
|
|
|
|
|
|
return frame->hitTestContent(pos).linkUrl();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-03-22 23:20:01 -07:00
|
|
|
void WebView::updateZoomFactor()
|
2015-01-06 23:15:17 -08:00
|
|
|
{
|
|
|
|
|
setZoomFactor(1 + m_zoomFactor / 10.);
|
|
|
|
|
}
|