wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
ClipboardManager Class Reference

Manages clipboard operations (copy/cut/paste) and clone-drag for the circuit scene. More...

#include <ClipboardManager.h>

Public Member Functions

 ClipboardManager (Scene *scene)
void cloneDrag (const QPointF &mousePos)
 Initiates a clone-drag (Ctrl+drag) of the current selection.
void copy ()
 Copies the currently selected items to the system clipboard.
void cut ()
 Cuts the currently selected items (copy + delete).
void duplicate ()
void paste ()
 Pastes items from the system clipboard into the scene.

Static Public Member Functions

static QImage buildDragImage (Scene *scene, const QTransform &viewTransform, const QRectF &sourceRect)
 Renders sourceRect of scene, mapped through viewTransform, into a transparent-filled QImage bounded by kMaxDragImageDimension.
static bool canPaste (const QMimeData *mimeData)
 Returns whether mimeData carries circuit data paste() accepts.

Static Public Attributes

static constexpr int kMaxDragImageDimension = 1024

Detailed Description

Manages clipboard operations (copy/cut/paste) and clone-drag for the circuit scene.

Extracted from Scene to decouple clipboard serialization and blob-registry handling from the main circuit scene. Delegates item creation and undo commands back to the owning Scene.

Definition at line 33 of file ClipboardManager.h.

Constructor & Destructor Documentation

◆ ClipboardManager()

ClipboardManager::ClipboardManager ( Scene * scene)
explicit

Definition at line 29 of file ClipboardManager.cpp.

Member Function Documentation

◆ buildDragImage()

QImage ClipboardManager::buildDragImage ( Scene * scene,
const QTransform & viewTransform,
const QRectF & sourceRect )
static

Renders sourceRect of scene, mapped through viewTransform, into a transparent-filled QImage bounded by kMaxDragImageDimension.

sourceRect is a union of selected elements' scene bounding rects — unbounded magnitude, since position validation on load only rejects non-finite coordinates, never bounds them. Scaled down to fit rather than allocated proportionally. Exposed for testing.

Definition at line 191 of file ClipboardManager.cpp.

References kMaxDragImageDimension.

Referenced by cloneDrag().

◆ canPaste()

bool ClipboardManager::canPaste ( const QMimeData * mimeData)
static

Returns whether mimeData carries circuit data paste() accepts.

Single source of truth for paste gating (context menu, future action enabling): paste() reads both the current and the legacy mime format, so any gate that checks only one of them silently drifts.

Definition at line 183 of file ClipboardManager.cpp.

References MimeType::Clipboard, and MimeType::ClipboardLegacy.

Referenced by Scene::contextMenu().

◆ cloneDrag()

void ClipboardManager::cloneDrag ( const QPointF & mousePos)

Initiates a clone-drag (Ctrl+drag) of the current selection.

Definition at line 216 of file ClipboardManager.cpp.

References buildDragImage(), MimeType::CloneDrag, qCDebug, sentryBreadcrumb(), Connection::Type, GraphicElement::Type, Scene::view(), and Serialization::writePandaHeader().

◆ copy()

void ClipboardManager::copy ( )

Copies the currently selected items to the system clipboard.

Definition at line 34 of file ClipboardManager.cpp.

References MimeType::BlobRegistry, MimeType::BlobRegistryV2, MimeType::Clipboard, and Serialization::writePandaHeader().

◆ cut()

void ClipboardManager::cut ( )

Cuts the currently selected items (copy + delete).

Definition at line 78 of file ClipboardManager.cpp.

References MimeType::BlobRegistry, MimeType::BlobRegistryV2, MimeType::Clipboard, and Serialization::writePandaHeader().

◆ duplicate()

void ClipboardManager::duplicate ( )

Duplicates the current selection in place (a grid step down-right), without touching the system clipboard, as a single undoable step; the copies become the new selection.

Definition at line 331 of file ClipboardManager.cpp.

References Constants::gridSize, Serialization::readPandaHeader(), and Serialization::writePandaHeader().

◆ paste()

void ClipboardManager::paste ( )

Member Data Documentation

◆ kMaxDragImageDimension

int ClipboardManager::kMaxDragImageDimension = 1024
staticconstexpr

Maximum width/height (in device pixels) buildDragImage() will allocate. A drag ghost is a transient visual aid, not saved output, so a modest cap is enough — selection extent beyond this is scaled down to fit rather than sized proportionally.

Definition at line 67 of file ClipboardManager.h.

Referenced by buildDragImage().


The documentation for this class was generated from the following files: