1717#include " circuitViewWidget.h"
1818#include " backend/backend.h"
1919
20- CircuitViewWidget::CircuitViewWidget (QWidget* parent, Ui::CircuitViewUi* ui, CircuitFileManager* fileManager) :
21- QWidget(parent), mouseControls(false ), circuitSelector(ui->CircuitSelector), evaluatorSelector(ui->EvaluatorSelector), fileManager(fileManager) {
20+ CircuitViewWidget::CircuitViewWidget (QWidget* parent, Ui::CircuitViewUi* ui, CircuitFileManager* fileManager, KeybindManager* keybindManager ) :
21+ QWidget(parent), mouseControls(false ), circuitSelector(ui->CircuitSelector), evaluatorSelector(ui->EvaluatorSelector), fileManager(fileManager), keybindManager(keybindManager) {
2222
2323 // create circuitView
2424 renderer = std::make_unique<QtRenderer>();
2525 circuitView = std::make_unique<CircuitView>(renderer.get ());
26-
26+
2727 // qt settings
2828 setFocusPolicy (Qt::StrongFocus);
2929 grabGesture (Qt::PinchGesture);
@@ -46,9 +46,25 @@ CircuitViewWidget::CircuitViewWidget(QWidget* parent, Ui::CircuitViewUi* ui, Cir
4646 renderer->resize (w, h);
4747 renderer->initializeTileSet (" :logicTiles.png" );
4848
49+ // create keybind shortcuts and connect them
50+ connect (keybindManager->createShortcut (" Save" , this ), &QShortcut::activated, this , &CircuitViewWidget::save);
51+ connect (keybindManager->createShortcut (" Undo" , this ), &QShortcut::activated, this , [this ]() {
52+ circuitView->getCircuit ()->undo ();
53+ });
54+ connect (keybindManager->createShortcut (" Redo" , this ), &QShortcut::activated, this , [this ]() {
55+ circuitView->getCircuit ()->redo ();
56+ });
57+ connect (keybindManager->createShortcut (" BlockRotateCCW" , this ), &QShortcut::activated, this , [this ]() {
58+ circuitView->getEventRegister ().doEvent (Event (" tool rotate block ccw" ));
59+ });
60+ connect (keybindManager->createShortcut (" BlockRotateCW" , this ), &QShortcut::activated, this , [this ]() {
61+ circuitView->getEventRegister ().doEvent (Event (" tool rotate block cw" ));
62+ });
63+ connect (keybindManager->createShortcut (" ToggleInteractive" , this ), &QShortcut::activated, this , [this ]() {
64+ circuitView->toggleInteractive ();
65+ });
66+
4967 // connect buttons and actions
50- QShortcut* saveShortcut = new QShortcut (QKeySequence (" Ctrl+S" ), this );
51- connect (saveShortcut, &QShortcut::activated, this , &CircuitViewWidget::save);
5268 connect (ui->StartSim , &QPushButton::clicked, this , &CircuitViewWidget::setSimState);
5369 connect (ui->UseSpeed , &QCheckBox::checkStateChanged, this , &CircuitViewWidget::simUseSpeed);
5470 connect (ui->Speed , &QDoubleSpinBox::valueChanged, this , &CircuitViewWidget::setSimSpeed);
@@ -229,29 +245,6 @@ void CircuitViewWidget::wheelEvent(QWheelEvent* event) {
229245 }
230246}
231247
232- void CircuitViewWidget::keyPressEvent (QKeyEvent* event) {
233- if (/* event->modifiers() & Qt::MetaModifier && */ event->key () == Qt::Key_Z) {
234- circuitView->getCircuit ()->undo ();
235- event->accept ();
236- } else if (/* event->modifiers() & Qt::MetaModifier && */ event->key () == Qt::Key_Y) {
237- circuitView->getCircuit ()->redo ();
238- event->accept ();
239- } else if (event->key () == Qt::Key_Q) {
240- if (circuitView->getEventRegister ().doEvent (Event (" tool rotate block ccw" ))) {
241- event->accept ();
242- }
243- } else if (event->key () == Qt::Key_E) {
244- if (circuitView->getEventRegister ().doEvent (Event (" tool rotate block cw" ))) {
245- event->accept ();
246- }
247- } else if (event->key () == Qt::Key_I) {
248- circuitView->toggleInteractive ();
249- event->accept ();
250- }
251- }
252-
253- void CircuitViewWidget::keyReleaseEvent (QKeyEvent* event) { }
254-
255248void CircuitViewWidget::mousePressEvent (QMouseEvent* event) {
256249 if (event->button () == Qt::LeftButton) {
257250 if (QGuiApplication::keyboardModifiers ().testFlag (Qt::AltModifier)) {
@@ -295,13 +288,14 @@ void CircuitViewWidget::leaveEvent(QEvent* event) {
295288
296289// save current circuit view widget we are viewing. Right now only works if it is the only widget in application.
297290void CircuitViewWidget::save () {
298- std::cout << " Trying to save\n " ;
299- if (fileManager) {
300- QString filePath = QFileDialog::getSaveFileName (this , " Save Circuit" , " " , " Circuit Files (*.cir);;All Files (*)" );
301- if (!filePath.isEmpty ()) {
302- fileManager->saveToFile (filePath.toStdString (), circuitView->getCircuit ());
303- }
304- }
291+ logInfo (" Trying to save Circuit" );
292+ if (fileManager) {
293+ QString filePath = QFileDialog::getSaveFileName (this , " Save Circuit" , " " , " Circuit Files (*.cir);;All Files (*)" );
294+ if (!filePath.isEmpty ()) {
295+ fileManager->saveToFile (filePath.toStdString (), circuitView->getCircuit ());
296+ logInfo (" Successfully saved Circuit to: " + filePath.toStdString ());
297+ }
298+ }
305299}
306300
307301// for drag and drop load directly onto this circuit view widget
0 commit comments