| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | class 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 {}; | - |
| 16 | public: | - |
| 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); | - |
| 36 | protected: | - |
| 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 | | - |
| 43 | public : | - |
| 44 | | - |
| 45 | | - |
| 46 | | - |
| 47 | void styleSheetParentDestroyed() { | - |
| 48 | setProperty("_q_stylesheet_parent", QVariant()); | - |
| 49 | styleSheetParent = 0; | - |
| 50 | } | - |
| 51 | | - |
| 52 | private: | - |
| 53 | QWidget *styleSheetParent; | - |
| 54 | | - |
| 55 | | - |
| 56 | private: | - |
| 57 | QWidget *widget; | - |
| 58 | QRect rect; | - |
| 59 | }; | - |
| 60 | | - |
| 61 | QTipLabel *QTipLabel::instance = 0; | - |
| 62 | | - |
| 63 | QTipLabel::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 | } | - |
| 86 | | - |
| 87 | void QTipLabel::restartExpireTimer(int msecDisplayTime) | - |
| 88 | { | - |
| 89 | int time = 10000 + 40 * qMax(0, text().length()-100); | - |
| 90 | if (msecDisplayTime > 0) | - |
| 91 | time = msecDisplayTime; | - |
| 92 | expireTimer.start(time, this); | - |
| 93 | hideTimer.stop(); | - |
| 94 | } | - |
| 95 | | - |
| 96 | void QTipLabel::reuseTip(const QString &text, int msecDisplayTime) | - |
| 97 | { | - |
| 98 | | - |
| 99 | if (styleSheetParent){ | - |
| 100 | disconnect(styleSheetParent, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "197""203"), | - |
| 101 | QTipLabel::instance, qFlagLocation("1""styleSheetParentDestroyed()" "\0" __FILE__ ":" "198""204")); | - |
| 102 | styleSheetParent = 0; | - |
| 103 | } | - |
| 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.ascent() >= 11) | - |
| 112 | ++extra.rheight(); | - |
| 113 | resize(sizeHint() + extra); | - |
| 114 | restartExpireTimer(msecDisplayTime); | - |
| 115 | } | - |
| 116 | | - |
| 117 | void 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 | } | - |
| 127 | | - |
| 128 | void 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)) | - |
| 134 | setMask(frameMask.region); | - |
| 135 | | - |
| 136 | QLabel::resizeEvent(e); | - |
| 137 | } | - |
| 138 | | - |
| 139 | void QTipLabel::mouseMoveEvent(QMouseEvent *e) | - |
| 140 | { | - |
| 141 | if (rect.isNull()) | - |
| 142 | return; | - |
| 143 | QPoint pos = e->globalPos(); | - |
| 144 | if (widget) | - |
| 145 | pos = widget->mapFromGlobal(pos); | - |
| 146 | if (!rect.contains(pos)) | - |
| 147 | hideTip(); | - |
| 148 | QLabel::mouseMoveEvent(e); | - |
| 149 | } | - |
| 150 | | - |
| 151 | QTipLabel::~QTipLabel() | - |
| 152 | { | - |
| 153 | instance = 0; | - |
| 154 | } | - |
| 155 | | - |
| 156 | void QTipLabel::hideTip() | - |
| 157 | { | - |
| 158 | if (!hideTimer.isActive()) | - |
| 159 | hideTimer.start(300, this); | - |
| 160 | } | - |
| 161 | | - |
| 162 | void QTipLabel::hideTipImmediately() | - |
| 163 | { | - |
| 164 | close(); | - |
| 165 | deleteLater(); | - |
| 166 | } | - |
| 167 | | - |
| 168 | void QTipLabel::setTipRect(QWidget *w, const QRect &r) | - |
| 169 | { | - |
| 170 | if (!(__builtin_expect(!!(!| TRUE | never evaluated | | FALSE | never evaluated |
r.isNull() && !w)), false)| TRUE | never evaluated | | FALSE | never evaluated |
) { | 0 |
| 171 | QMessageLogger(__FILE__, 268274, __PRETTY_FUNCTION__).warning("QToolTip::setTipRect: Cannot pass null widget if rect is set"); | - |
| 172 | else{return; never executed: return; | 0 |
| 173 | } | - |
| 174 | widget = w; | - |
| 175 | rect = r; | - |
| }} never executed: end of block | |
| 177 | | - |
| 178 | void QTipLabel::timerEvent(QTimerEvent *e) | - |
| 179 | { | - |
| 180 | if (e->timerId() == hideTimer.timerId() | - |
| 181 | || e->timerId() == expireTimer.timerId()){ | - |
| 182 | hideTimer.stop(); | - |
| 183 | expireTimer.stop(); | - |
| 184 | hideTipImmediately(); | - |
| 185 | | - |
| 186 | } | - |
| 187 | } | - |
| 188 | | - |
| 189 | bool QTipLabel::eventFilter(QObject *o, QEvent *e) | - |
| 190 | { | - |
| 191 | switch (e->type()) { | - |
| 192 | case QEvent::Leave: | - |
| 193 | hideTip(); | - |
| 194 | break; | - |
| 195 | case QEvent::WindowActivate: | - |
| 196 | case QEvent::WindowDeactivate: | - |
| 197 | case QEvent::FocusIn: | - |
| 198 | case QEvent::FocusOut: | - |
| 199 | | - |
| 200 | case QEvent::Close: | - |
| 201 | case QEvent::MouseButtonPress: | - |
| 202 | case QEvent::MouseButtonRelease: | - |
| 203 | case QEvent::MouseButtonDblClick: | - |
| 204 | case QEvent::Wheel: | - |
| 205 | hideTipImmediately(); | - |
| 206 | break; | - |
| 207 | | - |
| 208 | case QEvent::MouseMove: | - |
| 209 | if (o == widget && !rect.isNull() && !rect.contains(static_cast<QMouseEvent*>(e)->pos())) | - |
| 210 | hideTip(); | - |
| 211 | default: | - |
| 212 | break; | - |
| 213 | } | - |
| 214 | return false; | - |
| 215 | } | - |
| 216 | | - |
| 217 | int QTipLabel::getTipScreen(const QPoint &pos, QWidget *w) | - |
| 218 | { | - |
| 219 | if (QApplication::desktop()->isVirtualDesktop()) | - |
| 220 | return QApplication::desktop()->screenNumber(pos); | - |
| 221 | else | - |
| 222 | return QApplication::desktop()->screenNumber(w); | - |
| 223 | } | - |
| 224 | | - |
| 225 | void QTipLabel::placeTip(const QPoint &pos, QWidget *w) | - |
| 226 | { | - |
| 227 | | - |
| 228 | if (testAttribute(Qt::WA_StyleSheet) || (w && qobject_cast<QStyleSheetStyle *>(w->style()))) { | - |
| 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) { | - |
| 237 | connect(w, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "376""382"), | - |
| 238 | QTipLabel::instance, qFlagLocation("1""styleSheetParentDestroyed()" "\0" __FILE__ ":" "377""383")); | - |
| 239 | } | - |
| 240 | } | - |
| 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()) | - |
| 253 | p.rx() -= 4 + this->width(); | - |
| 254 | if (p.y() + this->height() > screen.y() + screen.height()) | - |
| 255 | p.ry() -= 24 + this->height(); | - |
| 256 | if (p.y() < screen.y()) | - |
| 257 | p.setY(screen.y()); | - |
| 258 | if (p.x() + this->width() > screen.x() + screen.width()) | - |
| 259 | p.setX(screen.x() + screen.width() - this->width()); | - |
| 260 | if (p.x() < screen.x()) | - |
| 261 | p.setX(screen.x()); | - |
| 262 | if (p.y() + this->height() > screen.y() + screen.height()) | - |
| 263 | p.setY(screen.y() + screen.height() - this->height()); | - |
| 264 | this->move(p); | - |
| 265 | } | - |
| 266 | | - |
| 267 | bool QTipLabel::tipChanged(const QPoint &pos, const QString &text, QObject *o) | - |
| 268 | { | - |
| 269 | if (QTipLabel::instance->text() != text) | - |
| 270 | return true; | - |
| 271 | | - |
| 272 | if (o != widget) | - |
| 273 | return true; | - |
| 274 | | - |
| 275 | if (!rect.isNull()) | - |
| 276 | return !rect.contains(pos); | - |
| 277 | else | - |
| 278 | return false; | - |
| 279 | } | - |
| 280 | void QToolTip::showText(const QPoint &pos, const QString &text, QWidget *w, const QRect &rect) | - |
| 281 | { | - |
| 282 | showText(pos, text, w, rect, -1); | - |
| 283 | } | - |
| 284 | void QToolTip::showText(const QPoint &pos, const QString &text, QWidget *w, const QRect &rect, int msecDisplayTime) | - |
| 285 | { | - |
| 286 | if (QTipLabel::instance && QTipLabel::instance->isVisible()){ | - |
| 287 | if (text.isEmpty()){ | - |
| 288 | QTipLabel::instance->hideTip(); | - |
| 289 | return; | - |
| 290 | } | - |
| 291 | else if (!QTipLabel::instance->fadingOut){ | - |
| 292 | | - |
| 293 | | - |
| 294 | QPoint localPos = pos; | - |
| 295 | if (w) | - |
| 296 | localPos = w->mapFromGlobal(pos); | - |
| 297 | if (QTipLabel::instance->tipChanged(localPos, text, w)){ | - |
| 298 | QTipLabel::instance->reuseTip(text, msecDisplayTime); | - |
| 299 | QTipLabel::instance->setTipRect(w, rect); | - |
| 300 | QTipLabel::instance->placeTip(pos, w); | - |
| 301 | } | - |
| 302 | return; | - |
| 303 | } | - |
| 304 | } | - |
| 305 | | - |
| 306 | if (!text.isEmpty()){ | - |
| 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)) | - |
| 321 | qFadeEffect(QTipLabel::instance); | - |
| 322 | else if (QApplication::isEffectEnabled(Qt::UI_AnimateTooltip)) | - |
| 323 | qScrollEffect(QTipLabel::instance); | - |
| 324 | else | - |
| 325 | QTipLabel::instance->showNormal(); | - |
| 326 | | - |
| 327 | | - |
| 328 | | - |
| 329 | } | - |
| 330 | } | - |
| 331 | | - |
| 332 | | - |
| 333 | | - |
| 334 | | - |
| 335 | | - |
| 336 | | - |
| 337 | | - |
| 338 | void QToolTip::showText(const QPoint &pos, const QString &text, QWidget *w) | - |
| 339 | { | - |
| 340 | QToolTip::showText(pos, text, w, QRect()); | - |
| 341 | } | - |
| 342 | bool QToolTip::isVisible() | - |
| 343 | { | - |
| 344 | return (QTipLabel::instance != 0 && QTipLabel::instance->isVisible()); | - |
| 345 | } | - |
| 346 | | - |
| 347 | | - |
| 348 | | - |
| 349 | | - |
| 350 | | - |
| 351 | | - |
| 352 | | - |
| 353 | QString QToolTip::text() | - |
| 354 | { | - |
| 355 | if (QTipLabel::instance) | - |
| 356 | return QTipLabel::instance->text(); | - |
| 357 | return QString(); | - |
| 358 | } | - |
| 359 | | - |
| 360 | | - |
| 361 | namespace { 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.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QPalette, Q_QGS_tooltip_palette::innerFunction, Q_QGS_tooltip_palette::guard> tooltip_palette; | - |
| 362 | | - |
| 363 | | - |
| 364 | | - |
| 365 | | - |
| 366 | | - |
| 367 | | - |
| 368 | | - |
| 369 | QPalette QToolTip::palette() | - |
| 370 | { | - |
| 371 | return *tooltip_palette(); | - |
| 372 | } | - |
| 373 | | - |
| 374 | | - |
| 375 | | - |
| 376 | | - |
| 377 | | - |
| 378 | | - |
| 379 | QFont QToolTip::font() | - |
| 380 | { | - |
| 381 | return QApplication::font("QTipLabel"); | - |
| 382 | } | - |
| 383 | void QToolTip::setPalette(const QPalette &palette) | - |
| 384 | { | - |
| 385 | *tooltip_palette() = palette; | - |
| 386 | if (QTipLabel::instance) | - |
| 387 | QTipLabel::instance->setPalette(palette); | - |
| 388 | } | - |
| 389 | | - |
| 390 | | - |
| 391 | | - |
| 392 | | - |
| 393 | | - |
| 394 | | - |
| 395 | void QToolTip::setFont(const QFont &font) | - |
| 396 | { | - |
| 397 | QApplication::setFont(font, "QTipLabel"); | - |
| 398 | } | - |
| 399 | | - |
| 400 | | - |
| 401 | | - |
| | |