2015-08-30 23:46:15 -04:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2015 Oleg Shparber
|
|
|
|
|
** Copyright (C) 2013-2014 Jerzy Kozera
|
|
|
|
|
** Contact: http://zealdocs.org/contact.html
|
|
|
|
|
**
|
|
|
|
|
** 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
|
|
|
|
|
** along with Zeal. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
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-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;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWebView::mousePressEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
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-03-22 23:20:01 -07:00
|
|
|
void WebView::updateZoomFactor()
|
2015-01-06 23:15:17 -08:00
|
|
|
{
|
|
|
|
|
setZoomFactor(1 + m_zoomFactor / 10.);
|
|
|
|
|
}
|