• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • lib
  • marble
TinyWebBrowser.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Project.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2006-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 // Copyright 2008 Simon Hausmann <hausmann@kde.org>
11 //
12 
13 // Self
14 #include "TinyWebBrowser.h"
15 
16 // Qt
17 #include <QFileInfo>
18 #include <QPointer>
19 #include <QRegExp>
20 #include <QAction>
21 #include <QDesktopServices>
22 #include <QPainter>
23 #include <QPrintDialog>
24 #include <QPrinter>
25 #include <QTextFrame>
26 
27 // Marble
28 #include "MarbleGlobal.h"
29 #include "MarbleDebug.h"
30 #include "MarbleDirs.h"
31 #include "MarbleLocale.h"
32 
33 namespace Marble
34 {
35 
36 class TinyWebBrowserPrivate
37 {
38 };
39 
40 static QString guessWikipediaDomain()
41 {
42  const QString code = MarbleLocale::languageCode();
43 
44  return QString ( "http://%1.m.wikipedia.org/" ).arg ( code );
45 }
46 
47 TinyWebBrowser::TinyWebBrowser( QWidget* parent )
48  : QWebView( parent ),
49  d( 0 )
50 {
51  connect( this, SIGNAL(statusBarMessage(QString)),
52  this, SIGNAL(statusMessage(QString)) );
53 
54  page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
55  connect( this, SIGNAL(linkClicked(QUrl)),
56  this, SLOT(openExternalLink(QUrl)) );
57  connect( this, SIGNAL(titleChanged(QString)),
58  this, SLOT(setWindowTitle(QString)) );
59 
60  pageAction( QWebPage::OpenLinkInNewWindow )->setEnabled( false );
61  pageAction( QWebPage::OpenLinkInNewWindow )->setVisible( false );
62 }
63 
64 TinyWebBrowser::~TinyWebBrowser()
65 {
66  // not yet needed
67  //delete d;
68 }
69 
70 void TinyWebBrowser::setWikipediaPath( const QString& relativeUrl )
71 {
72  QUrl url = relativeUrl;
73  if ( url.isRelative() )
74  url = QUrl( guessWikipediaDomain() ).resolved( url );
75  load( url );
76 }
77 
78 void TinyWebBrowser::print()
79 {
80 #ifndef QT_NO_PRINTER
81  QPrinter printer;
82 
83  QPointer<QPrintDialog> dlg = new QPrintDialog( &printer, this );
84  if ( dlg->exec() )
85  QWebView::print( &printer );
86  delete dlg;
87 #endif
88 }
89 
90 QWebView *TinyWebBrowser::createWindow( QWebPage::WebWindowType type )
91 {
92  TinyWebBrowser *view = new TinyWebBrowser( this );
93 
94  if ( type == QWebPage::WebModalDialog ) {
95  view->setWindowModality( Qt::WindowModal );
96  }
97 
98  return view;
99 }
100 
101 void TinyWebBrowser::openExternalLink( QUrl url )
102 {
103  QDesktopServices::openUrl( url );
104 }
105 
106 QByteArray TinyWebBrowser::userAgent(const QString &platform, const QString &component)
107 {
108  QString result( "Mozilla/5.0 (compatible; Marble/%1; %2; %3; %4)" );
109  bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
110  QString const device = smallScreen ? "MobileDevice" : "DesktopDevice";
111  result = result.arg( MARBLE_VERSION_STRING, device, platform, component);
112  return result.toLatin1();
113 }
114 
115 
116 } // namespace Marble
117 
118 #include "TinyWebBrowser.moc"
Marble::TinyWebBrowser::TinyWebBrowser
TinyWebBrowser(QWidget *parent=0)
Definition: TinyWebBrowser.cpp:47
QWebView::titleChanged
void titleChanged(const QString &title)
QWidget
Marble::MarbleLocale::languageCode
static QString languageCode()
Definition: MarbleLocale.cpp:50
Marble::guessWikipediaDomain
static QString guessWikipediaDomain()
Definition: TinyWebBrowser.cpp:40
TinyWebBrowser.h
QWebView::load
void load(const QUrl &url)
Marble::TinyWebBrowser
This class provides a tiny web browser based on QWebView (WebKit).
Definition: TinyWebBrowser.h:35
Marble::TinyWebBrowser::statusMessage
void statusMessage(QString)
QWebView
QByteArray
QWidget::setWindowModality
void setWindowModality(Qt::WindowModality windowModality)
QPrinter
QAction::setVisible
void setVisible(bool)
QPointer
Marble::TinyWebBrowser::~TinyWebBrowser
~TinyWebBrowser()
Definition: TinyWebBrowser.cpp:64
QWebView::linkClicked
void linkClicked(const QUrl &url)
MarbleDebug.h
QWebView::print
void print(QPrinter *printer) const
QWebPage::setLinkDelegationPolicy
void setLinkDelegationPolicy(LinkDelegationPolicy policy)
QPrintDialog
QWebView::pageAction
QAction * pageAction(QWebPage::WebAction action) const
MarbleDirs.h
QString
MarbleLocale.h
MarbleGlobal.h
Marble::TinyWebBrowser::setWikipediaPath
void setWikipediaPath(const QString &relativeUrl)
Definition: TinyWebBrowser.cpp:70
QUrl
Marble::MarbleGlobal::SmallScreen
Definition: MarbleGlobal.h:287
Marble::MarbleGlobal::getInstance
static MarbleGlobal * getInstance()
Definition: MarbleGlobal.cpp:37
QWebView::url
QUrl url() const
QString::toLatin1
QByteArray toLatin1() const
QUrl::isRelative
bool isRelative() const
QWidget::setWindowTitle
void setWindowTitle(const QString &)
Marble::MarbleGlobal::profiles
Profiles profiles() const
Definition: MarbleGlobal.cpp:48
QWebView::page
QWebPage * page() const
Marble::TinyWebBrowser::createWindow
QWebView * createWindow(QWebPage::WebWindowType type)
Definition: TinyWebBrowser.cpp:90
Marble::TinyWebBrowser::userAgent
static QByteArray userAgent(const QString &platform, const QString &plugin)
Definition: TinyWebBrowser.cpp:106
QDesktopServices::openUrl
bool openUrl(const QUrl &url)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QAction::setEnabled
void setEnabled(bool)
QWebView::statusBarMessage
void statusBarMessage(const QString &text)
Marble::MARBLE_VERSION_STRING
const QString MARBLE_VERSION_STRING
Definition: MarbleGlobal.h:242
Marble::TinyWebBrowser::print
void print()
Definition: TinyWebBrowser.cpp:78
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal