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();
143#if QT_CONFIG(wayland)
144 extendedWindowType = QNativeInterface::Private::QWaylandWindow::ToolTip;
152 delayTimer.start(delay, q);
164 timeoutTimer.start(timeout, q);
174 QQuickPopupPrivate::opened();
178QQuickToolTip::QQuickToolTip(QQuickItem *parent)
179 : QQuickPopup(*(
new QQuickToolTipPrivate), parent)
182 d->allowVerticalFlip =
true;
183 d->allowHorizontalFlip =
true;
184 d->popupItem->setHoverEnabled(
false);
188
189
190
191
192QString QQuickToolTip::text()
const
194 Q_D(
const QQuickToolTip);
198void QQuickToolTip::setText(
const QString &text)
205 maybeSetAccessibleName(text);
210
211
212
213
214
215
216
217
218int QQuickToolTip::delay()
const
220 Q_D(
const QQuickToolTip);
224void QQuickToolTip::setDelay(
int delay)
227 if (d->delay == delay)
235
236
237
238
239
240
241
242
243int QQuickToolTip::timeout()
const
245 Q_D(
const QQuickToolTip);
249void QQuickToolTip::setTimeout(
int timeout)
252 if (d->timeout == timeout)
255 d->timeout = timeout;
262 emit timeoutChanged();
265void QQuickToolTip::setVisible(
bool visible)
279 QQuickPopup::setVisible(visible);
282QQuickToolTipAttached *QQuickToolTip::qmlAttachedProperties(QObject *object)
284 return new QQuickToolTipAttached(object);
288
289
290
291
292
293
294void QQuickToolTip::show(
const QString &text,
int ms)
303
304
305
306
307
308void QQuickToolTip::hide()
313QFont QQuickToolTip::defaultFont()
const
315 return QQuickTheme::font(QQuickTheme::ToolTip);
318void QQuickToolTip::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
321 QQuickPopup::itemChange(change, data);
322 if (change == QQuickItem::ItemVisibleHasChanged) {
326 QQuickToolTipAttached *attached = qobject_cast<QQuickToolTipAttached *>(qmlAttachedPropertiesObject<QQuickToolTip>(d->parentItem,
false));
328 emit attached->visibleChanged();
332void QQuickToolTip::timerEvent(QTimerEvent *event)
335 if (event->timerId() == d->timeoutTimer.timerId()) {
337 QQuickPopup::setVisible(
false);
340 if (event->timerId() == d->delayTimer.timerId()) {
342 QQuickPopup::setVisible(
true);
345 QQuickPopup::timerEvent(event);
348#if QT_CONFIG(accessibility)
349QAccessible::Role QQuickToolTip::accessibleRole()
const
351 return QAccessible::ToolTip;
354void QQuickToolTip::accessibilityActiveChanged(
bool active)
357 QQuickPopup::accessibilityActiveChanged(active);
360 maybeSetAccessibleName(d->text);
364QQuickToolTip *QQuickToolTipAttachedPrivate::instance(
bool create)
const
366 QQmlEngine *engine = qmlEngine(parent);
372 static const char *name =
"_q_shared_QQuickToolTip";
374 QQuickToolTip *tip = engine->property(name).value<QQuickToolTip *>();
375 if (!tip && create) {
376 QQmlComponent component(engine,
"QtQuick.Controls",
"ToolTip");
378 QObject *object = component.create();
380 object->setParent(engine);
382 tip = qobject_cast<QQuickToolTip *>(object);
386 engine->setProperty(name, QVariant::fromValue(object));
391void QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(
392 const QObject *attachee,
bool visible)
394 auto *toolTipAttached = qobject_cast<QQuickToolTipAttached *>(
395 qmlAttachedPropertiesObject<QQuickToolTip>(attachee,
false));
397 if (!toolTipAttached)
400 auto *toolTipAttachedPrivate = toolTipAttached->d_func();
403 if (toolTipAttachedPrivate->isVisibleExplicitlySet()
404 || toolTipAttachedPrivate->policy == QQuickToolTip::Manual) {
410 const bool effectiveVisible = visible ? visible && !toolTipAttachedPrivate->text.isEmpty() :
false;
411 toolTipAttachedPrivate->setVisible(effectiveVisible, QQml::PropertyUtils::State::ImplicitlySet);
414void QQuickToolTipAttachedPrivate::setVisible(
bool visible, QQml::PropertyUtils::State propertyState)
416 Q_Q(QQuickToolTipAttached);
417 if (warnIfAttacheeIsNotAnItem(QStringLiteral(
"setVisible")))
420 explicitVisible = isExplicitlySet(propertyState);
422 if (!complete && visible) {
433bool QQuickToolTipAttachedPrivate::isVisibleExplicitlySet()
const
435 return explicitVisible;
438void QQuickToolTipAttachedPrivate::setDelay(
int delay, QQml::PropertyUtils::State propertyState)
440 Q_Q(QQuickToolTipAttached);
441 if (warnIfAttacheeIsNotAnItem(QStringLiteral(
"setDelay")))
444 explicitDelay = isExplicitlySet(propertyState);
446 if (
this->delay == delay)
450 emit q->delayChanged();
453 instance(
true)->setDelay(delay);
456bool QQuickToolTipAttachedPrivate::isDelayExplicitlySet()
const
458 return explicitDelay;
461void QQuickToolTipAttachedPrivate::setTimeout(
int timeout, QQml::PropertyUtils::State propertyState)
463 Q_Q(QQuickToolTipAttached);
464 if (warnIfAttacheeIsNotAnItem(QStringLiteral(
"setTimeout")))
467 explicitTimeout = isExplicitlySet(propertyState);
469 if (
this->timeout == timeout)
472 this->timeout = timeout;
473 emit q->timeoutChanged();
476 instance(
true)->setTimeout(timeout);
479bool QQuickToolTipAttachedPrivate::isTimeoutExplicitlySet()
const
481 return explicitTimeout;
484void QQuickToolTipAttachedPrivate::inheritPolicy(QQuickToolTip::Policy policy)
486 Q_Q(QQuickToolTipAttached);
487 if (
this->policy == policy)
490 this->policy = policy;
492 emit q->policyChanged();
495void QQuickToolTipAttachedPrivate::propagatePolicy()
497 Q_Q(QQuickToolTipAttached);
498 const auto attachedToolTipChildren = q->attachedChildren();
499 for (QtPrivate::QQuickAttachedPropertyPropagator *child : attachedToolTipChildren) {
500 auto *attachedToolTipChild = qobject_cast<QQuickToolTipAttached *>(child);
501 if (attachedToolTipChild)
502 attachedToolTipChild->d_func()->inheritPolicy(policy);
507
508
509
510
511
512
513
514bool QQuickToolTipAttachedPrivate::warnIfAttacheeIsNotAnItem(
const QString &functionName)
516 QQuickItem *item = qobject_cast<QQuickItem *>(parent);
520 qmlWarning(parent).nospace().noquote() <<
"The attached function ToolTip::" << functionName
521 <<
" can only be called when the attachee derives from Item";
525int QQuickToolTipAttachedPrivate::calculateTimeout(
const QString &text)
527 if (Q_UNLIKELY(qt_quicktooltipattachedprivate_short_timeout)) {
533 return 10000 + 40 * qMax(0, text.length() - 100);
536QQuickToolTipAttached::QQuickToolTipAttached(QObject *parent)
537 : QtPrivate::QQuickAttachedPropertyPropagator(*(
new QQuickToolTipAttachedPrivate), parent)
543
544
545
546
547
548
549
550QString QQuickToolTipAttached::text()
const
552 Q_D(
const QQuickToolTipAttached);
556void QQuickToolTipAttached::setText(
const QString &text)
558 Q_D(QQuickToolTipAttached);
559 if (d->warnIfAttacheeIsNotAnItem(QStringLiteral(
"setText")))
568 d->instance(
true)->setText(text);
572
573
574
575
576
577
578
579
580
581
582int QQuickToolTipAttached::delay()
const
584 Q_D(
const QQuickToolTipAttached);
585 return d->explicitDelay || d->policy == QQuickToolTip::Manual ? d->delay
586 : qt_quicktooltipattachedprivate_delay;
589void QQuickToolTipAttached::setDelay(
int delay)
591 Q_D(QQuickToolTipAttached);
592 d->setDelay(delay, QQml::PropertyUtils::State::ExplicitlySet);
596
597
598
599
600
601
602
603
604
605
606int QQuickToolTipAttached::timeout()
const
608 Q_D(
const QQuickToolTipAttached);
609 return d->explicitTimeout || d->policy == QQuickToolTip::Manual ? d->timeout
610 : d->calculateTimeout(d->text);
613void QQuickToolTipAttached::setTimeout(
int timeout)
615 Q_D(QQuickToolTipAttached);
616 d->setTimeout(timeout, QQml::PropertyUtils::State::ExplicitlySet);
620
621
622
623
624
625
626
627bool QQuickToolTipAttached::isVisible()
const
629 Q_D(
const QQuickToolTipAttached);
630 QQuickToolTip *tip = d->instance(
false);
634 return tip->isVisible() && tip->parentItem() == parent();
637void QQuickToolTipAttached::setVisible(
bool visible)
639 Q_D(QQuickToolTipAttached);
640 d->setVisible(visible, QQml::PropertyUtils::State::ExplicitlySet);
644
645
646
647
648
649
650
651QQuickToolTip *QQuickToolTipAttached::toolTip()
const
653 Q_D(
const QQuickToolTipAttached);
654 return d->instance(
true);
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
699
700
701
702QQuickToolTip::Policy QQuickToolTipAttached::policy()
const
704 Q_D(
const QQuickToolTipAttached);
708void QQuickToolTipAttached::setVisiblePolicy(QQuickToolTip::Policy policy)
710 Q_D(QQuickToolTipAttached);
711 if (d->policy == policy)
715 d->propagatePolicy();
716 emit policyChanged();
719void QQuickToolTipAttached::resetVisiblePolicy()
721 setVisiblePolicy(QQuickToolTip::Automatic);
725
726
727
728
729
730
731
732void QQuickToolTipAttached::show(
const QString &text,
int ms)
734 Q_D(QQuickToolTipAttached);
735 if (d->warnIfAttacheeIsNotAnItem(QStringLiteral(
"show")))
738 QQuickToolTip *tip = d->instance(
true);
744 tip->setParentItem(qobject_cast<QQuickItem *>(parent()));
745 tip->setDelay(delay());
746 tip->setTimeout(ms >= 0 ? ms : timeout());
751
752
753
754
755
756
757void QQuickToolTipAttached::hide()
759 Q_D(QQuickToolTipAttached);
760 QQuickToolTip *tip = d->instance(
false);
764 if (parent() == tip->parentItem())
768void QQuickToolTipAttached::attachedParentChange(QQuickAttachedPropertyPropagator *newParent,
769 QQuickAttachedPropertyPropagator *)
771 auto *attachedToolTipParent = qobject_cast<QQuickToolTipAttached *>(newParent);
772 if (!attachedToolTipParent)
775 Q_D(QQuickToolTipAttached);
776 d->inheritPolicy(attachedToolTipParent->policy());
779void QQuickToolTipAttached::classBegin()
781 Q_D(QQuickToolTipAttached);
785void QQuickToolTipAttached::componentComplete()
787 Q_D(QQuickToolTipAttached);
790 if (d->pendingShow) {
791 d->pendingShow =
false;
798#include "moc_qquicktooltip_p.cpp"
Combined button and popup list for selecting options.