Home | History | Annotate | Download | only in Api
      1 /*
      2     Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
      3     Copyright (C) 2007 Staikos Computing Services Inc.
      4 
      5     This library is free software; you can redistribute it and/or
      6     modify it under the terms of the GNU Library General Public
      7     License as published by the Free Software Foundation; either
      8     version 2 of the License, or (at your option) any later version.
      9 
     10     This library is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13     Library General Public License for more details.
     14 
     15     You should have received a copy of the GNU Library General Public License
     16     along with this library; see the file COPYING.LIB.  If not, write to
     17     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18     Boston, MA 02110-1301, USA.
     19 */
     20 
     21 #ifndef QWEBVIEW_H
     22 #define QWEBVIEW_H
     23 
     24 #include "qwebkitglobal.h"
     25 #include "qwebpage.h"
     26 #include <QtGui/qwidget.h>
     27 #include <QtGui/qicon.h>
     28 #include <QtGui/qpainter.h>
     29 #include <QtCore/qurl.h>
     30 #include <QtNetwork/qnetworkaccessmanager.h>
     31 
     32 QT_BEGIN_NAMESPACE
     33 class QNetworkRequest;
     34 class QPrinter;
     35 QT_END_NAMESPACE
     36 
     37 class QWebPage;
     38 class QWebViewPrivate;
     39 class QWebNetworkRequest;
     40 
     41 class QWEBKIT_EXPORT QWebView : public QWidget {
     42     Q_OBJECT
     43     Q_PROPERTY(QString title READ title)
     44     Q_PROPERTY(QUrl url READ url WRITE setUrl)
     45     Q_PROPERTY(QIcon icon READ icon)
     46     Q_PROPERTY(QString selectedText READ selectedText)
     47     Q_PROPERTY(bool modified READ isModified)
     48     //Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
     49     Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false)
     50     Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor)
     51 
     52     Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints)
     53     Q_FLAGS(QPainter::RenderHints)
     54 public:
     55     explicit QWebView(QWidget* parent = 0);
     56     virtual ~QWebView();
     57 
     58     QWebPage* page() const;
     59     void setPage(QWebPage* page);
     60 
     61     void load(const QUrl& url);
     62     void load(const QNetworkRequest& request,
     63               QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation,
     64               const QByteArray &body = QByteArray());
     65     void setHtml(const QString& html, const QUrl& baseUrl = QUrl());
     66     void setContent(const QByteArray& data, const QString& mimeType = QString(), const QUrl& baseUrl = QUrl());
     67 
     68     QWebHistory* history() const;
     69     QWebSettings* settings() const;
     70 
     71     QString title() const;
     72     void setUrl(const QUrl &url);
     73     QUrl url() const;
     74     QIcon icon() const;
     75 
     76     QString selectedText() const;
     77 
     78     QAction* pageAction(QWebPage::WebAction action) const;
     79     void triggerPageAction(QWebPage::WebAction action, bool checked = false);
     80 
     81     bool isModified() const;
     82 
     83     /*
     84     Qt::TextInteractionFlags textInteractionFlags() const;
     85     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
     86     void setTextInteractionFlag(Qt::TextInteractionFlag flag);
     87     */
     88 
     89     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
     90 
     91     QSize sizeHint() const;
     92 
     93     qreal zoomFactor() const;
     94     void setZoomFactor(qreal factor);
     95 
     96     void setTextSizeMultiplier(qreal factor);
     97     qreal textSizeMultiplier() const;
     98 
     99     QPainter::RenderHints renderHints() const;
    100     void setRenderHints(QPainter::RenderHints hints);
    101     void setRenderHint(QPainter::RenderHint hint, bool enabled = true);
    102 
    103     bool findText(const QString& subString, QWebPage::FindFlags options = 0);
    104 
    105     virtual bool event(QEvent*);
    106 
    107 public Q_SLOTS:
    108     void stop();
    109     void back();
    110     void forward();
    111     void reload();
    112 
    113     void print(QPrinter*) const;
    114 
    115 Q_SIGNALS:
    116     void loadStarted();
    117     void loadProgress(int progress);
    118     void loadFinished(bool);
    119     void titleChanged(const QString& title);
    120     void statusBarMessage(const QString& text);
    121     void linkClicked(const QUrl&);
    122     void selectionChanged();
    123     void iconChanged();
    124     void urlChanged(const QUrl&);
    125 
    126 protected:
    127     void resizeEvent(QResizeEvent*);
    128     void paintEvent(QPaintEvent*);
    129 
    130     virtual QWebView *createWindow(QWebPage::WebWindowType type);
    131 
    132     virtual void changeEvent(QEvent*);
    133     virtual void mouseMoveEvent(QMouseEvent*);
    134     virtual void mousePressEvent(QMouseEvent*);
    135     virtual void mouseDoubleClickEvent(QMouseEvent*);
    136     virtual void mouseReleaseEvent(QMouseEvent*);
    137 #ifndef QT_NO_CONTEXTMENU
    138     virtual void contextMenuEvent(QContextMenuEvent*);
    139 #endif
    140 #ifndef QT_NO_WHEELEVENT
    141     virtual void wheelEvent(QWheelEvent*);
    142 #endif
    143     virtual void keyPressEvent(QKeyEvent*);
    144     virtual void keyReleaseEvent(QKeyEvent*);
    145     virtual void dragEnterEvent(QDragEnterEvent*);
    146     virtual void dragLeaveEvent(QDragLeaveEvent*);
    147     virtual void dragMoveEvent(QDragMoveEvent*);
    148     virtual void dropEvent(QDropEvent*);
    149     virtual void focusInEvent(QFocusEvent*);
    150     virtual void focusOutEvent(QFocusEvent*);
    151     virtual void inputMethodEvent(QInputMethodEvent*);
    152 
    153     virtual bool focusNextPrevChild(bool next);
    154 
    155 private:
    156     friend class QWebPage;
    157     QWebViewPrivate* d;
    158     Q_PRIVATE_SLOT(d, void _q_pageDestroyed())
    159 };
    160 
    161 #endif // QWEBVIEW_H
    162