Overlay.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef OVERLAY_H
  2. #define OVERLAY_H
  3. #include <QWidget>
  4. #include <QTimer>
  5. /**
  6. * @brief Overlay Widget
  7. * Works in Android, IOS, Linux, Windows and MacOS (Catalina, not on HighSierra)
  8. */
  9. class Overlay : public QWidget
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit Overlay(QWidget *parent = 0);
  14. virtual ~Overlay();
  15. signals:
  16. public slots:
  17. protected:
  18. void paintEvent(QPaintEvent *event) override;
  19. void resizeEvent(QResizeEvent *event) override;
  20. //! installs the event filter
  21. void newParent();
  22. //! catches resize and child events from parent widget
  23. bool eventFilter(QObject *obj, QEvent *ev) override;
  24. //! tracks parent widget changes
  25. bool event(QEvent *ev) override;
  26. };
  27. class MessageOverlay : public Overlay
  28. {
  29. Q_OBJECT
  30. public:
  31. explicit MessageOverlay(QWidget *parent = nullptr,
  32. const int drawAlignFlags=Qt::AlignHCenter | Qt::AlignJustify,
  33. const QColor &textColor=QColor(Qt::red));
  34. virtual ~MessageOverlay();
  35. public slots:
  36. void showMessage (const QString msg, const int forSeconds=0);
  37. void hideMessage ();
  38. protected:
  39. void paintEvent(QPaintEvent *event) override;
  40. bool m_visible = false;
  41. QString m_text;
  42. QColor m_textColor = QColor (Qt::red);
  43. int m_drawAlignFlags = Qt::AlignHCenter | Qt::AlignJustify;
  44. };
  45. #endif // OVERLAY_H