1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 17:42:10 +01:00
falkonOfficial/src/lib/popupwindow/popupwebview.cpp

114 lines
2.9 KiB
C++
Raw Normal View History

/* ============================================================
* QupZilla - Qt web browser
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
2012-01-21 20:29:33 +01:00
#include "popupwebview.h"
#include "mainapplication.h"
#include "browserwindow.h"
#include "tabwidget.h"
#include "tabbedwebview.h"
2012-01-21 20:29:33 +01:00
#include "iconprovider.h"
#include "enhancedmenu.h"
#include "loadrequest.h"
2015-09-29 23:15:46 +02:00
#include "webpage.h"
#include "webhittestresult.h"
#include "webinspector.h"
2012-01-21 20:29:33 +01:00
2012-08-31 15:19:07 +02:00
#include <QContextMenuEvent>
2012-01-21 20:29:33 +01:00
PopupWebView::PopupWebView(QWidget* parent)
: WebView(parent)
, m_menu(new Menu(this))
2012-01-21 20:29:33 +01:00
{
m_menu->setCloseOnMiddleClick(true);
2012-01-21 20:29:33 +01:00
}
QWidget* PopupWebView::overlayWidget()
2012-01-21 20:29:33 +01:00
{
return parentWidget();
2012-01-21 20:29:33 +01:00
}
void PopupWebView::loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position)
2012-01-21 20:29:33 +01:00
{
Q_UNUSED(position)
2012-01-21 20:29:33 +01:00
BrowserWindow* window = mApp->getWindow();
2012-01-21 20:29:33 +01:00
if (window) {
int index = window->tabWidget()->addView(QUrl(), Qz::NT_SelectedTab);
window->weView(index)->load(req);
window->raise();
2012-01-21 20:29:33 +01:00
}
}
2012-01-21 20:29:33 +01:00
void PopupWebView::closeView()
{
parentWidget()->close();
}
bool PopupWebView::isFullScreen()
{
return parentWidget()->isFullScreen();
}
void PopupWebView::requestFullScreen(bool enable)
{
if (enable)
parentWidget()->showFullScreen();
else
parentWidget()->showNormal();
}
void PopupWebView::inspectElement()
{
if (!WebInspector::isEnabled())
return;
if (m_inspector) {
triggerPageAction(QWebEnginePage::InspectElement);
return;
}
m_inspector = new WebInspector;
m_inspector->setView(this);
m_inspector->inspectElement();
m_inspector->show();
}
2015-09-29 23:15:46 +02:00
void PopupWebView::_contextMenuEvent(QContextMenuEvent *event)
{
m_menu->clear();
2012-01-21 20:29:33 +01:00
WebHitTestResult hitTest = page()->hitTestContent(event->pos());
2015-09-29 23:15:46 +02:00
createContextMenu(m_menu, hitTest);
2012-01-21 20:29:33 +01:00
if (WebInspector::isEnabled()) {
m_menu->addSeparator();
m_menu->addAction(tr("Inspect Element"), this, SLOT(inspectElement()));
}
2012-01-21 20:29:33 +01:00
if (!m_menu->isEmpty()) {
// Prevent choosing first option with double rightclick
const QPoint pos = event->globalPos();
2012-01-21 20:29:33 +01:00
QPoint p(pos.x(), pos.y() + 1);
2015-09-29 23:15:46 +02:00
2012-01-21 20:29:33 +01:00
m_menu->popup(p);
return;
}
2015-09-29 23:15:46 +02:00
WebView::_contextMenuEvent(event);
2012-01-21 20:29:33 +01:00
}