itom  4.1.0
toolTip.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 
22  --------------------------------
23  This class is a modified version of the class QToolTip of the
24  Qt framework (licensed under LGPL):
25  https://code.woboq.org/qt5/qtbase/src/widgets/kernel/qtooltip.cpp.html
26 *********************************************************************** */
27 
28 #ifndef TOOLTIP_H
29 #define TOOLTIP_H
30 
31 //#include <QtWidgets/qtwidgetsglobal.h>
32 #include <QtWidgets/qwidget.h>
33 #include <qlabel.h>
34 #include <qbasictimer.h>
35 
36 class ToolTipLabel : public QLabel
37 {
38  Q_OBJECT
39 public:
40  ToolTipLabel(const QString &text, const QPoint &pos, QWidget *w, int msecDisplayTime);
41  ~ToolTipLabel();
42  static ToolTipLabel *instance;
43  void adjustTooltipScreen(const QPoint &pos);
44  void updateSize(const QPoint &pos);
45  bool eventFilter(QObject *, QEvent *) override;
46  QBasicTimer hideTimer, expireTimer;
47  bool fadingOut;
48  void reuseTip(const QString &text, int msecDisplayTime, const QPoint &pos);
49  void hideTip();
50  void hideTipImmediately();
51  void setTipRect(QWidget *w, const QRect &r);
52  void restartExpireTimer(int msecDisplayTime);
53  bool tipChanged(const QPoint &pos, const QString &text, QObject *o);
54  void placeTip(const QPoint &pos, QWidget *w, const QPoint &alternativeTopRightPos = QPoint());
55  static int getTipScreen(const QPoint &pos, QWidget *w);
56 protected:
57  void timerEvent(QTimerEvent *e) override;
58  void paintEvent(QPaintEvent *e) override;
59  void mouseMoveEvent(QMouseEvent *e) override;
60  void resizeEvent(QResizeEvent *e) override;
61 #ifndef QT_NO_STYLE_STYLESHEET
62 public slots:
66  void styleSheetParentDestroyed() {
67  setProperty("_q_stylesheet_parent", QVariant());
68  styleSheetParent = 0;
69  }
70 private:
71  QWidget *styleSheetParent;
72 #endif
73 private:
74  QWidget *widget;
75  QRect rect;
76 };
77 
78 class ToolTip
79 {
80  ToolTip() = delete;
81 public:
82  // ### Qt 6 - merge the three showText functions below
83  static void showText(const QPoint &pos, const QString &text, QWidget *w = nullptr, const QPoint &alternativeTopRightPos = QPoint());
84  static void showText(const QPoint &pos, const QString &text, QWidget *w, const QRect &rect);
85  static void showText(const QPoint &pos, const QString &text, QWidget *w, const QRect &rect, int msecShowTime, const QPoint &alternativeTopRightPos = QPoint());
86  static inline void hideText() { showText(QPoint(), QString()); }
87  static bool isVisible();
88  static QString text();
89  static QPalette palette();
90  static void setPalette(const QPalette &);
91  static QFont font();
92  static void setFont(const QFont &);
93 };
94 
95 
96 #endif // TOOLTIP_H
Definition: toolTip.h:36
static void showText(const QPoint &pos, const QString &text, QWidget *w=nullptr, const QPoint &alternativeTopRightPos=QPoint())
Definition: toolTip.cpp:373
static QString text()
Definition: toolTip.cpp:398
static QPalette palette()
Definition: toolTip.cpp:410
static bool isVisible()
Definition: toolTip.cpp:389
static void setFont(const QFont &)
Definition: toolTip.cpp:438
static QFont font()
Definition: toolTip.cpp:418
static void setPalette(const QPalette &)
Definition: toolTip.cpp:428
Definition: toolTip.h:78