Files
zeal/src/ui/widgets/webview.cpp
T

88 lines
2.0 KiB
C++
Raw Normal View History

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/>.
**
****************************************************************************/
#include "webview.h"
2015-01-04 18:02:35 -08:00
#include "../mainwindow.h"
#include <QApplication>
#include <QWheelEvent>
WebView::WebView(QWidget *parent) :
2015-01-06 23:15:17 -08:00
QWebView(parent)
{
}
int WebView::zealZoomFactor() const
2015-01-06 23:15:17 -08:00
{
return m_zoomFactor;
}
void WebView::setZealZoomFactor(int zf)
2015-01-06 23:15:17 -08:00
{
m_zoomFactor = zf;
updateZoomFactor();
}
QWebView *WebView::createWindow(QWebPage::WebWindowType type)
{
Q_UNUSED(type)
MainWindow *mw = qobject_cast<MainWindow *>(qApp->activeWindow());
mw->createTab();
return this;
}
2014-11-20 15:09:25 +08: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);
}
void WebView::wheelEvent(QWheelEvent *event)
{
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
void WebView::updateZoomFactor()
2015-01-06 23:15:17 -08:00
{
setZoomFactor(1 + m_zoomFactor / 10.);
}