All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Stylish::AttributeFont Class Reference

Attribute for fonts. Implements parts of CSS Fonts Module: http://www.w3.org/TR/css3-fonts. More...

#include <Stylish/AttributeFont.hpp>

Inheritance diagram for Stylish::AttributeFont:
Valuable::Attribute Valuable::Serializable

Valuable Attributes

QStringList font-family = QStringList()
 CSS parameter "font-family". More...
 
Stylish::FontKerning font-kerning = FONT_KERNING_AUTO
 CSS parameter "font-kerning", values: "auto", "normal", "none" http://www.w3.org/TR/css3-fonts/#font-kerning-prop. More...
 
Valuable::StyleValue font-size = QByteArray("medium")
 CSS parameter "font-size". More...
 
Stylish::FontStretch font-stretch = FONT_STRETCH_NORMAL
 CSS parameter "font-stretch". More...
 
Stylish::FontStyle font-style = FONT_STYLE_NORMAL
 CSS parameter "font-style", values: "normal", "italic", "oblique". More...
 
Stylish::FontVariant font-variant = FONT_VARIANT_NORMAL
 CSS parameter "font-variant", values: "normal", "small-caps". More...
 
Valuable::StyleValue line-height = QByteArray("normal")
 CSS parameter "line-height". More...
 

Public Member Functions

virtual STYLISH_API QString asString (bool *const ok=0, Layer layer=LAYER_CURRENT) const
 Converts the value object to a string. More...
 
STYLISH_API AttributeFont (Valuable::Node *host=0, const QByteArray &name="", bool transit=false)
 Constructs a new value object and attaches it to its host. More...
 
virtual STYLISH_API bool deserialize (const Valuable::ArchiveElement &element)
 Deserializes (reads) this object from serializer element. More...
 
STYLISH_API const QStringList & fontFamily () const
 CSS parameter "font-family". More...
 
STYLISH_API FontKerning fontKerning () const
 CSS parameter "font-kerning", values: "auto", "normal", "none" http://www.w3.org/TR/css3-fonts/#font-kerning-prop. More...
 
STYLISH_API Valuable::StyleValue fontSize () const
 CSS parameter "font-size". More...
 
STYLISH_API float fontSizePixels () const
 Returns font-size in pixels. More...
 
STYLISH_API FontStretch fontStretch () const
 CSS parameter "font-stretch". More...
 
STYLISH_API FontStyle fontStyle () const
 CSS parameter "font-style", values: "normal", "italic", "oblique". More...
 
STYLISH_API FontVariant fontVariant () const
 CSS parameter "font-variant", values: "normal", "small-caps". More...
 
STYLISH_API int fontWeight () const
 CSS parameter "font-weight". More...
 
virtual STYLISH_API bool handleShorthand (const Valuable::StyleValue &value, Radiant::ArrayMap< Valuable::Attribute *, Valuable::StyleValue > &expanded)
 If attribute supports shorthand properties, this should be used to parse those. More...
 
STYLISH_API const
Valuable::StyleValue
lineHeight () const
 CSS parameter "line-height". More...
 
STYLISH_API void setFontFamily (const QStringList &family)
 Setter for attribute font-family. More...
 
STYLISH_API void setFontKerning (FontKerning kerning)
 Setter for attribute font-kerning. More...
 
STYLISH_API void setFontSize (const Valuable::StyleValue &size)
 Setter for attribute font-size. More...
 
STYLISH_API void setFontSize (float size)
 Sets font-size in pixels. More...
 
STYLISH_API void setFontStretch (FontStretch stretch)
 Setter for attribute font-stretch. More...
 
STYLISH_API void setFontStyle (FontStyle style)
 Setter for attribute font-style. More...
 
STYLISH_API void setFontVariant (FontVariant variant)
 Setter for attribute font-variant. More...
 
STYLISH_API void setFontWeight (int weight)
 
STYLISH_API void setLineHeight (const Valuable::StyleValue &height)
 Setter for attribute line-height. More...
 
STYLISH_API QFont toQFont () const
 Converts AttributeFont to QFont. More...
 
- Public Member Functions inherited from Valuable::Attribute
long addListener (ListenerFunc func, int role=CHANGE_ROLE)
 Adds a listener that is invoked whenever the value is changed. More...
 
long addListener (Node *listener, ListenerFunc func, int role=CHANGE_ROLE)
 Adds a listener that is invoked whenever the value is changed. More...
 
long addListener (v8::Persistent< v8::Function > func, int role=CHANGE_ROLE)
 Adds a JavaScript listener that is invoked whenever the value is changed. More...
 
virtual float asFloat (bool *const ok=0, Layer layer=LAYER_CURRENT) const
 Converts the value object in a floating point number. More...
 
virtual int asInt (bool *const ok=0, Layer layer=LAYER_CURRENT) const
 Converts the value object in an integer. More...
 
 Attribute (const Attribute &o)
 Create a copy of the given Attribute WITHOUT the link to host, listeners, or the attribute name. More...
 
 Attribute (Node *host, const QByteArray &name, bool transit=false)
 Constructs a new value object and attaches it to its host. More...
 
virtual Attributeattribute (const QByteArray &name) const
 Gets an Attribute with the given name. More...
 
virtual void clearValue (Layer layer)
 Unsets the value from a specific layer. More...
 
virtual void emitChange ()
 Invokes the change valueChanged function of all listeners.
 
virtual void eventProcess (const QByteArray &id, Radiant::BinaryData &data)
 Process a message. More...
 
void eventProcessFloat (const char *id, float v)
 Utility function for sending a float message to the object.
 
void eventProcessInt (const char *id, int v)
 Utility function for sending an int message to the object.
 
void eventProcessString (const char *id, const QString &str)
 Utility function for sending string message to the object.
 
void eventProcessString (const char *id, const char *str)
 Utility function for sending string message to the object.
 
void eventProcessVector2 (const char *id, Nimble::Vector2)
 Utility function for sending a Nimble::Vector2f message to the object.
 
void eventProcessVector3 (const char *id, Nimble::Vector3)
 Utility function for sending a Vector3 message to the object.
 
void eventProcessVector4 (const char *id, Nimble::Vector4)
 Utility function for sending a Vector4 message to the object.
 
Nodehost () const
 The host object of the value object (is any). More...
 
virtual bool isChanged () const
 
virtual bool isValueDefinedOnLayer (Layer layer) const
 Check if the given layer defines a value. More...
 
bool layerForSerialization (SerializationOptions flags, Layer &layer) const
 
const QByteArray & name () const
 Returns the name of the object.
 
const Attributeoperator= (const Attribute &)
 Create a copy of the given Attribute WITHOUT the link to host, listeners, or the attribute name. More...
 
AttributeownerShorthand () const
 
QByteArray path () const
 Returns the path (separated by '/'s) from the root.
 
void removeHost ()
 Sets the host pointer to zero and removes this object from the host. More...
 
bool removeListener (Node *listener, int role=ALL_ROLES)
 Removes a listener from the listener list. More...
 
bool removeListener (long id)
 Removes a listener from the listener list. More...
 
void removeListeners (int role=ALL_ROLES)
 Removes listeners from the listener list.
 
virtual ArchiveElement serialize (Archive &archive) const
 The object is serialized using its name as a tag name. More...
 
virtual bool set (float v, Layer layer=USER, ValueUnit unit=VU_UNKNOWN)
 Sets the value of the object.
 
virtual bool set (int v, Layer layer=USER, ValueUnit unit=VU_UNKNOWN)
 Sets the value of the object.
 
virtual bool set (const QString &v, Layer layer=USER, ValueUnit unit=VU_UNKNOWN)
 Sets the value of the object.
 
virtual bool set (const Nimble::Vector2f &v, Layer layer=USER, QList< ValueUnit > units=QList< ValueUnit >())
 Sets the value of the object.
 
virtual bool set (const Nimble::Vector3f &v, Layer layer=USER, QList< ValueUnit > units=QList< ValueUnit >())
 Sets the value of the object.
 
virtual bool set (const Nimble::Vector4f &v, Layer layer=USER, QList< ValueUnit > units=QList< ValueUnit >())
 Sets the value of the object.
 
virtual bool set (const StyleValue &value, Layer layer=USER)
 Sets the value of the object.
 
virtual void setAsDefaults ()
 Sets the current USER attribute value as the default value and clears the USER value. More...
 
void setName (const QByteArray &s)
 Sets the name of the object.
 
void setOwnerShorthand (Attribute *owner)
 
virtual QByteArray type () const
 Get the type id of the attribute. More...
 
- Public Member Functions inherited from Valuable::Serializable
virtual bool deserializeXML (const DOMElement &element)
 Deserializes (reads) this object from an XML element. More...
 
bool isSerializable () const
 
void setSerializable (bool v)
 

Additional Inherited Members

- Public Types inherited from Valuable::Attribute
enum  Layer {
  DEFAULT = 0, STYLE, USER, STYLE_IMPORTANT,
  LAYER_COUNT, LAYER_CURRENT
}
 Attribute has multiple independent attribute values on LAYER_COUNT different layers. More...
 
typedef std::function< void()> ListenerFunc
 Callback function type in the listener API.
 
enum  ListenerRole { DELETE_ROLE = 1 << 0, CHANGE_ROLE = 1 << 1, ALL_ROLES = (CHANGE_ROLE << 1) -1 }
 Different listener roles, used when adding a new listener.
 
enum  ValueUnit {
  VU_UNKNOWN, VU_PXS, VU_PERCENTAGE, VU_EMS,
  VU_EXS
}
 Units of a value. More...
 
- Protected Member Functions inherited from Valuable::Attribute
virtual void emitDelete ()
 Invokes the change valueDeleted function of all listeners.
 

Detailed Description

Attribute for fonts. Implements parts of CSS Fonts Module: http://www.w3.org/TR/css3-fonts.

Constructor & Destructor Documentation

STYLISH_API Stylish::AttributeFont::AttributeFont ( Valuable::Node host = 0,
const QByteArray &  name = "",
bool  transit = false 
)

Constructs a new value object and attaches it to its host.

Parameters
hostThe host object. This object is automatically added to the host.
nameThe name (or id) of this attribute. Names are typically human-readable. The names should not contain white-spaces as they may be used in XML files etc.
transitShould value changes be transmitted forward. This is related to future uses, and can be largely ignored at the moment.

Member Function Documentation

virtual STYLISH_API QString Stylish::AttributeFont::asString ( bool *const  ok = 0,
Layer  layer = LAYER_CURRENT 
) const
virtual

Converts the value object to a string.

Parameters
okIf non-null, *ok is set to true/false on success/error
Returns
Object as a string, the default implementation returns an empty string

Reimplemented from Valuable::Attribute.

virtual STYLISH_API bool Stylish::AttributeFont::deserialize ( const Valuable::ArchiveElement element)
virtual

Deserializes (reads) this object from serializer element.

Parameters
elementSerialized element that holds the data that should be deserialized.
Returns
Returns true if the read process worked correctly, and false otherwise.

Implements Valuable::Serializable.

const QStringList & Stylish::AttributeFont::fontFamily ( ) const

CSS parameter "font-family".

This takes list of family names or generic family names in order. First one found on the system is used. Example: ["Verdana", "sans-serif"]

See Also
http://www.w3.org/TR/css3-fonts/#font-family-prop
setFontFamily
Returns
Current value of the font-family attribute
Stylish::FontKerning Stylish::AttributeFont::fontKerning ( ) const

CSS parameter "font-kerning", values: "auto", "normal", "none" http://www.w3.org/TR/css3-fonts/#font-kerning-prop.

See Also
Stylish::FontKerning
setFontKerning
Returns
Current value of the font-kerning attribute
Valuable::StyleValue Stylish::AttributeFont::fontSize ( ) const

CSS parameter "font-size".

See Also
setFontSize
http://www.w3.org/TR/css3-fonts/#propdef-font-size
Returns
Current value of the font-size attribute
STYLISH_API float Stylish::AttributeFont::fontSizePixels ( ) const

Returns font-size in pixels.

See Also
setFontSize(float)
Returns
Value of font-size in pixels
Stylish::FontStretch Stylish::AttributeFont::fontStretch ( ) const

CSS parameter "font-stretch".

See Also
http://www.w3.org/TR/css3-fonts/#propdef-font-stretch
Stylish::FontStretch
setFontStretch
Returns
Current value of the font-stretch attribute
Stylish::FontStyle Stylish::AttributeFont::fontStyle ( ) const

CSS parameter "font-style", values: "normal", "italic", "oblique".

See Also
http://www.w3.org/TR/css3-fonts/#propdef-font-style
Stylish::FontStyle
setFontStyle
Returns
Current value of the font-style attribute
Stylish::FontVariant Stylish::AttributeFont::fontVariant ( ) const

CSS parameter "font-variant", values: "normal", "small-caps".

See Also
http://www.w3.org/TR/CSS2/fonts.html#propdef-font-variant
Stylish::FontVariant
setFontVariant
Returns
Current value of the font-variant attribute
STYLISH_API int Stylish::AttributeFont::fontWeight ( ) const

CSS parameter "font-weight".

The possible values for this are normal, bold or integer value between 100 and 900. Unlike the CSS3 specification, we allow arbitrary weight value. However, depending on the font, there can only be two usable weights, normal and bold. Value is rounded to the nearest supported weight.

See Also
http://www.w3.org/TR/css3-fonts/#propdef-font-weight
Stylish::FontWeight
setFontWeight
virtual STYLISH_API bool Stylish::AttributeFont::handleShorthand ( const Valuable::StyleValue value,
Radiant::ArrayMap< Valuable::Attribute *, Valuable::StyleValue > &  expanded 
)
virtual

If attribute supports shorthand properties, this should be used to parse those.

For example "background: url('image.png') repeat" is a shorhand for setting background-image to "url('image.png')" and background-repeat to "repeat".

Parameters
[in]valueshorthand value
[out]expandedshorthand property split to parts. With the previous background-example map should have two values.
Returns
true if shorthand was successfully handled
See Also
http://www.w3.org/TR/CSS21/about.html#shorthand

Reimplemented from Valuable::Attribute.

const Valuable::StyleValue & Stylish::AttributeFont::lineHeight ( ) const

CSS parameter "line-height".

See Also
http://www.w3.org/TR/CSS2/visudet.html#propdef-line-height
setLineHeight
Returns
Current value of the line-height attribute
void Stylish::AttributeFont::setFontFamily ( const QStringList &  family)

Setter for attribute font-family.

See Also
fontFamily
Parameters
familynew attribute value
void Stylish::AttributeFont::setFontKerning ( Stylish::FontKerning  kerning)

Setter for attribute font-kerning.

See Also
fontKerning
Stylish::FontKerning
Parameters
kerningnew attribute value
void Stylish::AttributeFont::setFontSize ( const Valuable::StyleValue size)

Setter for attribute font-size.

See Also
setFontSize(float)
Parameters
sizenew attribute value
STYLISH_API void Stylish::AttributeFont::setFontSize ( float  size)

Sets font-size in pixels.

Parameters
sizeFont size in pixels
void Stylish::AttributeFont::setFontStretch ( Stylish::FontStretch  stretch)

Setter for attribute font-stretch.

See Also
fontStretch
Stylish::FontStretch
Parameters
stretchnew attribute value
void Stylish::AttributeFont::setFontStyle ( Stylish::FontStyle  style)

Setter for attribute font-style.

See Also
fontStyle
Parameters
stylenew attribute value
void Stylish::AttributeFont::setFontVariant ( Stylish::FontVariant  variant)

Setter for attribute font-variant.

See Also
fontVariant
Parameters
variantnew attribute value
STYLISH_API void Stylish::AttributeFont::setFontWeight ( int  weight)
void Stylish::AttributeFont::setLineHeight ( const Valuable::StyleValue height)

Setter for attribute line-height.

See Also
lineHeight
Parameters
heightnew attribute value
STYLISH_API QFont Stylish::AttributeFont::toQFont ( ) const

Converts AttributeFont to QFont.

Returns
QFont with same parameters that the AttributeFont has