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(QString selectedHtml READ selectedHtml)
     48     Q_PROPERTY(bool hasSelection READ hasSelection)
     49     Q_PROPERTY(bool modified READ isModified)
     50     //Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
     51     Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false)
     52     Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor)
     53 
     54     Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints)
     55     Q_FLAGS(QPainter::RenderHints)
     56 public:
     57     explicit QWebView(QWidget* parent = 0);
     58     virtual ~QWebView();
     59 
     60     QWebPage* page() const;
     61     void setPage(QWebPage* page);
     62 
     63     void load(const QUrl& url);
     64     void load(const QNetworkRequest& request,
     65               QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation,
     66               const QByteArray &body = QByteArray());
     67     void setHtml(const QString& html, const QUrl& baseUrl = QUrl());
     68     void setContent(const QByteArray& data, const QString& mimeType = QString(), const QUrl& baseUrl = QUrl());
     69 
     70     QWebHistory* history() const;
     71     QWebSettings* settings() const;
     72 
     73     QString title() const;
     74     void setUrl(const QUrl &url);
     75     QUrl url() const;
     76     QIcon icon() const;
     77 
     78     bool hasSelection() const;
     79     QString selectedText() const;
     80     QString selectedHtml() const;
     81 
     82 #ifndef QT_NO_ACTION
     83     QAction* pageAction(QWebPage::WebAction action) const;
     84 #endif
     85     void triggerPageAction(QWebPage::WebAction action, bool checked = false);
     86 
     87     bool isModified() const;
     88 
     89     /*
     90     Qt::TextInteractionFlags textInteractionFlags() const;
     91     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
     92     void setTextInteractionFlag(Qt::TextInteractionFlag flag);
     93     */
     94 
     95     QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
     96 
     97     QSize sizeHint() const;
     98 
     99     qreal zoomFactor() const;
    100     void setZoomFactor(qreal factor);
    101 
    102     void setTextSizeMultiplier(qreal factor);
    103     qreal textSizeMultiplier() const;
    104 
    105     QPainter::RenderHints renderHints() const;
    106     void setRenderHints(QPainter::RenderHints hints);
    107     void setRenderHint(QPainter::RenderHint hint, bool enabled = true);
    108 
    109     bool findText(const QString& subString, QWebPage::FindFlags options = 0);
    110 
    111     virtual bool event(QEvent*);
    112 
    113 public Q_SLOTS:
    114     void stop();
    115     void back();
    116     void forward();
    117     void reload();
    118 
    119     void print(QPrinter*) const;
    120 
    121 Q_SIGNALS:
    122     void loadStarted();
    123     void loadProgress(int progress);
    124     void loadFinished(bool);
    125     void titleChanged(const QString& title);
    126     void statusBarMessage(const QString& text);
    127     void linkClicked(const QUrl&);
    128     void selectionChanged();
    129     void iconChanged();
    130     void urlChanged(const QUrl&);
    131 
    132 protected:
    133     void resizeEvent(QResizeEvent*);
    134     void paintEvent(QPaintEvent*);
    135 
    136     virtual QWebView *createWindow(QWebPage::WebWindowType type);
    137 
    138     virtual void changeEvent(QEvent*);
    139     virtual void mouseMoveEvent(QMouseEvent*);
    140     virtual void mousePressEvent(QMouseEvent*);
    141     virtual void mouseDoubleClickEvent(QMouseEvent*);
    142     virtual void mouseReleaseEvent(QMouseEvent*);
    143 #ifndef QT_NO_CONTEXTMENU
    144     virtual void contextMenuEvent(QContextMenuEvent*);
    145 #endif
    146 #ifndef QT_NO_WHEELEVENT
    147     virtual void wheelEvent(QWheelEvent*);
    148 #endif
    149     virtual void keyPressEvent(QKeyEvent*);
    150     virtual void keyReleaseEvent(QKeyEvent*);
    151     virtual void dragEnterEvent(QDragEnterEvent*);
    152     virtual void dragLeaveEvent(QDragLeaveEvent*);
    153     virtual void dragMoveEvent(QDragMoveEvent*);
    154     virtual void dropEvent(QDropEvent*);
    155     virtual void focusInEvent(QFocusEvent*);
    156     virtual void focusOutEvent(QFocusEvent*);
    157     virtual void inputMethodEvent(QInputMethodEvent*);
    158 
    159     virtual bool focusNextPrevChild(bool next);
    160 
    161 private:
    162     friend class QWebPage;
    163     QWebViewPrivate* d;
    164     Q_PRIVATE_SLOT(d, void _q_pageDestroyed())
    165 };
    166 
    167 #endif // QWEBVIEW_H
    168