Falkon Develop
Cross-platform Qt-based web browser
popupwebview.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "popupwebview.h"
19#include "mainapplication.h"
20#include "browserwindow.h"
21#include "tabwidget.h"
22#include "tabbedwebview.h"
23#include "iconprovider.h"
24#include "enhancedmenu.h"
25#include "loadrequest.h"
26#include "webpage.h"
27#include "webhittestresult.h"
28#include "webinspector.h"
29
30#include <QContextMenuEvent>
31
33 : WebView(parent)
34 , m_menu(new Menu(this))
35{
36 m_menu->setCloseOnMiddleClick(true);
37}
38
40{
41 return parentWidget();
42}
43
44void PopupWebView::loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position)
45{
46 Q_UNUSED(position)
47
48 BrowserWindow* window = mApp->getWindow();
49
50 if (window) {
51 int index = window->tabWidget()->addView(QUrl(), Qz::NT_SelectedTab);
52 window->weView(index)->load(req);
53 window->raise();
54 }
55}
56
58{
59 window()->close();
60}
61
63{
64 return parentWidget()->isFullScreen();
65}
66
68{
69 if (enable)
70 parentWidget()->showFullScreen();
71 else
72 parentWidget()->showNormal();
73}
74
76{
78 return;
79
80 if (m_inspector) {
81 triggerPageAction(QWebEnginePage::InspectElement);
82 return;
83 }
84
85 m_inspector = new WebInspector;
86 m_inspector->setView(this);
87 m_inspector->inspectElement();
88 m_inspector->show();
89}
90
91void PopupWebView::_contextMenuEvent(QContextMenuEvent *event)
92{
93 m_menu->clear();
94
95 WebHitTestResult hitTest = page()->hitTestContent(event->pos());
96 createContextMenu(m_menu, hitTest);
97
99 m_menu->addSeparator();
100 m_menu->addAction(tr("Inspect Element"), this, &PopupWebView::inspectElement);
101 }
102
103 if (!m_menu->isEmpty()) {
104 // Prevent choosing first option with double rightclick
105 const QPoint pos = event->globalPos();
106 QPoint p(pos.x(), pos.y() + 1);
107
108 m_menu->popup(p);
109 return;
110 }
111
113}
TabWidget * tabWidget() const
TabbedWebView * weView() const
void setCloseOnMiddleClick(bool close)
bool isFullScreen() override
void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) override
void closeView() override
PopupWebView(QWidget *parent=nullptr)
void requestFullScreen(bool enable) override
void inspectElement()
QWidget * overlayWidget() override
int addView(const LoadRequest &req, const Qz::NewTabPositionFlags &openFlags, bool selectLine=false, bool pinned=false)
Definition: tabwidget.cpp:314
static bool isEnabled()
WebHitTestResult hitTestContent(const QPoint &pos) const
Definition: webpage.cpp:189
void createContextMenu(QMenu *menu, WebHitTestResult &hitTest)
Definition: webview.cpp:672
WebPage * page() const
Definition: webview.cpp:132
void load(const QUrl &url)
Definition: webview.cpp:177
virtual void _contextMenuEvent(QContextMenuEvent *event)
Definition: webview.cpp:1237
#define mApp
@ NT_SelectedTab
Definition: qzcommon.h:97