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 
52  setup();
53  hide();
54  }
55 
57  {
58  QStyle* s = style();
59 
60  s->unpolish(this);
61  s->polish(this);
62  }
63 
64  void FileActions::handleFileStatusChanged(bool gateLibraryAffected, bool isDirty)
65  {
66  Q_UNUSED(gateLibraryAffected);
67  mActionSave->setEnabled(isDirty);
68  }
69 
70 
71  void FileActions::handleFileOpenChanged(bool gateLibraryAffected, bool isOpen)
72  {
73  Q_UNUSED(gateLibraryAffected);
74  mActionSaveAs->setEnabled(isOpen);
75  }
76 
77 
79  {
80  mGatelibReference = glcw;
81  mGuiPluginReference = plmgr;
82  mActionCreate->disconnect();
83  mActionOpen->disconnect();
84  mActionClose->disconnect();
85  mActionSave->disconnect();
86  mActionSaveAs->disconnect();
87  if (mGatelibReference)
88  {
89  mActionCreate->setText("New Gate Library");
90  mActionOpen->setText("Open Gate Library");
91  mActionClose->setText("Close Gate Lib Manager");
92  mActionSave->setText("Save Gate Library");
93  mActionSaveAs->setText("Save Gate Library As");
94  connect(mActionCreate, &Action::triggered, mGatelibReference, &GateLibraryManager::handleCreateAction);
95  connect(mActionOpen, &Action::triggered, mMainWindowReference, &MainWindow::handleActionGatelibraryManager);
96  connect(mActionClose, &Action::triggered, mGatelibReference, &GateLibraryManager::handleCancelClicked);
97  connect(mActionSave, &Action::triggered, mGatelibReference, &GateLibraryManager::handleSaveAction);
98  connect(mActionSaveAs, &Action::triggered, mGatelibReference, &GateLibraryManager::handleSaveAsAction);
99  mActionCreate->setEnabled(!mGatelibReference->isReadOnly());
100  mActionOpen->setEnabled(!mGatelibReference->isReadOnly());
102  }
103  else if (mGuiPluginReference)
104  {
105  mActionCreate->setText("");
106  mActionOpen->setText("Load HAL Plugin");
107  mActionClose->setText("Close Plugin Manager");
108  mActionSave->setText("");
109  mActionSaveAs->setText("");
110  connect(mActionOpen, &Action::triggered, mGuiPluginReference, &GuiPluginManager::handleLoadExternalPlugin);
111  connect(mActionClose, &Action::triggered, mGuiPluginReference, &GuiPluginManager::handleButtonCancel);
112  mActionCreate->setDisabled(true);
113  mActionOpen->setEnabled(true);
114  mActionSave->setDisabled(true);
115  mActionSaveAs->setDisabled(true);
116  }
117  else
118  {
119  mActionCreate->setText("New Project");
120  mActionCreate->setEnabled(true);
121  mActionOpen->setText("Open Project");
122  mActionClose->setText("Close Project");
123  mActionSave->setText("Save HAL Project");
124  mActionSaveAs->setText("Save HAL Project As");
125  connect(mActionCreate, &Action::triggered, mMainWindowReference, &MainWindow::handleActionNew);
126  connect(mActionOpen, &Action::triggered, mMainWindowReference, &MainWindow::handleActionOpenProject);
127  connect(mActionClose, &Action::triggered, mMainWindowReference, &MainWindow::handleActionCloseFile);
128  connect(mActionSave, &Action::triggered, mMainWindowReference, &MainWindow::handleSaveTriggered);
129  connect(mActionSaveAs, &Action::triggered, mMainWindowReference, &MainWindow::handleSaveAsTriggered);
130  mActionCreate->setEnabled(true);
131  mActionOpen->setEnabled(true);
134  }
135  }
136 }
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
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