From 98071d823c8a84b729169604ce24a14a3fc62db9 Mon Sep 17 00:00:00 2001 From: "G.K.MacGregor" Date: Tue, 9 Jul 2024 18:01:17 +0100 Subject: [PATCH] Split out X28 commands --- levelonecommands.cpp | 216 ----------------------------- levelonecommands.h | 89 ------------ pageenhancementsdockwidget.cpp | 2 +- palettedockwidget.cpp | 2 +- qteletextmaker.pro | 6 +- x28commands.cpp | 243 +++++++++++++++++++++++++++++++++ x28commands.h | 126 +++++++++++++++++ 7 files changed, 375 insertions(+), 309 deletions(-) create mode 100644 x28commands.cpp create mode 100644 x28commands.h diff --git a/levelonecommands.cpp b/levelonecommands.cpp index 1d3e8ed..73a4c60 100644 --- a/levelonecommands.cpp +++ b/levelonecommands.cpp @@ -804,219 +804,3 @@ void DeleteSubPageCommand::undo() m_teletextDocument->unDeleteSubPageFromRecycle(m_subPageIndex); m_teletextDocument->selectSubPageIndex(m_subPageIndex, true); } - - -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->contentsChanged(); - emit m_teletextDocument->pageOptionsChanged(); -} - -void SetFullScreenColourCommand::undo() -{ - m_teletextDocument->selectSubPageIndex(m_subPageIndex); - m_teletextDocument->currentSubPage()->setDefaultScreenColour(m_oldColour); - - emit m_teletextDocument->contentsChanged(); - 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->contentsChanged(); - emit m_teletextDocument->pageOptionsChanged(); -} - -void SetFullRowColourCommand::undo() -{ - m_teletextDocument->selectSubPageIndex(m_subPageIndex); - m_teletextDocument->currentSubPage()->setDefaultRowColour(m_oldColour); - - emit m_teletextDocument->contentsChanged(); - 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->contentsChanged(); - emit m_teletextDocument->pageOptionsChanged(); -} - -void SetCLUTRemapCommand::undo() -{ - m_teletextDocument->selectSubPageIndex(m_subPageIndex); - m_teletextDocument->currentSubPage()->setColourTableRemap(m_oldMap); - - emit m_teletextDocument->contentsChanged(); - 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->contentsChanged(); - emit m_teletextDocument->pageOptionsChanged(); -} - -void SetBlackBackgroundSubstCommand::undo() -{ - m_teletextDocument->selectSubPageIndex(m_subPageIndex); - m_teletextDocument->currentSubPage()->setBlackBackgroundSubst(m_oldSub); - - emit m_teletextDocument->contentsChanged(); - 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; - m_oldColour = teletextDocument->currentSubPage()->CLUT(colourIndex); - m_newColour = newColour; - - setText(QObject::tr("colour change")); - -} - -void SetColourCommand::redo() -{ - m_teletextDocument->selectSubPageIndex(m_subPageIndex); - m_teletextDocument->currentSubPage()->setCLUT(m_colourIndex, m_newColour); - - emit m_teletextDocument->colourChanged(m_colourIndex); - emit m_teletextDocument->contentsChanged(); -} - -void SetColourCommand::undo() -{ - m_teletextDocument->selectSubPageIndex(m_subPageIndex); - m_teletextDocument->currentSubPage()->setCLUT(m_colourIndex, m_oldColour); - - emit m_teletextDocument->colourChanged(m_colourIndex); - emit m_teletextDocument->contentsChanged(); -} - - -ResetCLUTCommand::ResetCLUTCommand(TeletextDocument *teletextDocument, int colourTable, QUndoCommand *parent) : LevelOneCommand(teletextDocument, parent) -{ - m_colourTable = colourTable; - for (int i=m_colourTable*8; icurrentSubPage()->CLUT(i); - - setText(QObject::tr("CLUT %1 reset").arg(m_colourTable)); -} - -void ResetCLUTCommand::redo() -{ - m_teletextDocument->selectSubPageIndex(m_subPageIndex); - for (int i=m_colourTable*8; icurrentSubPage()->setCLUT(i, m_teletextDocument->currentSubPage()->CLUT(i, 0)); - emit m_teletextDocument->colourChanged(i); - } - - emit m_teletextDocument->contentsChanged(); -} - -void ResetCLUTCommand::undo() -{ - m_teletextDocument->selectSubPageIndex(m_subPageIndex); - for (int i=m_colourTable*8; icurrentSubPage()->setCLUT(i, m_oldColourEntry[i&7]); - emit m_teletextDocument->colourChanged(i); - } - - emit m_teletextDocument->contentsChanged(); -} diff --git a/levelonecommands.h b/levelonecommands.h index caf02f3..70ed0c0 100644 --- a/levelonecommands.h +++ b/levelonecommands.h @@ -194,93 +194,4 @@ private: }; #endif // !QT_NO_CLIPBOARD -class SetFullScreenColourCommand : public LevelOneCommand -{ -public: - enum { Id = 105 }; - - SetFullScreenColourCommand(TeletextDocument *teletextDocument, int newColour, QUndoCommand *parent = 0); - - void redo() override; - void undo() override; - bool mergeWith(const QUndoCommand *command) override; - int id() const override { return Id; } - -private: - int m_oldColour, m_newColour; -}; - -class SetFullRowColourCommand : public LevelOneCommand -{ -public: - enum { Id = 106 }; - - SetFullRowColourCommand(TeletextDocument *teletextDocument, int newColour, QUndoCommand *parent = 0); - - void redo() override; - void undo() override; - bool mergeWith(const QUndoCommand *command) override; - int id() const override { return Id; } - -private: - int m_oldColour, m_newColour; -}; - -class SetCLUTRemapCommand : public LevelOneCommand -{ -public: - enum { Id = 107 }; - - SetCLUTRemapCommand(TeletextDocument *teletextDocument, int newMap, QUndoCommand *parent = 0); - - void redo() override; - void undo() override; - bool mergeWith(const QUndoCommand *command) override; - int id() const override { return Id; } - -private: - int m_oldMap, m_newMap; -}; - -class SetBlackBackgroundSubstCommand : public LevelOneCommand -{ -public: - enum { Id = 108 }; - - SetBlackBackgroundSubstCommand(TeletextDocument *teletextDocument, bool newSub, QUndoCommand *parent = 0); - - void redo() override; - void undo() override; - bool mergeWith(const QUndoCommand *command) override; - int id() const override { return Id; } - -private: - int m_oldSub, m_newSub; -}; - -class SetColourCommand : public LevelOneCommand -{ -public: - SetColourCommand(TeletextDocument *teletextDocument, int colourIndex, int newColour, QUndoCommand *parent = 0); - - void redo() override; - void undo() override; - -private: - int m_colourIndex, m_oldColour, m_newColour; -}; - -class ResetCLUTCommand : public LevelOneCommand -{ -public: - ResetCLUTCommand(TeletextDocument *teletextDocument, int colourTable, QUndoCommand *parent = 0); - - void redo() override; - void undo() override; - -private: - int m_colourTable; - int m_oldColourEntry[8]; -}; - #endif diff --git a/pageenhancementsdockwidget.cpp b/pageenhancementsdockwidget.cpp index d29ba73..ed1ae12 100644 --- a/pageenhancementsdockwidget.cpp +++ b/pageenhancementsdockwidget.cpp @@ -26,7 +26,7 @@ #include "pageenhancementsdockwidget.h" -#include "levelonecommands.h" +#include "x28commands.h" PageEnhancementsDockWidget::PageEnhancementsDockWidget(TeletextWidget *parent): QDockWidget(parent) { diff --git a/palettedockwidget.cpp b/palettedockwidget.cpp index 4600530..023a8e2 100644 --- a/palettedockwidget.cpp +++ b/palettedockwidget.cpp @@ -28,7 +28,7 @@ #include "palettedockwidget.h" -#include "levelonecommands.h" +#include "x28commands.h" #include "document.h" #include "mainwidget.h" diff --git a/qteletextmaker.pro b/qteletextmaker.pro index 31dceca..cd78884 100644 --- a/qteletextmaker.pro +++ b/qteletextmaker.pro @@ -21,7 +21,8 @@ HEADERS = decode.h \ x26dockwidget.h \ x26menus.h \ x26model.h \ - x26triplets.h + x26triplets.h \ + x28commands.h SOURCES = decode.cpp \ document.cpp \ levelonecommands.cpp \ @@ -41,7 +42,8 @@ SOURCES = decode.cpp \ x26dockwidget.cpp \ x26menus.cpp \ x26model.cpp \ - x26triplets.cpp + x26triplets.cpp \ + x28commands.cpp RESOURCES = qteletextmaker.qrc # install diff --git a/x28commands.cpp b/x28commands.cpp new file mode 100644 index 0000000..5ba7da8 --- /dev/null +++ b/x28commands.cpp @@ -0,0 +1,243 @@ +/* + * Copyright (C) 2020-2024 Gavin MacGregor + * + * This file is part of QTeletextMaker. + * + * QTeletextMaker is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QTeletextMaker is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QTeletextMaker. If not, see . + */ + +#include "x28commands.h" + +#include "document.h" + +X28Command::X28Command(TeletextDocument *teletextDocument, QUndoCommand *parent) : QUndoCommand(parent) +{ + m_teletextDocument = teletextDocument; + m_subPageIndex = teletextDocument->currentSubPageIndex(); +} + + +SetFullScreenColourCommand::SetFullScreenColourCommand(TeletextDocument *teletextDocument, int newColour, QUndoCommand *parent) : X28Command(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->contentsChanged(); + emit m_teletextDocument->pageOptionsChanged(); +} + +void SetFullScreenColourCommand::undo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setDefaultScreenColour(m_oldColour); + + emit m_teletextDocument->contentsChanged(); + 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) : X28Command(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->contentsChanged(); + emit m_teletextDocument->pageOptionsChanged(); +} + +void SetFullRowColourCommand::undo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setDefaultRowColour(m_oldColour); + + emit m_teletextDocument->contentsChanged(); + 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) : X28Command(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->contentsChanged(); + emit m_teletextDocument->pageOptionsChanged(); +} + +void SetCLUTRemapCommand::undo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setColourTableRemap(m_oldMap); + + emit m_teletextDocument->contentsChanged(); + 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) : X28Command(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->contentsChanged(); + emit m_teletextDocument->pageOptionsChanged(); +} + +void SetBlackBackgroundSubstCommand::undo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setBlackBackgroundSubst(m_oldSub); + + emit m_teletextDocument->contentsChanged(); + 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) : X28Command(teletextDocument, parent) +{ + m_colourIndex = colourIndex; + m_oldColour = teletextDocument->currentSubPage()->CLUT(colourIndex); + m_newColour = newColour; + + setText(QObject::tr("colour change")); +} + +void SetColourCommand::redo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setCLUT(m_colourIndex, m_newColour); + + emit m_teletextDocument->colourChanged(m_colourIndex); + emit m_teletextDocument->contentsChanged(); +} + +void SetColourCommand::undo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + m_teletextDocument->currentSubPage()->setCLUT(m_colourIndex, m_oldColour); + + emit m_teletextDocument->colourChanged(m_colourIndex); + emit m_teletextDocument->contentsChanged(); +} + + +ResetCLUTCommand::ResetCLUTCommand(TeletextDocument *teletextDocument, int colourTable, QUndoCommand *parent) : X28Command(teletextDocument, parent) +{ + m_colourTable = colourTable; + for (int i=m_colourTable*8; icurrentSubPage()->CLUT(i); + + setText(QObject::tr("CLUT %1 reset").arg(m_colourTable)); +} + +void ResetCLUTCommand::redo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + for (int i=m_colourTable*8; icurrentSubPage()->setCLUT(i, m_teletextDocument->currentSubPage()->CLUT(i, 0)); + emit m_teletextDocument->colourChanged(i); + } + + emit m_teletextDocument->contentsChanged(); +} + +void ResetCLUTCommand::undo() +{ + m_teletextDocument->selectSubPageIndex(m_subPageIndex); + for (int i=m_colourTable*8; icurrentSubPage()->setCLUT(i, m_oldColourEntry[i&7]); + emit m_teletextDocument->colourChanged(i); + } + + emit m_teletextDocument->contentsChanged(); +} diff --git a/x28commands.h b/x28commands.h new file mode 100644 index 0000000..e0440ab --- /dev/null +++ b/x28commands.h @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2020-2024 Gavin MacGregor + * + * This file is part of QTeletextMaker. + * + * QTeletextMaker is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QTeletextMaker is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QTeletextMaker. If not, see . + */ + +#ifndef X28COMMANDS_H +#define X28COMMANDS_H + +#include + +#include "document.h" + +class X28Command : public QUndoCommand +{ +public: + X28Command(TeletextDocument *teletextDocument, QUndoCommand *parent = 0); + +protected: + TeletextDocument *m_teletextDocument; + int m_subPageIndex; +}; + +class SetFullScreenColourCommand : public X28Command +{ +public: + enum { Id = 301 }; + + SetFullScreenColourCommand(TeletextDocument *teletextDocument, int newColour, QUndoCommand *parent = 0); + + void redo() override; + void undo() override; + bool mergeWith(const QUndoCommand *command) override; + int id() const override { return Id; } + +private: + int m_oldColour, m_newColour; +}; + +class SetFullRowColourCommand : public X28Command +{ +public: + enum { Id = 302 }; + + SetFullRowColourCommand(TeletextDocument *teletextDocument, int newColour, QUndoCommand *parent = 0); + + void redo() override; + void undo() override; + bool mergeWith(const QUndoCommand *command) override; + int id() const override { return Id; } + +private: + int m_oldColour, m_newColour; +}; + +class SetCLUTRemapCommand : public X28Command +{ +public: + enum { Id = 303 }; + + SetCLUTRemapCommand(TeletextDocument *teletextDocument, int newMap, QUndoCommand *parent = 0); + + void redo() override; + void undo() override; + bool mergeWith(const QUndoCommand *command) override; + int id() const override { return Id; } + +private: + int m_oldMap, m_newMap; +}; + +class SetBlackBackgroundSubstCommand : public X28Command +{ +public: + enum { Id = 304 }; + + SetBlackBackgroundSubstCommand(TeletextDocument *teletextDocument, bool newSub, QUndoCommand *parent = 0); + + void redo() override; + void undo() override; + bool mergeWith(const QUndoCommand *command) override; + int id() const override { return Id; } + +private: + int m_oldSub, m_newSub; +}; + +class SetColourCommand : public X28Command +{ +public: + SetColourCommand(TeletextDocument *teletextDocument, int colourIndex, int newColour, QUndoCommand *parent = 0); + + void redo() override; + void undo() override; + +private: + int m_colourIndex, m_oldColour, m_newColour; +}; + +class ResetCLUTCommand : public X28Command +{ +public: + ResetCLUTCommand(TeletextDocument *teletextDocument, int colourTable, QUndoCommand *parent = 0); + + void redo() override; + void undo() override; + +private: + int m_colourTable; + int m_oldColourEntry[8]; +}; + +#endif