KTextWidgets 5.109.0
Public Types | Properties | Public Slots | Public Member Functions | Protected Member Functions | List of all members
KRichTextWidget

A KRichTextEdit with common actions. More...

#include <KRichTextWidget>

Public Types

typedef QFlags< RichTextSupportValuesRichTextSupport
 Stores a combination of #RichTextSupportValues values.
 
enum  RichTextSupportValues {
  DisableRichText = 0x00 , SupportBold = 0x01 , SupportItalic = 0x02 , SupportUnderline = 0x04 ,
  SupportStrikeOut = 0x08 , SupportFontFamily = 0x10 , SupportFontSize = 0x20 , SupportTextForegroundColor = 0x40 ,
  SupportTextBackgroundColor = 0x80 , FullTextFormattingSupport = 0xff , SupportChangeListStyle = 0x100 , SupportIndentLists = 0x200 ,
  SupportDedentLists = 0x400 , FullListSupport = 0xf00 , SupportAlignment = 0x100000 , SupportRuleLine = 0x400000 ,
  SupportHyperlinks = 0x800000 , SupportFormatPainting = 0x1000000 , SupportToPlainText = 0x2000000 , SupportSuperScriptAndSubScript = 0x4000000 ,
  SupportDirection = 0x8000000 , SupportHeading = 0x10000000 , FullSupport = 0xffffffff
}
 These flags describe what actions will be created by createActions() after passing a combination of these flags to setRichTextSupport(). More...
 
- Public Types inherited from KRichTextEdit
enum  Mode { Plain , Rich }
 The mode the edit widget is in. More...
 

Properties

RichTextSupport richTextSupport
 
- Properties inherited from KTextEdit
bool checkSpellingEnabled
 
QString spellCheckingLanguage
 

Public Slots

void setActionsEnabled (bool enabled)
 Disables or enables all of the actions created by createActions().
 
- Public Slots inherited from KRichTextEdit
void alignCenter ()
 Sets the alignment of the current block to Centered.
 
void alignJustify ()
 Sets the alignment of the current block to Justified.
 
void alignLeft ()
 Sets the alignment of the current block to Left Aligned.
 
void alignRight ()
 Sets the alignment of the current block to Right Aligned.
 
void indentListLess ()
 Decreases the nesting level of the current block or selected blocks.
 
void indentListMore ()
 Increases the nesting level of the current block or selected blocks.
 
void insertHorizontalRule ()
 Inserts a horizontal rule below the current block.
 
void insertPlainTextImplementation ()
 
void makeLeftToRight ()
 Sets the direction of the current block to Left-To-Right.
 
void makeRightToLeft ()
 Sets the direction of the current block to Right-To-Left.
 
void setFont (const QFont &font)
 Sets the current word or selection to the font font.
 
void setFontFamily (const QString &fontFamily)
 Sets the current word or selection to the font family fontFamily.
 
void setFontSize (int size)
 Sets the current word or selection to the font size size.
 
void setHeadingLevel (int level)
 Sets the heading level of a current block or selection.
 
void setListStyle (int _styleIndex)
 Sets the list style of the current list, or creates a new list using the current block.
 
void setTextBackgroundColor (const QColor &color)
 Sets the background color of the current word or selection to color.
 
void setTextBold (bool bold)
 Toggles the bold formatting of the current word or selection at the current cursor position.
 
void setTextForegroundColor (const QColor &color)
 Sets the foreground color of the current word or selection to color.
 
void setTextItalic (bool italic)
 Toggles the italic formatting of the current word or selection at the current cursor position.
 
void setTextStrikeOut (bool strikeOut)
 Toggles the strikeout formatting of the current word or selection at the current cursor position.
 
void setTextSubScript (bool subscript)
 Toggles the subscript formatting of the current word or selection at the current cursor position.
 
void setTextSuperScript (bool superscript)
 Toggles the superscript formatting of the current word or selection at the current cursor position.
 
void setTextUnderline (bool underline)
 Toggles the underline formatting of the current word or selection at the current cursor position.
 
void switchToPlainText ()
 This will switch the editor to plain text mode.
 
QString toCleanHtml () const
 This will clean some of the bad html produced by the underlying QTextEdit It walks over all lines and cleans up a bit.
 
- Public Slots inherited from KTextEdit
void addTextDecorator (Sonnet::SpellCheckDecorator *decorator)
 Add custom spell checker decorator.
 
void checkSpelling ()
 Show a dialog to check the spelling.
 
void clearDecorator ()
 clearDecorator clear the spellcheckerdecorator
 
void replace ()
 Create replace dialogbox.
 
void setSpellCheckingLanguage (const QString &language)
 Set the spell check language which will be used for highlighting spelling mistakes and for the spellcheck dialog.
 
void showSpellConfigDialog (const QString &windowIcon=QString())
 Opens a Sonnet::ConfigDialog for this text edit.
 

Public Member Functions

 KRichTextWidget (const QString &text, QWidget *parent=nullptr)
 Constructs a KRichTextWidget object.
 
 KRichTextWidget (QWidget *parent)
 Constructor.
 
 ~KRichTextWidget () override
 Destructor.
 
virtual QList< QAction * > createActions ()
 Creates the actions and adds them to the given action collection.
 
RichTextSupport richTextSupport () const
 Returns the supported rich text subset available.
 
void setRichTextSupport (const KRichTextWidget::RichTextSupport &support)
 Sets the supported rich text subset available.
 
void updateActionStates ()
 Tells KRichTextWidget to update the state of the actions created by createActions().
 
- Public Member Functions inherited from KRichTextEdit
 KRichTextEdit (const QString &text, QWidget *parent=nullptr)
 Constructs a KRichTextEdit object.
 
 KRichTextEdit (QWidget *parent=nullptr)
 Constructs a KRichTextEdit object.
 
 ~KRichTextEdit () override
 Destructor.
 
bool canDedentList () const
 Returns true if the list item at the current position can be dedented.
 
bool canIndentList () const
 Returns true if the list item at the current position can be indented.
 
QString currentLinkText () const
 Returns the text of the link at the current position or an empty string if the cursor is not on a link.
 
QString 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.
 
void enableRichTextMode ()
 This enables rich text mode.
 
void selectLinkText () const
 Convenience function to select the link text using the active cursor.
 
void selectLinkText (QTextCursor *cursor) const
 If the cursor is on a link, sets the cursor to a selection of the text of the link.
 
void setTextOrHtml (const QString &text)
 Replaces all the content of the text edit with the given string.
 
Mode textMode () const
 
QString textOrHtml () const
 
void updateLink (const QString &linkUrl, const QString &linkText)
 Replaces the current selection with a hyperlink with the link URL linkUrl and the link text linkText.
 
- Public Member Functions inherited from KTextEdit
 KTextEdit (const QString &text, QWidget *parent=nullptr)
 Constructs a KTextEdit object.
 
 KTextEdit (QWidget *parent=nullptr)
 Constructs a KTextEdit object.
 
 ~KTextEdit () override
 Destroys the KTextEdit object.
 
virtual bool checkSpellingEnabled () const
 Returns true if background spell checking is enabled for this text edit.
 
virtual void createHighlighter ()
 Allows to create a specific highlighter if reimplemented.
 
void enableFindReplace (bool enabled)
 Enable find replace action.
 
void forceSpellChecking ()
 
Sonnet::Highlighter * highlighter () const
 Returns the current highlighter, which is 0 if spell checking is disabled.
 
void highlightWord (int length, int pos)
 Selects the characters at the specified position.
 
virtual QMenu * mousePopupMenu ()
 Return standard KTextEdit popupMenu.
 
virtual void setCheckSpellingEnabled (bool check)
 Turns background spell checking for this text edit on or off.
 
void setHighlighter (Sonnet::Highlighter *_highLighter)
 Sets a custom background spell highlighter for this text edit.
 
virtual void setReadOnly (bool readOnly)
 Reimplemented to set a proper "deactivated" background color.
 
virtual bool shouldBlockBeSpellChecked (const QString &block) const
 Returns true if the given paragraph or block should be spellcheck.
 
void showAutoCorrectButton (bool show)
 
void showTabAction (bool show)
 
const QString & spellCheckingLanguage () const
 

Protected Member Functions

void mouseReleaseEvent (QMouseEvent *event) override
 Reimplemented.
 
- Protected Member Functions inherited from KRichTextEdit
 __attribute__ ((visibility("hidden"))) KRichTextEdit(KRichTextEditPrivate &dd
 
 __attribute__ ((visibility("hidden"))) KRichTextEdit(KRichTextEditPrivate &dd
 
void keyPressEvent (QKeyEvent *event) override
 Reimplemented.
 
- Protected Member Functions inherited from KTextEdit
KTEXTWIDGETS_NO_EXPORT KTextEdit (KTextEditPrivate &dd, const QString &text, QWidget *parent)
 
KTEXTWIDGETS_NO_EXPORT KTextEdit (KTextEditPrivate &dd, QWidget *parent)
 
void contextMenuEvent (QContextMenuEvent *) override
 Reimplemented from QTextEdit to add spelling related items when appropriate.
 
virtual void deleteWordBack ()
 Deletes a word backwards from the current cursor position, if available.
 
virtual void deleteWordForward ()
 Deletes a word forwards from the current cursor position, if available.
 
bool event (QEvent *) override
 Reimplemented to catch "delete word" shortcut events.
 
void focusInEvent (QFocusEvent *) override
 Reimplemented to instantiate a KDictSpellingHighlighter, if spellchecking is enabled.
 
void keyPressEvent (QKeyEvent *) override
 Reimplemented for internal reasons.
 

Additional Inherited Members

- Signals inherited from KRichTextEdit
void selectionFinished ()
 Emitted whenever the user has finished making a selection.
 
void textModeChanged (KRichTextEdit::Mode mode)
 Emitted whenever the text mode is changed.
 
- Signals inherited from KTextEdit
void aboutToShowContextMenu (QMenu *menu)
 Emitted before the context menu is displayed.
 
void checkSpellingChanged (bool)
 emit signal when we activate or not autospellchecking
 
void languageChanged (const QString &language)
 Emitted when the user changes the language in the spellcheck dialog shown by checkSpelling() or when calling setSpellCheckingLanguage().
 
void spellCheckerAutoCorrect (const QString &currentWord, const QString &autoCorrectWord)
 
void spellCheckingCanceled ()
 signal spellCheckingCanceled is sent when we cancel spell checking.
 
void spellCheckingFinished ()
 signal spellCheckingFinished is sent when we finish spell check or we click on "Terminate" button in sonnet dialogbox
 
void spellCheckStatus (const QString &)
 Signal sends when spell checking is finished/stopped/completed.
 
- Protected Slots inherited from KTextEdit
void slotDoFind ()
 
void slotDoReplace ()
 
void slotFind ()
 
void slotFindNext ()
 
void slotFindPrevious ()
 
void slotReplace ()
 
void slotReplaceNext ()
 
void slotSpeakText ()
 
- Protected Attributes inherited from KRichTextEdit
const QString QWidget * parent
 
QWidget * parent
 
const QString & text
 

Detailed Description

A KRichTextEdit with common actions.

This class implements common actions which are often used with KRichTextEdit. All you need to do is to call createActions(), and the actions will be added to your KXMLGUIWindow. Remember to also add the chosen actions to your application ui.rc file.

See the KRichTextWidget::RichTextSupportValues enum for an overview of supported actions.

Author
Stephen Kelly steve.nosp@m.ire@.nosp@m.gmail.nosp@m..com
Thomas McGuire thoma.nosp@m.s.mc.nosp@m.guire.nosp@m.@gmx.nosp@m..net
KRichTextWidget Widget
Since
4.1

Member Typedef Documentation

◆ RichTextSupport

Stores a combination of #RichTextSupportValues values.

Member Enumeration Documentation

◆ RichTextSupportValues

These flags describe what actions will be created by createActions() after passing a combination of these flags to setRichTextSupport().

See also
RichTextSupport
Enumerator
DisableRichText 

No rich text support at all, no actions will be created.

Do not use in combination with other flags.

SupportBold 

Action to format the selected text as bold.

If no text is selected, the word under the cursor is formatted bold. This is a KToggleAction. The status is automatically updated when the text cursor is moved.

SupportItalic 

Action to format the selected text as italic.

If no text is selected, the word under the cursor is formatted italic. This is a KToggleAction. The status is automatically updated when the text cursor is moved.

SupportUnderline 

Action to underline the selected text.

If no text is selected, the word under the cursor is underlined. This is a KToggleAction. The status is automatically updated when the text cursor is moved.

SupportStrikeOut 

Action to strike out the selected text.

If no text is selected, the word under the cursor is struck out. This is a KToggleAction. The status is automatically updated when the text cursor is moved.

SupportFontFamily 

Action to change the font family of the currently selected text.

If no text is selected, the font family of the word under the cursor is changed. Displayed as a combobox when inserted into the toolbar. This is a KFontAction. The status is automatically updated when the text cursor is moved.

SupportFontSize 

Action to change the font size of the currently selected text.

If no text is selected, the font size of the word under the cursor is changed. Displayed as a combobox when inserted into the toolbar. This is a KFontSizeAction. The status is automatically updated when the text cursor is moved.

SupportTextForegroundColor 

Action to change the text color of the currently selected text.

If no text is selected, the text color of the word under the cursor is changed. Opens a QColorDialog to select the color.

SupportTextBackgroundColor 

Action to change the background color of the currently selected text.

If no text is selected, the background color of the word under the cursor is changed. Opens a QColorDialog to select the color.

FullTextFormattingSupport 

A combination of all the flags above.

Includes all actions that change the format of the text.

SupportChangeListStyle 

Action to make the current line a list element, change the list style or remove list formatting.

Displayed as a combobox when inserted into a toolbar. This is a KSelectAction. The status is automatically updated when the text cursor is moved.

SupportIndentLists 

Action to increase the current list nesting level.

This makes it possible to create nested lists.

SupportDedentLists 

Action to decrease the current list nesting level.

FullListSupport 

All of the three list actions above.

Includes all list-related actions.

SupportAlignment 

Actions to align the current paragraph left, righ, center or justify.

These actions are KToogleActions. The status is automatically updated when the text cursor is moved.

SupportRuleLine 

Action to insert a horizontal line.

SupportHyperlinks 

Action to convert the current text to a hyperlink.

If no text is selected, the word under the cursor is converted. This action opens a dialog where the user can enter the link target.

SupportFormatPainting 

Action to make the mouse cursor a format painter.

The user can select text with that painter. The selected text gets the same format as the text that was previously selected.

SupportToPlainText 

Action to change the text of the whole text edit to plain text.

All rich text formatting will get lost.

SupportSuperScriptAndSubScript 

Actions to format text as superscript or subscript.

If no text is selected, the word under the cursor is formatted as selected. This is a KToggleAction. The status is automatically updated when the text cursor is moved.

SupportDirection 

Action to change direction of text to Right-To-Left or Left-To-Right.

SupportHeading 

Action to make the current line a heading (up to six levels, corresponding to HTML h1...h6 tags) Displayed as a combobox when inserted into a toolbar.

This is a KSelectAction. The status is automatically updated when the text cursor is moved.

Since
5.70
FullSupport 

Includes all above actions for full rich text support.

Constructor & Destructor Documentation

◆ KRichTextWidget() [1/2]

KRichTextWidget::KRichTextWidget ( QWidget *  parent)
explicit

Constructor.

Parameters
parentthe parent widget

◆ KRichTextWidget() [2/2]

KRichTextWidget::KRichTextWidget ( const QString &  text,
QWidget *  parent = nullptr 
)
explicit

Constructs a KRichTextWidget object.

Parameters
textThe initial text of the text edit, which is interpreted as HTML.
parentThe parent widget

◆ ~KRichTextWidget()

KRichTextWidget::~KRichTextWidget ( )
override

Destructor.

Member Function Documentation

◆ createActions()

virtual QList< QAction * > KRichTextWidget::createActions ( )
virtual

Creates the actions and adds them to the given action collection.

Call this before calling setupGUI() in your application, but after calling setRichTextSupport().

The XML file of your KXmlGuiWindow needs to have the action names in them, so that the actions actually appear in the menu and in the toolbars.

Below is a list of actions that are created,depending on the supported rich text subset set by setRichTextSupport(). The list contains action names. Those names need to be the same in your XML file.

See the KRichTextWidget::RichTextSupportValues enum documentation for a detailed explanation of each action.

XML NameRichTextSupportValues flag
format_text_foreground_colorSupportTextForegroundColor
format_text_background_colorSupportTextBackgroundColor
format_font_familySupportFontFamily
format_font_sizeSupportFontSize
format_text_boldSupportBold
format_text_italicSupportItalic
format_text_underlineSupportUnderline
format_text_strikeoutSupportStrikeOut
format_align_leftSupportAlignment
format_align_centerSupportAlignment
format_align_rightSupportAlignment
format_align_justifySupportAlignment
direction_ltrSupportDirection
direction_rtlSupportDirection
format_list_styleSupportChangeListStyle
format_list_indent_moreSupportIndentLists
format_list_indent_lessSupportDedentLists
insert_horizontal_ruleSupportRuleLine
manage_linkSupportHyperlinks
format_painterSupportFormatPainting
action_to_plain_textSupportToPlainText
format_text_subscript & format_text_superscriptSupportSuperScriptAndSubScript
format_heading_levelSupportHeading
Since
5.0

◆ mouseReleaseEvent()

void KRichTextWidget::mouseReleaseEvent ( QMouseEvent *  event)
overrideprotected

Reimplemented.

Catches mouse release events. Used to know when a selection has been completed.

◆ richTextSupport()

RichTextSupport KRichTextWidget::richTextSupport ( ) const

Returns the supported rich text subset available.

Returns
The supported subset.

◆ setActionsEnabled

void KRichTextWidget::setActionsEnabled ( bool  enabled)
slot

Disables or enables all of the actions created by createActions().

This may be useful in cases where rich text mode may be set on or off.

Parameters
enabledWhether to enable or disable the actions.

◆ setRichTextSupport()

void KRichTextWidget::setRichTextSupport ( const KRichTextWidget::RichTextSupport support)

Sets the supported rich text subset available.

The default is KRichTextWidget::FullSupport and will be set in the constructor.

You need to call createActions() afterwards.

Parameters
supportThe supported subset.

◆ updateActionStates()

void KRichTextWidget::updateActionStates ( )

Tells KRichTextWidget to update the state of the actions created by createActions().

This is normally automatically done, but there might be a few cases where you'll need to manually call this function.

Call this function only after calling createActions().