-
Notifications
You must be signed in to change notification settings - Fork 25
feature: IC preview on hover #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| // Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #include "App/Element/ICPreviewPopup.h" | ||
|
|
||
| #include <QGuiApplication> | ||
| #include <QScreen> | ||
| #include <QVBoxLayout> | ||
|
|
||
| #include "App/Element/IC.h" | ||
|
|
||
| ICPreviewPopup::ICPreviewPopup(QWidget *parent) | ||
| : QWidget(parent, Qt::ToolTip | Qt::FramelessWindowHint) | ||
| { | ||
| setAttribute(Qt::WA_TranslucentBackground); | ||
|
darktorres marked this conversation as resolved.
|
||
| setAttribute(Qt::WA_NoSystemBackground); // Prevent solid black fill on Windows | ||
| setAttribute(Qt::WA_ShowWithoutActivating); | ||
|
|
||
| auto *layout = new QVBoxLayout(this); | ||
| layout->setContentsMargins(4, 4, 4, 4); | ||
|
|
||
| m_imageLabel = new QLabel(this); | ||
| m_imageLabel->setObjectName(QStringLiteral("preview")); | ||
| m_imageLabel->setAlignment(Qt::AlignCenter); | ||
| layout->addWidget(m_imageLabel); | ||
|
|
||
| // Outer popup chrome + an inset frame around the preview pixmap so the | ||
| // rendered circuit reads as a framed image rather than floating content. | ||
| // The QLabel selector is scoped by objectName so future labels added to | ||
| // the popup don't silently inherit the inset frame styling. | ||
| setStyleSheet( | ||
| "ICPreviewPopup {" | ||
| " background-color: rgba(30, 30, 30, 230);" | ||
| " border: 1px solid rgba(120, 120, 120, 180);" | ||
| " border-radius: 6px;" | ||
| "}" | ||
| "QLabel#preview {" | ||
| " border: 1px solid rgba(170, 170, 170, 200);" | ||
| " border-radius: 3px;" | ||
| " padding: 6px;" | ||
| " background-color: rgba(15, 15, 15, 200);" | ||
| "}" | ||
| ); | ||
|
|
||
| m_hideTimer.setSingleShot(true); | ||
| m_hideTimer.setInterval(300); | ||
| connect(&m_hideTimer, &QTimer::timeout, this, &QWidget::hide); | ||
|
|
||
| m_showTimer.setSingleShot(true); | ||
| m_showTimer.setInterval(1000); | ||
| connect(&m_showTimer, &QTimer::timeout, this, &ICPreviewPopup::executeShow); | ||
| } | ||
|
darktorres marked this conversation as resolved.
|
||
|
|
||
| void ICPreviewPopup::showForIC(IC *ic, const QPoint &screenPos) | ||
| { | ||
| cancelHide(); | ||
|
|
||
| if (!ic) { | ||
| return; | ||
| } | ||
|
|
||
| m_pendingIC = ic; | ||
| m_pendingPos = screenPos; | ||
|
|
||
| if (isVisible()) { | ||
| // If the popup is already visible (e.g., moved quickly from another IC), | ||
| // update it immediately without a delay. | ||
| executeShow(); | ||
| } else { | ||
| m_showTimer.start(); | ||
| } | ||
| } | ||
|
|
||
| void ICPreviewPopup::executeShow() | ||
| { | ||
| if (!m_pendingIC) { | ||
| return; | ||
| } | ||
|
|
||
| // The pixmap is the single source of truth: it's null when the IC was | ||
| // empty or oversized at load time, or when generation otherwise failed. | ||
| const QPixmap &preview = m_pendingIC->previewPixmap(); | ||
| if (preview.isNull()) { | ||
| hide(); | ||
| return; | ||
| } | ||
|
|
||
| m_imageLabel->setPixmap(preview); | ||
| adjustSize(); | ||
|
|
||
| // Position slightly offset from the cursor, then clamp to the available | ||
| // screen geometry so the popup never extends off-screen. | ||
| QPoint pos = m_pendingPos + QPoint(16, 16); | ||
| if (const auto *screen = QGuiApplication::screenAt(pos)) { | ||
| const QRect avail = screen->availableGeometry(); | ||
| pos.setX(qMin(pos.x(), avail.right() - width())); | ||
| pos.setY(qMin(pos.y(), avail.bottom() - height())); | ||
| } | ||
| move(pos); | ||
| show(); | ||
| } | ||
|
|
||
| void ICPreviewPopup::scheduleHide() | ||
| { | ||
| m_showTimer.stop(); | ||
| m_hideTimer.start(); | ||
| } | ||
|
|
||
| void ICPreviewPopup::cancelHide() | ||
| { | ||
| m_hideTimer.stop(); | ||
| m_showTimer.stop(); | ||
| } | ||
|
|
||
| void ICPreviewPopup::updatePendingPos(const QPoint &screenPos) | ||
| { | ||
| if (!isVisible()) { | ||
| m_pendingPos = screenPos; | ||
| } | ||
| } | ||
|
|
||
| void ICPreviewPopup::enterEvent(QEnterEvent *event) | ||
| { | ||
| Q_UNUSED(event) | ||
| cancelHide(); | ||
| } | ||
|
|
||
| void ICPreviewPopup::leaveEvent(QEvent *event) | ||
| { | ||
| Q_UNUSED(event) | ||
| scheduleHide(); | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.