class KHTMLPart

HTML Browser Widget. More...

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

Public Methods

Signals

Protected Methods

Protected Slots


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 HTML page at some URL) is the following:


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

By default the Widget behaves as a full browser, so clicking on some link on the page you just opened will lead yu to that page. This is inconvenient, if you want to use the widget to display for example formatted emails, but don't want the widget to open the site in this window in case someone clicks on an embedded link. In this case just use setFollowsLinks(false). You will then get a Signal urlClicked() instead of KHTMLPart following the links directly.

By default Java and JavaScript support is disabled. You can enable it by using the enableJava() and enableJScript() 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 * argument. These should not get mixed, since the method usnig the char * argument does an additional decoding step to convert the written data to Unicode.

void  autoloadImages ( bool enable )

should images be loaded automatically? Default is true. (not implemented at the moment)

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

[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( QString("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.
_dxis the initial horizontal scrollbar value. Usually you don't want to use this.
_dyis the initial vertical scrollbar value. Usually you don't want to use this.

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

[virtual]

Writes another part of the HTML code to the widget. You may call this function many times in sequence. But remember: The less calls the faster the widget is.

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 )

[virtual]

Writes another part of the HTML code to the widget. You may call this function many times in sequence. But remember: The less calls the faster the widget is.

void  end ()

[virtual]

Call this after your last call to write.

const khtml::Settingssettings ()

[const]

Print current HTML page layouted for the printer. (not implemented at the moment)

void  setBaseURL ( const KURL &url )

Mainly used internally. Sets the document's base URL

KURL  baseURL ()

[const]

The base url is ususally set by an <base url=...> tag in the document head.

Returns: the base URL of this document

void  setBaseTarget ( const QString &target )

Mainly used internally. Sets the document's base target.

QString  baseTarget ()

[const]

Returns: the base target of this document The base target is ususally set by an <base target=...> tag in the document head.

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

sets the charset to use for displaying html pages. If override is true, it will override charset specifications of the document.

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

set the encoding the page uses. This can be different form the charset.

void  setUserStyleSheet (const KURL &url)

set 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)

set 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  setFontSizes (const int *newFontSizes, int numFontSizes = 7)

Sets point sizes to be associated with the HTML-sizes used in <FONT size=Html-Font-Size>

Html-Font-Sizes range from 0 (smallest) to 6 (biggest), but you can specify up to 15 font sizes, the bigger ones will get used, if <font size=+1> extends over 7, or if a 'font-size: larger' style declaration gets into this region.

They are related to the CSS font sizes by 0 == xx-small to 6 == xx-large.

const int * fontSizes ()

[const]

Gets point sizes to be associated with the HTML-sizes used in <FONT size=Html-Font-Size>

Html-Font-Sizes range from 0 (smallest) to 6 (biggest).

They are related to the CSS font sizes by 0 == xx-small to 6 == xx-large.

void  resetFontSizes ()

Resets the point sizes to be associated with the HTML-sizes used in <FONT size=Html-Font-Size> to their default.

Html-Font-Sizes range from 1 (smallest) to 7 (biggest).

void  setStandardFont ( const QString &name )

Sets the standard font style.

Parameters:
nameis the font name to use for standard text.

void  setFixedFont ( const QString &name )

Sets the fixed font style.

Parameters:
nameis the font name to use for fixed text, e.g. the <tt>&lt;pre&gt;</tt> tag.

bool  gotoAnchor ( const QString &name )

Find the anchor named '_name'. If the anchor is found, the widget scrolls to the closest position. Returns TRUE if the anchor has been found.

void  setURLCursor ( const QCursor &c )

Sets the cursor to use when the cursor is on a link. (convenience function, just calls htmlWidget->setURLCursor() )

const QCursor&  urlCursor ()

Returns the cursor which is used when the cursor is on a link. (convenience function, just cals htmlWidget->urlCursor() )

void  findTextBegin ()

Initiate a text search.

bool  findTextNext ( const QRegExp &exp )

Find the next occurrance of the expression.

QString  selectedText ()

[const virtual]

Get the text the user has marked.

DOM::Range  selection ()

[const]

Returns: the selected part of the HTML

bool  hasSelection ()

[const]

Has the user selected anything? Call selectedText to retrieve the selected text.

Returns: true if there is text selected.