wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
ElementEditor.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 <memory>
11#include <utility>
12
13#include <QDialog>
14#include <QTableWidget>
15#include <QVBoxLayout>
16#include <QWidget>
17
19#include "App/Scene/Scene.h"
22
24
34class ElementEditor : public QWidget
35{
36 Q_OBJECT
37
38public:
39 // --- Lifecycle ---
40
42 explicit ElementEditor(QWidget *parent = nullptr);
43 ~ElementEditor() override;
44
45 // --- Scene Binding ---
46
48 void setScene(Scene *scene);
49
50 // --- UI Refresh ---
51
53 void update();
55 void retranslateUi();
57 void updateTheme();
59 void fillColorComboBox();
60
61 // --- User Actions ---
62
64 void renameAction();
68 void audioBox();
70 void truthTable();
73
74 // --- Context Menu ---
75
77 void contextMenu(QPoint screenPos, QGraphicsItem *itemAtMouse);
78
79signals:
84 void sendCommand(QUndoCommand *cmd);
85
87 void editSubcircuitRequested(const QString &blobName, int icElementId);
88
90 void openSubcircuitFileRequested(const QString &filePath);
91
94
97
98private:
99 Q_DISABLE_COPY(ElementEditor)
100
102 friend class TestElementEditor;
103
104 // --- Helpers ---
105
107 void apply();
109 void applyCapabilitiesToUi();
111 void applyProperty(GraphicElement *elm, PropertyDescriptor::Type type);
113 void defaultAppearance();
115 void rebuildAppearanceStateTiles(const QList<std::pair<int, QString>> &states);
117 void inputIndexChanged(const int index);
119 void inputLocked(const bool value);
121 void outputIndexChanged(const int index);
123 void outputValueChanged(const QString &value);
125 void selectionChanged();
127 void setCurrentElements(const QList<GraphicElement *> &elements);
129 void setTruthTableProposition(const int row, const int column);
131 void triggerChanged(const QString &cmd);
133 void blobNameEditingFinished();
134
135 // --- Members ---
136
137 std::unique_ptr<ElementEditorUi> m_ui;
138 QDialog *m_tableBox = nullptr;
139 QTableWidget *m_table = nullptr;
140 Scene *m_scene = nullptr;
141 ElementTabNavigator *m_tabNavigator = nullptr;
142 QList<GraphicElement *> m_elements;
143 SelectionCapabilities m_caps;
144
145 // Appearance state
146 QString m_appearanceName;
147 bool m_isDefaultAppearance = true;
148 bool m_isUpdatingAppearance = false;
149
150 // Placeholder strings for multi-selection display
151 QString m_manyAudios = tr("<Many sounds>");
152 QString m_manyColors = tr("<Many colors>");
153 QString m_manyDelay = tr("<Many values>");
154 QString m_manyFreq = tr("<Many values>");
155 QString m_manyIS = tr("<Many values>");
156 QString m_manyLabels = tr("<Many labels>");
157 QString m_manyOS = tr("<Many values>");
158 QString m_manyOV = tr("<Many values>");
159 QString m_manyTriggers = tr("<Many triggers>");
160 QString m_manyWirelessModes = tr("<Many modes>");
161};
ElementEditorUi: hand-written UI class for the ElementEditor widget.
PropertyDescriptor struct for describing editable element properties.
Main circuit editing scene with undo/redo and user interaction.
SelectionCapabilities struct and computeCapabilities() free function.
void openSubcircuitFileRequested(const QString &filePath)
Emitted when the user requests editing a file-backed IC's sub-circuit file.
void setScene(Scene *scene)
Associates the editor with scene to read/write selected elements.
void audioBox()
Opens the audio file selector for the selected element(s).
friend class TestElementEditor
void update()
Refreshes the editor UI to reflect the current selection.
void sendCommand(QUndoCommand *cmd)
Emitted when a property change should be pushed onto the undo stack.
~ElementEditor() override
void fillColorComboBox()
Repopulates the color combo box with available color options.
void contextMenu(QPoint screenPos, QGraphicsItem *itemAtMouse)
Shows the element context menu at screenPos for the item under itemAtMouse.
void updateElementAppearance()
Applies the chosen appearance to the selected element(s).
void editSubcircuitRequested(const QString &blobName, int icElementId)
Emitted when the user requests editing an embedded IC sub-circuit.
void truthTable()
Opens the truth table editor for the selected element(s).
void renameAction()
Opens an inline editor to rename the selected element(s).
ElementEditor(QWidget *parent=nullptr)
Constructs the element editor with optional parent.
void updateTheme()
Applies the current theme colors to the editor widgets.
friend class ElementTabNavigator
void extractToFileRequested()
Emitted when the user requests extracting an embedded IC to file.
void changeTriggerAction()
Opens a dialog to change the trigger key for the selected element(s).
void embedSubcircuitRequested()
Emitted when the user requests embedding a file-backed IC.
void retranslateUi()
Re-applies translatable strings to all editor widgets.
Event filter that cycles scene element selection on Tab / Shift+Tab.
Abstract base class for all graphical circuit elements in wiRedPanda.
Main circuit editing scene.
Definition Scene.h:56
Describes one editable property that a GraphicElement exposes in the ElementEditor.
Computed capabilities and consensus state of the current element selection.