TextStyleDefinition
#include <bb/cascades/TextStyleDefinition>
Used to define style sets for sets of text nodes in an application.
This class is useful if you need to modify the look and feel of the text displayed in your application. Instead of specifying each style characteristic for each individual control, you can create a TextStyleDefinition and apply it to each of the controls.
The TextStyleDefinition constructs a text style based on a base text style in combination with its own parameters. All parameters that are set to non default values will be used to override the base style. The resulting text style can be queried using the style property.
When creating a TextStyleDefinition you can base the style off of one of the existing system defaults specified in SystemDefaults::TextStyle. For example, if you're creating a custom title, you might want to base the TextStyleDefinition off of SystemDefaults::TextStyles::titleText(). Then you would override the individual properties that you want to change with style properties of your own. The resulting text style can be queried using the style property.
This example demonstrates how to create a text style based on SystemDefaults::TextStyle::bodyText(), with the fontWeight property being overridden to bold and fontSize being overridden to "small".
TextStyleDefinition *pTSD = new TextStyleDefinition(); pTSD->setBase(SystemDefaults::TextStyles::bodyText()); pTSD->setWeight(FontWeight::Bold); pTSD->setFontSize(FontSize::Small); TextStyle boldBodyText = pTSD->style();
import bb.cascades 1.0
Container {
attachedObjects: [
TextStyleDefinition
{
id: tsd
base: SystemDefaults.TextStyles.BodyText
fontWeight: FontWeight.Bold
fontSize: FontSize.Small
}
]
Label{
id: label
text: "Hello, world!"
textStyle
{
base: tsd.style
}
}
}
BlackBerry 10.0.0
Inheritance
| bb::cascades::BaseObject | ||
| bb::cascades::TextStyleDefinition | ||
QML properties
| base | : bb::cascades::TextStyle |
| style | : bb::cascades::TextStyle [read-only] |
| fontFamily | : QString |
| fontStyle | : bb::cascades::FontStyle::Type |
| fontWeight | : bb::cascades::FontWeight::Type |
| color | : bb::cascades::Color | bb::cascades::ColorPaint |
| lineHeight | : float |
| fontSizeValue | : float |
| fontSize | : bb::cascades::FontSize::Type |
| textAlign | : bb::cascades::TextAlign::Type |
| objectName | : QString |
| parent | : QObject [read-only] |
QML signals
Properties Index
Public Functions Index
| TextStyleDefinition () | |
| virtual | ~TextStyleDefinition () |
| bb::cascades::TextStyle | base () |
| bb::cascades::TextStyle | style () |
| void | setBase (const bb::cascades::TextStyle &base) |
| Q_INVOKABLE void | resetBase () |
| Q_SLOT void | setFontFamily (const QString &fontFamily) |
| QString | fontFamily () const |
| Q_INVOKABLE void | resetFontFamily () |
| Q_SLOT void | setFontStyle (bb::cascades::FontStyle::Type fontStyle) |
| bb::cascades::FontStyle::Type | fontStyle () const |
| Q_INVOKABLE void | resetFontStyle () |
| Q_SLOT void | setFontWeight (bb::cascades::FontWeight::Type fontWeight) |
| bb::cascades::FontWeight::Type | fontWeight () const |
| Q_INVOKABLE void | resetFontWeight () |
| Q_SLOT void | setColor (const bb::cascades::ColorPaint &color) |
| Q_SLOT void | setColor (const QVariant &color) |
| QVariant | color () |
| Q_INVOKABLE void | resetColor () |
| Q_SLOT void | setLineHeight (float lineHeight) |
| float | lineHeight () const |
| Q_INVOKABLE void | resetLineHeight () |
| Q_SLOT void | setFontSizeValue (float size) |
| float | fontSizeValue () const |
| Q_INVOKABLE void | resetFontSizeValue () |
| Q_SLOT void | setFontSize (bb::cascades::FontSize::Type size) |
| bb::cascades::FontSize::Type | fontSize () const |
| Q_INVOKABLE void | resetFontSize () |
| Q_SLOT void | setTextAlign (bb::cascades::TextAlign::Type alignment) |
| bb::cascades::TextAlign::Type | textAlign () |
| Q_INVOKABLE void | resetTextAlign () |
| void | setObjectName (const QString &name) |
| virtual Q_INVOKABLE QString | toDebugString () const |
Protected Functions Index
Only has inherited protected functions
| BaseObject (QObject *parent=0) |
Signals Index
| void | styleChanged () |
| void | baseChanged (const bb::cascades::TextStyle &textStyle) |
| void | fontFamilyChanged (const QString &fontFamily) |
| void | fontStyleChanged (bb::cascades::FontStyle::Type newFontStyle) |
| void | fontWeightChanged (bb::cascades::FontWeight::Type newFontWeight) |
| void | colorChanged (const bb::cascades::ColorPaint &color) |
| void | lineHeightChanged (float lineHeight) |
| void | fontSizeValueChanged (float fontSizeValue) |
| void | fontSizeChanged (bb::cascades::FontSize::Type newFontSize) |
| void | textAlignChanged (bb::cascades::TextAlign::Type newAlignment) |
| void | creationCompleted () |
| void | objectNameChanged (const QString &objectName) |
Properties
QVariant
The base text style.
The parameters of this text style will be used if not explicitly overidden.
The default value is a null TextStyle.
BlackBerry 10.0.0
QVariant
The style constructed by the text style definiton.
The style is constructed from the base text style. All parameters that are set to non default values on the text style definition will override the corresponding parameter from base.
BlackBerry 10.0.0
QString
The font family name.
Example: Helvectica
Default value is QString::null which means that the fontFamily will not be overridden and the value from the base text style will be used instead.
BlackBerry 10.0.0
bb::cascades::FontStyle::Type
The font style.
Font styles are defined in FontStyle, which includes options such as normal and italic.
Default value is FontStyle::Default which means that the fontStyle will not be overridden and the value from the base text style will be used instead.
BlackBerry 10.0.0
bb::cascades::FontWeight::Type
The font weight.
Font weights are defined in FontWeight, which includes options such as W100, W200, ..., W800, W900, normal and bold.
Default value is FontWeight::Default which means that the fontWeight will not be overridden and the value from the base text style will be used instead.
BlackBerry 10.0.0
QVariant
The color of the text.
The default value is an invalid color which means that the color will not be overridden and the value from the base text style will be used instead.
Valid value types for this propety are Color and ColorPaint, and an invalid QVariant.
BlackBerry 10.0.0
float
The line height.
This indicates the 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 which means that the lineHeight will not be overridden and the value from the base text style will be used instead.
BlackBerry 10.0.0
float
The font size value.
This indicates the font size in post script units or percentage depending on the setting of fontSize. Valid ranges are >= 0.Sizes < 0 will be clamped to 0.
The default value is 0.0 which means that the size will not be overridden and the value from the base text style will be used instead.
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
BlackBerry 10.0.0
bb::cascades::FontSize::Type
The logical font size.
Logical font sizes are defined in FontSize. Logical size will be translated to the actual size according to system font settings.
E.g. the large size can vary from 12pt to 20pt depending on the font size set in accesibility settings
Default value is FontSize::Default which means that the logical font size will not be overridden, and the value from the base text style will be used instead.
BlackBerry 10.0.0
bb::cascades::TextAlign::Type
The horizontal alignment.
Horizontal alignment is defined in TextAlign, which includes options such as center, left, right and justify.
The default value is TextAlign::Default which will result in that the alignment will not be overridden and the value from the base text style will be used instead.
BlackBerry 10.0.0
QString
This property is overridden from QObject.
As the objectName property is overridden from the QObject class, this signal will not be emitted if setObjectName() function is called directly on QObject.
The default value of this property is QString::null.
QObject::objectName().
BlackBerry 10.0.0
QObject
A read-only property that represents this object's parent.
The parent of an object is specified using QObject::setParent(QObject*). The purpose of the property is to expose the object's parent to QML.
This property is read-only to prevent modifications from QML, where typically the parent is declaratively set. In C++ code, the parent can be explicitly set using QObject::setParent(QObject*), or implicitly set by adding it to a visual container.
The default value of this property is 0.
BlackBerry 10.0.0
Public Functions
virtual
Destructor.
bb::cascades::TextStyle
Returns the base TextStyle.
bb::cascades::TextStyle
Returns the constructed TextStyle.
void
Sets the base TextStyle.
Q_INVOKABLE void
Resets the base TextStyle to its default value as a null text style.
BlackBerry 10.0.0
Q_SLOT void
Sets the font family name to use for font matching.
Setting this value to anything other than the default value of QString::null will make the TextStyleDefinition construct its style with this value instead of the one provided from base.
| Parameters | |
|---|---|
| fontFamily |
The font family name. |
BlackBerry 10.0.0
QString
Returns the font family.
The font family if set, otherwise an null QString will be returned.
BlackBerry 10.0.0
Q_INVOKABLE void
Resets the fontFamily to its default value of QString::null.
BlackBerry 10.0.0
Q_SLOT void
Sets the font style to use for font matching.
Setting this value to anything other than the default value of FontStyle::Default will make the TextStyleDefinition construct its style with this value instead of the one provided from base.
| Parameters | |
|---|---|
| fontStyle |
The font style. |
BlackBerry 10.0.0
bb::cascades::FontStyle::Type
Returns the font style.
The fontstyle if set otherwise FontStyle::Default will be returned.
BlackBerry 10.0.0
Q_SLOT void
Sets the font weight.
Setting this value to anything other than the default value of FontWeight::Default will make the TextStyleDefinition construct its style with this value instead of the one provided from base.
| Parameters | |
|---|---|
| fontWeight |
The font weight. |
BlackBerry 10.0.0
bb::cascades::FontWeight::Type
Returns the font weight.
The weight if set otherwise FontWeight::Default will be returned.
BlackBerry 10.0.0
Q_SLOT void
Sets the text color.
Setting this value to anything other than the default value of an invalid color will make the TextStyleDefinition construct it's style with this value instead of the one provided from base.
| Parameters | |
|---|---|
| color |
The text color. |
BlackBerry 10.0.0
Q_SLOT void
Sets the text color.
Setting this value to anything other than the default value of an invalid color will make the TextStyleDefinition construct it's style with this value instead of the one provided from base.
The 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().
styleDef2->setColor(styleDef1->color());
BlackBerry 10.0.0
QVariant
Returns the text color.
The returned QVariant will be either invalid or contain values of type Color or ColorPaint.
Use QVariant::canConvert<Type T>() to find actual type, and then QVariant::value<Type T>() to get the value.
QVariant v = style->color();
if (v.canConvert<Color>()) {
Color c = v.value<Color>();
// use the color
} else if (v.canConvert<ColorPaint>()) {
ColorPaint cp = v.value<ColorPaint>();
// must be a system default paint
}
The text color if set, otherwise an invalid color will be returned.
BlackBerry 10.0.0
Q_INVOKABLE void
Resets the color to its default value as an invalid Color.
BlackBerry 10.0.0
Q_SLOT void
Sets the line height.
Setting this value to anything other than the default value of 0.0 will make the TextStyleDefinition construct its style with this value instead of the one provided from base.
| Parameters | |
|---|---|
| lineHeight |
The line height. |
BlackBerry 10.0.0
float
Returns the line height.
The default value is 0.0.
Line height if set. If not set the default value will be returned.
BlackBerry 10.0.0
Q_SLOT void
Sets the font size value.
Setting this value to anything other than the default value of 0.0 will make the TextStyleDefinition construct its style with this value instead of the one provided from base.
If FontSize is set to PercentageValue, size value 100.0 corresponds to the locial 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. |
BlackBerry 10.0.0
float
Returns the font size value.
The default value is 0.0.
Font size value if set. If not set the default value will be returned.
BlackBerry 10.0.0
Q_SLOT void
Sets the logical font size.
| Parameters | |
|---|---|
| size |
The logical font size. |
BlackBerry 10.0.0
bb::cascades::FontSize::Type
Returns the logical font size.
The logical font size if set.
BlackBerry 10.0.0
Q_INVOKABLE void
Resets the logical size to its default value.
BlackBerry 10.0.0
Q_SLOT void
Sets the horizontal text alignment.
Setting this value to anything other than the default value of TextAlign::Default will make the TextStyleDefinition construct its style with this value instead of the one provided from base.
| Parameters | |
|---|---|
| alignment |
The horizontal text alignment. |
BlackBerry 10.0.0
bb::cascades::TextAlign::Type
Returns the horizontal text alignment.
The text alignment if set, otherwise bb::cascades::TextAlign::Default will be returned.
BlackBerry 10.0.0
void 
Sets the objectName property.
| Parameters | |
|---|---|
| name |
The new name for the object. |
BlackBerry 10.0.0
virtual Q_INVOKABLE QString 
Returns a debug string representing this object.
A debug string for the object.
BlackBerry 10.0.0
Protected Functions
(Only has inherited protected functions)
Constructs an instance of BaseObject's subclass.
| Parameters | |
|---|---|
| parent |
An optional parent, defaults to 0. |
BlackBerry 10.0.0
Signals
void
Emitted when the style has changed.
This will will happen when any of the parameters of the TextStyleDefinition has changed.
BlackBerry 10.0.0
void
Emitted when the base TextStyle has changed.
| Parameters | |
|---|---|
| textStyle |
The new base TextStyle. |
BlackBerry 10.0.0
void
Emitted when fontFamily has been changed.
| Parameters | |
|---|---|
| fontFamily |
The new font family name. |
BlackBerry 10.0.0
void
Emitted when fontStyle has been changed.
| Parameters | |
|---|---|
| newFontStyle |
The new font style. |
BlackBerry 10.0.0
void
Emitted when fontWeight has been changed.
| Parameters | |
|---|---|
| newFontWeight |
The new font weight. |
BlackBerry 10.0.0
void
Emitted when color has been changed.
| Parameters | |
|---|---|
| color |
The new color. |
BlackBerry 10.0.0
void
Emitted when lineHeight has been changed.
| Parameters | |
|---|---|
| lineHeight |
The new line height. |
BlackBerry 10.0.0
void
Emitted when font size value has been changed.
| Parameters | |
|---|---|
| fontSizeValue |
The new font size value. |
BlackBerry 10.0.0
void
Emitted when logical size has been changed.
| Parameters | |
|---|---|
| newFontSize |
The new logical font size. |
BlackBerry 10.0.0
void
Emitted when alignment has been changed.
| Parameters | |
|---|---|
| newAlignment |
The new alignment. |
BlackBerry 10.0.0
void 
This signal is emitted only when this object is instantiated as a result of loading a QML document and creating the root node, or when an object is being constructed using its builder class.
This signal is emitted only when this object is instantiated as a result of loading a QML document and creating the root node (only after the root component that caused this instantiation has completed construction), or when the object is being constructed from its builder class. This signal is emitted to indicate that the construction and initialization of the object has been completed, the properties are initialized, and any QML binding values have been assigned to the object.
This signal is not emitted when the object is constructed from C++ using the constructor. If the object is constructed using its builder class, the signal is emitted when the the builder class returns the fully constructed object.
This signal can be used when there is an activity that needs to be performed, such as a property state integrity verification after the object is instantiated from a QML document or a builder, but before control is returned to the application.
BlackBerry 10.0.0
void 
This signal is emitted when the objectName property is changed.
BlackBerry 10.0.0