11#include <QtCore/qbasictimer.h>
12#include <QtQml/qqmlinfo.h>
13#include <QtQml/qqmlengine.h>
14#include <QtQml/qqmlcontext.h>
15#include <QtQml/qqmlcomponent.h>
16#include <QtQuick/qquickwindow.h>
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
98#ifdef QT_BUILD_INTERNAL
99Q_CONSTINIT Q_AUTOTEST_EXPORT
107#ifdef QT_BUILD_INTERNAL
108Q_CONSTINIT Q_AUTOTEST_EXPORT
116 Q_DECLARE_PUBLIC(QQuickToolTip)
140 windowFlags = Qt::ToolTip;
141 if (qt_quicktooltipattachedprivate_delay == -1)
142 qt_quicktooltipattachedprivate_delay = qGuiApp->styleHints()->toolTipWakeUpDelay();
149 delayTimer.start(delay, q);
161 timeoutTimer.start(timeout, q);
171 QQuickPopupPrivate::opened();
175QQuickToolTip::QQuickToolTip(QQuickItem *parent)
176 : QQuickPopup(*(
new QQuickToolTipPrivate), parent)
179 d->allowVerticalFlip =
true;
180 d->allowHorizontalFlip =
true;
181 d->popupItem->setHoverEnabled(
false);
185
186
187
188
189QString QQuickToolTip::text()
const
191 Q_D(
const QQuickToolTip);
195void QQuickToolTip::setText(
const QString &text)
202 maybeSetAccessibleName(text);
207
208
209
210
211
212
213
214
215int QQuickToolTip::delay()
const
217 Q_D(
const QQuickToolTip);
221void QQuickToolTip::setDelay(
int delay)
224 if (d->delay == delay)
232
233
234
235
236
237
238
239
240int QQuickToolTip::timeout()
const
242 Q_D(
const QQuickToolTip);
246void QQuickToolTip::setTimeout(
int timeout)
249 if (d->timeout == timeout)
252 d->timeout = timeout;
259 emit timeoutChanged();
262void QQuickToolTip::setVisible(
bool visible)
276 QQuickPopup::setVisible(visible);
279QQuickToolTipAttached *QQuickToolTip::qmlAttachedProperties(QObject *object)
281 return new QQuickToolTipAttached(object);
285
286
287
288
289
290
291void QQuickToolTip::show(
const QString &text,
int ms)
300
301
302
303
304
305void QQuickToolTip::hide()
310QFont QQuickToolTip::defaultFont()
const
312 return QQuickTheme::font(QQuickTheme::ToolTip);
315void QQuickToolTip::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
318 QQuickPopup::itemChange(change, data);
319 if (change == QQuickItem::ItemVisibleHasChanged) {
323 QQuickToolTipAttached *attached = qobject_cast<QQuickToolTipAttached *>(qmlAttachedPropertiesObject<QQuickToolTip>(d->parentItem,
false));
325 emit attached->visibleChanged();
329void QQuickToolTip::timerEvent(QTimerEvent *event)
332 if (event->timerId() == d->timeoutTimer.timerId()) {
334 QQuickPopup::setVisible(
false);
337 if (event->timerId() == d->delayTimer.timerId()) {
339 QQuickPopup::setVisible(
true);
342 QQuickPopup::timerEvent(event);
345#if QT_CONFIG(accessibility)
346QAccessible::Role QQuickToolTip::accessibleRole()
const
348 return QAccessible::ToolTip;
351void QQuickToolTip::accessibilityActiveChanged(
bool active)
354 QQuickPopup::accessibilityActiveChanged(active);
357 maybeSetAccessibleName(d->text);
361QQuickToolTip *QQuickToolTipAttachedPrivate::instance(
bool create)
const
363 QQmlEngine *engine = qmlEngine(parent);
369 static const char *name =
"_q_shared_QQuickToolTip";
371 QQuickToolTip *tip = engine->property(name).value<QQuickToolTip *>();
372 if (!tip && create) {
373 QQmlComponent component(engine,
"QtQuick.Controls",
"ToolTip");
375 QObject *object = component.create();
377 object->setParent(engine);
379 tip = qobject_cast<QQuickToolTip *>(object);
383 engine->setProperty(name, QVariant::fromValue(object));
388void QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(
389 const QObject *attachee,
bool visible)
391 auto *toolTipAttached = qobject_cast<QQuickToolTipAttached *>(
392 qmlAttachedPropertiesObject<QQuickToolTip>(attachee,
false));
394 if (!toolTipAttached)
397 auto *toolTipAttachedPrivate = toolTipAttached->d_func();
400 if (toolTipAttachedPrivate->isVisibleExplicitlySet()
401 || toolTipAttachedPrivate->policy == QQuickToolTip::Manual) {
407 const bool effectiveVisible = visible ? visible && !toolTipAttachedPrivate->text.isEmpty() :
false;
408 toolTipAttachedPrivate->setVisible(effectiveVisible, QQml::PropertyUtils::State::ImplicitlySet);
411void QQuickToolTipAttachedPrivate::setVisible(
bool visible, QQml::PropertyUtils::State propertyState)
413 Q_Q(QQuickToolTipAttached);
414 if (warnIfAttacheeIsNotAnItem(QStringLiteral(
"setVisible")))
417 explicitVisible = isExplicitlySet(propertyState);
419 if (!complete && visible) {
430bool QQuickToolTipAttachedPrivate::isVisibleExplicitlySet()
const
432 return explicitVisible;
435void QQuickToolTipAttachedPrivate::setDelay(
int delay, QQml::PropertyUtils::State propertyState)
437 Q_Q(QQuickToolTipAttached);
438 if (warnIfAttacheeIsNotAnItem(QStringLiteral(
"setDelay")))
441 explicitDelay = isExplicitlySet(propertyState);
443 if (
this->delay == delay)
447 emit q->delayChanged();
450 instance(
true)->setDelay(delay);
453bool QQuickToolTipAttachedPrivate::isDelayExplicitlySet()
const
455 return explicitDelay;
458void QQuickToolTipAttachedPrivate::setTimeout(
int timeout, QQml::PropertyUtils::State propertyState)
460 Q_Q(QQuickToolTipAttached);
461 if (warnIfAttacheeIsNotAnItem(QStringLiteral(
"setTimeout")))
464 explicitTimeout = isExplicitlySet(propertyState);
466 if (
this->timeout == timeout)
469 this->timeout = timeout;
470 emit q->timeoutChanged();
473 instance(
true)->setTimeout(timeout);
476bool QQuickToolTipAttachedPrivate::isTimeoutExplicitlySet()
const
478 return explicitTimeout;
481void QQuickToolTipAttachedPrivate::inheritPolicy(QQuickToolTip::Policy policy)
483 Q_Q(QQuickToolTipAttached);
484 if (
this->policy == policy)
487 this->policy = policy;
489 emit q->policyChanged();
492void QQuickToolTipAttachedPrivate::propagatePolicy()
494 Q_Q(QQuickToolTipAttached);
495 const auto attachedToolTipChildren = q->attachedChildren();
496 for (QtPrivate::QQuickAttachedPropertyPropagator *child : attachedToolTipChildren) {
497 auto *attachedToolTipChild = qobject_cast<QQuickToolTipAttached *>(child);
498 if (attachedToolTipChild)
499 attachedToolTipChild->d_func()->inheritPolicy(policy);
504
505
506
507
508
509
510
511bool QQuickToolTipAttachedPrivate::warnIfAttacheeIsNotAnItem(
const QString &functionName)
513 QQuickItem *item = qobject_cast<QQuickItem *>(parent);
517 qmlWarning(parent).nospace().noquote() <<
"The attached function ToolTip::" << functionName
518 <<
" can only be called when the attachee derives from Item";
522int QQuickToolTipAttachedPrivate::calculateTimeout(
const QString &text)
524 if (Q_UNLIKELY(qt_quicktooltipattachedprivate_short_timeout)) {
530 return 10000 + 40 * qMax(0, text.length() - 100);
533QQuickToolTipAttached::QQuickToolTipAttached(QObject *parent)
534 : QtPrivate::QQuickAttachedPropertyPropagator(*(
new QQuickToolTipAttachedPrivate), parent)
540
541
542
543
544
545
546
547QString QQuickToolTipAttached::text()
const
549 Q_D(
const QQuickToolTipAttached);
553void QQuickToolTipAttached::setText(
const QString &text)
555 Q_D(QQuickToolTipAttached);
556 if (d->warnIfAttacheeIsNotAnItem(QStringLiteral(
"setText")))
565 d->instance(
true)->setText(text);
569
570
571
572
573
574
575
576
577
578
579int QQuickToolTipAttached::delay()
const
581 Q_D(
const QQuickToolTipAttached);
582 return d->explicitDelay || d->policy == QQuickToolTip::Manual ? d->delay
583 : qt_quicktooltipattachedprivate_delay;
586void QQuickToolTipAttached::setDelay(
int delay)
588 Q_D(QQuickToolTipAttached);
589 d->setDelay(delay, QQml::PropertyUtils::State::ExplicitlySet);
593
594
595
596
597
598
599
600
601
602
603int QQuickToolTipAttached::timeout()
const
605 Q_D(
const QQuickToolTipAttached);
606 return d->explicitTimeout || d->policy == QQuickToolTip::Manual ? d->timeout
607 : d->calculateTimeout(d->text);
610void QQuickToolTipAttached::setTimeout(
int timeout)
612 Q_D(QQuickToolTipAttached);
613 d->setTimeout(timeout, QQml::PropertyUtils::State::ExplicitlySet);
617
618
619
620
621
622
623
624bool QQuickToolTipAttached::isVisible()
const
626 Q_D(
const QQuickToolTipAttached);
627 QQuickToolTip *tip = d->instance(
false);
631 return tip->isVisible() && tip->parentItem() == parent();
634void QQuickToolTipAttached::setVisible(
bool visible)
636 Q_D(QQuickToolTipAttached);
637 d->setVisible(visible, QQml::PropertyUtils::State::ExplicitlySet);
641
642
643
644
645
646
647
648QQuickToolTip *QQuickToolTipAttached::toolTip()
const
650 Q_D(
const QQuickToolTipAttached);
651 return d->instance(
true);
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699QQuickToolTip::Policy QQuickToolTipAttached::policy()
const
701 Q_D(
const QQuickToolTipAttached);
705void QQuickToolTipAttached::setVisiblePolicy(QQuickToolTip::Policy policy)
707 Q_D(QQuickToolTipAttached);
708 if (d->policy == policy)
712 d->propagatePolicy();
713 emit policyChanged();
716void QQuickToolTipAttached::resetVisiblePolicy()
718 setVisiblePolicy(QQuickToolTip::Automatic);
722
723
724
725
726
727
728
729void QQuickToolTipAttached::show(
const QString &text,
int ms)
731 Q_D(QQuickToolTipAttached);
732 if (d->warnIfAttacheeIsNotAnItem(QStringLiteral(
"show")))
735 QQuickToolTip *tip = d->instance(
true);
741 tip->setParentItem(qobject_cast<QQuickItem *>(parent()));
742 tip->setDelay(delay());
743 tip->setTimeout(ms >= 0 ? ms : timeout());
748
749
750
751
752
753
754void QQuickToolTipAttached::hide()
756 Q_D(QQuickToolTipAttached);
757 QQuickToolTip *tip = d->instance(
false);
761 if (parent() == tip->parentItem())
765void QQuickToolTipAttached::attachedParentChange(QQuickAttachedPropertyPropagator *newParent,
766 QQuickAttachedPropertyPropagator *)
768 auto *attachedToolTipParent = qobject_cast<QQuickToolTipAttached *>(newParent);
769 if (!attachedToolTipParent)
772 Q_D(QQuickToolTipAttached);
773 d->inheritPolicy(attachedToolTipParent->policy());
776void QQuickToolTipAttached::classBegin()
778 Q_D(QQuickToolTipAttached);
782void QQuickToolTipAttached::componentComplete()
784 Q_D(QQuickToolTipAttached);
787 if (d->pendingShow) {
788 d->pendingShow =
false;
795#include "moc_qquicktooltip_p.cpp"
Combined button and popup list for selecting options.