HAL
file_actions.cpp
Go to the documentation of this file.
8 #include "gui/gui_globals.h"
9 
10 #include <QShortcut>
11 
12 namespace hal {
13 
15  : QWidget(parent), mGatelibReference(nullptr), mGuiPluginReference(nullptr)
16  {
17  repolish();
18  mMainWindowReference = dynamic_cast<MainWindow*>(parent);
19  mActionCreate = new Action(this);
20  mActionOpen = new Action(this);
21  mActionClose = new Action(this);
22  mActionSave = new Action(this);
23  mActionSaveAs = new Action(this);
24 
25  mActionCreate->setIcon(gui_utility::getStyledSvgIcon(mNewFileIconStyle, mNewFileIconPath, mDisabledIconStyle));
26  mActionOpen->setIcon(gui_utility::getStyledSvgIcon(mOpenProjIconStyle, mOpenProjIconPath, mDisabledIconStyle));
27  mActionClose->setIcon(gui_utility::getStyledSvgIcon(mCloseIconStyle, mCloseIconPath));
28  mActionSave->setIcon(gui_utility::getStyledSvgIcon(mEnabledIconStyle, mSaveIconPath, mDisabledIconStyle));
29  mActionSaveAs->setIcon(gui_utility::getStyledSvgIcon(mEnabledIconStyle, mSaveAsIconPath, mDisabledIconStyle));
30 
31  mSettingSaveFile =
32  new SettingsItemKeybind("HAL Shortcut 'Save File'", "keybinds/project_save_file", QKeySequence("Ctrl+S"), "Keybindings:Global", "Keybind for saving the currently opened file.");
33  mSettingCreateFile = new SettingsItemKeybind(
34  "HAL Shortcut 'Create Empty Netlist'", "keybinds/project_create_file", QKeySequence("Ctrl+N"), "Keybindings:Global", "Keybind for creating a new and empty netlist in HAL.");
35 
36  mSettingOpenFile = new SettingsItemKeybind("HAL Shortcut 'Open File'", "keybinds/project_open_file", QKeySequence("Ctrl+O"), "Keybindings:Global", "Keybind for opening a new File in HAL.");
37 
38  QShortcut* shortCutNewFile = new QShortcut(mSettingCreateFile->value().toString(), this);
39  QShortcut* shortCutOpenFile = new QShortcut(mSettingOpenFile->value().toString(), this);
40  QShortcut* shortCutSaveFile = new QShortcut(mSettingSaveFile->value().toString(), this);
41 
42  connect(mSettingCreateFile, &SettingsItemKeybind::keySequenceChanged, shortCutNewFile, &QShortcut::setKey);
43  connect(mSettingOpenFile, &SettingsItemKeybind::keySequenceChanged, shortCutOpenFile, &QShortcut::setKey);
44  connect(mSettingSaveFile, &SettingsItemKeybind::keySequenceChanged, shortCutSaveFile, &QShortcut::setKey);
45 
46  connect(shortCutNewFile, &QShortcut::activated, mActionCreate, &QAction::trigger);
47  connect(shortCutOpenFile, &QShortcut::activated, mActionOpen, &QAction::trigger);
48  connect(shortCutSaveFile, &QShortcut::activated, mActionSave, &QAction::trigger);
49 
51  setup();
52  hide();
53  }
54 
56  {
57  QStyle* s = style();
58 
59  s->unpolish(this);
60  s->polish(this);
61  }
62 
63  void FileActions::handleFileStatusChanged(bool gateLibrary, bool isDirty)
64  {
65  if (gateLibrary == (mGatelibReference==nullptr)) return;
66 
67  mActionSave->setEnabled(isDirty);
68  mActionSaveAs->setEnabled(isDirty);
69  }
70 
72  {
73  mGatelibReference = glcw;
74  mGuiPluginReference = plmgr;
75  mActionCreate->disconnect();
76  mActionOpen->disconnect();
77  mActionClose->disconnect();
78  mActionSave->disconnect();
79  mActionSaveAs->disconnect();
80  if (mGatelibReference)
81  {
82  mActionCreate->setText("New Gate Library");
83  mActionOpen->setText("Open Gate Library");
84  mActionClose->setText("Close Gate Lib Manager");
85  mActionSave->setText("Save Gate Library");
86  mActionSaveAs->setText("Save Gate Library As");
87  connect(mActionCreate, &Action::triggered, mGatelibReference, &GateLibraryManager::handleCreateAction);
88  connect(mActionOpen, &Action::triggered, mMainWindowReference, &MainWindow::handleActionGatelibraryManager);
89  connect(mActionClose, &Action::triggered, mGatelibReference, &GateLibraryManager::handleCancelClicked);
90  connect(mActionSave, &Action::triggered, mGatelibReference, &GateLibraryManager::handleSaveAction);
91  connect(mActionSaveAs, &Action::triggered, mGatelibReference, &GateLibraryManager::handleSaveAsAction);
92  mActionCreate->setEnabled(!mGatelibReference->isReadOnly());
93  mActionOpen->setEnabled(!mGatelibReference->isReadOnly());
96  }
97  else if (mGuiPluginReference)
98  {
99  mActionCreate->setText("");
100  mActionOpen->setText("Load HAL Plugin");
101  mActionClose->setText("Close Plugin Manager");
102  mActionSave->setText("");
103  mActionSaveAs->setText("");
104  connect(mActionOpen, &Action::triggered, mGuiPluginReference, &GuiPluginManager::handleLoadExternalPlugin);
105  connect(mActionClose, &Action::triggered, mGuiPluginReference, &GuiPluginManager::handleButtonCancel);
106  mActionCreate->setDisabled(true);
107  mActionOpen->setEnabled(true);
108  mActionSave->setDisabled(true);
109  mActionSaveAs->setDisabled(true);
110  }
111  else
112  {
113  mActionCreate->setText("New Project");
114  mActionCreate->setEnabled(true);
115  mActionOpen->setText("Open Project");
116  mActionClose->setText("Close Project");
117  mActionSave->setText("Save HAL Project");
118  mActionSaveAs->setText("Save HAL Project As");
119  connect(mActionCreate, &Action::triggered, mMainWindowReference, &MainWindow::handleActionNew);
120  connect(mActionOpen, &Action::triggered, mMainWindowReference, &MainWindow::handleActionOpenProject);
121  connect(mActionClose, &Action::triggered, mMainWindowReference, &MainWindow::handleActionCloseFile);
122  connect(mActionSave, &Action::triggered, mMainWindowReference, &MainWindow::handleSaveTriggered);
123  connect(mActionSaveAs, &Action::triggered, mMainWindowReference, &MainWindow::handleSaveAsTriggered);
124  mActionCreate->setEnabled(true);
125  mActionOpen->setEnabled(true);
128  }
129  }
130 }
Provides an interface for triggerable functionality that can be inserted into widgets and also connec...
Definition: action.h:42
void setText(const QString &text)
Definition: action.cpp:21
void handleFileStatusChanged(bool gateLibrary, bool isDirty)
FileActions(QWidget *parent=nullptr)
void setup(GateLibraryManager *glcw=nullptr, GuiPluginManager *plmgr=nullptr)
void status_changed(bool gateLibrary, bool isDirty)
The top level widget.
Definition: main_window.h:65
void handleActionOpenProject()
void handleActionGatelibraryManager()
void handleSaveAsTriggered()
void handleActionCloseFile()
void handleActionNew()
void handleSaveTriggered()
A SettingsItem to modify keybinds.
void keySequenceChanged(QKeySequence value)
virtual QVariant value() const override
QIcon getStyledSvgIcon(const QString &from_to_colors_enabled, const QString &svg_path, QString from_to_colors_disabled=QString())
Definition: graphics.cpp:60
FileStatusManager * gFileStatusManager
Definition: plugin_gui.cpp:84
void setEnabled(bool)
void setIcon(const QIcon &icon)
void setDisabled(bool b)
void trigger()
void triggered(bool checked)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QObject * parent() const const
void activated()
void setKey(const QKeySequence &key)
virtual void polish(QWidget *widget)
virtual void unpolish(QWidget *widget)
QString toString() const const
void hide()
QStyle * style() const const