Files
QTeletextMaker/levelonecommands.h

247 lines
6.4 KiB
C
Raw Normal View History

2020-11-10 18:48:12 +00:00
/*
2024-01-01 00:12:17 +00:00
* Copyright (C) 2020-2024 Gavin MacGregor
2020-11-10 18:48:12 +00:00
*
* 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
2021-05-03 22:17:51 +01:00
#include <QByteArrayList>
#include <QSet>
2020-11-10 18:48:12 +00:00
#include <QUndoCommand>
#include "document.h"
class LevelOneCommand : public QUndoCommand
{
public:
LevelOneCommand(TeletextDocument *teletextDocument, QUndoCommand *parent = 0);
protected:
2024-07-09 22:16:58 +01:00
QByteArrayList storeCharacters(int topRow, int leftColumn, int bottomRow, int rightColumn);
void retrieveCharacters(int topRow, int leftColumn, const QByteArrayList &oldChars);
TeletextDocument *m_teletextDocument;
int m_subPageIndex, m_row, m_column;
bool m_firstDo;
};
class TypeCharacterCommand : public LevelOneCommand
2020-11-10 18:48:12 +00:00
{
public:
enum { Id = 101 };
TypeCharacterCommand(TeletextDocument *teletextDocument, unsigned char newCharacter, bool insertMode, QUndoCommand *parent = 0);
2020-11-10 18:48:12 +00:00
void redo() override;
void undo() override;
bool mergeWith(const QUndoCommand *command) override;
int id() const override { return Id; }
2020-11-10 18:48:12 +00:00
private:
unsigned char m_newCharacter, m_oldRowContents[40], m_newRowContents[40];
int m_columnStart, m_columnEnd;
bool m_insertMode;
2020-11-10 18:48:12 +00:00
};
class ToggleMosaicBitCommand : public LevelOneCommand
2020-11-10 18:48:12 +00:00
{
public:
enum { Id = 102 };
2020-11-10 18:48:12 +00:00
ToggleMosaicBitCommand(TeletextDocument *teletextDocument, unsigned char bitToToggle, QUndoCommand *parent = 0);
2020-11-10 18:48:12 +00:00
void redo() override;
void undo() override;
bool mergeWith(const QUndoCommand *command) override;
2020-11-10 18:48:12 +00:00
int id() const override { return Id; }
private:
unsigned char m_oldCharacter, m_newCharacter;
};
class BackspaceKeyCommand : public LevelOneCommand
2020-11-10 18:48:12 +00:00
{
public:
enum { Id = 103 };
BackspaceKeyCommand(TeletextDocument *teletextDocument, bool insertMode, QUndoCommand *parent = 0);
2020-11-10 18:48:12 +00:00
void redo() override;
void undo() override;
bool mergeWith(const QUndoCommand *command) override;
int id() const override { return Id; }
2020-11-10 18:48:12 +00:00
private:
unsigned char m_oldRowContents[40], m_newRowContents[40];
int m_columnStart, m_columnEnd;
bool m_insertMode;
2020-11-10 18:48:12 +00:00
};
class DeleteKeyCommand : public LevelOneCommand
2021-02-12 21:33:06 +00:00
{
public:
enum { Id = 104 };
DeleteKeyCommand(TeletextDocument *teletextDocument, QUndoCommand *parent = 0);
2021-02-12 21:33:06 +00:00
void redo() override;
void undo() override;
bool mergeWith(const QUndoCommand *command) override;
2021-02-12 21:33:06 +00:00
int id() const override { return Id; }
private:
unsigned char m_oldRowContents[40], m_newRowContents[40];
};
class ShiftMosaicsCommand : public LevelOneCommand
{
public:
ShiftMosaicsCommand(TeletextDocument *teletextDocument, const QSet<QPair<int, int>> &mosaicList, QUndoCommand *parent = 0);
void redo() override;
void undo() override;
bool mergeWith(const QUndoCommand *command) override;
protected:
QByteArrayList m_oldCharacters, m_newCharacters;
QSet<QPair<int, int>> m_mosaicList;
int m_selectionTopRow, m_selectionBottomRow, m_selectionLeftColumn, m_selectionRightColumn;
int m_selectionCornerRow, m_selectionCornerColumn;
};
class ShiftMosaicsUpCommand : public ShiftMosaicsCommand
{
public:
enum { Id = 110 };
ShiftMosaicsUpCommand(TeletextDocument *teletextDocument, const QSet<QPair<int, int>> &mosaicList, QUndoCommand *parent = 0);
int id() const override { return Id; }
};
class ShiftMosaicsDownCommand : public ShiftMosaicsCommand
{
public:
enum { Id = 111 };
ShiftMosaicsDownCommand(TeletextDocument *teletextDocument, const QSet<QPair<int, int>> &mosaicList, QUndoCommand *parent = 0);
int id() const override { return Id; }
};
class ShiftMosaicsLeftCommand : public ShiftMosaicsCommand
{
public:
enum { Id = 112 };
ShiftMosaicsLeftCommand(TeletextDocument *teletextDocument, const QSet<QPair<int, int>> &mosaicList, QUndoCommand *parent = 0);
int id() const override { return Id; }
};
class ShiftMosaicsRightCommand : public ShiftMosaicsCommand
{
public:
enum { Id = 113 };
ShiftMosaicsRightCommand(TeletextDocument *teletextDocument, const QSet<QPair<int, int>> &mosaicList, QUndoCommand *parent = 0);
int id() const override { return Id; }
};
class InsertSubPageCommand : public LevelOneCommand
2020-11-10 18:48:12 +00:00
{
public:
InsertSubPageCommand(TeletextDocument *teletextDocument, bool afterCurrentSubPage, bool copySubPage, QUndoCommand *parent = 0);
2020-11-10 18:48:12 +00:00
void redo() override;
void undo() override;
private:
int m_newSubPageIndex;
bool m_copySubPage;
};
class DeleteSubPageCommand : public LevelOneCommand
2020-12-15 21:57:42 +00:00
{
public:
DeleteSubPageCommand(TeletextDocument *teletextDocument, QUndoCommand *parent = 0);
2020-12-15 21:57:42 +00:00
void redo() override;
void undo() override;
};
class InsertRowCommand : public LevelOneCommand
2020-11-10 18:48:12 +00:00
{
public:
InsertRowCommand(TeletextDocument *teletextDocument, bool copyRow, QUndoCommand *parent = 0);
2020-11-10 18:48:12 +00:00
void redo() override;
void undo() override;
private:
bool m_copyRow;
unsigned char m_deletedBottomRow[40];
};
class DeleteRowCommand : public LevelOneCommand
2020-11-10 18:48:12 +00:00
{
public:
DeleteRowCommand(TeletextDocument *teletextDocument, QUndoCommand *parent = 0);
2020-11-10 18:48:12 +00:00
void redo() override;
void undo() override;
private:
unsigned char m_deletedRow[40];
};
2021-05-03 22:17:51 +01:00
#ifndef QT_NO_CLIPBOARD
2024-07-09 22:16:58 +01:00
class CutCommand : public LevelOneCommand
2021-05-03 22:17:51 +01:00
{
public:
CutCommand(TeletextDocument *teletextDocument, QUndoCommand *parent = 0);
2021-05-03 22:17:51 +01:00
void redo() override;
void undo() override;
private:
2024-07-09 22:16:58 +01:00
QByteArrayList m_oldCharacters;
2021-05-03 22:17:51 +01:00
int m_selectionTopRow, m_selectionBottomRow, m_selectionLeftColumn, m_selectionRightColumn;
int m_selectionCornerRow, m_selectionCornerColumn;
};
2024-07-09 22:16:58 +01:00
class PasteCommand : public LevelOneCommand
2021-05-03 22:17:51 +01:00
{
public:
PasteCommand(TeletextDocument *teletextDocument, int pageCharSet, QUndoCommand *parent = 0);
2021-05-03 22:17:51 +01:00
void redo() override;
void undo() override;
private:
2024-07-09 22:16:58 +01:00
QByteArrayList m_oldCharacters, m_pastingCharacters;
2021-05-03 22:17:51 +01:00
int m_pasteTopRow, m_pasteBottomRow, m_pasteLeftColumn, m_pasteRightColumn;
int m_clipboardDataHeight, m_clipboardDataWidth;
int m_selectionCornerRow, m_selectionCornerColumn;
bool m_selectionActive, m_plainText;
2021-05-03 22:17:51 +01:00
};
#endif // !QT_NO_CLIPBOARD
2020-11-10 18:48:12 +00:00
#endif