• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

KRichTextEdit Class Reference

The KRichTextEdit class provides a widget to edit and display rich text. More...

#include <krichtextedit.h>

Inheritance diagram for KRichTextEdit:
KTextEdit QTextEdit KRichTextWidget

List of all members.

Public Types

enum  Mode { Plain, Rich }

Public Slots

void alignCenter ()
void alignJustify ()
void alignLeft ()
void alignRight ()
void indentListLess ()
void indentListMore ()
void insertHorizontalRule ()
void setFont (const QFont &font)
void setFontFamily (const QString &fontFamily)
void setFontSize (int size)
void setListStyle (int _styleIndex)
void setTextBackgroundColor (const QColor &color)
void setTextBold (bool bold)
void setTextForegroundColor (const QColor &color)
void setTextItalic (bool italic)
void setTextStrikeOut (bool strikeOut)
void setTextSubScript (bool subscript)
void setTextSuperScript (bool superscript)
void setTextUnderline (bool underline)
void switchToPlainText ()
QString toCleanHtml () const

Signals

void selectionFinished ()
void textModeChanged (KRichTextEdit::Mode mode)

Public Member Functions

bool canDedentList () const
bool canIndentList () const
QString currentLinkText () const
QString currentLinkUrl () const
void enableRichTextMode ()
 KRichTextEdit (QWidget *parent=0)
 KRichTextEdit (const QString &text, QWidget *parent=0)
void selectLinkText () const
void selectLinkText (QTextCursor *cursor) const
void setTextOrHtml (const QString &text)
Mode textMode () const
QString textOrHtml () const
void updateLink (const QString &linkUrl, const QString &linkText)
virtual ~KRichTextEdit ()

Protected Member Functions

virtual void keyPressEvent (QKeyEvent *event)

Detailed Description

The KRichTextEdit class provides a widget to edit and display rich text.

It offers several additional rich text editing functions to KTextEdit and makes them easier to access including:

  • Changing fonts, sizes.
  • Font formatting, such as bold, underline, italic, foreground and background color.
  • Paragraph alignment
  • Ability to edit and remove hyperlinks
  • Nested list handling
  • Simple actions to insert tables. TODO

The KRichTextEdit can be in two modes: Rich text mode and plain text mode. Calling functions which modify the format/style of the text will automatically enable the rich text mode. Rich text mode is sometimes also referred to as HTML mode.

Do not call setAcceptRichText() or acceptRichText() yourself. Instead simply connect to the slots which insert the rich text, use switchToPlainText() or enableRichTextMode().

Since:
4.1

Definition at line 61 of file krichtextedit.h.


Member Enumeration Documentation

enum KRichTextEdit::Mode

The mode the edit widget is in.

Enumerator:
Plain 

Plain text mode.

Rich 

Rich text mode.

Definition at line 70 of file krichtextedit.h.


Constructor & Destructor Documentation

KRichTextEdit::KRichTextEdit ( const QString &  text,
QWidget *  parent = 0 
) [explicit]

Constructs a KRichTextEdit object.

Private class that helps to provide binary compatibility between releases.

Parameters:
text The initial text of the text edit, which is interpreted as HTML.
parent The parent widget

For internal use only.

Definition at line 117 of file krichtextedit.cpp.

KRichTextEdit::KRichTextEdit ( QWidget *  parent = 0  )  [explicit]

Constructs a KRichTextEdit object.

Parameters:
parent The parent widget

Definition at line 123 of file krichtextedit.cpp.

KRichTextEdit::~KRichTextEdit (  )  [virtual]

Destructor.

Definition at line 129 of file krichtextedit.cpp.


Member Function Documentation

void KRichTextEdit::alignCenter (  )  [slot]

Sets the alignment of the current block to Centered.

Definition at line 181 of file krichtextedit.cpp.

void KRichTextEdit::alignJustify (  )  [slot]

Sets the alignment of the current block to Justified.

Definition at line 195 of file krichtextedit.cpp.

void KRichTextEdit::alignLeft (  )  [slot]

Sets the alignment of the current block to Left Aligned.

Definition at line 174 of file krichtextedit.cpp.

void KRichTextEdit::alignRight (  )  [slot]

Sets the alignment of the current block to Right Aligned.

Definition at line 188 of file krichtextedit.cpp.

bool KRichTextEdit::canDedentList (  )  const

Returns true if the list item at the current position can be dedented.

See also:
canIndentList

Definition at line 510 of file krichtextedit.cpp.

bool KRichTextEdit::canIndentList (  )  const

Returns true if the list item at the current position can be indented.

See also:
canDedentList

Definition at line 505 of file krichtextedit.cpp.

QString KRichTextEdit::currentLinkText (  )  const

Returns the text of the link at the current position or an empty string if the cursor is not on a link.

See also:
currentLinkUrl
Returns:
The link text

Definition at line 343 of file krichtextedit.cpp.

QString KRichTextEdit::currentLinkUrl (  )  const

Returns the URL target (href) of the link at the current position or an empty string if the cursor is not on a link.

See also:
currentLinkText
Returns:
The link target URL

Definition at line 390 of file krichtextedit.cpp.

void KRichTextEdit::enableRichTextMode (  ) 

This enables rich text mode.

Nothing is done except changing the internal mode and allowing rich text pastes.

Definition at line 312 of file krichtextedit.cpp.

void KRichTextEdit::indentListLess (  )  [slot]

Decreases the nesting level of the current block or selected blocks.

See also:
canDedentList

Definition at line 155 of file krichtextedit.cpp.

void KRichTextEdit::indentListMore (  )  [slot]

Increases the nesting level of the current block or selected blocks.

See also:
canIndentList

Definition at line 149 of file krichtextedit.cpp.

void KRichTextEdit::insertHorizontalRule (  )  [slot]

Inserts a horizontal rule below the current block.

Definition at line 160 of file krichtextedit.cpp.

void KRichTextEdit::keyPressEvent ( QKeyEvent *  event  )  [protected, virtual]

Reimplemented.

Catches key press events. Used to handle some key presses on lists.

Reimplemented from KTextEdit.

Definition at line 472 of file krichtextedit.cpp.

void KRichTextEdit::selectionFinished (  )  [signal]

Emitted whenever the user has finished making a selection.

(on mouse up)

void KRichTextEdit::selectLinkText (  )  const

Convenience function to select the link text using the active cursor.

See also:
selectLinkText

Definition at line 350 of file krichtextedit.cpp.

void KRichTextEdit::selectLinkText ( QTextCursor *  cursor  )  const

If the cursor is on a link, sets the cursor to a selection of the text of the link.

If the cursor is not on a link, selects the current word or existing selection.

Parameters:
cursor The cursor to use to select the text.
See also:
updateLink

Definition at line 357 of file krichtextedit.cpp.

void KRichTextEdit::setFont ( const QFont &  font  )  [slot]

Sets the current word or selection to the font font.

Parameters:
font the font of the text will be set to this font

Definition at line 274 of file krichtextedit.cpp.

void KRichTextEdit::setFontFamily ( const QString &  fontFamily  )  [slot]

Sets the current word or selection to the font family fontFamily.

Parameters:
fontFamily The text's font family will be changed to this one

Definition at line 256 of file krichtextedit.cpp.

void KRichTextEdit::setFontSize ( int  size  )  [slot]

Sets the current word or selection to the font size size.

Parameters:
size The text's font will get this size

Definition at line 265 of file krichtextedit.cpp.

void KRichTextEdit::setListStyle ( int  _styleIndex  )  [slot]

Sets the list style of the current list, or creates a new list using the current block.

The _styleindex corresponds to the QTextListFormat::Style

Parameters:
_styleIndex The list will get this style

Definition at line 142 of file krichtextedit.cpp.

void KRichTextEdit::setTextBackgroundColor ( const QColor &  color  )  [slot]

Sets the background color of the current word or selection to color.

Parameters:
color The text will get this foreground color

Definition at line 247 of file krichtextedit.cpp.

void KRichTextEdit::setTextBold ( bool  bold  )  [slot]

Toggles the bold formatting of the current word or selection at the current cursor position.

Parameters:
bold If true, the text will be set to bold

Definition at line 202 of file krichtextedit.cpp.

void KRichTextEdit::setTextForegroundColor ( const QColor &  color  )  [slot]

Sets the foreground color of the current word or selection to color.

Parameters:
color The text will get this background color

Definition at line 238 of file krichtextedit.cpp.

void KRichTextEdit::setTextItalic ( bool  italic  )  [slot]

Toggles the italic formatting of the current word or selection at the current cursor position.

Parameters:
italic If true, the text will be set to italic

Definition at line 211 of file krichtextedit.cpp.

void KRichTextEdit::setTextOrHtml ( const QString &  text  ) 

Replaces all the content of the text edit with the given string.

If the string is in rich text format, the text is inserted as rich text, otherwise it is inserted as plain text.

Parameters:
text The text to insert

Definition at line 330 of file krichtextedit.cpp.

void KRichTextEdit::setTextStrikeOut ( bool  strikeOut  )  [slot]

Toggles the strikeout formatting of the current word or selection at the current cursor position.

Parameters:
strikeOut If true, the text will be struck out

Definition at line 229 of file krichtextedit.cpp.

void KRichTextEdit::setTextSubScript ( bool  subscript  )  [slot]

Toggles the subscript formatting of the current word or selection at the current cursor position.

Parameters:
subscript If true, the text will be set to subscript

Definition at line 303 of file krichtextedit.cpp.

void KRichTextEdit::setTextSuperScript ( bool  superscript  )  [slot]

Toggles the superscript formatting of the current word or selection at the current cursor position.

Parameters:
superscript If true, the text will be set to superscript

Definition at line 294 of file krichtextedit.cpp.

void KRichTextEdit::setTextUnderline ( bool  underline  )  [slot]

Toggles the underline formatting of the current word or selection at the current cursor position.

Parameters:
underline If true, the text will be underlined

Definition at line 220 of file krichtextedit.cpp.

void KRichTextEdit::switchToPlainText (  )  [slot]

This will switch the editor to plain text mode.

All rich text formatting will be destroyed.

Definition at line 283 of file krichtextedit.cpp.

KRichTextEdit::Mode KRichTextEdit::textMode (  )  const
Returns:
The current text mode

Definition at line 317 of file krichtextedit.cpp.

void KRichTextEdit::textModeChanged ( KRichTextEdit::Mode  mode  )  [signal]

Emitted whenever the text mode is changed.

Parameters:
mode The new text mode
QString KRichTextEdit::textOrHtml (  )  const
Returns:
The plain text string if in plain text mode or the HTML code if in rich text mode. The text is not word-wrapped.

Definition at line 322 of file krichtextedit.cpp.

QString KRichTextEdit::toCleanHtml (  )  const [slot]

This will clean some of the bad html produced by the underlying QTextEdit It walks over all lines and cleans up a bit.

Should be improved to produce our own Html.

Definition at line 515 of file krichtextedit.cpp.

void KRichTextEdit::updateLink ( const QString &  linkUrl,
const QString &  linkText 
)

Replaces the current selection with a hyperlink with the link URL linkUrl and the link text linkText.

See also:
selectLinkText
currentLinkUrl
currentLinkText
Parameters:
linkUrl The link will get this URL as href (target)
linkText The link will get this alternative text, which is the text displayed in the text edit.

Definition at line 395 of file krichtextedit.cpp.


The documentation for this class was generated from the following files:
  • krichtextedit.h
  • krichtextedit.cpp

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal