24 m_iconLabel.setPixmap(
pixmap);
25 m_iconLabel.setScaledContents(
true);
26 m_iconLabel.setFixedSize(64, 64);
30 }
else if (type == ElementType::IC) {
31 m_nameLabel.setText(QFileInfo(
icFileName).baseName().toUpper());
41 }
else if (type == ElementType::IC) {
42 tip = tr(
"IC from file: %1").arg(QFileInfo(
icFileName).fileName());
46 const QString addHint = tr(
"Drag or double-click to add.");
47 tip = tip.isEmpty() ? addHint : tip + QLatin1Char(
'\n') + addHint;
49 m_iconLabel.setToolTip(tip);
50 m_nameLabel.setToolTip(tip);
52 auto *itemLayout =
new QHBoxLayout();
53 itemLayout->setSpacing(6);
54 itemLayout->setObjectName(QStringLiteral(
"itemLayout"));
56 setLayout(itemLayout);
58 itemLayout->addWidget(&m_iconLabel);
59 itemLayout->addStretch();
60 itemLayout->addWidget(&m_nameLabel);
61 itemLayout->addStretch();
62 itemLayout->setContentsMargins(0, 0, 0, 0);
67 if (m_elementType != ElementType::IC) {
77 if (event->button() == Qt::LeftButton) {
78 m_dragStartPos =
event->pos();
84 if (!(event->buttons() & Qt::LeftButton)) {
87 if ((event->pos() - m_dragStartPos).manhattanLength() < QApplication::startDragDistance()) {
103 return m_elementType;
113 return m_nameLabel.text();
130 QPoint offset = m_iconLabel.pixmap(Qt::ReturnByValue).rect().center();
132 auto *drag =
new QDrag(parent());
134 drag->setPixmap(
pixmap());
135 drag->setHotSpot(offset);
138 drag->exec(Qt::CopyAction, Qt::CopyAction);
143 QPoint offset = m_iconLabel.pixmap(Qt::ReturnByValue).rect().center();
145 QDataStream stream(&itemData, QIODevice::WriteOnly);
147 stream << offset << m_elementType << m_icFileName << m_isEmbedded << (m_isEmbedded ? m_icFileName : QString());
158 m_iconLabel.setPixmap(m_pixmap);
Singleton factory for all circuit element types.
Draggable element icon+label widget used in the element palette.
Enums::ElementType ElementType
MIME type string constants for drag-and-drop operations.
Circuit and waveform file serialization/deserialization utilities.
static QString translatedName(const ElementType type)
Returns the translated human-readable name for type.
static QPixmap pixmap(const ElementType type)
Returns the pixmap icon for the given element type.
static QString description(const ElementType type)
void startDrag()
Initiates a drag operation carrying this label's element type.
void mouseMoveEvent(QMouseEvent *event) override
Starts the drag once the pointer moves past the platform drag threshold.
void addToSceneRequested(QMimeData *mimeData)
QString name() const
Returns the displayed element name.
bool isEmbedded() const
Returns true if this label represents an embedded IC.
void mousePressEvent(QMouseEvent *event) override
const QPixmap & pixmap() const
Returns the icon pixmap shown in this label.
void updateName()
Updates the displayed name to match the current application locale.
QMimeData * mimeData() const
Creates and returns the MIME data payload used for drag-and-drop.
QString icFileName() const
Returns the IC file path, or an empty string for built-in elements.
void mouseDoubleClickEvent(QMouseEvent *event) override
Requests adding this element to the active scene (drag-free shortcut).
void updateTheme()
Updates colors to match the current application theme.
const ElementType & elementType() const
Returns the element type identifier for this label.
ElementLabel(const QPixmap &pixmap, ElementType type, const QString &icFileName, QWidget *parent=nullptr, bool isEmbedded=false)
Constructs an ElementLabel from a pixmap.
static void writePandaHeader(QDataStream &stream)
Writes the .panda circuit file header to stream.
constexpr const char * DragDrop
Current drag-and-drop MIME type for element palette → scene drops.