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