[Marble-commits] KDE/kdeedu/marble/src

Bastian Holst bastianholst at gmx.de
Wed Aug 12 13:32:13 CEST 2009


SVN commit 1010397 by bholst:

Further work regarding TinyWebBrowser:
* Now part of the public API.
* PhotoPluginItem and WikipediaItem use it now.


 M  +1 -0      lib/CMakeLists.txt  
 M  +1 -0      lib/MarbleWidgetPopupMenu.cpp  
 M  +1 -1      lib/PlacemarkInfoDialog.cpp  
 M  +33 -3     lib/TinyWebBrowser.cpp  
 M  +19 -4     lib/TinyWebBrowser.h  
 M  +2 -6      plugins/render/photo/PhotoPluginItem.cpp  
 M  +3 -2      plugins/render/photo/PhotoPluginItem.h  
 M  +3 -5      plugins/render/wikipedia/WikipediaItem.cpp  
 M  +3 -1      plugins/render/wikipedia/WikipediaItem.h  


--- trunk/KDE/kdeedu/marble/src/lib/CMakeLists.txt #1010396:1010397
@@ -283,6 +283,7 @@
     MapThemeManager.h
     MarbleAboutDialog.h
     MarbleWidgetInputHandler.h
+    TinyWebBrowser.h
 
     MapThemeSortFilterProxyModel.h
     
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidgetPopupMenu.cpp #1010396:1010397
@@ -159,6 +159,7 @@
         QModelIndex index = m_featurelist.at( actionidx -1 );
 
         PlacemarkInfoDialog dialog( index, m_widget );
+        dialog.setWindowModality( Qt::WindowModal );
         dialog.exec();
     }
 }
--- trunk/KDE/kdeedu/marble/src/lib/PlacemarkInfoDialog.cpp #1010396:1010397
@@ -40,7 +40,7 @@
     connect( m_pWikipediaBrowser, SIGNAL( statusMessage( QString ) ),
              this,                SLOT( showMessage( QString) ) );
     connect( this,                SIGNAL( source( QString ) ),
-             m_pWikipediaBrowser, SLOT( setSource( QString ) ) );//for wikipedia
+             m_pWikipediaBrowser, SLOT( setWikipediaPath( QString ) ) );//for wikipedia
 
     showContent();
 }
--- trunk/KDE/kdeedu/marble/src/lib/TinyWebBrowser.cpp #1010396:1010397
@@ -15,9 +15,11 @@
 
 // Qt
 #include <QtCore/QFileInfo>
+#include <QtCore/QPointer>
 #include <QtCore/QUrl>
 #include <QtCore/QDebug>
 #include <QtCore/QRegExp>
+#include <QtGui/QAction>
 #include <QtGui/QPainter>
 #include <QtGui/QPrintDialog>
 #include <QtGui/QPrinter>
@@ -29,8 +31,16 @@
 #include "MarbleDirs.h"
 #include "MarbleLocale.h"
 
-using namespace Marble;
+namespace Marble
+{
 
+class TinyWebBrowserPrivate
+{
+ public:
+    ~TinyWebBrowserPrivate() {
+    }
+};
+
 static QString guessWikipediaDomain()
 {
     const QString code = MarbleLocale::languageCode();
@@ -39,7 +49,8 @@
 }
 
 TinyWebBrowser::TinyWebBrowser( QWidget* parent )
-    : QWebView( parent )
+    : QWebView( parent ),
+      d( new TinyWebBrowserPrivate() )
 {
     connect( this, SIGNAL( statusBarMessage( QString ) ),
              this, SIGNAL( statusMessage( QString ) ) );
@@ -47,13 +58,19 @@
     page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
     connect( this, SIGNAL( linkClicked( QUrl ) ),
              this, SLOT( openExternalLink( QUrl ) ) );
+    connect( this, SIGNAL( titleChanged( QString ) ),
+             this, SLOT( setWindowTitle( QString ) ) );
+
+    pageAction( QWebPage::OpenLinkInNewWindow )->setEnabled( false );
+    pageAction( QWebPage::OpenLinkInNewWindow )->setVisible( false );
 }
 
 TinyWebBrowser::~TinyWebBrowser()
 {
+    delete d;
 }
 
-void TinyWebBrowser::setSource( const QString& relativeUrl )
+void TinyWebBrowser::setWikipediaPath( const QString& relativeUrl )
 {
     QUrl url = relativeUrl;
     if ( url.isRelative() )
@@ -70,9 +87,22 @@
     QWebView::print( &printer );
 }
 
+QWebView *TinyWebBrowser::createWindow( QWebPage::WebWindowType type )
+{
+    TinyWebBrowser *view = new TinyWebBrowser( this );
+
+    if ( type == QWebPage::WebModalDialog ) {
+        view->setWindowModality( Qt::WindowModal );
+    }
+
+    return view;
+}
+
 void TinyWebBrowser::openExternalLink( QUrl url )
 {
     QDesktopServices::openUrl( url );
 }
 
+} // namespace Marble
+
 #include "TinyWebBrowser.moc"
--- trunk/KDE/kdeedu/marble/src/lib/TinyWebBrowser.h #1010396:1010397
@@ -15,18 +15,30 @@
 // Author: Torsten Rahn
 //
 
-#include <qglobal.h>
 
 #ifndef TINYWEBBROWSER_H
 #define TINYWEBBROWSER_H
 
+// Qt
+#include <qglobal.h>
 #include <QtWebKit/QWebView>
 #include <QtGui/QDesktopServices>
 
+// Marble
+#include "marble_export.h"
+
 namespace Marble
 {
 
-class TinyWebBrowser : public QWebView
+class TinyWebBrowserPrivate;
+
+/**
+ * This class provides a tiny web browser based on QWebView (WebKit).
+ * It is different from QWebView as it has the button "Open in new Window"
+ * disabled per default and instead opens every link in the default web
+ * browser of the user.
+ */
+class MARBLE_EXPORT TinyWebBrowser : public QWebView
 {
     Q_OBJECT
 
@@ -35,17 +47,20 @@
     ~TinyWebBrowser();
 
  public Q_SLOTS:
-    void setSource( const QString& relativeUrl );
+    void setWikipediaPath( const QString& relativeUrl );
     void print();
 
  Q_SIGNALS:
     void statusMessage( QString );
 
+ protected:
+    QWebView *createWindow( QWebPage::WebWindowType type );
+
  private Q_SLOTS:
     void openExternalLink( QUrl );
 
  private:
-    QString         m_source;
+    TinyWebBrowserPrivate *d;
 };
 
 }
--- trunk/KDE/kdeedu/marble/src/plugins/render/photo/PhotoPluginItem.cpp #1010396:1010397
@@ -31,7 +31,6 @@
 #include <QtCore/QHash>
 #include <QtCore/QUrl>
 #include <QtGui/QMouseEvent>
-#include <QtWebKit/QWebView>
 
 using namespace Marble;
 
@@ -178,15 +177,12 @@
 
 void PhotoPluginItem::openBrowser()
 {
-    if( m_browser ) {
-        delete m_browser;
+    if( !m_browser ) {
+        m_browser = new TinyWebBrowser();
     }
-    m_browser = new QWebView();
     QString url = "http://www.flickr.com/photos/%1/%2/";
     m_browser->load( QUrl( url.arg( owner() ).arg( id() ) ) );
     m_browser->show();
-    connect( m_browser, SIGNAL( titleChanged(QString) ),
-             m_browser, SLOT( setWindowTitle(QString) ) );
 }
 
 #include "PhotoPluginItem.moc"
--- trunk/KDE/kdeedu/marble/src/plugins/render/photo/PhotoPluginItem.h #1010396:1010397
@@ -17,10 +17,11 @@
 
 class QAction;
 class QUrl;
-class QWebView;
 
 namespace Marble
 {
+
+class TinyWebBrowser;
  
 class PhotoPluginItem : public AbstractDataPluginItem
 {
@@ -75,7 +76,7 @@
     bool m_hasCoordinates;
     QPixmap m_smallImage;
     QPixmap m_microImage;
-    QWebView *m_browser;
+    TinyWebBrowser *m_browser;
     QAction *m_action;
     
     QString m_server;
--- trunk/KDE/kdeedu/marble/src/plugins/render/wikipedia/WikipediaItem.cpp #1010396:1010397
@@ -23,6 +23,7 @@
 #include "GeoPainter.h"
 #include "ViewportParams.h"
 #include "GeoSceneLayer.h"
+#include "TinyWebBrowser.h"
 
 using namespace Marble;
 
@@ -174,14 +175,11 @@
 
 void WikipediaItem::openBrowser( )
 {
-    if( m_browser ) {
-        delete m_browser;
+    if( !m_browser ) {
+        m_browser = new TinyWebBrowser();
     }
-    m_browser = new QWebView();
     m_browser->load( url() );
     m_browser->show();
-    connect( m_browser, SIGNAL( titleChanged(QString) ),
-             m_browser, SLOT( setWindowTitle(QString) ) );
 }
     
 void WikipediaItem::setIcon( const QIcon& icon )
--- trunk/KDE/kdeedu/marble/src/plugins/render/wikipedia/WikipediaItem.h #1010396:1010397
@@ -23,6 +23,8 @@
 
 namespace Marble
 {
+
+class TinyWebBrowser;
  
 class WikipediaItem : public AbstractDataPluginItem
 {
@@ -85,7 +87,7 @@
     QUrl m_url;
     QUrl m_thumbnailImageUrl;
     QString m_summary;
-    QWebView *m_browser;
+    TinyWebBrowser *m_browser;
     QAction *m_action;
 
     QPixmap m_thumbnail;


More information about the Marble-commits mailing list