Marble

TinyWebBrowser.cpp
1// SPDX-FileCopyrightText: 2006-2007 Torsten Rahn <tackat@kde.org>
2// SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
3// SPDX-FileCopyrightText: 2008 Simon Hausmann <hausmann@kde.org>
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
25namespace Marble
26{
27
28class TinyWebBrowserPrivate
29{
30};
31
32static QString guessWikipediaDomain()
33{
34 const QString code = MarbleLocale::languageCode();
35
36 return QLatin1String("https://") + code + QLatin1String(".m.wikipedia.org/");
37}
38
39TinyWebBrowser::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
58TinyWebBrowser::~TinyWebBrowser()
59{
60 // not yet needed
61 //delete d;
62}
63
64void 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
72void 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
84QWebEngineView *TinyWebBrowser::createWindow( QWebEnginePage::WebWindowType type )
85{
86 Q_UNUSED(type)
87 TinyWebBrowser *view = new TinyWebBrowser( this );
88 return view;
89}
90
91void 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)
Binds a QML item to a specific geodetic location in screen coordinates.
bool openUrl(const QUrl &url)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QUrl resolved(const QUrl &relative) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.