[nostalgia/studio] Add Cut action hook

This commit is contained in:
Gary Talent 2020-10-19 20:14:20 -05:00
parent 79acffcc29
commit 9effdad200
4 changed files with 41 additions and 0 deletions

View File

@ -13,6 +13,9 @@ namespace nostalgia::studio {
Editor::Editor(QWidget *parent): QWidget(parent) {
}
void Editor::cut() {
}
void Editor::copy() {
}
@ -49,6 +52,15 @@ bool Editor::exportable() const {
return m_exportable;
}
void Editor::setCutEnabled(bool v) {
m_cutEnabled = v;
emit cutEnabledChanged(v);
}
bool Editor::cutEnabled() const {
return m_cutEnabled;
}
void Editor::setCopyEnabled(bool v) {
m_copyEnabled = v;
emit copyEnabledChanged(v);

View File

@ -22,6 +22,7 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
QUndoStack m_cmdStack;
bool m_unsavedChanges = false;
bool m_exportable = false;
bool m_cutEnabled = false;
bool m_copyEnabled = false;
bool m_pasteEnabled = false;
@ -35,6 +36,8 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
*/
virtual QString itemName() const = 0;
virtual void cut();
virtual void copy();
virtual void paste();
@ -63,6 +66,10 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
[[nodiscard]] bool exportable() const;
void setCutEnabled(bool);
[[nodiscard]] bool cutEnabled() const;
void setCopyEnabled(bool);
[[nodiscard]] bool copyEnabled() const;
@ -82,6 +89,8 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
void exportableChanged(bool);
void cutEnabledChanged(bool);
void copyEnabledChanged(bool);
void pasteEnabledChanged(bool);

View File

@ -194,6 +194,17 @@ void MainWindow::setupMenu() {
editMenu->addSeparator();
// Copy
m_cutAction = addAction(
editMenu,
tr("&Cut"),
tr(""),
QKeySequence::Cut,
this,
SLOT(cutAction())
);
m_cutAction->setEnabled(false);
// Copy
m_copyAction = addAction(
editMenu,
@ -500,6 +511,10 @@ void MainWindow::exportFile() {
m_currentEditor->exportFile();
}
void MainWindow::cutAction() {
m_currentEditor->cut();
}
void MainWindow::copyAction() {
m_currentEditor->copy();
}
@ -533,6 +548,7 @@ void MainWindow::changeTab(int idx) {
disconnect(m_currentEditor, &Editor::unsavedChangesChanged, m_saveAction, &QAction::setEnabled);
disconnect(m_currentEditor, &Editor::unsavedChangesChanged, this, &MainWindow::markUnsavedChanges);
disconnect(m_currentEditor, &Editor::exportableChanged, m_exportAction, &QAction::setEnabled);
disconnect(m_currentEditor, &Editor::cutEnabledChanged, m_cutAction, &QAction::setEnabled);
disconnect(m_currentEditor, &Editor::copyEnabledChanged, m_copyAction, &QAction::setEnabled);
disconnect(m_currentEditor, &Editor::pasteEnabledChanged, m_pasteAction, &QAction::setEnabled);
}
@ -541,6 +557,7 @@ void MainWindow::changeTab(int idx) {
m_saveAction->setEnabled(m_currentEditor->unsavedChanges());
connect(m_currentEditor, &Editor::unsavedChangesChanged, m_saveAction, &QAction::setEnabled);
connect(m_currentEditor, &Editor::unsavedChangesChanged, this, &MainWindow::markUnsavedChanges);
connect(m_currentEditor, &Editor::cutEnabledChanged, m_cutAction, &QAction::setEnabled);
connect(m_currentEditor, &Editor::copyEnabledChanged, m_copyAction, &QAction::setEnabled);
connect(m_currentEditor, &Editor::pasteEnabledChanged, m_pasteAction, &QAction::setEnabled);
m_exportAction->setEnabled(m_currentEditor->exportable());

View File

@ -75,6 +75,7 @@ class MainWindow: public QMainWindow {
QAction *m_importAction = nullptr;
QAction *m_saveAction = nullptr;
QAction *m_exportAction = nullptr;
QAction *m_cutAction = nullptr;
QAction *m_copyAction = nullptr;
QAction *m_pasteAction = nullptr;
Context m_ctx;
@ -149,6 +150,8 @@ class MainWindow: public QMainWindow {
void exportFile();
void cutAction();
void copyAction();
void pasteAction();