wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
ICPreviewPopup.h
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
7
8#pragma once
9
10#include <QLabel>
11#include <QPointer>
12#include <QTimer>
13#include <QWidget>
14
15class IC;
16
26class ICPreviewPopup : public QWidget
27{
28 Q_OBJECT
29
30 // Test-only seam: executeShow() is the real timer-fired slot, but waiting out the real
31 // 1-second m_showTimer in a test is slow and non-deterministic. Calling it directly lets
32 // tests drive the exact same logic showForIC() would eventually trigger, synchronously.
33 friend class TestICUnit;
34
35public:
37 static constexpr int MaxWidth = 500;
38 static constexpr int MaxHeight = 350;
39
43 static constexpr int MaxElementCount = 500;
44
46 explicit ICPreviewPopup(QWidget *parent = nullptr);
47
51 void showForIC(IC *ic, const QPoint &screenPos);
52
55 void scheduleHide();
56
58 void cancelHide();
59
63 void updatePendingPos(const QPoint &screenPos);
64
66 IC *pendingIC() const;
67
71 bool isShowActiveFor(const IC *ic) const;
72
76 static QPoint clampedPopupPos(const QPoint &cursorPos, const QSize &popupSize, const QRect &availableGeometry);
77
78protected:
80 void enterEvent(QEnterEvent *event) override;
81
83 void leaveEvent(QEvent *event) override;
84
85private:
86 void executeShow();
87
88 QLabel *m_titleLabel;
89 QLabel *m_imageLabel;
90 QTimer m_hideTimer;
91 QTimer m_showTimer;
92 QPointer<IC> m_pendingIC;
93 QPoint m_pendingPos;
94};
void leaveEvent(QEvent *event) override
IC * pendingIC() const
Returns the IC currently pending display (may be null).
friend class TestICUnit
ICPreviewPopup(QWidget *parent=nullptr)
Constructs the popup as a frameless, non-activating child of parent.
bool isShowActiveFor(const IC *ic) const
static QPoint clampedPopupPos(const QPoint &cursorPos, const QSize &popupSize, const QRect &availableGeometry)
static constexpr int MaxWidth
Maximum preview dimensions in pixels.
static constexpr int MaxHeight
void cancelHide()
Cancels a pending show/hide.
void showForIC(IC *ic, const QPoint &screenPos)
static constexpr int MaxElementCount
void updatePendingPos(const QPoint &screenPos)
void enterEvent(QEnterEvent *event) override
Graphic element representing an Integrated Circuit (sub-circuit) box.
Definition IC.h:31