2012-03-04 14:25:52 +01:00
|
|
|
/* ============================================================
|
2017-01-22 14:43:22 +01:00
|
|
|
* QupZilla - Qt web browser
|
|
|
|
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
|
2012-03-04 14:25:52 +01:00
|
|
|
*
|
|
|
|
* 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"
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2012-01-22 11:49:58 +01:00
|
|
|
#include "tabwidget.h"
|
2013-11-09 13:32:03 +01:00
|
|
|
#include "tabbedwebview.h"
|
2012-01-21 20:29:33 +01:00
|
|
|
#include "iconprovider.h"
|
2012-01-24 23:28:18 +01:00
|
|
|
#include "enhancedmenu.h"
|
2014-03-19 21:27:43 +01:00
|
|
|
#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-02-29 18:33:50 +01:00
|
|
|
|
2012-01-21 20:29:33 +01:00
|
|
|
PopupWebView::PopupWebView(QWidget* parent)
|
|
|
|
: WebView(parent)
|
2012-01-24 23:28:18 +01:00
|
|
|
, m_menu(new Menu(this))
|
2012-01-21 20:29:33 +01:00
|
|
|
{
|
2014-02-10 21:34:46 +01:00
|
|
|
m_menu->setCloseOnMiddleClick(true);
|
2012-01-21 20:29:33 +01:00
|
|
|
}
|
|
|
|
|
2014-04-01 16:32:55 +02:00
|
|
|
QWidget* PopupWebView::overlayWidget()
|
2012-01-21 20:29:33 +01:00
|
|
|
{
|
2017-01-22 14:43:22 +01:00
|
|
|
return parentWidget();
|
2012-01-21 20:29:33 +01:00
|
|
|
}
|
|
|
|
|
2014-03-19 21:27:43 +01:00
|
|
|
void PopupWebView::loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position)
|
2012-01-21 20:29:33 +01:00
|
|
|
{
|
2012-01-22 15:15:43 +01:00
|
|
|
Q_UNUSED(position)
|
2012-01-21 20:29:33 +01:00
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
BrowserWindow* window = mApp->getWindow();
|
2012-01-21 20:29:33 +01:00
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
if (window) {
|
2013-11-09 13:32:03 +01:00
|
|
|
int index = window->tabWidget()->addView(QUrl(), Qz::NT_SelectedTab);
|
2014-03-19 21:27:43 +01:00
|
|
|
window->weView(index)->load(req);
|
2012-01-22 15:15:43 +01:00
|
|
|
window->raise();
|
2012-01-21 20:29:33 +01:00
|
|
|
}
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
2012-01-21 20:29:33 +01:00
|
|
|
|
2012-01-22 15:15:43 +01:00
|
|
|
void PopupWebView::closeView()
|
|
|
|
{
|
|
|
|
parentWidget()->close();
|
|
|
|
}
|
|
|
|
|
2015-10-05 17:39:52 +02:00
|
|
|
bool PopupWebView::isFullScreen()
|
|
|
|
{
|
|
|
|
return parentWidget()->isFullScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWebView::requestFullScreen(bool enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
parentWidget()->showFullScreen();
|
|
|
|
else
|
|
|
|
parentWidget()->showNormal();
|
|
|
|
}
|
|
|
|
|
2013-01-25 20:00:37 +01:00
|
|
|
void PopupWebView::inspectElement()
|
|
|
|
{
|
2016-02-20 15:07:36 +01:00
|
|
|
if (!WebInspector::isEnabled())
|
|
|
|
return;
|
|
|
|
|
2015-10-15 17:19:16 +02:00
|
|
|
if (m_inspector) {
|
|
|
|
triggerPageAction(QWebEnginePage::InspectElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_inspector = new WebInspector;
|
|
|
|
m_inspector->setView(this);
|
|
|
|
m_inspector->inspectElement();
|
|
|
|
m_inspector->show();
|
2013-01-25 20:00:37 +01:00
|
|
|
}
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
void PopupWebView::_contextMenuEvent(QContextMenuEvent *event)
|
2012-01-22 11:49:58 +01:00
|
|
|
{
|
|
|
|
m_menu->clear();
|
2012-01-21 20:29:33 +01:00
|
|
|
|
2016-12-26 17:23:52 +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
|
|
|
|
2016-04-05 09:19:57 +02:00
|
|
|
if (WebInspector::isEnabled()) {
|
|
|
|
m_menu->addSeparator();
|
|
|
|
m_menu->addAction(tr("Inspect Element"), this, SLOT(inspectElement()));
|
|
|
|
}
|
2013-01-25 20:00:37 +01:00
|
|
|
|
2012-01-21 20:29:33 +01:00
|
|
|
if (!m_menu->isEmpty()) {
|
2013-01-25 20:00:37 +01:00
|
|
|
// Prevent choosing first option with double rightclick
|
2013-12-30 13:43:48 +01:00
|
|
|
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
|
|
|
}
|