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;
147 wmWindowType = QNativeInterface::Private::QXcbWindow::Tooltip;
156 delayTimer.start(delay, q);
168 timeoutTimer.start(timeout, q);
178 QQuickPopupPrivate::opened();
182QQuickToolTip::QQuickToolTip(QQuickItem *parent)
183 : QQuickPopup(*(
new QQuickToolTipPrivate), parent)
186 d->allowVerticalFlip =
true;
187 d->allowHorizontalFlip =
true;
188 d->popupItem->setHoverEnabled(
false);
192
193
194
195
196QString QQuickToolTip::text()
const
198 Q_D(
const QQuickToolTip);
202void QQuickToolTip::setText(
const QString &text)
209 maybeSetAccessibleName(text);
214
215
216
217
218
219
220
221
222int QQuickToolTip::delay()
const
224 Q_D(
const QQuickToolTip);
228void QQuickToolTip::setDelay(
int delay)
231 if (d->delay == delay)
239
240
241
242
243
244
245
246
247int QQuickToolTip::timeout()
const
249 Q_D(
const QQuickToolTip);
253void QQuickToolTip::setTimeout(
int timeout)
256 if (d->timeout == timeout)
259 d->timeout = timeout;
266 emit timeoutChanged();
269void QQuickToolTip::setVisible(
bool visible)
283 QQuickPopup::setVisible(visible);
286QQuickToolTipAttached *QQuickToolTip::qmlAttachedProperties(QObject *object)
288 return new QQuickToolTipAttached(object);
292
293
294
295
296
297
298void QQuickToolTip::show(
const QString &text,
int ms)
307
308
309
310
311
312void QQuickToolTip::hide()
317QFont QQuickToolTip::defaultFont()
const
319 return QQuickTheme::font(QQuickTheme::ToolTip);
322void QQuickToolTip::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
325 QQuickPopup::itemChange(change, data);
326 if (change == QQuickItem::ItemVisibleHasChanged) {
330 QQuickToolTipAttached *attached = qobject_cast<QQuickToolTipAttached *>(qmlAttachedPropertiesObject<QQuickToolTip>(d->parentItem,
false));
332 emit attached->visibleChanged();
336void QQuickToolTip::timerEvent(QTimerEvent *event)
339 if (event->timerId() == d->timeoutTimer.timerId()) {
341 QQuickPopup::setVisible(
false);
344 if (event->timerId() == d->delayTimer.timerId()) {
346 QQuickPopup::setVisible(
true);
349 QQuickPopup::timerEvent(event);
352#if QT_CONFIG(accessibility)
353QAccessible::Role QQuickToolTip::accessibleRole()
const
355 return QAccessible::ToolTip;
358void QQuickToolTip::accessibilityActiveChanged(
bool active)
361 QQuickPopup::accessibilityActiveChanged(active);
364 maybeSetAccessibleName(d->text);
368QQuickToolTip *QQuickToolTipAttachedPrivate::instance(
bool create)
const
370 QQmlEngine *engine = qmlEngine(parent);
376 static const char *name =
"_q_shared_QQuickToolTip";
378 QQuickToolTip *tip = engine->property(name).value<QQuickToolTip *>();
379 if (!tip && create) {
380 QQmlComponent component(engine,
"QtQuick.Controls",
"ToolTip");
382 QObject *object = component.create();
384 object->setParent(engine);
386 tip = qobject_cast<QQuickToolTip *>(object);
390 engine->setProperty(name, QVariant::fromValue(object));
395void QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(
396 const QObject *attachee,
bool visible)
398 auto *toolTipAttached = qobject_cast<QQuickToolTipAttached *>(
399 qmlAttachedPropertiesObject<QQuickToolTip>(attachee,
false));
401 if (!toolTipAttached)
404 auto *toolTipAttachedPrivate = toolTipAttached->d_func();
407 if (toolTipAttachedPrivate->isVisibleExplicitlySet()
408 || toolTipAttachedPrivate->policy == QQuickToolTip::Manual) {
414 const bool effectiveVisible = visible ? visible && !toolTipAttachedPrivate->text.isEmpty() :
false;
415 toolTipAttachedPrivate->setVisible(effectiveVisible, QQml::PropertyUtils::State::ImplicitlySet);
418void QQuickToolTipAttachedPrivate::setVisible(
bool visible, QQml::PropertyUtils::State propertyState)
420 Q_Q(QQuickToolTipAttached);
421 if (warnIfAttacheeIsNotAnItem(QStringLiteral(
"setVisible")))
424 explicitVisible = isExplicitlySet(propertyState);
426 if (!complete && visible) {
437bool QQuickToolTipAttachedPrivate::isVisibleExplicitlySet()
const
439 return explicitVisible;
442void QQuickToolTipAttachedPrivate::setDelay(
int delay, QQml::PropertyUtils::State propertyState)
444 Q_Q(QQuickToolTipAttached);
445 if (warnIfAttacheeIsNotAnItem(QStringLiteral(
"setDelay")))
448 explicitDelay = isExplicitlySet(propertyState);
450 if (
this->delay == delay)
454 emit q->delayChanged();
457 instance(
true)->setDelay(delay);
460bool QQuickToolTipAttachedPrivate::isDelayExplicitlySet()
const
462 return explicitDelay;
465void QQuickToolTipAttachedPrivate::setTimeout(
int timeout, QQml::PropertyUtils::State propertyState)
467 Q_Q(QQuickToolTipAttached);
468 if (warnIfAttacheeIsNotAnItem(QStringLiteral(
"setTimeout")))
471 explicitTimeout = isExplicitlySet(propertyState);
473 if (
this->timeout == timeout)
476 this->timeout = timeout;
477 emit q->timeoutChanged();
480 instance(
true)->setTimeout(timeout);
483bool QQuickToolTipAttachedPrivate::isTimeoutExplicitlySet()
const
485 return explicitTimeout;
488void QQuickToolTipAttachedPrivate::inheritPolicy(QQuickToolTip::Policy policy)
490 Q_Q(QQuickToolTipAttached);
491 if (
this->policy == policy)
494 this->policy = policy;
496 emit q->policyChanged();
499void QQuickToolTipAttachedPrivate::propagatePolicy()
501 Q_Q(QQuickToolTipAttached);
502 const auto attachedToolTipChildren = q->attachedChildren();
503 for (QtPrivate::QQuickAttachedPropertyPropagator *child : attachedToolTipChildren) {
504 auto *attachedToolTipChild = qobject_cast<QQuickToolTipAttached *>(child);
505 if (attachedToolTipChild)
506 attachedToolTipChild->d_func()->inheritPolicy(policy);
511
512
513
514
515
516
517
518bool QQuickToolTipAttachedPrivate::warnIfAttacheeIsNotAnItem(
const QString &functionName)
520 QQuickItem *item = qobject_cast<QQuickItem *>(parent);
524 qmlWarning(parent).nospace().noquote() <<
"The attached function ToolTip::" << functionName
525 <<
" can only be called when the attachee derives from Item";
529int QQuickToolTipAttachedPrivate::calculateTimeout(
const QString &text)
531 if (Q_UNLIKELY(qt_quicktooltipattachedprivate_short_timeout)) {
537 return 10000 + 40 * qMax(0, text.length() - 100);
540QQuickToolTipAttached::QQuickToolTipAttached(QObject *parent)
541 : QtPrivate::QQuickAttachedPropertyPropagator(*(
new QQuickToolTipAttachedPrivate), parent)
547
548
549
550
551
552
553
554QString QQuickToolTipAttached::text()
const
556 Q_D(
const QQuickToolTipAttached);
560void QQuickToolTipAttached::setText(
const QString &text)
562 Q_D(QQuickToolTipAttached);
563 if (d->warnIfAttacheeIsNotAnItem(QStringLiteral(
"setText")))
572 d->instance(
true)->setText(text);
576
577
578
579
580
581
582
583
584
585
586int QQuickToolTipAttached::delay()
const
588 Q_D(
const QQuickToolTipAttached);
589 return d->explicitDelay || d->policy == QQuickToolTip::Manual ? d->delay
590 : qt_quicktooltipattachedprivate_delay;
593void QQuickToolTipAttached::setDelay(
int delay)
595 Q_D(QQuickToolTipAttached);
596 d->setDelay(delay, QQml::PropertyUtils::State::ExplicitlySet);
600
601
602
603
604
605
606
607
608
609
610int QQuickToolTipAttached::timeout()
const
612 Q_D(
const QQuickToolTipAttached);
613 return d->explicitTimeout || d->policy == QQuickToolTip::Manual ? d->timeout
614 : d->calculateTimeout(d->text);
617void QQuickToolTipAttached::setTimeout(
int timeout)
619 Q_D(QQuickToolTipAttached);
620 d->setTimeout(timeout, QQml::PropertyUtils::State::ExplicitlySet);
624
625
626
627
628
629
630
631bool QQuickToolTipAttached::isVisible()
const
633 Q_D(
const QQuickToolTipAttached);
634 QQuickToolTip *tip = d->instance(
false);
638 return tip->isVisible() && tip->parentItem() == parent();
641void QQuickToolTipAttached::setVisible(
bool visible)
643 Q_D(QQuickToolTipAttached);
644 d->setVisible(visible, QQml::PropertyUtils::State::ExplicitlySet);
648
649
650
651
652
653
654
655QQuickToolTip *QQuickToolTipAttached::toolTip()
const
657 Q_D(
const QQuickToolTipAttached);
658 return d->instance(
true);
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
702
703
704QQuickToolTip::Policy QQuickToolTipAttached::policy()
const
706 Q_D(
const QQuickToolTipAttached);
710void QQuickToolTipAttached::setVisiblePolicy(QQuickToolTip::Policy policy)
712 Q_D(QQuickToolTipAttached);
713 if (d->policy == policy)
717 d->propagatePolicy();
718 emit policyChanged();
721void QQuickToolTipAttached::resetVisiblePolicy()
723 setVisiblePolicy(QQuickToolTip::Automatic);
727
728
729
730
731
732
733
734void QQuickToolTipAttached::show(
const QString &text,
int ms)
736 Q_D(QQuickToolTipAttached);
737 if (d->warnIfAttacheeIsNotAnItem(QStringLiteral(
"show")))
740 QQuickToolTip *tip = d->instance(
true);
746 tip->setParentItem(qobject_cast<QQuickItem *>(parent()));
747 tip->setDelay(delay());
748 tip->setTimeout(ms >= 0 ? ms : timeout());
753
754
755
756
757
758
759void QQuickToolTipAttached::hide()
761 Q_D(QQuickToolTipAttached);
762 QQuickToolTip *tip = d->instance(
false);
766 if (parent() == tip->parentItem())
770void QQuickToolTipAttached::attachedParentChange(QQuickAttachedPropertyPropagator *newParent,
771 QQuickAttachedPropertyPropagator *)
773 auto *attachedToolTipParent = qobject_cast<QQuickToolTipAttached *>(newParent);
774 if (!attachedToolTipParent)
777 Q_D(QQuickToolTipAttached);
778 d->inheritPolicy(attachedToolTipParent->policy());
781void QQuickToolTipAttached::classBegin()
783 Q_D(QQuickToolTipAttached);
787void QQuickToolTipAttached::componentComplete()
789 Q_D(QQuickToolTipAttached);
792 if (d->pendingShow) {
793 d->pendingShow =
false;
800#include "moc_qquicktooltip_p.cpp"
Combined button and popup list for selecting options.