Files
QTeletextMaker/src/qteletextmaker/x28commands.cpp

275 lines
8.4 KiB
C++
Raw Normal View History

2024-07-09 18:01:17 +01:00
/*
2024-12-31 10:51:06 +00:00
* Copyright (C) 2020-2025 Gavin MacGregor
2024-07-09 18:01:17 +01: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/>.
*/
#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<const SetFullScreenColourCommand *>(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<const SetFullRowColourCommand *>(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<const SetCLUTRemapCommand *>(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<const SetBlackBackgroundSubstCommand *>(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; i<m_colourTable*8+8; i++)
m_oldColourEntry[i&7] = teletextDocument->currentSubPage()->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; i<m_colourTable*8+8; i++) {
m_teletextDocument->currentSubPage()->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; i<m_colourTable*8+8; i++) {
m_teletextDocument->currentSubPage()->setCLUT(i, m_oldColourEntry[i&7]);
emit m_teletextDocument->colourChanged(i);
}
emit m_teletextDocument->contentsChanged();
}
2025-07-20 15:32:13 +01:00
SetDCLUTCommand::SetDCLUTCommand(TeletextDocument *teletextDocument, bool globalDrcs, int mode, int index, int colour, QUndoCommand *parent) : X28Command(teletextDocument, parent)
{
m_globalDrcs = globalDrcs;
m_mode = mode;
m_index = index;
m_oldColour = teletextDocument->currentSubPage()->dCLUT(globalDrcs, mode, index);
m_newColour = colour;
setText(QObject::tr("DCLUT"));
}
void SetDCLUTCommand::redo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
m_teletextDocument->currentSubPage()->setDCLUT(m_globalDrcs, m_mode, m_index, m_newColour);
emit m_teletextDocument->dClutChanged(m_globalDrcs, m_mode, m_index);
emit m_teletextDocument->contentsChanged();
}
void SetDCLUTCommand::undo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
m_teletextDocument->currentSubPage()->setDCLUT(m_globalDrcs, m_mode, m_index, m_oldColour);
emit m_teletextDocument->dClutChanged(m_globalDrcs, m_mode, m_index);
// We don't emit contentsChanged() here, dClutChanged does that after
// marking DRCS character cells for refresh
}