KTextEditor
KTextEditor::Attribute Class Reference
#include <attribute.h>

Detailed Description
A class which provides customized text decorations.The Attribute class extends QTextCharFormat, the class which Qt uses internally to provide formatting information to characters in a text document.
In addition to its inherited properties, it provides support for:
- several customized text formatting properties
- dynamic highlighting of associated ranges of text
- binding of actions with associated ranges of text (note: not currently implemented)
Unfortunately, as QTextFormat's setProperty() is not virtual, changes that are made to this attribute cannot automatically be redrawn. Once you have finished changing properties, you should call changed() to force redrawing of affected ranges of text.
- See also:
- SmartInterface
Definition at line 59 of file attribute.h.
Public Types | |
enum | ActivationType { ActivateMouseIn = 0, ActivateCaretIn } |
enum | CustomProperties { Outline = QTextFormat::UserProperty, SelectedForeground, SelectedBackground, BackgroundFillWhitespace, AttributeDynamicEffect = 0x10A00, AttributeInternalProperty = 0x10E00, AttributeUserProperty = 0x110000 } |
enum | Effect { EffectNone = 0x0, EffectFadeIn = 0x1, EffectFadeOut = 0x2, EffectPulse = 0x4, EffectCycleGradient = 0x8 } |
typedef KSharedPtr< Attribute > | Ptr |
Public Member Functions | |
Attribute (const Attribute &a) | |
Attribute () | |
void | changed () const |
Attribute & | operator+= (const Attribute &a) |
Attribute & | operator= (const Attribute &a) |
virtual | ~Attribute () |
Action association | |
void | associateAction (KAction *action) |
const QList< KAction * > & | associatedActions () const |
void | clearAssociatedActions () |
void | dissociateAction (KAction *action) |
Custom properties | |
The following functions provide custom properties which can be set for rendering by editor implementations. | |
bool | backgroundFillWhitespace () const |
void | clear () |
bool | fontBold () const |
bool | hasAnyProperty () const |
QBrush | outline () const |
QBrush | selectedBackground () const |
QBrush | selectedForeground () const |
void | setBackgroundFillWhitespace (bool fillWhitespace) |
void | setFontBold (bool bold=true) |
void | setOutline (const QBrush &brush) |
void | setSelectedBackground (const QBrush &brush) |
void | setSelectedForeground (const QBrush &foreground) |
Dynamic highlighting | |
The following functions allow for text to be highlighted dynamically based on several events. | |
Attribute::Ptr | dynamicAttribute (ActivationType type) const |
Effects | effects () const |
void | setDynamicAttribute (ActivationType type, Attribute::Ptr attribute) |
void | setEffects (Effects effects) |
Member Typedef Documentation
Definition at line 64 of file attribute.h.
Member Enumeration Documentation
Several automatic activation mechanisms exist for associated attributes.
Using this you can conveniently have your ranges highlighted when either the mouse or cursor enter the range.
- Enumerator:
-
ActivateMouseIn Activate attribute on mouse in. ActivateCaretIn Activate attribute on caret in.
Definition at line 261 of file attribute.h.
Custom property types, which may or may not be supported by implementations.
- Enumerator:
-
Outline Draws an outline around the text. SelectedForeground Changes the brush used to paint the text when it is selected. SelectedBackground Changes the brush used to paint the background when it is selected. BackgroundFillWhitespace Determines whether background color is drawn over whitespace. Defaults to true. AttributeDynamicEffect Defined to allow storage of dynamic effect information. AttributeInternalProperty Defined for internal usage of KTextEditor implementations. AttributeUserProperty Defined to allow 3rd party code to create their own custom attributes - you may use values at or above this property.
Definition at line 94 of file attribute.h.
Dynamic effects for display.
- Todo:
- Pulse and CycleGradient are unclear.
- Enumerator:
-
EffectNone No effect. Just display.
EffectFadeIn Fade in and stay there. EffectFadeOut Fade out to vanish. EffectPulse Pulse (throb); change weight. EffectCycleGradient Cycle colors.
Definition at line 272 of file attribute.h.
Constructor & Destructor Documentation
Attribute::Attribute | ( | ) |
Default constructor.
The resulting Attribute has no properties set to begin with.
Definition at line 36 of file attribute.cpp.
Attribute::Attribute | ( | const Attribute & | a | ) |
Attribute::~Attribute | ( | ) | [virtual] |
Member Function Documentation
void KTextEditor::Attribute::associateAction | ( | KAction * | action | ) |
Associate an action with this attribute.
When assigned to a range, this attribute will enable the associated action(s) when the caret enters the range, and disable them on exit. The action is also added to the context menu when the caret is within an associated range.
bool Attribute::backgroundFillWhitespace | ( | ) | const |
Determine whether background color is drawn over whitespace.
Defaults to true if not set.
- Returns:
- whether the background color should be drawn over whitespace
Definition at line 114 of file attribute.cpp.
void KTextEditor::Attribute::changed | ( | ) | const |
Notify the editor implementation that a property of this attribute has been changed.
This is used to re-render any text which has this attribute assigned to it.
void Attribute::clear | ( | ) |
void Attribute::clearAssociatedActions | ( | ) |
Clears all associations between KActions and this attribute.
Definition at line 160 of file attribute.cpp.
void KTextEditor::Attribute::dissociateAction | ( | KAction * | action | ) |
Attribute::Ptr Attribute::dynamicAttribute | ( | ActivationType | type | ) | const |
Return the attribute to use when the event referred to by type occurs.
- Parameters:
-
type the activation type for which to return the Attribute.
- Returns:
- the attribute to be used for events specified by type, or null if none is set.
Definition at line 72 of file attribute.cpp.
Attribute::Effects KTextEditor::Attribute::effects | ( | ) | const |
Definition at line 175 of file attribute.cpp.
bool Attribute::fontBold | ( | ) | const |
Definition at line 150 of file attribute.cpp.
bool Attribute::hasAnyProperty | ( | ) | const |
Determine if any properties are set.
- Returns:
- true if any properties are set, otherwise false
Definition at line 165 of file attribute.cpp.
Addition assignment operator.
Use this to merge another Attribute with this Attribute. Where both attributes have a particular property set, the property in a will be used.
- Parameters:
-
a attribute to merge into this attribute.
Definition at line 55 of file attribute.cpp.
Replacement assignment operator.
Use this to overwrite this Attribute with another Attribute.
- Parameters:
-
a attribute to assign to this attribute.
Definition at line 188 of file attribute.cpp.
QBrush Attribute::outline | ( | ) | const |
Get the brush used to draw an outline around text, if any.
- Returns:
- brush to be used to draw an outline, or Qt::NoBrush if no outline is set.
Definition at line 88 of file attribute.cpp.
QBrush Attribute::selectedBackground | ( | ) | const |
Get the brush used to draw the background of selected text, if any.
- Returns:
- brush to be used to draw the background of selected text, or Qt::NoBrush if not set
Definition at line 127 of file attribute.cpp.
QBrush Attribute::selectedForeground | ( | ) | const |
Get the brush used to draw text when it is selected, if any.
- Returns:
- brush to be used to draw selected text, or Qt::NoBrush if not set
Definition at line 101 of file attribute.cpp.
void Attribute::setBackgroundFillWhitespace | ( | bool | fillWhitespace | ) |
Set whether background color is drawn over whitespace.
Defaults to true if not set.
Use clearProperty(BackgroundFillWhitespace)
to clear.
- Parameters:
-
fillWhitespace whether the background should be drawn over whitespace.
Definition at line 122 of file attribute.cpp.
void Attribute::setDynamicAttribute | ( | ActivationType | type, | |
Attribute::Ptr | attribute | |||
) |
Set the attribute to use when the event referred to by type occurs.
- Note:
- Nested dynamic attributes are ignored.
- Parameters:
-
type the activation type to set the attribute for attribute the attribute to assign. As attribute is refcounted, ownership is not an issue.
Definition at line 80 of file attribute.cpp.
void KTextEditor::Attribute::setEffects | ( | Effects | effects | ) |
Definition at line 183 of file attribute.cpp.
void Attribute::setFontBold | ( | bool | bold = true |
) |
Definition at line 155 of file attribute.cpp.
void Attribute::setOutline | ( | const QBrush & | brush | ) |
Set a brush to be used to draw an outline around text.
Use clearProperty(Outline)
to clear.
- Parameters:
-
brush brush to be used to draw an outline.
Definition at line 96 of file attribute.cpp.
void Attribute::setSelectedBackground | ( | const QBrush & | brush | ) |
Set a brush to be used to draw the background of selected text, if any.
Use clearProperty(SelectedBackground)
to clear.
- Parameters:
-
brush brush to be used to draw the background of selected text
Definition at line 135 of file attribute.cpp.
void Attribute::setSelectedForeground | ( | const QBrush & | foreground | ) |
Set a brush to be used to draw selected text.
Use clearProperty(SelectedForeground)
to clear.
- Parameters:
-
foreground brush to be used to draw selected text.
Definition at line 109 of file attribute.cpp.
The documentation for this class was generated from the following files: