File indexing completed on 2024-05-05 05:57:02

0001 /*
0002   SPDX-FileCopyrightText: 2009 Eike Hein <hein@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #ifndef VISUALEVENTOVERLAY_H
0008 #define VISUALEVENTOVERLAY_H
0009 
0010 #include <QElapsedTimer>
0011 #include <QRect>
0012 #include <QTime>
0013 #include <QWidget>
0014 
0015 class SessionStack;
0016 class Terminal;
0017 
0018 class QTimer;
0019 
0020 class EventRect : public QRect
0021 {
0022 public:
0023     enum EventType {
0024         TerminalHighlight,
0025         KeyboardInputBlocked,
0026     };
0027 
0028     enum EventFlag {
0029         NoFlags = 0x00000000,
0030         Singleton = 0x00000001,
0031         Exclusive = 0x00000002,
0032         Persistent = 0x00000004,
0033     };
0034     Q_DECLARE_FLAGS(EventFlags, EventFlag)
0035 
0036     EventRect(const QPoint &topLeft, const QPoint &bottomRight, EventType type, EventFlags flags = EventRect::NoFlags);
0037     ~EventRect();
0038 
0039     EventType eventType() const
0040     {
0041         return m_eventType;
0042     }
0043     const QElapsedTimer &timeStamp() const
0044     {
0045         return m_timeStamp;
0046     }
0047 
0048     EventFlags eventFlags() const
0049     {
0050         return m_eventFlags;
0051     }
0052     void setEventFlags(EventFlags flags)
0053     {
0054         m_eventFlags = flags;
0055     }
0056     inline bool testFlag(EventFlag flag) const
0057     {
0058         return m_eventFlags & flag;
0059     }
0060 
0061     bool operator==(const EventRect &eventRect) const;
0062     bool operator<(const EventRect &eventRect) const;
0063 
0064 private:
0065     EventType m_eventType;
0066     EventFlags m_eventFlags;
0067 
0068     QElapsedTimer m_timeStamp;
0069 };
0070 
0071 Q_DECLARE_OPERATORS_FOR_FLAGS(EventRect::EventFlags)
0072 
0073 class VisualEventOverlay : public QWidget
0074 {
0075     Q_OBJECT
0076 
0077 public:
0078     explicit VisualEventOverlay(SessionStack *parent = nullptr);
0079     ~VisualEventOverlay();
0080 
0081 public Q_SLOTS:
0082     void highlightTerminal(Terminal *terminal, bool persistent = false);
0083     void removeTerminalHighlight();
0084 
0085     void indicateKeyboardInputBlocked(Terminal *terminal);
0086 
0087     void terminalEvent(Terminal *terminal, EventRect::EventType type, EventRect::EventFlags flags = EventRect::NoFlags);
0088 
0089 protected:
0090     void showEvent(QShowEvent *) override;
0091     void hideEvent(QHideEvent *) override;
0092     void paintEvent(QPaintEvent *) override;
0093 
0094 private Q_SLOTS:
0095     void cleanupOverlay();
0096 
0097 private:
0098     void scheduleCleanup(int in);
0099 
0100     QList<EventRect> m_eventRects;
0101 
0102     QTimer *m_cleanupTimer;
0103     QElapsedTimer m_cleanupTimerStarted;
0104     int m_cleanupTimerCeiling;
0105 
0106     QElapsedTimer m_time;
0107 
0108     SessionStack *m_sessionStack;
0109 };
0110 
0111 #endif