TextStyle

Since: BlackBerry 10.0.0

#include <bb/cascades/TextStyle>

Represents a text style that defines how a text is rendered.

Each text style has a different set of visual characteristics associated with it like weight, font style etc. If set to other values than their default values, these values will override the default characteristic of controls that they are applied on. For example setting fontFamily to "helvetica" on a textstyle applied to a label will override the default system font with a font from the Helvetica family.


Overview

Inheritance

bb::cascades::Resource
bb::cascades::TextStyle

Public Functions Index

TextStyle ()
TextStyle (const TextStyle &other)
virtual ~TextStyle ()
QVariantcolor () const
QStringfontFamily () const
FontSize::TypefontSize () const
floatfontSizeValue () const
FontStyle::TypefontStyle () const
bb::cascades::FontWeight::TypefontWeight () const
floatlineHeight () const
TextStyle &operator= (const TextStyle &other)
voidresetColor ()
voidresetFontFamily ()
voidresetFontSize ()
voidresetFontSizeValue ()
voidresetFontStyle ()
voidresetFontWeight ()
voidresetLineHeight ()
voidresetTextAlign ()
voidsetColor (const bb::cascades::ColorPaint &color)
voidsetColor (const QVariant &color)
voidsetFontFamily (const QString &fontFamily)
voidsetFontSize (FontSize::Type size)
voidsetFontSizeValue (float size)
voidsetFontStyle (FontStyle::Type fontStyle)
voidsetFontWeight (bb::cascades::FontWeight::Type fontWeight)
voidsetLineHeight (float lineHeight)
voidsetTextAlign (bb::cascades::TextAlign::Type alignment)
bb::cascades::TextAlign::TypetextAlign () const
boolisNull () const Inherited

Public Functions

TextStyle ()

Constructs a null TextStyle.

Since:

BlackBerry 10.0.0

TextStyle (

Constructs a copy of another TextStyle.

 TextStyle a = SystemDefaults::TextStyles::bigText();
 TextStyle b(a);
Parameters
other

The TextStyle to be copied.

Since:

BlackBerry 10.0.0

virtual~TextStyle ()

Destructor.

QVariant color ()

Returns the text color.

Returned QVariant will be either invalid or contain values of type Color or ColorPaint. Invalid QVariant signifies an unset color.

Use QVariant::canConvert<Type T>() to find actual type, and then QVariant::value<Type T>() to get the value.

For example:
 QVariant v = style->textColor();
 if (v.canConvert<Color>()) {
   Color c = v.value<Color>();
 } else if (v.canConvert<ColorPaint>()) {
   ColorPaint cp = v.value<ColorPaint>();
 }
Return:

The current font color, wrapped in a QVariant or invalid QVariant if text color wasn't set

Since:

BlackBerry 10.0.0

QString fontFamily ()

Returns the font family for the TextStyle.

Return:

The font family if set, otherwise QString::null is returned.

Since:

BlackBerry 10.0.0

FontSize::Type fontSize ()

Returns the logical font size.

Return:

Font size.

Since:

BlackBerry 10.0.0

float fontSizeValue ()

Returns the font size value in points or percent The unit of the return value depends on the current setting of the fontSize property.

If it is set to FontSize::PointValue, the unit is post script points. If it is set to FontSize::PercentageValue, the unit is percent and the size is relative to the point size of parent style element. If there is no parent element, the size will be in relation to the system default size, which typically matches the logical size Medium.

Return:

Font size value.

Since:

BlackBerry 10.0.0

FontStyle::Type fontStyle ()

Returns the font style.

Return:

The font style if set, otherwise FontStyle::Default is returned.

Since:

BlackBerry 10.0.0

bb::cascades::FontWeight::Type fontWeight ()

Returns the font weight.

Return:

The weight if set, otherwise FontWeight::Default is returned.

Since:

BlackBerry 10.0.0

float lineHeight ()

Returns the line height.

The default value is -1.0.

Return:

Line height if set. If not set the default value will be returned.

Since:

BlackBerry 10.0.0

TextStyle & operator= (

Assigns another TextStyle to this TextStyle.

Parameters
other

The TextStyle to be assigned.

Return:

A reference to the TextStyle.

Since:

BlackBerry 10.0.0

void resetColor ()

Resets the color to its default value as an invalid Color.

Since:

BlackBerry 10.0.0

void resetFontFamily ()

Resets the font family to its default.

The default value is a QString::null.

Since:

BlackBerry 10.0.0

void resetFontSize ()

Resets the logical font size to its default value.

Since:

BlackBerry 10.0.0

void resetFontSizeValue ()

Resets the font size value to its default value 0.0.

Since:

BlackBerry 10.0.0

void resetFontStyle ()

Resets the font style to its default value.

Since:

BlackBerry 10.0.0

void resetFontWeight ()

Resets the font weight to its default value.

Since:

BlackBerry 10.0.0

void resetLineHeight ()

Resets the line height to its default value of -1.0.

Since:

BlackBerry 10.0.0

void resetTextAlign ()

Resets the horizontal alignment to its default value.

Since:

BlackBerry 10.0.0

void setColor (

Sets the text color.

Setting an invalid color is equivalent to calling resetColor().

Parameters
color

The color to use.

Since:

BlackBerry 10.0.0

void setColor (

Convenience method for setting the text color for colors wrapped in QVariant.

Passed QVariant can either be invalid or contain values of type Color or PaintColor or it will be ignored.

Setting an invalid QVariant or a QVariant containing invalid color is equivalent to calling resetColor().

Example:
 style2.setColor(style1.color());
Parameters
color

A QVariant containing the color to use or an invalid QVariant

Since:

BlackBerry 10.0.0

void setFontFamily (

Sets the font family name to use for font matching in the TextStyle.

For example setting font family to "helvetica" will make the TextStyle try to find a font of the helvetica family. The font family name can be specified with multiple fallbacks specified as either ordinary font familys (times, arial etc.) or generic family names (serif, sans-serif) The names should be separated by a comma and family names containing multiple word like Times New Roman should be enclosed by quotations. Start by specifying specific font families and end with generic font families. Currently only one specific font family is supported.

Example:
 style.setFontFamily("\"Times New Roman\", serif");
Parameters
fontFamily

The font family name.

Since:

BlackBerry 10.0.0

void setFontSize (

Sets the logical font size.

Logical font size will be translated to actual font size according to font size set in accessibility settings.

Parameters
size

The font size to use.

Since:

BlackBerry 10.0.0

void setFontSizeValue (
  • floatsize)

Sets the font size value.

Font size in post script units or percent, depending on the FontSize setting. Valid ranges are >= 0. Sizes < 0 will be clamped to 0 The default value is 0.0.

If FontSize is set to PercentageValue, size value 100.0 corresponds to the size of the parent style element. If there is no parent element, the size will be in relation to the system default size, which typically matches the logical size Medium. Note, this value will take effect only when font size is set to FontSize::PointValue or FontSize::PercentageValue

Parameters
size

The font size value to use.

Since:

BlackBerry 10.0.0

void setFontStyle (

Sets the font style.

Parameters
fontStyle

The style to use.

Since:

BlackBerry 10.0.0

void setFontWeight (

Set the font weight.

Parameters
fontWeight

The weight to use.

Since:

BlackBerry 10.0.0

void setLineHeight (
  • floatlineHeight)

Sets the line height.

Distance between rows of text. 1.0 is equal to 1 ordinary row height. 1.5 would make the distance between rows 1.5 ordinary row heights. The default value is -1.0.

Parameters
lineHeight

The line height to use.

Since:

BlackBerry 10.0.0

void setTextAlign (

Sets the horizontal alignment for the text.

Parameters
alignment

The horizontal text alignment to use.

Since:

BlackBerry 10.0.0

bb::cascades::TextAlign::Type textAlign ()

Returns the horizontal alignment for the text.

Return:

The text alignment if set, otherwise TextAlign::Default is returned.

Since:

BlackBerry 10.0.0

bool isNull ()Inherited

Returns true if the resource is null.

Return:

true if this resource is null, false otherwise.

Since:

BlackBerry 10.0.0

Last modified: 2014-09-30



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus