1 /* 2 web_engine_page_link_navigation_policy.h MindForger thinking notebook 3 4 Copyright (C) 2016-2020 Martin Dvorak <martin.dvorak@mindforger.com> 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 as published by the Free Software Foundation; either version 2 9 of the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 #ifndef M8RUI_WEB_ENGINE_PAGE_LINK_NAVIGATION_POLICY_H 20 #define M8RUI_WEB_ENGINE_PAGE_LINK_NAVIGATION_POLICY_H 21 22 #include "../lib/src/gear/lang_utils.h" 23 #include "../lib/src/debug.h" 24 25 #include <QtWidgets> 26 #ifdef MF_QT_WEB_ENGINE 27 #include <QWebEngineView> 28 #endif 29 30 namespace m8r { 31 32 #ifdef MF_QT_WEB_ENGINE 33 34 class WebEnginePageLinkNavigationPolicy : public QWebEnginePage 35 { 36 Q_OBJECT 37 38 public: 39 explicit WebEnginePageLinkNavigationPolicy(QObject* parent = nullptr); 40 WebEnginePageLinkNavigationPolicy(const WebEnginePageLinkNavigationPolicy&) = delete; 41 WebEnginePageLinkNavigationPolicy(const WebEnginePageLinkNavigationPolicy&&) = delete; 42 WebEnginePageLinkNavigationPolicy &operator=(const WebEnginePageLinkNavigationPolicy&) = delete; 43 WebEnginePageLinkNavigationPolicy &operator=(const WebEnginePageLinkNavigationPolicy&&) = delete; 44 ~WebEnginePageLinkNavigationPolicy(); 45 acceptNavigationRequest(const QUrl & url,QWebEnginePage::NavigationType type,bool isMainFrame)46 bool acceptNavigationRequest(const QUrl& url, QWebEnginePage::NavigationType type, bool isMainFrame) 47 { 48 //MF_DEBUG("acceptNavigationRequest(" << url.toString().toStdString() << "," << type << "," << isMainFrame << ")" << std::endl); 49 UNUSED_ARG(type); 50 UNUSED_ARG(isMainFrame); 51 52 if(type == QWebEnginePage::NavigationTypeLinkClicked) { 53 MF_DEBUG("acceptNavigationRequest() link CLICKED" << std::endl); 54 emit signalLinkClicked(url); 55 return false; 56 } else { 57 return true; 58 } 59 } 60 61 signals: 62 void signalLinkClicked(const QUrl& url); 63 }; 64 65 #endif 66 67 } 68 #endif // M8RUI_WEB_ENGINE_PAGE_LINK_NAVIGATION_POLICY_H 69