29
29
: oldParentItem(Q_NULLPTR)
30
30
, styleComponent(Q_NULLPTR)
31
31
, styleItem(Q_NULLPTR)
32
, highlighted(Q_NULLPTR)
35
, componentState(UCStyledItemBase::Undefined)
33
37
, keyNavigationFocus(false)
34
38
, activeFocusOnPress(false)
62
66
QObject::connect(q, &QQuickItem::activeFocusOnTabChanged, q, &UCStyledItemBase::activeFocusOnTabChanged2);
69
// initializes state builders
70
void UCStyledItemBasePrivate::setupHighlightedStateBinging()
72
Q_Q(UCStyledItemBase);
73
const QMetaObject *mo = q->metaObject();
74
// detect highlight setup
75
if (mo->indexOfProperty("pressed") > 0) {
76
QMetaMethod change = mo->method(mo->indexOfSignal("pressedChanged()"));
77
auto getter = [=] ()->bool {
78
return QQmlProperty::read(q, "pressed", qmlContext(q)).toBool();
80
highlighted = new UbuntuToolkit::PropertyBinding<bool>(
82
std::bind(&UCStyledItemBase::componentStateChanged, q),
83
{UbuntuToolkit::Binding(q, change)});
84
} else if (mo->indexOfProperty("highlighted") > 0) {
85
QMetaMethod change = mo->method(mo->indexOfSignal("highlightedChanged()"));
86
auto getter = [=] ()->bool {
87
return QQmlProperty::read(q, "highlighted", qmlContext(q)).toBool();
89
highlighted = new UbuntuToolkit::PropertyBinding<bool>(
91
std::bind(&UCStyledItemBase::componentStateChanged, q),
92
{UbuntuToolkit::Binding(q, change)});
96
void UCStyledItemBasePrivate::setupFocusedStateBinging()
98
Q_Q(UCStyledItemBase);
99
auto getter = [=] () -> bool {
100
return q->window() && q->window()->activeFocusItem() == q;
103
const QMetaObject *mo = q->metaObject();
104
focused = new UbuntuToolkit::PropertyBinding<bool> (
106
std::bind(&UCStyledItemBase::componentComplete, q),
108
UbuntuToolkit::Binding(q, mo->method(mo->indexOfMethod("windowChanged(QQuickWindow*)")))
113
void UCStyledItemBasePrivate::setupSelectedStateBinging()
66
119
void UCStyledItemBasePrivate::setFocusable(bool focus)
480
533
d->loadStyleItem();
537
* \qmlproperty ComponentState StyledItem::componentState
539
* \since Ubuntu.Components 1.3
540
* The property reports the current state of the component.
542
UCStyledItemBase::ComponentState UCStyledItemBase::componentState()
544
Q_D(const UCStyledItemBase);
546
if (d->highlighted && d->highlighted->value()) {
549
if (d->focused && d->focused->value()) {
552
if (d->selected && d->selected->value()) {
556
} else if (d->selected && d->selected->value()) {
557
return SelectedDisabled;
483
565
QString UCStyledItemBasePrivate::propertyForVersion(quint16 version) const
485
567
switch (MINOR_VERSION(version)) {
510
592
* The member defaults to true. Additionally, the focus scope flag must
511
593
* be set before the parentItem is set and child items are added.
513
if (d_func()->isFocusScope) {
595
Q_D(UCStyledItemBase);
596
if (d->isFocusScope) {
514
597
setFlag(QQuickItem::ItemIsFocusScope);
516
599
QQuickItem::classBegin();
601
// build state transitioners
602
d->setupHighlightedStateBinging();
603
d->setupFocusedStateBinging();
604
d->setupSelectedStateBinging();
519
607
void UCStyledItemBase::componentComplete()