qtooltip.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qtooltip.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9class QTipLabel : public QLabel-
10{-
11 public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }-
12#pragma GCC diagnostic push-
13 static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);-
14#pragma GCC diagnostic pop-
15 struct QPrivateSignal {};-
16public:-
17 QTipLabel(const QString &text, QWidget *w, int msecDisplayTime);-
18 ~QTipLabel();-
19 static QTipLabel *instance;-
20-
21 bool eventFilter(QObject *, QEvent *) override;-
22-
23 QBasicTimer hideTimer, expireTimer;-
24-
25 bool fadingOut;-
26-
27 void reuseTip(const QString &text, int msecDisplayTime);-
28 void hideTip();-
29 void hideTipImmediately();-
30 void setTipRect(QWidget *w, const QRect &r);-
31 void restartExpireTimer(int msecDisplayTime);-
32 bool tipChanged(const QPoint &pos, const QString &text, QObject *o);-
33 void placeTip(const QPoint &pos, QWidget *w);-
34-
35 static int getTipScreen(const QPoint &pos, QWidget *w);-
36protected:-
37 void timerEvent(QTimerEvent *e) override;-
38 void paintEvent(QPaintEvent *e) override;-
39 void mouseMoveEvent(QMouseEvent *e) override;-
40 void resizeEvent(QResizeEvent *e) override;-
41-
42-
43public :-
44-
45-
46-
47 void styleSheetParentDestroyed() {-
48 setProperty("_q_stylesheet_parent", QVariant());-
49 styleSheetParent = 0;-
50 }
never executed: end of block
0
51-
52private:-
53 QWidget *styleSheetParent;-
54-
55-
56private:-
57 QWidget *widget;-
58 QRect rect;-
59};-
60-
61QTipLabel *QTipLabel::instance = 0;-
62-
63QTipLabel::QTipLabel(const QString &text, QWidget *w, int msecDisplayTime)-
64-
65 : QLabel(w, Qt::ToolTip | Qt::BypassGraphicsProxyWidget), styleSheetParent(0), widget(0)-
66-
67-
68-
69{-
70 delete instance;-
71 instance = this;-
72 setForegroundRole(QPalette::ToolTipText);-
73 setBackgroundRole(QPalette::ToolTipBase);-
74 setPalette(QToolTip::palette());-
75 ensurePolished();-
76 setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this));-
77 setFrameStyle(QFrame::NoFrame);-
78 setAlignment(Qt::AlignLeft);-
79 setIndent(1);-
80 (static_cast<QApplication *>(QCoreApplication::instance()))->installEventFilter(this);-
81 setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity, 0, this) / 255.0);-
82 setMouseTracking(true);-
83 fadingOut = false;-
84 reuseTip(text, msecDisplayTime);-
85}
never executed: end of block
0
86-
87void QTipLabel::restartExpireTimer(int msecDisplayTime)-
88{-
89 int time = 10000 + 40 * qMax(0, text().length()-100);-
90 if (msecDisplayTime > 0
msecDisplayTime > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
91 time = msecDisplayTime;
never executed: time = msecDisplayTime;
0
92 expireTimer.start(time, this);-
93 hideTimer.stop();-
94}
never executed: end of block
0
95-
96void QTipLabel::reuseTip(const QString &text, int msecDisplayTime)-
97{-
98-
99 if (styleSheetParent
styleSheetParentDescription
TRUEnever evaluated
FALSEnever evaluated
){
0
100 disconnect(styleSheetParent, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "203"),-
101 QTipLabel::instance, qFlagLocation("1""styleSheetParentDestroyed()" "\0" __FILE__ ":" "204"));-
102 styleSheetParent = 0;-
103 }
never executed: end of block
0
104-
105-
106 setWordWrap(Qt::mightBeRichText(text));-
107 setText(text);-
108 QFontMetrics fm(font());-
109 QSize extra(1, 0);-
110-
111 if (fm.descent() == 2
fm.descent() == 2Description
TRUEnever evaluated
FALSEnever evaluated
&& fm.ascent() >= 11
fm.ascent() >= 11Description
TRUEnever evaluated
FALSEnever evaluated
)
0
112 ++
never executed: ++extra.rheight();
extra.rheight();
never executed: ++extra.rheight();
0
113 resize(sizeHint() + extra);-
114 restartExpireTimer(msecDisplayTime);-
115}
never executed: end of block
0
116-
117void QTipLabel::paintEvent(QPaintEvent *ev)-
118{-
119 QStylePainter p(this);-
120 QStyleOptionFrame opt;-
121 opt.init(this);-
122 p.drawPrimitive(QStyle::PE_PanelTipLabel, opt);-
123 p.end();-
124-
125 QLabel::paintEvent(ev);-
126}
never executed: end of block
0
127-
128void QTipLabel::resizeEvent(QResizeEvent *e)-
129{-
130 QStyleHintReturnMask frameMask;-
131 QStyleOption option;-
132 option.init(this);-
133 if (style()->styleHint(QStyle::SH_ToolTip_Mask, &option, this, &frameMask)
style()->style...s, &frameMask)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
134 setMask(frameMask.region);
never executed: setMask(frameMask.region);
0
135-
136 QLabel::resizeEvent(e);-
137}
never executed: end of block
0
138-
139void QTipLabel::mouseMoveEvent(QMouseEvent *e)-
140{-
141 if (rect.isNull()
rect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
142 return;
never executed: return;
0
143 QPoint pos = e->globalPos();-
144 if (widget
widgetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
145 pos = widget->mapFromGlobal(pos);
never executed: pos = widget->mapFromGlobal(pos);
0
146 if (!rect.contains(pos)
!rect.contains(pos)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
147 hideTip();
never executed: hideTip();
0
148 QLabel::mouseMoveEvent(e);-
149}
never executed: end of block
0
150-
151QTipLabel::~QTipLabel()-
152{-
153 instance = 0;-
154}
never executed: end of block
0
155-
156void QTipLabel::hideTip()-
157{-
158 if (!hideTimer.isActive()
!hideTimer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
159 hideTimer.start(300, this);
never executed: hideTimer.start(300, this);
0
160}
never executed: end of block
0
161-
162void QTipLabel::hideTipImmediately()-
163{-
164 close();-
165 deleteLater();-
166}
never executed: end of block
0
167-
168void QTipLabel::setTipRect(QWidget *w, const QRect &r)-
169{-
170 if (__builtin_expect(!!(!r.isNull() && !w), false)
__builtin_expe...&& !w), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
171 QMessageLogger(__FILE__, 274, __PRETTY_FUNCTION__).warning("QToolTip::setTipRect: Cannot pass null widget if rect is set");-
172 return;
never executed: return;
0
173 }-
174 widget = w;-
175 rect = r;-
176}
never executed: end of block
0
177-
178void QTipLabel::timerEvent(QTimerEvent *e)-
179{-
180 if (e->timerId() == hideTimer.timerId()
e->timerId() =...imer.timerId()Description
TRUEnever evaluated
FALSEnever evaluated
0
181 || e->timerId() == expireTimer.timerId()
e->timerId() =...imer.timerId()Description
TRUEnever evaluated
FALSEnever evaluated
){
0
182 hideTimer.stop();-
183 expireTimer.stop();-
184 hideTipImmediately();-
185-
186 }
never executed: end of block
0
187}
never executed: end of block
0
188-
189bool QTipLabel::eventFilter(QObject *o, QEvent *e)-
190{-
191 switch (e->type()) {-
192 case
never executed: case QEvent::Leave:
QEvent::Leave:
never executed: case QEvent::Leave:
0
193 hideTip();-
194 break;
never executed: break;
0
195 case
never executed: case QEvent::WindowActivate:
QEvent::WindowActivate:
never executed: case QEvent::WindowActivate:
0
196 case
never executed: case QEvent::WindowDeactivate:
QEvent::WindowDeactivate:
never executed: case QEvent::WindowDeactivate:
0
197 case
never executed: case QEvent::FocusIn:
QEvent::FocusIn:
never executed: case QEvent::FocusIn:
0
198 case
never executed: case QEvent::FocusOut:
QEvent::FocusOut:
never executed: case QEvent::FocusOut:
0
199-
200 case
never executed: case QEvent::Close:
QEvent::Close:
never executed: case QEvent::Close:
0
201 case
never executed: case QEvent::MouseButtonPress:
QEvent::MouseButtonPress:
never executed: case QEvent::MouseButtonPress:
0
202 case
never executed: case QEvent::MouseButtonRelease:
QEvent::MouseButtonRelease:
never executed: case QEvent::MouseButtonRelease:
0
203 case
never executed: case QEvent::MouseButtonDblClick:
QEvent::MouseButtonDblClick:
never executed: case QEvent::MouseButtonDblClick:
0
204 case
never executed: case QEvent::Wheel:
QEvent::Wheel:
never executed: case QEvent::Wheel:
0
205 hideTipImmediately();-
206 break;
never executed: break;
0
207-
208 case
never executed: case QEvent::MouseMove:
QEvent::MouseMove:
never executed: case QEvent::MouseMove:
0
209 if (o == widget
o == widgetDescription
TRUEnever evaluated
FALSEnever evaluated
&& !rect.isNull()
!rect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
&& !rect.contains(static_cast<QMouseEvent*>(e)->pos())
!rect.contains...t*>(e)->pos())Description
TRUEnever evaluated
FALSEnever evaluated
)
0
210 hideTip();
never executed: hideTip();
0
211 default
never executed: default:
:
never executed: default:
code before this statement never executed: default:
0
212 break;
never executed: break;
0
213 }-
214 return
never executed: return false;
false;
never executed: return false;
0
215}-
216-
217int QTipLabel::getTipScreen(const QPoint &pos, QWidget *w)-
218{-
219 if (QApplication::desktop()->isVirtualDesktop()
QApplication::...rtualDesktop()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
220 return
never executed: return QApplication::desktop()->screenNumber(pos);
QApplication::desktop()->screenNumber(pos);
never executed: return QApplication::desktop()->screenNumber(pos);
0
221 else-
222 return
never executed: return QApplication::desktop()->screenNumber(w);
QApplication::desktop()->screenNumber(w);
never executed: return QApplication::desktop()->screenNumber(w);
0
223}-
224-
225void QTipLabel::placeTip(const QPoint &pos, QWidget *w)-
226{-
227-
228 if (testAttribute(Qt::WA_StyleSheet)
testAttribute(...WA_StyleSheet)Description
TRUEnever evaluated
FALSEnever evaluated
|| (w
wDescription
TRUEnever evaluated
FALSEnever evaluated
&& qobject_cast<QStyleSheetStyle *>(w->style())
qobject_cast<Q...*>(w->style())Description
TRUEnever evaluated
FALSEnever evaluated
)) {
0
229-
230 QTipLabel::instance->setProperty("_q_stylesheet_parent", QVariant::fromValue(w));-
231-
232 QTipLabel::instance->setStyleSheet(QLatin1String("/* */"));-
233-
234-
235 QTipLabel::instance->styleSheetParent = w;-
236 if (w
wDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
237 connect(w, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "382"),-
238 QTipLabel::instance, qFlagLocation("1""styleSheetParentDestroyed()" "\0" __FILE__ ":" "383"));-
239 }
never executed: end of block
0
240 }
never executed: end of block
0
241 QRect screen = QApplication::desktop()->screenGeometry(getTipScreen(pos, w));-
242-
243-
244 QPoint p = pos;-
245 p += QPoint(2,-
246-
247-
248-
249 16-
250-
251 );-
252 if (p.x() + this->width() > screen.x() + screen.width()
p.x() + this->...screen.width()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
253 p.rx() -= 4 + this->width();
never executed: p.rx() -= 4 + this->width();
0
254 if (p.y() + this->height() > screen.y() + screen.height()
p.y() + this->...creen.height()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
255 p.ry() -= 24 + this->height();
never executed: p.ry() -= 24 + this->height();
0
256 if (p.y() < screen.y()
p.y() < screen.y()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
257 p.setY(screen.y());
never executed: p.setY(screen.y());
0
258 if (p.x() + this->width() > screen.x() + screen.width()
p.x() + this->...screen.width()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
259 p.setX(screen.x() + screen.width() - this->width());
never executed: p.setX(screen.x() + screen.width() - this->width());
0
260 if (p.x() < screen.x()
p.x() < screen.x()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
261 p.setX(screen.x());
never executed: p.setX(screen.x());
0
262 if (p.y() + this->height() > screen.y() + screen.height()
p.y() + this->...creen.height()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
263 p.setY(screen.y() + screen.height() - this->height());
never executed: p.setY(screen.y() + screen.height() - this->height());
0
264 this->move(p);-
265}
never executed: end of block
0
266-
267bool QTipLabel::tipChanged(const QPoint &pos, const QString &text, QObject *o)-
268{-
269 if (QTipLabel::instance->text() != text
QTipLabel::ins...text() != textDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
270 return
never executed: return true;
true;
never executed: return true;
0
271-
272 if (o != widget
o != widgetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
273 return
never executed: return true;
true;
never executed: return true;
0
274-
275 if (!rect.isNull()
!rect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
276 return
never executed: return !rect.contains(pos);
!rect.contains(pos);
never executed: return !rect.contains(pos);
0
277 else-
278 return
never executed: return false;
false;
never executed: return false;
0
279}-
280void QToolTip::showText(const QPoint &pos, const QString &text, QWidget *w, const QRect &rect)-
281{-
282 showText(pos, text, w, rect, -1);-
283}
never executed: end of block
0
284void QToolTip::showText(const QPoint &pos, const QString &text, QWidget *w, const QRect &rect, int msecDisplayTime)-
285{-
286 if (QTipLabel::instance
QTipLabel::instanceDescription
TRUEnever evaluated
FALSEnever evaluated
&& QTipLabel::instance->isVisible()
QTipLabel::ins...e->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
){
0
287 if (text.isEmpty()
text.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
){
0
288 QTipLabel::instance->hideTip();-
289 return;
never executed: return;
0
290 }-
291 else if (!QTipLabel::instance->fadingOut
!QTipLabel::in...nce->fadingOutDescription
TRUEnever evaluated
FALSEnever evaluated
){
0
292-
293-
294 QPoint localPos = pos;-
295 if (w
wDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
296 localPos = w->mapFromGlobal(pos);
never executed: localPos = w->mapFromGlobal(pos);
0
297 if (QTipLabel::instance->tipChanged(localPos, text, w)
QTipLabel::ins...lPos, text, w)Description
TRUEnever evaluated
FALSEnever evaluated
){
0
298 QTipLabel::instance->reuseTip(text, msecDisplayTime);-
299 QTipLabel::instance->setTipRect(w, rect);-
300 QTipLabel::instance->placeTip(pos, w);-
301 }
never executed: end of block
0
302 return;
never executed: return;
0
303 }-
304 }
never executed: end of block
0
305-
306 if (!text.isEmpty()
!text.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
){
0
307-
308 new QTipLabel(text, w, msecDisplayTime);-
309-
310-
311-
312-
313-
314 QTipLabel::instance->setTipRect(w, rect);-
315 QTipLabel::instance->placeTip(pos, w);-
316 QTipLabel::instance->setObjectName(QLatin1String("qtooltip_label"));-
317-
318-
319-
320 if (QApplication::isEffectEnabled(Qt::UI_FadeTooltip)
QApplication::...I_FadeTooltip)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
321 qFadeEffect(QTipLabel::instance);
never executed: qFadeEffect(QTipLabel::instance);
0
322 else if (QApplication::isEffectEnabled(Qt::UI_AnimateTooltip)
QApplication::...nimateTooltip)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
323 qScrollEffect(QTipLabel::instance);
never executed: qScrollEffect(QTipLabel::instance);
0
324 else-
325 QTipLabel::instance->showNormal();
never executed: QTipLabel::instance->showNormal();
0
326-
327-
328-
329 }-
330}
never executed: end of block
0
331-
332-
333-
334-
335-
336-
337-
338void QToolTip::showText(const QPoint &pos, const QString &text, QWidget *w)-
339{-
340 QToolTip::showText(pos, text, w, QRect());-
341}
never executed: end of block
0
342bool QToolTip::isVisible()-
343{-
344 return
never executed: return (QTipLabel::instance != 0 && QTipLabel::instance->isVisible());
(QTipLabel::instance != 0 && QTipLabel::instance->isVisible());
never executed: return (QTipLabel::instance != 0 && QTipLabel::instance->isVisible());
0
345}-
346-
347-
348-
349-
350-
351-
352-
353QString QToolTip::text()-
354{-
355 if (QTipLabel::instance
QTipLabel::instanceDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
356 return
never executed: return QTipLabel::instance->text();
QTipLabel::instance->text();
never executed: return QTipLabel::instance->text();
0
357 return
never executed: return QString();
QString();
never executed: return QString();
0
358}-
359-
360-
361namespace { namespace Q_QGS_tooltip_palette { typedef QPalette Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
guard.load() =...c::InitializedDescription
TRUEnever evaluated
FALSEnever evaluated
) guard.store(QtGlobalStatic::Destroyed);
never executed: guard.store(QtGlobalStatic::Destroyed);
}
never executed: end of block
}; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return
never executed: return &holder.value;
&holder.value;
never executed: return &holder.value;
} } } static QGlobalStatic<QPalette, Q_QGS_tooltip_palette::innerFunction, Q_QGS_tooltip_palette::guard> tooltip_palette;
0
362-
363-
364-
365-
366-
367-
368-
369QPalette QToolTip::palette()-
370{-
371 return
never executed: return *tooltip_palette();
*tooltip_palette();
never executed: return *tooltip_palette();
0
372}-
373-
374-
375-
376-
377-
378-
379QFont QToolTip::font()-
380{-
381 return
never executed: return QApplication::font("QTipLabel");
QApplication::font("QTipLabel");
never executed: return QApplication::font("QTipLabel");
0
382}-
383void QToolTip::setPalette(const QPalette &palette)-
384{-
385 *tooltip_palette() = palette;-
386 if (QTipLabel::instance
QTipLabel::instanceDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
387 QTipLabel::instance->setPalette(palette);
never executed: QTipLabel::instance->setPalette(palette);
0
388}
never executed: end of block
0
389-
390-
391-
392-
393-
394-
395void QToolTip::setFont(const QFont &font)-
396{-
397 QApplication::setFont(font, "QTipLabel");-
398}
never executed: end of block
0
399-
400-
401-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9