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

marble

  • sources
  • kde-4.12
  • 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)" );
109  result = result.arg( MARBLE_VERSION_STRING, platform, component);
110  return result.toLatin1();
111 }
112 
113 
114 } // namespace Marble
115 
116 #include "TinyWebBrowser.moc"
Marble::TinyWebBrowser::TinyWebBrowser
TinyWebBrowser(QWidget *parent=0)
Definition: TinyWebBrowser.cpp:47
Marble::MarbleLocale::languageCode
static QString languageCode()
Definition: MarbleLocale.cpp:50
Marble::guessWikipediaDomain
static QString guessWikipediaDomain()
Definition: TinyWebBrowser.cpp:40
TinyWebBrowser.h
Marble::TinyWebBrowser
This class provides a tiny web browser based on QWebView (WebKit).
Definition: TinyWebBrowser.h:35
Marble::TinyWebBrowser::statusMessage
void statusMessage(QString)
QWidget
Marble::TinyWebBrowser::~TinyWebBrowser
~TinyWebBrowser()
Definition: TinyWebBrowser.cpp:64
MarbleDebug.h
MarbleDirs.h
MarbleLocale.h
MarbleGlobal.h
Marble::TinyWebBrowser::setWikipediaPath
void setWikipediaPath(const QString &relativeUrl)
Definition: TinyWebBrowser.cpp:70
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
QWebView
Marble::MARBLE_VERSION_STRING
const QString MARBLE_VERSION_STRING
Definition: MarbleGlobal.h:223
Marble::TinyWebBrowser::print
void print()
Definition: TinyWebBrowser.cpp:78
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:53 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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