From 6185ca7110b18531b731e987dcbf5b540cdf3838 Mon Sep 17 00:00:00 2001 From: "G.K.MacGregor" Date: Sun, 13 Aug 2023 21:39:25 +0100 Subject: [PATCH] Make full screen+row colours and CLUT remapping undoable --- document.h | 1 + levelonecommands.cpp | 155 +++++++++++++++++++++++++++++++++ levelonecommands.h | 64 ++++++++++++++ mainwidget.cpp | 27 ------ mainwidget.h | 4 - mainwindow.cpp | 1 + pageenhancementsdockwidget.cpp | 10 ++- 7 files changed, 227 insertions(+), 35 deletions(-) diff --git a/document.h b/document.h index d2e3fa1..7929593 100644 --- a/document.h +++ b/document.h @@ -108,6 +108,7 @@ signals: void selectionMoved(); void colourChanged(int); void contentsChange(int); + void pageOptionsChanged(); void aboutToChangeSubPage(); void subPageSelected(); void refreshNeeded(); diff --git a/levelonecommands.cpp b/levelonecommands.cpp index a5c8eaa..77a8e9d 100644 --- a/levelonecommands.cpp +++ b/levelonecommands.cpp @@ -732,6 +732,161 @@ void DeleteSubPageCommand::undo() } +SetFullScreenColourCommand::SetFullScreenColourCommand(TeletextDocument *teletextDocument, int newColour, QUndoCommand *parent) : LevelOneCommand(teletextDocument, parent) +{ + m_oldColour = teletextDocument->currentSubPage()->defaultScreenColour(); + m_newColour = newColour; + + setText(QObject::tr("full screen colour")); +} + +void SetFullScreenColourCommand::redo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setDefaultScreenColour(m_newColour); + + emit m_teletextDocument->refreshNeeded(); + emit m_teletextDocument->pageOptionsChanged(); +} + +void SetFullScreenColourCommand::undo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setDefaultScreenColour(m_oldColour); + + emit m_teletextDocument->refreshNeeded(); + emit m_teletextDocument->pageOptionsChanged(); +} + +bool SetFullScreenColourCommand::mergeWith(const QUndoCommand *command) +{ + const SetFullScreenColourCommand *newerCommand = static_cast(command); + + if (m_subPageIndex != newerCommand->m_subPageIndex) + return false; + + m_newColour = newerCommand->m_newColour; + + return true; +} + + +SetFullRowColourCommand::SetFullRowColourCommand(TeletextDocument *teletextDocument, int newColour, QUndoCommand *parent) : LevelOneCommand(teletextDocument, parent) +{ + m_oldColour = teletextDocument->currentSubPage()->defaultRowColour(); + m_newColour = newColour; + + setText(QObject::tr("full row colour")); +} + +void SetFullRowColourCommand::redo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setDefaultRowColour(m_newColour); + + emit m_teletextDocument->refreshNeeded(); + emit m_teletextDocument->pageOptionsChanged(); +} + +void SetFullRowColourCommand::undo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setDefaultRowColour(m_oldColour); + + emit m_teletextDocument->refreshNeeded(); + emit m_teletextDocument->pageOptionsChanged(); +} + +bool SetFullRowColourCommand::mergeWith(const QUndoCommand *command) +{ + const SetFullRowColourCommand *newerCommand = static_cast(command); + + if (m_subPageIndex != newerCommand->m_subPageIndex) + return false; + + m_newColour = newerCommand->m_newColour; + + return true; +} + + +SetCLUTRemapCommand::SetCLUTRemapCommand(TeletextDocument *teletextDocument, int newMap, QUndoCommand *parent) : LevelOneCommand(teletextDocument, parent) +{ + m_oldMap = teletextDocument->currentSubPage()->colourTableRemap(); + m_newMap = newMap; + + setText(QObject::tr("CLUT remapping")); +} + +void SetCLUTRemapCommand::redo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setColourTableRemap(m_newMap); + + emit m_teletextDocument->refreshNeeded(); + emit m_teletextDocument->pageOptionsChanged(); +} + +void SetCLUTRemapCommand::undo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setColourTableRemap(m_oldMap); + + emit m_teletextDocument->refreshNeeded(); + emit m_teletextDocument->pageOptionsChanged(); +} + +bool SetCLUTRemapCommand::mergeWith(const QUndoCommand *command) +{ + const SetCLUTRemapCommand *newerCommand = static_cast(command); + + if (m_subPageIndex != newerCommand->m_subPageIndex) + return false; + + m_newMap = newerCommand->m_newMap; + + return true; +} + + +SetBlackBackgroundSubstCommand::SetBlackBackgroundSubstCommand(TeletextDocument *teletextDocument, bool newSub, QUndoCommand *parent) : LevelOneCommand(teletextDocument, parent) +{ + m_oldSub = teletextDocument->currentSubPage()->blackBackgroundSubst(); + m_newSub = newSub; + + setText(QObject::tr("black background substitution")); +} + +void SetBlackBackgroundSubstCommand::redo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setBlackBackgroundSubst(m_newSub); + + emit m_teletextDocument->refreshNeeded(); + emit m_teletextDocument->pageOptionsChanged(); +} + +void SetBlackBackgroundSubstCommand::undo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setBlackBackgroundSubst(m_oldSub); + + emit m_teletextDocument->refreshNeeded(); + emit m_teletextDocument->pageOptionsChanged(); +} + +bool SetBlackBackgroundSubstCommand::mergeWith(const QUndoCommand *command) +{ + const SetBlackBackgroundSubstCommand *newerCommand = static_cast(command); + + if (m_subPageIndex != newerCommand->m_subPageIndex) + return false; + + setObsolete(true); + return true; +} + + SetColourCommand::SetColourCommand(TeletextDocument *teletextDocument, int colourIndex, int newColour, QUndoCommand *parent) : LevelOneCommand(teletextDocument, parent) { m_colourIndex = colourIndex; diff --git a/levelonecommands.h b/levelonecommands.h index 45945c2..bf7739b 100644 --- a/levelonecommands.h +++ b/levelonecommands.h @@ -183,6 +183,70 @@ private: }; #endif // !QT_NO_CLIPBOARD +class SetFullScreenColourCommand : public LevelOneCommand +{ +public: + enum { Id = 105 }; + + SetFullScreenColourCommand(TeletextDocument *, int, QUndoCommand *parent = 0); + + void redo() override; + void undo() override; + bool mergeWith(const QUndoCommand *) override; + int id() const override { return Id; } + +private: + int m_oldColour, m_newColour; +}; + +class SetFullRowColourCommand : public LevelOneCommand +{ +public: + enum { Id = 106 }; + + SetFullRowColourCommand(TeletextDocument *, int, QUndoCommand *parent = 0); + + void redo() override; + void undo() override; + bool mergeWith(const QUndoCommand *) override; + int id() const override { return Id; } + +private: + int m_oldColour, m_newColour; +}; + +class SetCLUTRemapCommand : public LevelOneCommand +{ +public: + enum { Id = 107 }; + + SetCLUTRemapCommand(TeletextDocument *, int, QUndoCommand *parent = 0); + + void redo() override; + void undo() override; + bool mergeWith(const QUndoCommand *) override; + int id() const override { return Id; } + +private: + int m_oldMap, m_newMap; +}; + +class SetBlackBackgroundSubstCommand : public LevelOneCommand +{ +public: + enum { Id = 108 }; + + SetBlackBackgroundSubstCommand(TeletextDocument *, bool, QUndoCommand *parent = 0); + + void redo() override; + void undo() override; + bool mergeWith(const QUndoCommand *) override; + int id() const override { return Id; } + +private: + int m_oldSub, m_newSub; +}; + class SetColourCommand : public LevelOneCommand { public: diff --git a/mainwidget.cpp b/mainwidget.cpp index 7643ee9..7af321e 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -200,33 +200,6 @@ void TeletextWidget::setDefaultNOS(int newDefaultNOS) m_levelOnePage->setDefaultNOS(newDefaultNOS); } -void TeletextWidget::setDefaultScreenColour(int newColour) -{ - m_levelOnePage->setDefaultScreenColour(newColour); - m_pageDecode.decodePage(); -} - -void TeletextWidget::setDefaultRowColour(int newColour) -{ - m_levelOnePage->setDefaultRowColour(newColour); - m_pageDecode.decodePage(); - update(); -} - -void TeletextWidget::setColourTableRemap(int newMap) -{ - m_levelOnePage->setColourTableRemap(newMap); - m_pageDecode.decodePage(); - update(); -} - -void TeletextWidget::setBlackBackgroundSubst(bool substOn) -{ - m_levelOnePage->setBlackBackgroundSubst(substOn); - m_pageDecode.decodePage(); - update(); -} - void TeletextWidget::setSidePanelWidths(int newLeftSidePanelColumns, int newRightSidePanelColumns) { m_levelOnePage->setLeftSidePanelDisplayed(newLeftSidePanelColumns != 0); diff --git a/mainwidget.h b/mainwidget.h index 7eab007..2ac6c06 100644 --- a/mainwidget.h +++ b/mainwidget.h @@ -74,10 +74,6 @@ public slots: void setControlBit(int, bool); void setDefaultCharSet(int); void setDefaultNOS(int); - void setDefaultScreenColour(int); - void setDefaultRowColour(int); - void setColourTableRemap(int); - void setBlackBackgroundSubst(bool); void setSidePanelWidths(int, int); void setSidePanelAtL35Only(bool); diff --git a/mainwindow.cpp b/mainwindow.cpp index ea31a29..5b85174 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -285,6 +285,7 @@ void MainWindow::init() connect(m_textWidget->document()->undoStack(), &QUndoStack::cleanChanged, this, [=]() { setWindowModified(!m_textWidget->document()->undoStack()->isClean()); } ); connect(m_textWidget->document(), &TeletextDocument::aboutToChangeSubPage, m_x26DockWidget, &X26DockWidget::unloadX26List); connect(m_textWidget->document(), &TeletextDocument::subPageSelected, this, &MainWindow::updatePageWidgets); + connect(m_textWidget->document(), &TeletextDocument::pageOptionsChanged, this, &MainWindow::updatePageWidgets); connect(m_textWidget, &TeletextWidget::sizeChanged, this, &MainWindow::setSceneDimensions); connect(m_textWidget->pageDecode(), &TeletextPageDecode::fullScreenColourChanged, m_textScene, &LevelOneScene::setFullScreenColour); connect(m_textWidget->pageDecode(), &TeletextPageDecode::fullRowColourChanged, m_textScene, &LevelOneScene::setFullRowColour); diff --git a/pageenhancementsdockwidget.cpp b/pageenhancementsdockwidget.cpp index 921b5fc..1a93a57 100644 --- a/pageenhancementsdockwidget.cpp +++ b/pageenhancementsdockwidget.cpp @@ -26,6 +26,8 @@ #include "pageenhancementsdockwidget.h" +#include "levelonecommands.h" + PageEnhancementsDockWidget::PageEnhancementsDockWidget(TeletextWidget *parent): QDockWidget(parent) { QVBoxLayout *pageEnhancementsLayout = new QVBoxLayout; @@ -48,9 +50,9 @@ PageEnhancementsDockWidget::PageEnhancementsDockWidget(TeletextWidget *parent): m_defaultRowColourCombo = new QComboBox; m_defaultRowColourCombo->setModel(m_parentMainWidget->document()->clutModel()); colourLayout->addWidget(m_defaultScreenColourCombo, 0, 1, 1, 1, Qt::AlignTop); - connect(m_defaultScreenColourCombo, QOverload::of(&QComboBox::currentIndexChanged), [=](int index){ m_parentMainWidget->setDefaultScreenColour(index); }); + connect(m_defaultScreenColourCombo, QOverload::of(&QComboBox::currentIndexChanged), [=](int index){ m_parentMainWidget->document()->undoStack()->push(new SetFullScreenColourCommand(m_parentMainWidget->document(), index)); }); colourLayout->addWidget(m_defaultRowColourCombo, 1, 1, 1, 1, Qt::AlignTop); - connect(m_defaultRowColourCombo, QOverload::of(&QComboBox::currentIndexChanged), [=](int index){ m_parentMainWidget->setDefaultRowColour(index); }); + connect(m_defaultRowColourCombo, QOverload::of(&QComboBox::currentIndexChanged), [=](int index){ m_parentMainWidget->document()->undoStack()->push(new SetFullRowColourCommand(m_parentMainWidget->document(), index)); }); // CLUT remapping colourLayout->addWidget(new QLabel(tr("CLUT remapping")), 2, 0, 1, 1); @@ -64,12 +66,12 @@ PageEnhancementsDockWidget::PageEnhancementsDockWidget(TeletextWidget *parent): m_colourTableCombo->addItem("Fore 2 Back 2"); m_colourTableCombo->addItem("Fore 2 Back 3"); colourLayout->addWidget(m_colourTableCombo, 2, 1, 1, 1, Qt::AlignTop); - connect(m_colourTableCombo, QOverload::of(&QComboBox::currentIndexChanged), [=](int index){ m_parentMainWidget->setColourTableRemap(index); }); + connect(m_colourTableCombo, QOverload::of(&QComboBox::currentIndexChanged), [=](int index){ m_parentMainWidget->document()->undoStack()->push(new SetCLUTRemapCommand(m_parentMainWidget->document(), index)); }); // Black background colour substitution m_blackBackgroundSubstAct = new QCheckBox("Black background colour substitution"); colourLayout->addWidget(m_blackBackgroundSubstAct, 3, 0, 1, 2, Qt::AlignTop); - connect(m_blackBackgroundSubstAct, &QCheckBox::stateChanged, m_parentMainWidget, &TeletextWidget::setBlackBackgroundSubst); + connect(m_blackBackgroundSubstAct, &QCheckBox::stateChanged, [=](int state){ m_parentMainWidget->document()->undoStack()->push(new SetBlackBackgroundSubstCommand(m_parentMainWidget->document(), state)); }); // Add group box to the main layout colourGroupBox->setLayout(colourLayout);