Communi  3.7.0
A cross-platform IRC framework written with Qt
Public Types | Public Slots | Public Member Functions | List of all members
IrcTextFormat Class Reference

Provides methods for text formatting. More...

Inherits QObject.

Public Types

enum  SpanFormat { SpanStyle , SpanClass }
 

Public Slots

void parse (const QString &text)
 

Public Member Functions

 IrcTextFormat (QObject *parent=nullptr)
 
 ~IrcTextFormat () override
 
QString html () const
 
IrcPalettepalette () const
 
QString plainText () const
 
SpanFormat spanFormat () const
 
Q_INVOKABLE QString toHtml (const QString &text) const
 
Q_INVOKABLE QString toPlainText (const QString &text) const
 
QString urlPattern () const
 
QList< QUrl > urls () const
 

Detailed Description

IrcTextFormat is used to convert IRC-style formatted messages to either plain text or HTML. When converting to plain text, the IRC-style formatting (colors, bold, underline etc.) are simply stripped away. When converting to HTML, the IRC-style formatting is converted to the corresponding HTML formatting.

QString text = format.toPlainText(message);
format.palette()->setColorName(Irc::Red, "#ff3333");
format.palette()->setColorName(Irc::Green, "#33ff33");
format.palette()->setColorName(Irc::Blue, "#3333ff");
// ...
QString html = format.toHtml(message);
void setColorName(int color, const QString &name)
Definition: ircpalette.cpp:519
Provides methods for text formatting.
Definition: irctextformat.h:46
Q_INVOKABLE QString toPlainText(const QString &text) const
Definition: irctextformat.cpp:460
Q_INVOKABLE QString toHtml(const QString &text) const
Definition: irctextformat.cpp:446
@ Red
The default value is "red".
Definition: irc.h:64
@ Blue
The default value is "blue".
Definition: irc.h:62
@ Green
The default value is "green".
Definition: irc.h:63
See also
IrcPalette

Member Enumeration Documentation

◆ SpanFormat

This enum describes the supported formats for HTML span-elements.

Enumerator
SpanStyle 

HTML span-elements with style-attributes.

SpanClass 

HTML span-elements with class-attributes.

Constructor & Destructor Documentation

◆ IrcTextFormat()

IrcTextFormat::IrcTextFormat ( QObject *  parent = nullptr)
explicit

Constructs a new text format with parent.

◆ ~IrcTextFormat()

IrcTextFormat::~IrcTextFormat ( )
override

Destructs the text format.

Member Function Documentation

◆ html()

QString IrcTextFormat::html ( ) const
Since
3.2

This property holds the current HTML content.

Access function:
  • QString html() const
See also
parse(), plainText, urls

◆ palette()

IrcPalette * IrcTextFormat::palette ( ) const

This property holds the palette used for color formatting.

Access function:

◆ parse

void IrcTextFormat::parse ( const QString &  text)
slot
Since
3.2

Parses text converting it to plain text and HTML and detects URLs.

See also
plainText, html, urls

◆ plainText()

QString IrcTextFormat::plainText ( ) const
Since
3.2

This property holds the current plain text content.

Access function:
  • QString plainText() const
See also
parse(), html, urls

◆ spanFormat()

IrcTextFormat::SpanFormat IrcTextFormat::spanFormat ( ) const
Since
3.1

This property holds the format used for HTML span-elements.

IrcTextFormat uses HTML span-elements for converting the IRC-style text formatting to the corresponding HTML formatting. The SpanStyle format generates self contained span-elements with style-attributes, resulting to HTML that is ready to be used with Qt's rich text classes without additional styling. For more flexible styling, the SpanClass generates span-elements with class-attributes that can be styled with additional style sheets.

The default value is SpanStyle. The following table illustrates the difference between SpanStyle and SpanClass HTML formatting:

IRC format SpanStyle SpanClass
Bold ("\02...\0F") <span style='font-weight: bold'>...</span> <span class='bold'>...</span>
Color ("\03fg...\0F") <span style='color: fg;'>...</span> <span class='fg'>...</span>
Background ("\03fgbg...\0F") <span style='color: fg; background-color: bg'>...</span> <span class='fg bg-background'>...</span>
Italic ("\09...\0F") <span style='font-style: italic'>...</span> <span class='italic'>...</span>
Line-through ("\13...\0F") <span style='text-decoration: line-through'>...</span> <span class='line-through'>...</span>
Underline ("\15...\0F" or "\1F...\0F") <span style='text-decoration: underline'>...</span> <span class='underline'>...</span>
Inverse ("\16...\0F") <span style='text-decoration: inverse'>...</span> <span class='inverse'>...</span>
Access functions:

◆ toHtml()

QString IrcTextFormat::toHtml ( const QString &  text) const

Converts text to HTML. This function parses the text and replaces IRC-style formatting (colors, bold, underline etc.) to the corresponding HTML formatting. Furthermore, this function detects URLs and replaces them with appropriate HTML hyperlinks.

Note
URL detection can be disabled by setting an empty regular expression pattern used for matching URLs.
See also
toPlainText(), parse(), palette, urlPattern, spanFormat

◆ toPlainText()

QString IrcTextFormat::toPlainText ( const QString &  text) const

Converts text to plain text. This function parses the text and strips away IRC-style formatting (colors, bold, underline etc.)

See also
toHtml(), parse()

◆ urlPattern()

QString IrcTextFormat::urlPattern ( ) const

This property holds the regular expression pattern used for matching URLs.

Access functions:
  • QString urlPattern() const
  • void setUrlPattern(const QString& pattern)

◆ urls()

QList< QUrl > IrcTextFormat::urls ( ) const
Since
3.2

This property holds the current list of URLs.

Access function:
  • QList<QUrl> urls() const
See also
parse(), plainText, html