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 <QAction>
12#include <QDesktopServices>
13#include <QPainter>
14#include <QPointer>
15#include <QPrintDialog>
16#include <QPrinter>
17
18// Marble
19#include "MarbleDebug.h"
20#include "MarbleDirs.h"
21#include "MarbleGlobal.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 QLatin1StringView("https://") + code + QLatin1StringView(".m.wikipedia.org/");
37}
38
39TinyWebBrowser::TinyWebBrowser(QWidget *parent)
40 : QWebEngineView(parent)
41 , d(nullptr)
42{
43 auto page = new MarbleWebPage();
44 setPage(page);
45
46 connect(this, SIGNAL(statusBarMessage(QString)), this, SIGNAL(statusMessage(QString)));
47
48 connect(page, &MarbleWebPage::linkClicked, this, &TinyWebBrowser::openExternalLink);
49 connect(this, &QWebEngineView::titleChanged, this, &QWidget::setWindowTitle);
50
51 pageAction(QWebEnginePage::OpenLinkInNewWindow)->setEnabled(false);
52 pageAction(QWebEnginePage::OpenLinkInNewWindow)->setVisible(false);
53}
54
55TinyWebBrowser::~TinyWebBrowser()
56{
57 // not yet needed
58 // delete d;
59}
60
61void TinyWebBrowser::setWikipediaPath(const QString &relativeUrl)
62{
63 QUrl url(relativeUrl);
64 if (url.isRelative())
65 url = QUrl(guessWikipediaDomain()).resolved(url);
66 load(url);
67}
68
69void TinyWebBrowser::print()
70{
71#ifndef QT_NO_PRINTER
72 QPrinter printer;
73
74 QPointer<QPrintDialog> dlg = new QPrintDialog(&printer, this);
75 if (dlg->exec())
76 QWebEngineView::print(&printer);
77 delete dlg;
78#endif
79}
80
81QWebEngineView *TinyWebBrowser::createWindow(QWebEnginePage::WebWindowType type)
82{
83 Q_UNUSED(type)
84 auto view = new TinyWebBrowser(this);
85 return view;
86}
87
88void TinyWebBrowser::openExternalLink(const QUrl &url)
89{
91}
92
93} // namespace Marble
94
95#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
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.