Communi  3.4.0
A cross-platform IRC framework written with Qt
Public Types | Public Slots | Public Member Functions | Properties | 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=0)
 
virtual ~IrcTextFormat ()
 
SpanFormat spanFormat () const
 
Q_INVOKABLE QString toHtml (const QString &text) const
 
Q_INVOKABLE QString toPlainText (const QString &text) const
 

Properties

QString html
 
IrcPalette palette
 
QString plainText
 
QString urlPattern
 
QList< QUrlurls
 

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);
See also
IrcPalette

Member Enumeration Documentation

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 ( QObject parent = 0)
explicit

Constructs a new text format with parent.

IrcTextFormat::~IrcTextFormat ( )
virtual

Destructs the text format.

Member Function Documentation

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
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:
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
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()

Property Documentation

QString IrcTextFormat::html
read
Since
3.2

This property holds the current HTML content.

Access function:
See also
parse(), plainText, urls
IrcPalette * IrcTextFormat::palette
read

This property holds the palette used for color formatting.

Access function:
QString IrcTextFormat::plainText
read
Since
3.2

This property holds the current plain text content.

Access function:
See also
parse(), html, urls
QString IrcTextFormat::urlPattern
readwrite

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

Access functions:
  • QString urlPattern() const
  • void setUrlPattern(const QString& pattern)
QList< QUrl > IrcTextFormat::urls
read
Since
3.2

This property holds the current list of URLs.

Access function:
See also
parse(), plainText, html