1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-23 02:32:10 +02:00
falkonOfficial/src/lib/popupwindow/popupwebview.cpp

91 lines
2.4 KiB
C++
Raw Normal View History

/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2015 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 this;
}
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();
}
void PopupWebView::inspectElement()
{
2015-09-29 23:15:46 +02:00
WebInspector *inspector = new WebInspector;
inspector->setView(this);
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
2015-09-29 23:15:46 +02:00
const WebHitTestResult hitTest = page()->hitTestContent(event->pos());
2012-01-21 20:29:33 +01:00
2015-09-29 23:15:46 +02:00
createContextMenu(m_menu, hitTest);
2012-01-21 20:29:33 +01:00
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
}