2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLASMA_WEBVIEW_H
|
|
|
|
#define PLASMA_WEBVIEW_H
|
|
|
|
|
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
#include <QtGui/QGraphicsWidget>
|
|
|
|
|
2008-11-06 00:39:30 +01:00
|
|
|
#include <kurl.h>
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
class QWebPage;
|
|
|
|
class QWebFrame;
|
|
|
|
class QKeyEvent;
|
|
|
|
class QGraphicsSceneDragDropEvent;
|
|
|
|
class QGraphicsSceneMouseEvent;
|
|
|
|
class QGraphicsSceneWheelEvent;
|
|
|
|
class QRect;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class WebViewPrivate;
|
|
|
|
|
|
|
|
/**
|
2009-01-10 01:08:31 +01:00
|
|
|
* @class WebView plasma/widgets/webview.h <Plasma/Widgets/WebView>
|
2008-11-04 00:08:39 +01:00
|
|
|
*
|
|
|
|
* @short Provides a widget to display html content in Plasma.
|
|
|
|
*/
|
|
|
|
class PLASMA_EXPORT WebView : public QGraphicsWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2009-04-07 10:33:51 +02:00
|
|
|
Q_PROPERTY(KUrl url READ url WRITE setUrl)
|
|
|
|
Q_PROPERTY(QString html READ html WRITE setHtml)
|
2009-03-30 15:27:25 +02:00
|
|
|
Q_PROPERTY(bool dragToScroll READ dragToScroll WRITE setDragToScroll)
|
2009-10-08 18:04:56 +02:00
|
|
|
Q_PROPERTY(QPointF scrollPosition READ scrollPosition WRITE setScrollPosition)
|
|
|
|
Q_PROPERTY(QSizeF contentsSize READ contentsSize)
|
|
|
|
Q_PROPERTY(QRectF viewportGeometry READ viewportGeometry)
|
2009-03-08 21:08:27 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
public:
|
|
|
|
explicit WebView(QGraphicsItem *parent = 0);
|
|
|
|
~WebView();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the URL to display. Loading may happen asynchronously.
|
|
|
|
*
|
|
|
|
* @param url the location of the content to load.
|
|
|
|
*/
|
2008-11-06 00:39:30 +01:00
|
|
|
void setUrl(const KUrl &url);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-04-07 10:33:51 +02:00
|
|
|
/**
|
|
|
|
* @return the html content of the page
|
|
|
|
*/
|
|
|
|
KUrl url() const;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
/**
|
|
|
|
* Sets the html to be shown along with a base URL to be used
|
|
|
|
* to resolve relative references.
|
|
|
|
*
|
|
|
|
* @param html the html (in utf8) to display in the content area
|
|
|
|
* @param baseUrl the base url for relative references
|
|
|
|
*/
|
2008-11-06 00:39:30 +01:00
|
|
|
void setHtml(const QByteArray &html, const KUrl &baseUrl = KUrl());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-04-07 10:33:51 +02:00
|
|
|
/**
|
|
|
|
* @return the html content of the page
|
|
|
|
*/
|
|
|
|
QString html() const;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
/**
|
|
|
|
* Sets the html to be shown along with a base URL to be used
|
|
|
|
* to resolve relative references.
|
|
|
|
*
|
|
|
|
* @param html the html (in utf8) to display in the content area
|
|
|
|
* @param baseUrl the base url for relative references
|
|
|
|
*/
|
2008-11-06 00:39:30 +01:00
|
|
|
void setHtml(const QString &html, const KUrl &baseUrl = KUrl());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reimplementation
|
|
|
|
*/
|
|
|
|
QRectF geometry() const;
|
|
|
|
|
2009-10-03 17:06:41 +02:00
|
|
|
/**
|
2009-10-08 18:04:56 +02:00
|
|
|
* @return the size of the internal widget
|
2009-10-03 17:06:41 +02:00
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-10-08 18:04:56 +02:00
|
|
|
QSizeF contentsSize() const;
|
2009-10-03 17:06:41 +02:00
|
|
|
|
|
|
|
/**
|
2009-10-08 18:04:56 +02:00
|
|
|
* Sets the position of the webpage relative to this widget
|
2009-10-03 17:06:41 +02:00
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-10-08 18:04:56 +02:00
|
|
|
void setScrollPosition(const QPointF &position);
|
2009-10-03 17:06:41 +02:00
|
|
|
|
|
|
|
/**
|
2009-10-08 18:04:56 +02:00
|
|
|
* @return the position of the webpage relative to this widget
|
2009-10-03 17:06:41 +02:00
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-10-08 18:04:56 +02:00
|
|
|
QPointF scrollPosition() const;
|
2009-10-03 17:06:41 +02:00
|
|
|
|
|
|
|
/**
|
2009-10-08 18:04:56 +02:00
|
|
|
* The geometry of the area that actually displays the web page
|
2009-10-03 17:06:41 +02:00
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-10-08 18:04:56 +02:00
|
|
|
QRectF viewportGeometry() const;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
/**
|
|
|
|
* Sets the page to use in this item. The owner of the webpage remains,
|
|
|
|
* however if this WebView object is the owner of the current page,
|
|
|
|
* then the current page is deleted
|
|
|
|
*
|
|
|
|
* @param page the page to set in this view
|
|
|
|
*/
|
|
|
|
void setPage(QWebPage *page);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The QWebPage associated with this item. Useful when more
|
|
|
|
* of the features of the full QWebPage object need to be accessed.
|
|
|
|
*/
|
|
|
|
QWebPage *page() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The main web frame associated with this item.
|
|
|
|
*/
|
|
|
|
QWebFrame *mainFrame() const;
|
|
|
|
|
2009-03-30 13:58:23 +02:00
|
|
|
/**
|
|
|
|
* Sets if the page can be scrolled around by dragging the contents with the mouse
|
2009-03-30 14:21:52 +02:00
|
|
|
* @since 4.3
|
2009-03-30 13:58:23 +02:00
|
|
|
*/
|
|
|
|
void setDragToScroll(bool drag);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if the page can be scrolled by dragging the mouse
|
2009-03-30 14:21:52 +02:00
|
|
|
* @since 4.3
|
2009-03-30 13:58:23 +02:00
|
|
|
*/
|
|
|
|
bool dragToScroll();
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
/**
|
|
|
|
* Reimplementation
|
|
|
|
*/
|
|
|
|
void setGeometry(const QRectF &geometry);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
|
|
|
* During loading progress, this signal is emitted. The values
|
|
|
|
* are always between 0 and 100, inclusive.
|
|
|
|
*
|
|
|
|
* @param percent the estimated amount the loading is complete
|
|
|
|
*/
|
|
|
|
void loadProgress(int percent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This signal is emitted when loading is completed.
|
|
|
|
*
|
|
|
|
* @param success true if the content was loaded successfully,
|
|
|
|
* otherwise false
|
|
|
|
*/
|
|
|
|
void loadFinished(bool success);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Reimplementation
|
|
|
|
*/
|
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
2008-11-20 16:38:51 +01:00
|
|
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
2008-11-04 00:08:39 +01:00
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
|
|
|
|
void wheelEvent(QGraphicsSceneWheelEvent *event);
|
|
|
|
void keyPressEvent(QKeyEvent * event);
|
|
|
|
void keyReleaseEvent(QKeyEvent * event);
|
|
|
|
void focusInEvent(QFocusEvent * event);
|
|
|
|
void focusOutEvent(QFocusEvent * event);
|
|
|
|
void dragEnterEvent(QGraphicsSceneDragDropEvent * event);
|
|
|
|
void dragLeaveEvent(QGraphicsSceneDragDropEvent * event);
|
|
|
|
void dragMoveEvent(QGraphicsSceneDragDropEvent * event);
|
|
|
|
void dropEvent(QGraphicsSceneDragDropEvent * event);
|
2009-11-04 15:16:14 +01:00
|
|
|
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
Q_PRIVATE_SLOT(d, void loadingFinished(bool success))
|
|
|
|
Q_PRIVATE_SLOT(d, void updateRequested(const QRect& dirtyRect))
|
|
|
|
Q_PRIVATE_SLOT(d, void scrollRequested(int dx, int dy, const QRect &scrollRect))
|
|
|
|
|
|
|
|
WebViewPrivate * const d;
|
|
|
|
friend class WebViewPrivate;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#endif // Multiple incluson guard
|
|
|
|
|