Union::Element Class
class Union::ElementAn element in a tree of elements that is used to match StyleRules. More...
Header: | #include <Element> |
CMake: | find_package(Union REQUIRED) target_link_libraries(mytarget PRIVATE Union::Union) |
Inherits: | QObject and |
Public Types
enum class | Change { Nothing, Type, Id, States, Hints, Attributes } |
flags | Changes |
enum class | ColorSet { None, View, Window, Button, Selection, …, Header } |
Ptr | |
enum class | State { None, Hovered, ActiveFocus, VisualFocus, Pressed, …, Highlighted } |
flags | States |
Properties
|
Public Functions
QVariant | attribute(const QString &name) const |
QVariantMap | attributes() const |
Union::Element::ColorSet | colorSet() const |
bool | hasAttribute(const QString &name) const |
bool | hasHint(const QString &name) |
QSet<QString> | hints() const |
QString | id() const |
void | setAttribute(const QString &name, const QVariant &value) |
void | setAttributes(const QVariantMap &attributes) |
void | setColorSet(Union::Element::ColorSet newColorSet) |
void | setHint(const QString &name, bool present = true) |
void | setHints(const QSet<QString> &newHints) |
void | setId(const QString &newId) |
void | setStates(Union::Element::States newStates) |
void | setType(const QString &type) |
Union::Element::States | states() const |
QString | toString() const |
QString | type() const |
Signals
void | attributesChanged() |
void | colorSetChanged() |
void | hintsChanged() |
void | idChanged() |
void | statesChanged() |
void | typeChanged() |
void | updated() |
Static Public Members
Union::Element::Ptr | create() |
Related Non-Members
ElementList | |
std::size_t | elementListCacheKey(const Union::ElementList &key, std::size_t seed = 0) |
QDebug | operator<<(QDebug debug, Union::Element::Ptr element) |
Detailed Description
This class mainly contains a set of properties to indicate element information, such as what type of element this is. These properties are used to determine if a StyleRule should be applied to an element.
Element instances should be created by output plugins to match the hierarchy of objects in the application and supplied values for as many of the properties as possible.
Note: Element inherits from std::enable_shared_from_this
as it is intended to be stored as a std::shared_ptr
. To create a new instance of Element, use Element::create() as the constructor is semi-private.
Member Type Documentation
enum class Element::Change
flags Element::Changes
A set of flags to indicate what changed about an element.
The Changes type is a typedef for QFlags<Change>. It stores an OR combination of Change values.
enum class Element::ColorSet
Which set of colours should be used to render the element.
[alias]
Element::Ptr
A shorthand for std::shared_ptr<Element>
.
enum class Element::State
flags Element::States
A set of flags to indicate an element's state.
Constant | Value | Description |
---|---|---|
Union::Element::State::None | 0 | No State is currently active. |
Union::Element::State::Hovered | 1 << 0 | The element is hovered. |
Union::Element::State::ActiveFocus | 1 << 1 | The element has active focus, it will receive keyboard input. |
Union::Element::State::VisualFocus | 1 << 2 | The element has active focus and that focus should be visualized. |
Union::Element::State::Pressed | 1 << 3 | The element is being pressed. |
Union::Element::State::Checked | 1 << 4 | The element has a checked state and is currently checked. |
Union::Element::State::Disabled | 1 << 5 | The element is disabled. |
Union::Element::State::Highlighted | 1 << 6 | The element should be highlighted, because it is selected or otherwise needs to stand out. |
The States type is a typedef for QFlags<State>. It stores an OR combination of State values.
Property Documentation
attributes : QVariantMap
A map of extra attributes that can be used for rule matching.
This can contain an arbitrary amount of key-value pairs that can be useful for rule matching.
Access functions:
QVariantMap | attributes() const |
void | setAttributes(const QVariantMap &attributes) |
Notifier signal:
void | attributesChanged() |
colorSet : ColorSet
The ColorSet to use to render this element.
Access functions:
Union::Element::ColorSet | colorSet() const |
void | setColorSet(Union::Element::ColorSet newColorSet) |
Notifier signal:
void | colorSetChanged() |
hints : QSet<QString>
A set of hints for this element.
Hints are used to indicate there's something different about the element which might be useful for style rule matching. This includes things like "is a toolbar at the top or bottom of a view" or "this button should be displayed with a special style". Hints should be fairly static and usually should not be used for state information, the states property should cover most of those.
Access functions:
QSet<QString> | hints() const |
void | setHints(const QSet<QString> &newHints) |
Notifier signal:
void | hintsChanged() |
id : QString
A unique ID to identify a specific element.
This can be any string that can be used to identify a specific element in an application. These IDs should be unique to ensure style rules intended to style a specific element aren't suddenly applied to other elements.
Access functions:
QString | id() const |
void | setId(const QString &newId) |
Notifier signal:
void | idChanged() |
states : States
The set of states this element currently has.
These are things like "Hovered" and often change fairly often in an application.
Access functions:
Union::Element::States | states() const |
void | setStates(Union::Element::States newStates) |
Notifier signal:
void | statesChanged() |
type : QString
The type of the element.
This can be any arbitrary string that can be used to describe an object in a user interface, such as "Button".
Access functions:
QString | type() const |
void | setType(const QString &type) |
Notifier signal:
void | typeChanged() |
Member Function Documentation
QVariant Element::attribute(const QString &name) const
Get the value of a certain attribute.
name The name of the attribute to get.
Returns the value of the attribute if it is set, or an empty QVariant if not.
See also setAttribute().
[static]
Union::Element::Ptr Element::create()
Returns a newly created instance of Element.
bool Element::hasAttribute(const QString &name) const
Check if a certain attribute is set on this element.
name The name of the attribute to check.
Returns true if the attribute is set, false if not.
bool Element::hasHint(const QString &name)
Check if a hint is set.
Returns true
if \p
name is present, otherwise returns false
.
void Element::setAttribute(const QString &name, const QVariant &value)
Set a single attribute value.
See also attribute().
void Element::setHint(const QString &name, bool present = true)
Add or remove a single hint.
This adds the hint \p
name if \p
present is true
and the hint was not yet added. It will remove the hint if \p
present is false
and the hint is present.
See also hasHint().
QString Element::toString() const
Returns a string representation of this Element.
[signal]
void Element::updated()
Emitted whenever any of the properties of the element have changed.
Related Non-Members
[alias]
ElementList
A list of elements.
std::size_t elementListCacheKey(const Union::ElementList &key, std::size_t seed = 0)
Get a cache key for an ElementList.
QDebug operator<<(QDebug debug, Union::Element::Ptr element)
Implements QDebug support for Union::Element.