class KHTMLPart

HTML Browser Widget. More...

Definition#include <khtml_part.h>
InheritsKParts::ReadOnlyPart (kparts) [public ]
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Types

Public Methods

Public Slots

Signals

Protected Methods


Detailed Description

This class is khtml's main class. It features an almost complete web browser, and html renderer.

The easiest way to use this class (if you just want to display a an HTML page at some URL) is the following:


 KURL url = "http://www.kde.org";
 KHTMLPart *w = new KHTMLPart();
 w->openURL(url);
 w->view()->resize(500, 400);
 w->show();

By default Java and JavaScript support are disabled. You can enable them by using the setJavaEnabled() and setJScriptEnabled() methods.

Some apps want to write their HTML code directly into the widget instead of it opening an url. You can also do that in the following way:


 QString myHTMLCode = ...;
 KHTMLPart *w = new KHTMLPart();
 w->begin();
 w->write(myHTMLCode);
 ...
 w->end();

You can do as many calls to write as you want. But there are two write() methods, one accepting a QString one accepting a char @p * argument. You should use one or the other (but not both) since the method using the char @p * argument does an additional decoding step to convert the written data to Unicode.

enum GUIProfile { DefaultGUI, BrowserViewGUI }

GUIProfile

 KHTMLPart ( QWidget *parentWidget = 0, const char *widgetname = 0, QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI )

KHTMLPart

Constructs a new KHTMLPart.

KHTML basically consists of two objects: The KHTMLPart itself, holding the document data (DOM document), and the KHTMLView, derived from QScrollView, in which the document content is rendered in. You can specify two different parent objects for a KHTMLPart, one parent for the KHTMLPart document and on parent for the KHTMLView. If the second parent argument is 0L, then parentWidget is used as parent for both objects, the part and the view.

 KHTMLPart ( KHTMLView *view, QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI )

KHTMLPart

 ~KHTMLPart ()

~KHTMLPart

[virtual]

Destructor.

bool  openURL ( const KURL &url )

openURL

[virtual]

Opens the specified URL url.

Reimplemented from KParts::ReadOnlyPart::openURL .

Reimplemented from ReadOnlyPart.

bool  closeURL ()

closeURL

[virtual]

Stops loading the document and kill all data requests (for images, etc.)

Reimplemented from ReadOnlyPart.

void  showError (KIO::Job* job)

showError

[virtual]

is called when a certain error situation (i.e. connection timed out) occured. default implementation either shows a KIO error dialog or loads a more verbose error description a as page, depending on the users configuration. job is the job that signaled the error situation

DOM::HTMLDocument  htmlDocument ()

htmlDocument

[const]

Returns a reference to the DOM HTML document (for non-HTML documents, returns null)

DOM::Document  document ()

document

[const]

Returns a reference to the DOM document.

DOM::Node  activeNode ()

activeNode

[const]

Returns the node that has the keyboard focus.

KParts::BrowserExtensionbrowserExtension ()

browserExtension

[const]

Returns a pointer to the KParts::BrowserExtension.

KHTMLViewview ()

view

[const]

Returns a pointer to the HTML document's view.

void  setJScriptEnabled ( bool enable )

setJScriptEnabled

Enable/disable Javascript support. Note that this will in either case permanently override the default usersetting. If you want to have the default UserSettings, don't call this method.

bool  jScriptEnabled ()

jScriptEnabled

[const]

Returns true if Javascript support is enabled or false otherwise.

void  setMetaRefreshEnabled ( bool enable )

setMetaRefreshEnabled

Enable/disable the automatic forwarding by

bool  metaRefreshEnabled ()

metaRefreshEnabled

[const]

Returns true if automtaic forwarding is enabled.

QVariant  executeScript ( const QString &script )

executeScript

Execute the specified snippet of JavaScript code.

Returns true if JavaScript was enabled, no error occured and the code returned true itself or false otherwise.

QVariant  executeScript ( const DOM::Node &n, const QString &script )

executeScript

Same as above except the Node parameter specifying the 'this' value.

void  setDNDEnabled ( bool b )

setDNDEnabled

Enables or disables Drag'n'Drop support. A drag operation is started if the users drags a link.

bool  dndEnabled ()

dndEnabled

[const]

Returns whether Dragn'n'Drop support is enabled or not.

void  setJavaEnabled ( bool enable )

setJavaEnabled

Enables/disables Java applet support. Note that calling this function will permanently override the User settings about Java applet support. Not calling this function is the only way to let the default settings apply.

bool  javaEnabled ()

javaEnabled

[const]

Return if Java applet support is enabled/disabled.

KJavaAppletContextjavaContext ()

javaContext

Returns the java context of the applets. If no applet exists, 0 is returned.

KJavaAppletContextcreateJavaContext ()

createJavaContext

Returns the java context of the applets. If no context exists yet, a new one is created.

void  setPluginsEnabled ( bool enable )

setPluginsEnabled

Enables or disables plugins via, default is enabled

bool  pluginsEnabled ()

pluginsEnabled

[const]

Returns trie if plugins are enabled/disabled.

void  setAutoloadImages ( bool enable )

setAutoloadImages

Specifies whether images contained in the document should be loaded automatically or not.

@note Request will be ignored if called before begin().

bool  autoloadImages ()

autoloadImages

[const]

Returns whether images contained in the document are loaded automatically or not. @note that the returned information is unrelieable as long as no begin() was called.

void  setOnlyLocalReferences (bool enable)

setOnlyLocalReferences

Security option.

Specify whether only local references ( stylesheets, images, scripts, subdocuments ) should be loaded. ( default false - everything is loaded, if the more specific options allow )

bool  onlyLocalReferences ()

onlyLocalReferences

[const]

Returnd whether references should be loaded ( default false )

void  enableJScript (bool e)

enableJScript

void  enableJava (bool e)

enableJava

void  enablePlugins (bool e)

enablePlugins

void  autoloadImages (bool e)

autoloadImages

void  enableMetaRefresh (bool e)

enableMetaRefresh

bool  setCharset ( const QString &, bool )

setCharset

KURL  baseURL ()

baseURL

[const]

QString  baseTarget ()

baseTarget

[const]

KURL  backgroundURL ()

backgroundURL

[const]

Returns the URL for the background Image (used by save background)

void  scheduleRedirection ( int delay, const QString &url, bool lockHistory = true )

scheduleRedirection

Schedules a redirection after delay seconds.

void  begin ( const KURL &url = KURL(), int xOffset = 0, int yOffset = 0 )

begin

[virtual]

Clears the widget and prepares it for new content.

If you want url() to return for example "file:/tmp/test.html", you can use the following code:


 view->begin( KURL("file:/tmp/test.html" ) );

All child frames and the old document are removed if you call this method.

Parameters:
urlis the url of the document to be displayed. Even if you are generating the HTML on the fly, it may be useful to specify a directory so that any pixmaps are found.
xOffsetis the initial horizontal scrollbar value. Usually you don't want to use this.
yOffsetis the initial vertical scrollbar value. Usually you don't want to use this.

void  write ( const char *str, int len = -1 )

write

[virtual]

Writes another part of the HTML code to the widget.

You may call this function many times in sequence. But remember: The fewer calls you make, the faster the widget will be.

The HTML code is send through a decoder which decodes the stream to Unicode.

The len parameter is needed for streams encoded in utf-16, since these can have \0 chars in them. In case the encoding you're using isn't utf-16, you can safely leave out the length parameter.

Attention: Don't mix calls to write( const char *) with calls to write( const QString & ).

The result might not be what you want.

void  write ( const QString &str )

write

[virtual]

Writes another part of the HTML code to the widget.

You may call this function many times in sequence. But remember: The fewer calls you make, the faster the widget will be.

void  end ()

end

[virtual]

Call this after your last call to write().

void  paint (QPainter *, const QRect &, int = 0, bool * = 0)

paint

Paints the HTML page to a QPainter. See KHTMLView::paint for details

bool  setEncoding ( const QString &name, bool override = false )

setEncoding

Sets the encoding the page uses.

This can be different from the charset. The widget will try to reload the current page in the new encoding, if url() is not empty.

QString  encoding ()

encoding

[const]

Returns the encoding the page currently uses.

Note that the encoding might be different from the charset.

void  setUserStyleSheet (const KURL &url)

setUserStyleSheet

Sets a user defined style sheet to be used on top of the HTML 4 default style sheet.

This gives a wide range of possibilities to change the layout of the page.

void  setUserStyleSheet (const QString &styleSheet)

setUserStyleSheet

Sets a user defined style sheet to be used on top of the HTML 4 default style sheet.

This gives a wide range of possibilities to change the layout of the page.

void  setStandardFont ( const QString &name )

setStandardFont

Sets the standard font style.

Parameters:
nameThe font name to use for standard text.

void  setFixedFont ( const QString &name )

setFixedFont

Sets the fixed font style.

Parameters:
nameThe font name to use for fixed text, e.g. the <pre> tag.

bool  gotoAnchor ( const QString &name )

gotoAnchor

Finds the anchor named name.

If the anchor is found, the widget scrolls to the closest position. Returns if the anchor has been found.

void  setURLCursor ( const QCursor &c )

setURLCursor

Sets the cursor to use when the cursor is on a link.

QCursor  urlCursor ()

urlCursor

[const]

Returns the cursor which is used when the cursor is on a link.

void  findTextBegin ()

findTextBegin

Initiates a text search.

bool  findTextNext ( const QString &str, bool forward, bool caseSensitive, bool isRegExp )

findTextNext

Finds the next occurence of the string or expression. If isRegExp is true then str is converted to a QRegExp, and caseSensitive is ignored.

void  setZoomFactor (int percent)

setZoomFactor

Sets the Zoom factor. The value is given in percent, larger values mean a generally larger font and larger page contents. It is not guaranteed that all parts of the page are scaled with the same factor though.

The given value should be in the range of 20..300, values outside that range are not guaranteed to work. A value of 100 will disable all zooming and show the page with the sizes determined via the given lengths in the stylesheets.

int  zoomFactor ()

zoomFactor

[const]

Returns the current zoom factor.

QString  selectedText ()

selectedText

[const virtual]

Returns the text the user has marked.

DOM::Range  selection ()

selection

[const]

Returns the selected part of the HTML.

void  setSelection ( const DOM::Range & )

setSelection

Sets the current selection.

bool  hasSelection ()

hasSelection

[const]

Has the user selected anything?

Call selectedText() to retrieve the selected text.

Returns: true if there is text selected.

void  selectAll ()

selectAll

Marks all text in the document as selected.

void  show ()

show

Convenience method to show the document's view.

Equivalent to widget()->show() or view()->show() .

void  hide ()

hide

Convenience method to hide the document's view.

Equivalent to widget()->hide() or view()->hide().

KParts::PartManagerpartManager ()

partManager

Returns a reference to the partmanager instance which manages html frame objects.

void  saveState ( QDataStream &stream )

saveState

[virtual]

Saves the KHTMLPart's complete state (including child frame objects) to the provided QDataStream.

This is called from the saveState() method of the browserExtension().

void  restoreState ( QDataStream &stream )

restoreState

[virtual]

Restores the KHTMLPart's previously saved state (including child frame objects) from the provided QDataStream.

This is called from the restoreState() method of the browserExtension() .

See also: saveState()

DOM::Node  nodeUnderMouse ()

nodeUnderMouse

[const]

Returns the Node currently under the mouse

const KHTMLSettingssettings ()

settings

[const]

KHTMLPartparentPart ()

parentPart

Returns a pointer to the parent KHTMLPart if the part is a frame in an HTML frameset.

Returns 0L otherwise.

QStringList  frameNames ()

frameNames

[const]

Returns a list of names of all frame (including iframe) objects of the current document. Note that this method is not working recursively for sub-frames.

QPtrList<KParts::ReadOnlyPart>  frames ()

frames

[const]

KHTMLPartfindFrame ( const QString &f )

findFrame

Finds a frame by name. Returns 0L if frame can't be found.

KParts::ReadOnlyPartcurrentFrame ()

currentFrame

[const]

Return the current frame (the one that has focus) Not necessarily a direct child of ours, framesets can be nested. Returns "this" if this part isn't a frameset.

bool  frameExists ( const QString &frameName )

frameExists

Returns whether a frame with the specified name is exists or not. In contrary to the findFrame method this one also returns true if the frame is defined but no displaying component has been found/loaded, yet.

void  setJSStatusBarText ( const QString &text )

setJSStatusBarText

Called by KJS. Sets the StatusBarText assigned via window.status

void  setJSDefaultStatusBarText ( const QString &text )

setJSDefaultStatusBarText

Called by KJS. Sets the DefaultStatusBarText assigned via window.defaultStatus

QString  jsStatusBarText ()

jsStatusBarText

[const]

Called by KJS. Returns the StatusBarText assigned via window.status

QString  jsDefaultStatusBarText ()

jsDefaultStatusBarText

[const]

Called by KJS. Returns the DefaultStatusBarText assigned via window.defaultStatus

QString  referrer ()

referrer

[const]

Referrer used for links in this page.

QString  lastModified ()

lastModified

[const]

Last-modified date (in raw string format), if received in the [HTTP] headers.

void  preloadStyleSheet (const QString &url, const QString &stylesheet)

preloadStyleSheet

Loads a style sheet into the stylesheet cache.

void  preloadScript (const QString &url, const QString &script)

preloadScript

Loads a script into the script cache.

bool  restored ()

restored

[const]

void  onURL ( const QString &url )

onURL

[signal]

Emitted if the cursor is moved over an URL.

void  popupMenu (const QString &url, const QPoint &point)

popupMenu

[signal]

Emitted when the user clicks the right mouse button on the document.

void  selectionChanged ()

selectionChanged

[signal]

This signal is emitted when the selection changes.

void  nodeActivated (const DOM::Node &)

nodeActivated

[signal]

This signal is emitted when an element retrieves the keyboard focus. Note that the signal argument can be a null node if no element is active, meaning a node has explicitly been deactivated without a new one becoming active.

KURL  completeURL ( const QString &url )

completeURL

[protected]

returns a KURL object for the given url. Use when you know what you're doing.

void  htmlError (int errorCode, const QString& text, const KURL& reqUrl)

htmlError

[protected]

presents a detailed error message to the user. errorCode kio error code, eg KIO::ERR_SERVER_TIMEOUT. text kio additional information text. url the url that triggered the error.

void  customEvent ( QCustomEvent *event )

customEvent

[protected virtual]

void  khtmlMousePressEvent ( khtml::MousePressEvent *event )

khtmlMousePressEvent

[protected virtual]

Eventhandler of the khtml::MousePressEvent.

void  khtmlMouseDoubleClickEvent ( khtml::MouseDoubleClickEvent * )

khtmlMouseDoubleClickEvent

[protected virtual]

Eventhandler for the khtml::MouseDoubleClickEvent.

void  khtmlMouseMoveEvent ( khtml::MouseMoveEvent *event )

khtmlMouseMoveEvent

[protected virtual]

Eventhandler for the khtml::MouseDoubleMoveEvent.

void  khtmlMouseReleaseEvent ( khtml::MouseReleaseEvent *event )

khtmlMouseReleaseEvent

[protected virtual]

Eventhandler for the khtml::MouseMoveEvent.

void  khtmlDrawContentsEvent ( khtml::DrawContentsEvent * )

khtmlDrawContentsEvent

[protected virtual]

Eventhandler for the khtml::DrawContentsEvent.

void  guiActivateEvent ( KParts::GUIActivateEvent *event )

guiActivateEvent

[protected virtual]

Internal reimplementation of KParts::Part::guiActivateEvent .

Reimplemented from ReadOnlyPart.

bool  openFile ()

openFile

[protected virtual]

Internal empty reimplementation of KParts::ReadOnlyPart::openFile .

Reimplemented from ReadOnlyPart.

void  urlSelected ( const QString &url, int button, int state, const QString &_target, KParts::URLArgs args = KParts::URLArgs())

urlSelected

[protected virtual]

KParts::ReadOnlyPartcreatePart ( QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, const QString &mimetype, QString &serviceName, QStringList &serviceTypes, const QStringList ¶ms)

createPart

[protected virtual]

This method is called when a new embedded object (include html frames) is to be created. Reimplement it if you want to add support for certain embeddable objects without registering them in the KDE wide registry system (KSyCoCa) . Another reason for re-implementing this method could be if you want to derive from KTHMLPart and also want all html frame objects to be a object of your derived type, in which case you should return a new instance for the mimetype 'text/html' .

void  setActiveNode (const DOM::Node &node)

setActiveNode

[slot]

Sets the focussed node of the document to the specified node. If the node is a form control, the control will receive focus in the same way that it would if the user had clicked on it or tabbed to it with the keyboard. For most other types of elements, there is no visul indiction of whether or not they are focussed.

See activeNode

Parameters:
nodeThe node to focus

void  stopAnimations ()

stopAnimations

[slot]

Stops all animated images on the current and child pages

QCString  dcopObjectId ()

dcopObjectId

[const slot]