Split out commands into their own file
This commit is contained in:
280
document.cpp
280
document.cpp
@@ -313,283 +313,3 @@ void TeletextDocument::cancelSelection()
|
||||
{
|
||||
m_selectionSubPage = nullptr;
|
||||
}
|
||||
|
||||
|
||||
OverwriteCharacterCommand::OverwriteCharacterCommand(TeletextDocument *teletextDocument, unsigned char newCharacter, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_row = teletextDocument->cursorRow();
|
||||
m_column = teletextDocument->cursorColumn();
|
||||
m_oldCharacter = teletextDocument->currentSubPage()->character(m_row, m_column);
|
||||
m_newCharacter = newCharacter;
|
||||
}
|
||||
|
||||
void OverwriteCharacterCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_newCharacter);
|
||||
m_teletextDocument->moveCursor(m_row, m_column);
|
||||
m_teletextDocument->cursorRight();
|
||||
setText(QObject::tr("overwrite char"));
|
||||
emit m_teletextDocument->contentsChange(m_row);
|
||||
}
|
||||
|
||||
void OverwriteCharacterCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_oldCharacter);
|
||||
m_teletextDocument->moveCursor(m_row, m_column);
|
||||
setText(QObject::tr("overwrite char"));
|
||||
emit m_teletextDocument->contentsChange(m_row);
|
||||
}
|
||||
|
||||
|
||||
ToggleMosaicBitCommand::ToggleMosaicBitCommand(TeletextDocument *teletextDocument, unsigned char bitToToggle, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_row = teletextDocument->cursorRow();
|
||||
m_column = teletextDocument->cursorColumn();
|
||||
m_oldCharacter = teletextDocument->currentSubPage()->character(m_row, m_column);
|
||||
if (bitToToggle == 0x20 || bitToToggle == 0x7f)
|
||||
m_newCharacter = bitToToggle;
|
||||
else
|
||||
m_newCharacter = m_oldCharacter ^ bitToToggle;
|
||||
}
|
||||
|
||||
void ToggleMosaicBitCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_newCharacter);
|
||||
m_teletextDocument->moveCursor(m_row, m_column);
|
||||
setText(QObject::tr("mosaic"));
|
||||
emit m_teletextDocument->contentsChange(m_row);
|
||||
}
|
||||
|
||||
void ToggleMosaicBitCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_oldCharacter);
|
||||
m_teletextDocument->moveCursor(m_row, m_column);
|
||||
setText(QObject::tr("mosaic"));
|
||||
emit m_teletextDocument->contentsChange(m_row);
|
||||
}
|
||||
|
||||
bool ToggleMosaicBitCommand::mergeWith(const QUndoCommand *command)
|
||||
{
|
||||
const ToggleMosaicBitCommand *previousCommand = static_cast<const ToggleMosaicBitCommand *>(command);
|
||||
|
||||
if (m_subPageIndex != previousCommand->m_subPageIndex || m_row != previousCommand->m_row || m_column != previousCommand->m_column)
|
||||
return false;
|
||||
m_newCharacter = previousCommand->m_newCharacter;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
BackspaceCommand::BackspaceCommand(TeletextDocument *teletextDocument, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_row = teletextDocument->cursorRow();
|
||||
m_column = teletextDocument->cursorColumn()-1;
|
||||
if (m_column == -1) {
|
||||
m_column = 39;
|
||||
if (--m_row == 0)
|
||||
m_row = 24;
|
||||
}
|
||||
m_deletedCharacter = teletextDocument->currentSubPage()->character(m_row, m_column);
|
||||
}
|
||||
|
||||
void BackspaceCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, 0x20);
|
||||
m_teletextDocument->moveCursor(m_row, m_column);
|
||||
setText(QObject::tr("backspace"));
|
||||
emit m_teletextDocument->contentsChange(m_row);
|
||||
}
|
||||
|
||||
void BackspaceCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_deletedCharacter);
|
||||
m_teletextDocument->moveCursor(m_row, m_column);
|
||||
m_teletextDocument->cursorRight();
|
||||
setText(QObject::tr("backspace"));
|
||||
emit m_teletextDocument->contentsChange(m_row);
|
||||
}
|
||||
|
||||
|
||||
InsertRowCommand::InsertRowCommand(TeletextDocument *teletextDocument, bool copyRow, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_row = teletextDocument->cursorRow();
|
||||
m_copyRow = copyRow;
|
||||
}
|
||||
|
||||
void InsertRowCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->moveCursor(m_row, -1);
|
||||
// Store copy of the bottom row we're about to push out, for undo
|
||||
for (int c=0; c<40; c++)
|
||||
m_deletedBottomRow[c] = m_teletextDocument->currentSubPage()->character(23, c);
|
||||
// Shuffle lines below the inserting row downwards without affecting the FastText row
|
||||
for (int r=22; r>=m_row; r--)
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(r+1, c, m_teletextDocument->currentSubPage()->character(r, c));
|
||||
if (m_copyRow)
|
||||
setText(QObject::tr("insert copy row"));
|
||||
else {
|
||||
// The above shuffle leaves a duplicate of the current row, so blank it if requested
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, c, ' ');
|
||||
setText(QObject::tr("insert blank row"));
|
||||
}
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
void InsertRowCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->moveCursor(m_row, -1);
|
||||
// Shuffle lines below the deleting row upwards without affecting the FastText row
|
||||
for (int r=m_row; r<23; r++)
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(r, c, m_teletextDocument->currentSubPage()->character(r+1, c));
|
||||
// Now repair the bottom row we pushed out
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(23, c, m_deletedBottomRow[c]);
|
||||
if (m_copyRow)
|
||||
setText(QObject::tr("insert copy row"));
|
||||
else
|
||||
setText(QObject::tr("insert blank row"));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
|
||||
DeleteRowCommand::DeleteRowCommand(TeletextDocument *teletextDocument, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_row = teletextDocument->cursorRow();
|
||||
}
|
||||
|
||||
void DeleteRowCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->moveCursor(m_row, -1);
|
||||
// Store copy of the row we're going to delete, for undo
|
||||
for (int c=0; c<40; c++)
|
||||
m_deletedRow[c] = m_teletextDocument->currentSubPage()->character(m_row, c);
|
||||
// Shuffle lines below the deleting row upwards without affecting the FastText row
|
||||
for (int r=m_row; r<23; r++)
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(r, c, m_teletextDocument->currentSubPage()->character(r+1, c));
|
||||
// If we deleted the FastText row blank that row, otherwise blank the last row
|
||||
int blankingRow = (m_row < 24) ? 23 : 24;
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(blankingRow, c, ' ');
|
||||
setText(QObject::tr("delete row"));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
void DeleteRowCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->moveCursor(m_row, -1);
|
||||
// Shuffle lines below the inserting row downwards without affecting the FastText row
|
||||
for (int r=22; r>=m_row; r--)
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(r+1, c, m_teletextDocument->currentSubPage()->character(r, c));
|
||||
// Now repair the row we deleted
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, c, m_deletedRow[c]);
|
||||
setText(QObject::tr("delete row"));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
|
||||
InsertSubPageCommand::InsertSubPageCommand(TeletextDocument *teletextDocument, bool afterCurrentSubPage, bool copySubPage, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_newSubPageIndex = teletextDocument->currentSubPageIndex()+afterCurrentSubPage;
|
||||
m_copySubPage = copySubPage;
|
||||
}
|
||||
|
||||
void InsertSubPageCommand::redo()
|
||||
{
|
||||
m_teletextDocument->insertSubPage(m_newSubPageIndex, m_copySubPage);
|
||||
m_teletextDocument->selectSubPageIndex(m_newSubPageIndex, true);
|
||||
setText(QObject::tr("insert subpage"));
|
||||
}
|
||||
|
||||
void InsertSubPageCommand::undo()
|
||||
{
|
||||
m_teletextDocument->deleteSubPage(m_newSubPageIndex);
|
||||
//TODO should we always wrench to "subpage viewed when we inserted"? Or just if subpage viewed is being deleted?
|
||||
m_teletextDocument->selectSubPageIndex(m_newSubPageIndex, true);
|
||||
setText(QObject::tr("insert subpage"));
|
||||
}
|
||||
|
||||
|
||||
SetColourCommand::SetColourCommand(TeletextDocument *teletextDocument, int colourIndex, int newColour, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_colourIndex = colourIndex;
|
||||
m_oldColour = teletextDocument->currentSubPage()->CLUT(colourIndex);
|
||||
m_newColour = newColour;
|
||||
}
|
||||
|
||||
void SetColourCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCLUT(m_colourIndex, m_newColour);
|
||||
emit m_teletextDocument->colourChanged(m_colourIndex);
|
||||
setText(QObject::tr("colour change"));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
void SetColourCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCLUT(m_colourIndex, m_oldColour);
|
||||
emit m_teletextDocument->colourChanged(m_colourIndex);
|
||||
setText(QObject::tr("colour change"));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
|
||||
ResetCLUTCommand::ResetCLUTCommand(TeletextDocument *teletextDocument, int colourTable, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_colourTable = colourTable;
|
||||
for (int i=m_colourTable*8; i<m_colourTable*8+8; i++)
|
||||
m_oldColourEntry[i&7] = teletextDocument->currentSubPage()->CLUT(i);
|
||||
}
|
||||
|
||||
void ResetCLUTCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
for (int i=m_colourTable*8; i<m_colourTable*8+8; i++) {
|
||||
m_teletextDocument->currentSubPage()->setCLUT(i, m_teletextDocument->currentSubPage()->CLUT(i, 0));
|
||||
emit m_teletextDocument->colourChanged(i);
|
||||
}
|
||||
setText(QObject::tr("CLUT %1 reset").arg(m_colourTable));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
void ResetCLUTCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
for (int i=m_colourTable*8; i<m_colourTable*8+8; i++) {
|
||||
m_teletextDocument->currentSubPage()->setCLUT(i, m_oldColourEntry[i&7]);
|
||||
emit m_teletextDocument->colourChanged(i);
|
||||
}
|
||||
setText(QObject::tr("CLUT %1 reset").arg(m_colourTable));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
117
document.h
117
document.h
@@ -23,7 +23,6 @@
|
||||
#include <QFile>
|
||||
#include <QObject>
|
||||
#include <QTextStream>
|
||||
#include <QUndoCommand>
|
||||
#include <QUndoStack>
|
||||
#include <vector>
|
||||
#include "levelonepage.h"
|
||||
@@ -89,120 +88,4 @@ private:
|
||||
LevelOnePage *m_selectionSubPage;
|
||||
};
|
||||
|
||||
|
||||
class OverwriteCharacterCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
OverwriteCharacterCommand(TeletextDocument *, unsigned char, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
unsigned char m_oldCharacter, m_newCharacter;
|
||||
int m_subPageIndex, m_row, m_column;
|
||||
};
|
||||
|
||||
class ToggleMosaicBitCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
enum { Id = 2 };
|
||||
|
||||
ToggleMosaicBitCommand(TeletextDocument *, unsigned char, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
bool mergeWith(const QUndoCommand *) override;
|
||||
int id() const override { return Id; }
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
unsigned char m_oldCharacter, m_newCharacter;
|
||||
int m_subPageIndex, m_row, m_column;
|
||||
};
|
||||
|
||||
class BackspaceCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
BackspaceCommand(TeletextDocument *, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
unsigned char m_deletedCharacter;
|
||||
int m_subPageIndex, m_row, m_column;
|
||||
};
|
||||
|
||||
class InsertSubPageCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
InsertSubPageCommand(TeletextDocument *, bool, bool, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
int m_newSubPageIndex;
|
||||
bool m_copySubPage;
|
||||
};
|
||||
|
||||
class InsertRowCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
InsertRowCommand(TeletextDocument *, bool, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
int m_subPageIndex, m_row;
|
||||
bool m_copyRow;
|
||||
unsigned char m_deletedBottomRow[40];
|
||||
};
|
||||
|
||||
class DeleteRowCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
DeleteRowCommand(TeletextDocument *, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
int m_subPageIndex, m_row;
|
||||
unsigned char m_deletedRow[40];
|
||||
};
|
||||
|
||||
class SetColourCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
SetColourCommand(TeletextDocument *, int, int, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
int m_subPageIndex, m_colourIndex, m_oldColour, m_newColour;
|
||||
};
|
||||
|
||||
class ResetCLUTCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
ResetCLUTCommand(TeletextDocument *, int, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
int m_subPageIndex, m_colourTable;
|
||||
int m_oldColourEntry[8];
|
||||
};
|
||||
#endif
|
||||
|
||||
301
levelonecommands.cpp
Normal file
301
levelonecommands.cpp
Normal file
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "levelonecommands.h"
|
||||
|
||||
#include "document.h"
|
||||
|
||||
OverwriteCharacterCommand::OverwriteCharacterCommand(TeletextDocument *teletextDocument, unsigned char newCharacter, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_row = teletextDocument->cursorRow();
|
||||
m_column = teletextDocument->cursorColumn();
|
||||
m_oldCharacter = teletextDocument->currentSubPage()->character(m_row, m_column);
|
||||
m_newCharacter = newCharacter;
|
||||
}
|
||||
|
||||
void OverwriteCharacterCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_newCharacter);
|
||||
m_teletextDocument->moveCursor(m_row, m_column);
|
||||
m_teletextDocument->cursorRight();
|
||||
setText(QObject::tr("overwrite char"));
|
||||
emit m_teletextDocument->contentsChange(m_row);
|
||||
}
|
||||
|
||||
void OverwriteCharacterCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_oldCharacter);
|
||||
m_teletextDocument->moveCursor(m_row, m_column);
|
||||
setText(QObject::tr("overwrite char"));
|
||||
emit m_teletextDocument->contentsChange(m_row);
|
||||
}
|
||||
|
||||
|
||||
ToggleMosaicBitCommand::ToggleMosaicBitCommand(TeletextDocument *teletextDocument, unsigned char bitToToggle, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_row = teletextDocument->cursorRow();
|
||||
m_column = teletextDocument->cursorColumn();
|
||||
m_oldCharacter = teletextDocument->currentSubPage()->character(m_row, m_column);
|
||||
if (bitToToggle == 0x20 || bitToToggle == 0x7f)
|
||||
m_newCharacter = bitToToggle;
|
||||
else
|
||||
m_newCharacter = m_oldCharacter ^ bitToToggle;
|
||||
}
|
||||
|
||||
void ToggleMosaicBitCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_newCharacter);
|
||||
m_teletextDocument->moveCursor(m_row, m_column);
|
||||
setText(QObject::tr("mosaic"));
|
||||
emit m_teletextDocument->contentsChange(m_row);
|
||||
}
|
||||
|
||||
void ToggleMosaicBitCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_oldCharacter);
|
||||
m_teletextDocument->moveCursor(m_row, m_column);
|
||||
setText(QObject::tr("mosaic"));
|
||||
emit m_teletextDocument->contentsChange(m_row);
|
||||
}
|
||||
|
||||
bool ToggleMosaicBitCommand::mergeWith(const QUndoCommand *command)
|
||||
{
|
||||
const ToggleMosaicBitCommand *previousCommand = static_cast<const ToggleMosaicBitCommand *>(command);
|
||||
|
||||
if (m_subPageIndex != previousCommand->m_subPageIndex || m_row != previousCommand->m_row || m_column != previousCommand->m_column)
|
||||
return false;
|
||||
m_newCharacter = previousCommand->m_newCharacter;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
BackspaceCommand::BackspaceCommand(TeletextDocument *teletextDocument, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_row = teletextDocument->cursorRow();
|
||||
m_column = teletextDocument->cursorColumn()-1;
|
||||
if (m_column == -1) {
|
||||
m_column = 39;
|
||||
if (--m_row == 0)
|
||||
m_row = 24;
|
||||
}
|
||||
m_deletedCharacter = teletextDocument->currentSubPage()->character(m_row, m_column);
|
||||
}
|
||||
|
||||
void BackspaceCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, 0x20);
|
||||
m_teletextDocument->moveCursor(m_row, m_column);
|
||||
setText(QObject::tr("backspace"));
|
||||
emit m_teletextDocument->contentsChange(m_row);
|
||||
}
|
||||
|
||||
void BackspaceCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_deletedCharacter);
|
||||
m_teletextDocument->moveCursor(m_row, m_column);
|
||||
m_teletextDocument->cursorRight();
|
||||
setText(QObject::tr("backspace"));
|
||||
emit m_teletextDocument->contentsChange(m_row);
|
||||
}
|
||||
|
||||
|
||||
InsertRowCommand::InsertRowCommand(TeletextDocument *teletextDocument, bool copyRow, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_row = teletextDocument->cursorRow();
|
||||
m_copyRow = copyRow;
|
||||
}
|
||||
|
||||
void InsertRowCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->moveCursor(m_row, -1);
|
||||
// Store copy of the bottom row we're about to push out, for undo
|
||||
for (int c=0; c<40; c++)
|
||||
m_deletedBottomRow[c] = m_teletextDocument->currentSubPage()->character(23, c);
|
||||
// Shuffle lines below the inserting row downwards without affecting the FastText row
|
||||
for (int r=22; r>=m_row; r--)
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(r+1, c, m_teletextDocument->currentSubPage()->character(r, c));
|
||||
if (m_copyRow)
|
||||
setText(QObject::tr("insert copy row"));
|
||||
else {
|
||||
// The above shuffle leaves a duplicate of the current row, so blank it if requested
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, c, ' ');
|
||||
setText(QObject::tr("insert blank row"));
|
||||
}
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
void InsertRowCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->moveCursor(m_row, -1);
|
||||
// Shuffle lines below the deleting row upwards without affecting the FastText row
|
||||
for (int r=m_row; r<23; r++)
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(r, c, m_teletextDocument->currentSubPage()->character(r+1, c));
|
||||
// Now repair the bottom row we pushed out
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(23, c, m_deletedBottomRow[c]);
|
||||
if (m_copyRow)
|
||||
setText(QObject::tr("insert copy row"));
|
||||
else
|
||||
setText(QObject::tr("insert blank row"));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
|
||||
DeleteRowCommand::DeleteRowCommand(TeletextDocument *teletextDocument, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_row = teletextDocument->cursorRow();
|
||||
}
|
||||
|
||||
void DeleteRowCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->moveCursor(m_row, -1);
|
||||
// Store copy of the row we're going to delete, for undo
|
||||
for (int c=0; c<40; c++)
|
||||
m_deletedRow[c] = m_teletextDocument->currentSubPage()->character(m_row, c);
|
||||
// Shuffle lines below the deleting row upwards without affecting the FastText row
|
||||
for (int r=m_row; r<23; r++)
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(r, c, m_teletextDocument->currentSubPage()->character(r+1, c));
|
||||
// If we deleted the FastText row blank that row, otherwise blank the last row
|
||||
int blankingRow = (m_row < 24) ? 23 : 24;
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(blankingRow, c, ' ');
|
||||
setText(QObject::tr("delete row"));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
void DeleteRowCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->moveCursor(m_row, -1);
|
||||
// Shuffle lines below the inserting row downwards without affecting the FastText row
|
||||
for (int r=22; r>=m_row; r--)
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(r+1, c, m_teletextDocument->currentSubPage()->character(r, c));
|
||||
// Now repair the row we deleted
|
||||
for (int c=0; c<40; c++)
|
||||
m_teletextDocument->currentSubPage()->setCharacter(m_row, c, m_deletedRow[c]);
|
||||
setText(QObject::tr("delete row"));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
|
||||
InsertSubPageCommand::InsertSubPageCommand(TeletextDocument *teletextDocument, bool afterCurrentSubPage, bool copySubPage, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_newSubPageIndex = teletextDocument->currentSubPageIndex()+afterCurrentSubPage;
|
||||
m_copySubPage = copySubPage;
|
||||
}
|
||||
|
||||
void InsertSubPageCommand::redo()
|
||||
{
|
||||
m_teletextDocument->insertSubPage(m_newSubPageIndex, m_copySubPage);
|
||||
m_teletextDocument->selectSubPageIndex(m_newSubPageIndex, true);
|
||||
setText(QObject::tr("insert subpage"));
|
||||
}
|
||||
|
||||
void InsertSubPageCommand::undo()
|
||||
{
|
||||
m_teletextDocument->deleteSubPage(m_newSubPageIndex);
|
||||
//TODO should we always wrench to "subpage viewed when we inserted"? Or just if subpage viewed is being deleted?
|
||||
m_teletextDocument->selectSubPageIndex(m_newSubPageIndex, true);
|
||||
setText(QObject::tr("insert subpage"));
|
||||
}
|
||||
|
||||
|
||||
SetColourCommand::SetColourCommand(TeletextDocument *teletextDocument, int colourIndex, int newColour, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_colourIndex = colourIndex;
|
||||
m_oldColour = teletextDocument->currentSubPage()->CLUT(colourIndex);
|
||||
m_newColour = newColour;
|
||||
}
|
||||
|
||||
void SetColourCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCLUT(m_colourIndex, m_newColour);
|
||||
emit m_teletextDocument->colourChanged(m_colourIndex);
|
||||
setText(QObject::tr("colour change"));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
void SetColourCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
m_teletextDocument->currentSubPage()->setCLUT(m_colourIndex, m_oldColour);
|
||||
emit m_teletextDocument->colourChanged(m_colourIndex);
|
||||
setText(QObject::tr("colour change"));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
|
||||
ResetCLUTCommand::ResetCLUTCommand(TeletextDocument *teletextDocument, int colourTable, QUndoCommand *parent) : QUndoCommand(parent)
|
||||
{
|
||||
m_teletextDocument = teletextDocument;
|
||||
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||
m_colourTable = colourTable;
|
||||
for (int i=m_colourTable*8; i<m_colourTable*8+8; i++)
|
||||
m_oldColourEntry[i&7] = teletextDocument->currentSubPage()->CLUT(i);
|
||||
}
|
||||
|
||||
void ResetCLUTCommand::redo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
for (int i=m_colourTable*8; i<m_colourTable*8+8; i++) {
|
||||
m_teletextDocument->currentSubPage()->setCLUT(i, m_teletextDocument->currentSubPage()->CLUT(i, 0));
|
||||
emit m_teletextDocument->colourChanged(i);
|
||||
}
|
||||
setText(QObject::tr("CLUT %1 reset").arg(m_colourTable));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
|
||||
void ResetCLUTCommand::undo()
|
||||
{
|
||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||
for (int i=m_colourTable*8; i<m_colourTable*8+8; i++) {
|
||||
m_teletextDocument->currentSubPage()->setCLUT(i, m_oldColourEntry[i&7]);
|
||||
emit m_teletextDocument->colourChanged(i);
|
||||
}
|
||||
setText(QObject::tr("CLUT %1 reset").arg(m_colourTable));
|
||||
emit m_teletextDocument->refreshNeeded();
|
||||
}
|
||||
143
levelonecommands.h
Normal file
143
levelonecommands.h
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LEVELONECOMMANDS_H
|
||||
#define LEVELONECOMMANDS_H
|
||||
|
||||
#include <QUndoCommand>
|
||||
|
||||
#include "document.h"
|
||||
|
||||
class OverwriteCharacterCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
OverwriteCharacterCommand(TeletextDocument *, unsigned char, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
unsigned char m_oldCharacter, m_newCharacter;
|
||||
int m_subPageIndex, m_row, m_column;
|
||||
};
|
||||
|
||||
class ToggleMosaicBitCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
enum { Id = 2 };
|
||||
|
||||
ToggleMosaicBitCommand(TeletextDocument *, unsigned char, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
bool mergeWith(const QUndoCommand *) override;
|
||||
int id() const override { return Id; }
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
unsigned char m_oldCharacter, m_newCharacter;
|
||||
int m_subPageIndex, m_row, m_column;
|
||||
};
|
||||
|
||||
class BackspaceCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
BackspaceCommand(TeletextDocument *, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
unsigned char m_deletedCharacter;
|
||||
int m_subPageIndex, m_row, m_column;
|
||||
};
|
||||
|
||||
class InsertSubPageCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
InsertSubPageCommand(TeletextDocument *, bool, bool, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
int m_newSubPageIndex;
|
||||
bool m_copySubPage;
|
||||
};
|
||||
|
||||
class InsertRowCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
InsertRowCommand(TeletextDocument *, bool, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
int m_subPageIndex, m_row;
|
||||
bool m_copyRow;
|
||||
unsigned char m_deletedBottomRow[40];
|
||||
};
|
||||
|
||||
class DeleteRowCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
DeleteRowCommand(TeletextDocument *, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
int m_subPageIndex, m_row;
|
||||
unsigned char m_deletedRow[40];
|
||||
};
|
||||
|
||||
class SetColourCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
SetColourCommand(TeletextDocument *, int, int, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
int m_subPageIndex, m_colourIndex, m_oldColour, m_newColour;
|
||||
};
|
||||
|
||||
class ResetCLUTCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
ResetCLUTCommand(TeletextDocument *, int, QUndoCommand *parent = 0);
|
||||
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
int m_subPageIndex, m_colourTable;
|
||||
int m_oldColourEntry[8];
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "mainwidget.h"
|
||||
|
||||
#include "document.h"
|
||||
#include "levelonecommands.h"
|
||||
#include "levelonepage.h"
|
||||
#include "render.h"
|
||||
#include "x26triplets.h"
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "levelonecommands.h"
|
||||
#include "mainwidget.h"
|
||||
#include "pageenhancementsdockwidget.h"
|
||||
#include "pageoptionsdockwidget.h"
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "palettedockwidget.h"
|
||||
|
||||
#include "levelonecommands.h"
|
||||
#include "document.h"
|
||||
#include "mainwidget.h"
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ QT += widgets
|
||||
requires(qtConfig(filedialog))
|
||||
|
||||
HEADERS = document.h \
|
||||
levelonecommands.h \
|
||||
levelonepage.h \
|
||||
mainwidget.h \
|
||||
mainwindow.h \
|
||||
@@ -14,6 +15,7 @@ HEADERS = document.h \
|
||||
x26model.h \
|
||||
x26triplets.h
|
||||
SOURCES = document.cpp \
|
||||
levelonecommands.cpp \
|
||||
levelonepage.cpp \
|
||||
main.cpp \
|
||||
mainwidget.cpp \
|
||||
|
||||
Reference in New Issue
Block a user