HAL  v4.5.0-133-g64838ea8d
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
file_actions.cpp
Go to the documentation of this file.
7 #include "gui/gui_globals.h"
8 
9 #include <QShortcut>
10 
11 namespace hal {
12 
14  : QWidget(parent), mGatelibReference(nullptr), mGuiPluginReference(nullptr)
15  {
16  repolish();
17  mMainWindowReference = dynamic_cast<MainWindow*>(parent);
18  mActionCreate = new Action(this);
19  mActionOpen = new Action(this);
20  mActionClose = new Action(this);
21  mActionSave = new Action(this);
22  mActionSaveAs = new Action(this);
23 
24  mActionCreate->setIcon(gui_utility::getStyledSvgIcon(mNewFileIconStyle, mNewFileIconPath, mDisabledIconStyle));
25  mActionOpen->setIcon(gui_utility::getStyledSvgIcon(mOpenProjIconStyle, mOpenProjIconPath, mDisabledIconStyle));
26  mActionClose->setIcon(gui_utility::getStyledSvgIcon(mCloseIconStyle, mCloseIconPath));
27  mActionSave->setIcon(gui_utility::getStyledSvgIcon(mEnabledIconStyle, mSaveIconPath, mDisabledIconStyle));
28  mActionSaveAs->setIcon(gui_utility::getStyledSvgIcon(mEnabledIconStyle, mSaveAsIconPath, mDisabledIconStyle));
29 
30  mSettingSaveFile =
31  new SettingsItemKeybind("HAL Shortcut 'Save File'", "keybinds/project_save_file", QKeySequence("Ctrl+S"), "Keybindings:Global", "Keybind for saving the currently opened file.");
32  mSettingCreateFile = new SettingsItemKeybind(
33  "HAL Shortcut 'Create Empty Netlist'", "keybinds/project_create_file", QKeySequence("Ctrl+N"), "Keybindings:Global", "Keybind for creating a new and empty netlist in HAL.");
34 
35  mSettingOpenFile = new SettingsItemKeybind("HAL Shortcut 'Open File'", "keybinds/project_open_file", QKeySequence("Ctrl+O"), "Keybindings:Global", "Keybind for opening a new File in HAL.");
36 
37  QShortcut* shortCutNewFile = new QShortcut(mSettingCreateFile->value().toString(), this);
38  QShortcut* shortCutOpenFile = new QShortcut(mSettingOpenFile->value().toString(), this);
39  QShortcut* shortCutSaveFile = new QShortcut(mSettingSaveFile->value().toString(), this);
40 
41  connect(mSettingCreateFile, &SettingsItemKeybind::keySequenceChanged, shortCutNewFile, &QShortcut::setKey);
42  connect(mSettingOpenFile, &SettingsItemKeybind::keySequenceChanged, shortCutOpenFile, &QShortcut::setKey);
43  connect(mSettingSaveFile, &SettingsItemKeybind::keySequenceChanged, shortCutSaveFile, &QShortcut::setKey);
44 
45  connect(shortCutNewFile, &QShortcut::activated, mActionCreate, &QAction::trigger);
46  connect(shortCutOpenFile, &QShortcut::activated, mActionOpen, &QAction::trigger);
47  connect(shortCutSaveFile, &QShortcut::activated, mActionSave, &QAction::trigger);
48 
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 gateLibraryAffected, bool isDirty)
64  {
65  Q_UNUSED(gateLibraryAffected);
66  mActionSave->setEnabled(isDirty);
67  }
68 
69 
70  void FileActions::handleFileOpenChanged(bool gateLibraryAffected, bool isOpen)
71  {
72  Q_UNUSED(gateLibraryAffected);
73  mActionSaveAs->setEnabled(isOpen);
74  }
75 
76 
78  {
79  mGatelibReference = glcw;
80  mGuiPluginReference = plmgr;
81  mActionCreate->disconnect();
82  mActionOpen->disconnect();
83  mActionClose->disconnect();
84  mActionSave->disconnect();
85  mActionSaveAs->disconnect();
86  if (mGatelibReference)
87  {
88  mActionCreate->setText("New Gate Library");
89  mActionOpen->setText("Open Gate Library");
90  mActionClose->setText("Close Gate Lib Manager");
91  mActionSave->setText("Save Gate Library");
92  mActionSaveAs->setText("Save Gate Library As");
93  connect(mActionCreate, &Action::triggered, mGatelibReference, &GateLibraryManager::handleCreateAction);
94  connect(mActionOpen, &Action::triggered, mMainWindowReference, &MainWindow::handleActionGatelibraryManager);
95  connect(mActionClose, &Action::triggered, mGatelibReference, &GateLibraryManager::handleCancelClicked);
96  connect(mActionSave, &Action::triggered, mGatelibReference, &GateLibraryManager::handleSaveAction);
97  connect(mActionSaveAs, &Action::triggered, mGatelibReference, &GateLibraryManager::handleSaveAsAction);
98  mActionCreate->setEnabled(!mGatelibReference->isReadOnly());
99  mActionOpen->setEnabled(!mGatelibReference->isReadOnly());
101  }
102  else if (mGuiPluginReference)
103  {
104  mActionCreate->setText("");
105  mActionOpen->setText("Load HAL Plugin");
106  mActionClose->setText("Close Plugin Manager");
107  mActionSave->setText("");
108  mActionSaveAs->setText("");
109  connect(mActionOpen, &Action::triggered, mGuiPluginReference, &GuiPluginManager::handleLoadExternalPlugin);
110  connect(mActionClose, &Action::triggered, mGuiPluginReference, &GuiPluginManager::handleButtonCancel);
111  mActionCreate->setDisabled(true);
112  mActionOpen->setEnabled(true);
113  mActionSave->setDisabled(true);
114  mActionSaveAs->setDisabled(true);
115  }
116  else
117  {
118  mActionCreate->setText("New Project");
119  mActionCreate->setEnabled(true);
120  mActionOpen->setText("Open Project");
121  mActionClose->setText("Close Project");
122  mActionSave->setText("Save HAL Project");
123  mActionSaveAs->setText("Save HAL Project As");
124  connect(mActionCreate, &Action::triggered, mMainWindowReference, &MainWindow::handleActionNew);
125  connect(mActionOpen, &Action::triggered, mMainWindowReference, &MainWindow::handleActionOpenProject);
126  connect(mActionClose, &Action::triggered, mMainWindowReference, &MainWindow::handleActionCloseFile);
127  connect(mActionSave, &Action::triggered, mMainWindowReference, &MainWindow::handleSaveTriggered);
128  connect(mActionSaveAs, &Action::triggered, mMainWindowReference, &MainWindow::handleSaveAsTriggered);
129  mActionCreate->setEnabled(true);
130  mActionOpen->setEnabled(true);
133  }
134  }
135 }
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
FileActions(QWidget *parent=nullptr)
void setup(GateLibraryManager *glcw=nullptr, GuiPluginManager *plmgr=nullptr)
void handleFileStatusChanged(bool gateLibraryAffected, bool isDirty)
void handleFileOpenChanged(bool gateLibraryAffected, bool isOpen)
void status_changed(bool gateLibraryAffected, bool isDirty)
void open_changed(bool gateLibraryAffected, bool isOpen)
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
Definition: defines.h:45
FileStatusManager * gFileStatusManager
Definition: plugin_gui.cpp:85
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