Implement Delete key command
This commit is contained in:
@@ -185,6 +185,58 @@ bool BackspaceCommand::mergeWith(const QUndoCommand *command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DeleteKeyCommand::DeleteKeyCommand(TeletextDocument *teletextDocument, QUndoCommand *parent) : QUndoCommand(parent)
|
||||||
|
{
|
||||||
|
m_teletextDocument = teletextDocument;
|
||||||
|
m_subPageIndex = teletextDocument->currentSubPageIndex();
|
||||||
|
m_row = teletextDocument->cursorRow();
|
||||||
|
m_column = teletextDocument->cursorColumn();
|
||||||
|
for (int c=0; c<40; c++)
|
||||||
|
m_oldRowContents[c] = m_newRowContents[c] = m_teletextDocument->currentSubPage()->character(m_row, c);
|
||||||
|
|
||||||
|
setText(QObject::tr("delete"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeleteKeyCommand::redo()
|
||||||
|
{
|
||||||
|
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||||
|
|
||||||
|
for (int c=m_column; c<39; c++)
|
||||||
|
m_newRowContents[c] = m_newRowContents[c+1];
|
||||||
|
m_newRowContents[39] = 0x20;
|
||||||
|
|
||||||
|
for (int c=0; c<40; c++)
|
||||||
|
m_teletextDocument->currentSubPage()->setCharacter(m_row, c, m_newRowContents[c]);
|
||||||
|
|
||||||
|
m_teletextDocument->moveCursor(m_row, m_column);
|
||||||
|
emit m_teletextDocument->contentsChange(m_row);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeleteKeyCommand::undo()
|
||||||
|
{
|
||||||
|
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||||
|
|
||||||
|
for (int c=0; c<40; c++)
|
||||||
|
m_teletextDocument->currentSubPage()->setCharacter(m_row, c, m_oldRowContents[c]);
|
||||||
|
|
||||||
|
m_teletextDocument->moveCursor(m_row, m_column);
|
||||||
|
emit m_teletextDocument->contentsChange(m_row);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeleteKeyCommand::mergeWith(const QUndoCommand *command)
|
||||||
|
{
|
||||||
|
const DeleteKeyCommand *newerCommand = static_cast<const DeleteKeyCommand *>(command);
|
||||||
|
|
||||||
|
if (m_subPageIndex != newerCommand->m_subPageIndex || m_row != newerCommand->m_row || m_column != newerCommand->m_column)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (int c=0; c<40; c++)
|
||||||
|
m_newRowContents[c] = newerCommand->m_newRowContents[c];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
InsertRowCommand::InsertRowCommand(TeletextDocument *teletextDocument, bool copyRow, QUndoCommand *parent) : QUndoCommand(parent)
|
InsertRowCommand::InsertRowCommand(TeletextDocument *teletextDocument, bool copyRow, QUndoCommand *parent) : QUndoCommand(parent)
|
||||||
{
|
{
|
||||||
m_teletextDocument = teletextDocument;
|
m_teletextDocument = teletextDocument;
|
||||||
@@ -318,6 +370,7 @@ void DeleteSubPageCommand::undo()
|
|||||||
m_teletextDocument->selectSubPageIndex(m_subPageToDelete, true);
|
m_teletextDocument->selectSubPageIndex(m_subPageToDelete, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SetColourCommand::SetColourCommand(TeletextDocument *teletextDocument, int colourIndex, int newColour, QUndoCommand *parent) : QUndoCommand(parent)
|
SetColourCommand::SetColourCommand(TeletextDocument *teletextDocument, int colourIndex, int newColour, QUndoCommand *parent) : QUndoCommand(parent)
|
||||||
{
|
{
|
||||||
m_teletextDocument = teletextDocument;
|
m_teletextDocument = teletextDocument;
|
||||||
|
|||||||
@@ -80,6 +80,24 @@ private:
|
|||||||
bool m_firstDo;
|
bool m_firstDo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DeleteKeyCommand : public QUndoCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum { Id = 104 };
|
||||||
|
|
||||||
|
DeleteKeyCommand(TeletextDocument *, 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_oldRowContents[40], m_newRowContents[40];
|
||||||
|
int m_subPageIndex, m_row, m_column;
|
||||||
|
};
|
||||||
|
|
||||||
class InsertSubPageCommand : public QUndoCommand
|
class InsertSubPageCommand : public QUndoCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -332,6 +332,10 @@ void TeletextWidget::keyPressEvent(QKeyEvent *event)
|
|||||||
case Qt::Key_Backspace:
|
case Qt::Key_Backspace:
|
||||||
backspaceEvent();
|
backspaceEvent();
|
||||||
break;
|
break;
|
||||||
|
case Qt::Key_Delete:
|
||||||
|
m_teletextDocument->undoStack()->push(new DeleteKeyCommand(m_teletextDocument));
|
||||||
|
break;
|
||||||
|
|
||||||
case Qt::Key_Up:
|
case Qt::Key_Up:
|
||||||
m_teletextDocument->cursorUp();
|
m_teletextDocument->cursorUp();
|
||||||
update();
|
update();
|
||||||
|
|||||||
Reference in New Issue
Block a user