Marble

TinyWebBrowser.cpp
1 // SPDX-FileCopyrightText: 2006-2007 Torsten Rahn <[email protected]>
2 // SPDX-FileCopyrightText: 2007 Inge Wallin <[email protected]>
3 // SPDX-FileCopyrightText: 2008 Simon Hausmann <[email protected]>
4 //
5 // SPDX-License-Identifier: LGPL-2.1-or-later
6 
7 // Self
8 #include "TinyWebBrowser.h"
9 
10 // Qt
11 #include <QPointer>
12 #include <QAction>
13 #include <QDesktopServices>
14 #include <QPainter>
15 #include <QPrintDialog>
16 #include <QPrinter>
17 
18 // Marble
19 #include "MarbleGlobal.h"
20 #include "MarbleDebug.h"
21 #include "MarbleDirs.h"
22 #include "MarbleLocale.h"
23 #include "MarbleWebView.h"
24 
25 namespace Marble
26 {
27 
28 class TinyWebBrowserPrivate
29 {
30 };
31 
32 static QString guessWikipediaDomain()
33 {
34  const QString code = MarbleLocale::languageCode();
35 
36  return QLatin1String("https://") + code + QLatin1String(".m.wikipedia.org/");
37 }
38 
39 TinyWebBrowser::TinyWebBrowser( QWidget* parent )
40  : QWebEngineView( parent ),
41  d( nullptr )
42 {
43  MarbleWebPage * page = new MarbleWebPage();
44  setPage(page);
45 
46  connect( this, SIGNAL(statusBarMessage(QString)),
47  this, SIGNAL(statusMessage(QString)) );
48 
49  connect( page, SIGNAL(linkClicked(QUrl)),
50  this, SLOT(openExternalLink(QUrl)) );
51  connect( this, SIGNAL(titleChanged(QString)),
52  this, SLOT(setWindowTitle(QString)) );
53 
54  pageAction( QWebEnginePage::OpenLinkInNewWindow )->setEnabled( false );
55  pageAction( QWebEnginePage::OpenLinkInNewWindow )->setVisible( false );
56 }
57 
58 TinyWebBrowser::~TinyWebBrowser()
59 {
60  // not yet needed
61  //delete d;
62 }
63 
64 void TinyWebBrowser::setWikipediaPath( const QString& relativeUrl )
65 {
66  QUrl url(relativeUrl);
67  if ( url.isRelative() )
68  url = QUrl( guessWikipediaDomain() ).resolved( url );
69  load( url );
70 }
71 
72 void TinyWebBrowser::print()
73 {
74 #ifndef QT_NO_PRINTER
75  QPrinter printer;
76 
77  QPointer<QPrintDialog> dlg = new QPrintDialog( &printer, this );
78  if ( dlg->exec() )
79  page()->print( &printer, [=](bool){} );
80  delete dlg;
81 #endif
82 }
83 
84 QWebEngineView *TinyWebBrowser::createWindow( QWebEnginePage::WebWindowType type )
85 {
86  Q_UNUSED(type)
87  TinyWebBrowser *view = new TinyWebBrowser( this );
88  return view;
89 }
90 
91 void TinyWebBrowser::openExternalLink( const QUrl& url )
92 {
94 }
95 
96 
97 } // namespace Marble
98 
99 #include "moc_TinyWebBrowser.cpp"
QAction * load(const QObject *recvr, const char *slot, QObject *parent)
bool openUrl(const QUrl &url)
Binds a QML item to a specific geodetic location in screen coordinates.
QUrl resolved(const QUrl &relative) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Sep 27 2023 04:09:08 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.