Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
QmitkFloatingTextPopup.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef QmitkFloatingTextPopup_h
14 #define QmitkFloatingTextPopup_h
15 
16 #include <QWidget>
17 #include <QString>
18 #include <MitkQtWidgetsExports.h>
19 
20 
27 {
28  Q_OBJECT
29  Q_PROPERTY(QString htmlContent READ GetHtmlContent WRITE SetHtmlContent)
30  Q_PROPERTY(int opacity READ GetOpacity WRITE SetOpacity)
31  Q_PROPERTY(bool popupEnabled READ IsEnabled WRITE SetEnabled)
32 
33 public:
34  explicit QmitkFloatingTextPopup(QWidget* parent = nullptr);
36 
37  QString GetHtmlContent() const;
38  void SetHtmlContent(const QString& html);
39 
40  int GetOpacity() const;
41  void SetOpacity(int opacity);
42 
45  bool IsEnabled() const;
46  void SetEnabled(bool enabled);
47 
48 protected:
49  void paintEvent(QPaintEvent* event) override;
50  QSize sizeHint() const override;
51  bool eventFilter(QObject* watched, QEvent* event) override;
52 
53 private:
54  void updatePosition(const QPoint& globalPos);
55  void updateGeometry();
56  void updateVisibility();
57  QPoint constrainToScreen(const QPoint& pos, const QSize& size) const;
58  void installGlobalEventFilter();
59  void removeGlobalEventFilter();
60 
61  QString m_HtmlContent;
62  int m_Opacity = 200; // 0-255 range
63  bool m_Enabled = false;
64  bool m_EventFilterInstalled = false;
65  QPoint m_CursorOffset{30, 30}; // Offset from cursor
66  static constexpr int m_Padding = 2;
67  static constexpr int m_MaxWidth = 200;
68 };
69 
70 #endif
#define MITKQTWIDGETS_EXPORT
void SetHtmlContent(const QString &html)
void SetOpacity(int opacity)
void SetEnabled(bool enabled)
QmitkFloatingTextPopup(QWidget *parent=nullptr)
~QmitkFloatingTextPopup() override
void paintEvent(QPaintEvent *event) override
QSize sizeHint() const override
QString GetHtmlContent() const
bool eventFilter(QObject *watched, QEvent *event) override
bool IsEnabled() const