itom
Loading...
Searching...
No Matches
toolTip.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität 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
36class ToolTipLabel : public QLabel
37{
38 Q_OBJECT
39public:
40 ToolTipLabel(const QString &text, const QPoint &pos, QWidget *w, int msecDisplayTime);
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(), bool doNotForceYToBeWithinScreen = false);
55#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
56 static QScreen *getTipScreen(const QPoint& pos, QWidget* w);
57#else
58 static int getTipScreen(const QPoint& pos, QWidget* w);
59#endif
60
61protected:
62 void timerEvent(QTimerEvent *e) override;
63 void paintEvent(QPaintEvent *e) override;
64 void mouseMoveEvent(QMouseEvent *e) override;
65 void resizeEvent(QResizeEvent *e) override;
66#ifndef QT_NO_STYLE_STYLESHEET
67public slots:
71 void styleSheetParentDestroyed() {
72 setProperty("_q_stylesheet_parent", QVariant());
73 styleSheetParent = 0;
74 }
75private:
76 QWidget *styleSheetParent;
77#endif
78private:
79 QWidget *widget;
80 QRect rect;
81};
82
84{
85 ToolTip() = delete;
86public:
87 // ### Qt 6 - merge the three showText functions below
88 static void showText(
89 const QPoint& pos,
90 const QString& text,
91 QWidget* w = nullptr,
92 const QPoint& alternativeTopRightPos = QPoint(),
93 bool doNotForceYToBeWithinScreen = false);
94 static void showText(
95 const QPoint& pos,
96 const QString& text,
97 QWidget* w,
98 const QRect& rect,
99 bool doNotForceYToBeWithinScreen = false);
100 static void showText(
101 const QPoint& pos,
102 const QString& text,
103 QWidget* w,
104 const QRect& rect,
105 int msecShowTime,
106 const QPoint& alternativeTopRightPos = QPoint(),
107 bool doNotForceYToBeWithinScreen = false);
108 static inline void hideText() { showText(QPoint(), QString()); }
109 static bool isVisible();
110 static QString text();
111 static QPalette palette();
112 static void setPalette(const QPalette &);
113 static QFont font();
114 static void setFont(const QFont &);
115};
116
117
118#endif // TOOLTIP_H
Definition toolTip.h:84
static QString text()
Definition toolTip.cpp:518
static void setFont(const QFont &)
Definition toolTip.cpp:558
static void setPalette(const QPalette &)
Definition toolTip.cpp:548
static QFont font()
Definition toolTip.cpp:538
static void showText(const QPoint &pos, const QString &text, QWidget *w=nullptr, const QPoint &alternativeTopRightPos=QPoint(), bool doNotForceYToBeWithinScreen=false)
Definition toolTip.cpp:487
static QPalette palette()
Definition toolTip.cpp:530
static bool isVisible()
Definition toolTip.cpp:509
Definition toolTip.h:37