NDEVR
API Documentation
QCustomTooltip.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: QCustomTooltip
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <QString>
35#include <QPoint>
36#include <QLabel>
37#include <QBasicTimer>
38#include <QPointer>
39namespace NDEVR
40{
41 class StringView;
47 class NDEVR_WIDGETS_API QCustomTooltip : public QLabel
48 {
49 Q_OBJECT
50 public:
57 QCustomTooltip(const StringView& text, const QPointF &pos, QWidget* parent = nullptr);
63 void updateSize(const QPointF &pos);
71 bool eventFilter(QObject *, QEvent *) override;
77 void reuseTip(const StringView& text, const QPointF &pos);
81 void hideTip();
86 void hideTipImmediately(int animation_duration = -1);
93 void setTipRect(const QWidget *w, const QRect &r);
101 bool tipChanged(const QPointF &pos, const QString &text, QObject *o);
110 static QCustomTooltip* show(const StringView& text, const QPointF &pos, const QWidget *w, int animation_duration = -1);
115 static void hide(int animation_duration = -1);
120 static bool IsShowing();
125 int margin() const;
130 QSize sizeHint() const override;
135 void setTargetOffset(QPoint target_offset);
136 protected:
141 void timerEvent(QTimerEvent *e) override;
146 void paintEvent(QPaintEvent *e) override;
151 void mouseMoveEvent(QMouseEvent *e) override;
156 void resizeEvent(QResizeEvent *e) override;
157 private:
158 int animation_duration = -1;
159 private:
160 static QPointer<QCustomTooltip> s_instance;
161 QPointer<const QWidget> m_widget;
162 QRect m_rect;
163 QPoint m_target_offset;
164 QBasicTimer m_hide_timer;
165 };
166}
static void hide(int animation_duration=-1)
Hides the currently showing tooltip with an optional fade-out animation.
void hideTipImmediately(int animation_duration=-1)
Hides the tooltip immediately with an optional fade-out animation.
void setTargetOffset(QPoint target_offset)
Sets an offset from the target position for tooltip placement.
void timerEvent(QTimerEvent *e) override
Handles timer events for auto-hiding the tooltip after a delay.
static QCustomTooltip * show(const StringView &text, const QPointF &pos, const QWidget *w, int animation_duration=-1)
Shows a tooltip with the given text at the specified position near a widget.
QSize sizeHint() const override
Returns the recommended size for the tooltip.
void hideTip()
Hides the tooltip after a short delay.
static bool IsShowing()
Checks whether a tooltip is currently being shown.
QCustomTooltip(const StringView &text, const QPointF &pos, QWidget *parent=nullptr)
Constructs a tooltip with the given text at the specified screen position.
void updateSize(const QPointF &pos)
Updates the tooltip size and position based on the new screen position.
void paintEvent(QPaintEvent *e) override
Paints the tooltip with its custom appearance.
void resizeEvent(QResizeEvent *e) override
Handles resize events to update the tooltip shape mask.
bool eventFilter(QObject *, QEvent *) override
Filters events to detect mouse movement and other events that should hide or reposition the tooltip.
void setTipRect(const QWidget *w, const QRect &r)
Sets the widget and rectangle region that the tooltip is associated with.
void mouseMoveEvent(QMouseEvent *e) override
Handles mouse move events to hide the tooltip when the mouse moves away.
bool tipChanged(const QPointF &pos, const QString &text, QObject *o)
Checks whether the tooltip content or position has changed.
int margin() const
Returns the margin around the tooltip text content.
void reuseTip(const StringView &text, const QPointF &pos)
Reuses the existing tooltip instance with new text and position.
The core String View class for the NDEVR API.
Definition StringView.h:58
The primary namespace for the NDEVR SDK.