Files
QTeletextMaker/x26model.cpp

852 lines
34 KiB
C++
Raw Normal View History

2020-09-06 16:47:38 +01:00
/*
2022-12-31 21:19:15 +00:00
* Copyright (C) 2020-2023 Gavin MacGregor
2020-09-06 16:47:38 +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 "x26model.h"
2020-09-06 16:47:38 +01:00
#include <QList>
#include "render.h"
#include "x26commands.h"
2020-09-06 16:47:38 +01:00
X26Model::X26Model(TeletextWidget *parent): QAbstractListModel(parent)
{
m_parentMainWidget = parent;
m_listLoaded = true;
}
void X26Model::setX26ListLoaded(bool newListLoaded)
{
beginResetModel();
m_listLoaded = newListLoaded;
endResetModel();
}
int X26Model::rowCount(const QModelIndex & /*parent*/) const
{
return m_listLoaded ? m_parentMainWidget->document()->currentSubPage()->enhancements()->size() : 0;
2020-09-06 16:47:38 +01:00
}
int X26Model::columnCount(const QModelIndex & /*parent*/) const
{
return 4;
}
QVariant X26Model::data(const QModelIndex &index, int role) const
{
2021-06-25 17:48:52 +01:00
const X26Triplet triplet = m_parentMainWidget->document()->currentSubPage()->enhancements()->at(index.row());
2020-09-06 16:47:38 +01:00
// Qt::UserRole will always return the raw values
if (role == Qt::UserRole)
switch (index.column()) {
case 0:
2021-06-25 17:48:52 +01:00
return triplet.address();
2020-09-06 16:47:38 +01:00
case 1:
2021-06-25 17:48:52 +01:00
return triplet.mode();
2020-09-06 16:47:38 +01:00
case 2:
2021-06-25 17:48:52 +01:00
return triplet.data();
2020-09-06 16:47:38 +01:00
default:
return QVariant();
}
// Error colours from KDE Plasma Breeze (light) theme
if (role == Qt::ForegroundRole) {
if (triplet.error() != X26Triplet::NoError && index.column() == m_tripletErrors[triplet.error()].columnHighlight)
return QColor(252, 252, 252);
else if ((index.column() == 2 && triplet.reservedMode()) || (index.column() == 3 && triplet.reservedData()))
return QColor(35, 38, 39);
}
if (role == Qt::BackgroundRole) {
if (triplet.error() != X26Triplet::NoError && index.column() == m_tripletErrors[triplet.error()].columnHighlight)
return QColor(218, 68, 63);
else if ((index.column() == 2 && triplet.reservedMode()) || (index.column() == 3 && triplet.reservedData()))
return QColor(246, 116, 0);
}
if (role == Qt::ToolTipRole && triplet.error() != X26Triplet::NoError)
return m_tripletErrors[triplet.error()].message;
2020-09-06 16:47:38 +01:00
if (role == Qt::DisplayRole || role == Qt::EditRole)
switch (index.column()) {
case 0:
// Show row number only if address part of triplet actually represents a row:
// Full row colour, Set Active Position and Origin Modifier
2020-09-06 16:47:38 +01:00
// For Origin Modifier address of 40 refers to same row, so show it as 0
2021-06-25 17:48:52 +01:00
if (triplet.modeExt() == 0x10) {
if (triplet.address() == 40)
return "+0";
2020-09-06 16:47:38 +01:00
else
return QString("+%1").arg(triplet.addressRow());
2020-09-06 16:47:38 +01:00
}
2021-06-25 17:48:52 +01:00
if (triplet.modeExt() == 0x01 || triplet.modeExt() == 0x04)
return triplet.addressRow();
2020-09-06 16:47:38 +01:00
else
return QVariant();
2020-09-06 16:47:38 +01:00
case 1:
2021-06-25 17:48:52 +01:00
if (!triplet.isRowTriplet())
return triplet.addressColumn();
2020-09-06 16:47:38 +01:00
// For Set Active Position and Origin Modifier, data is the column
else if (triplet.modeExt() == 0x04)
2021-06-25 17:48:52 +01:00
return triplet.data();
else if (triplet.modeExt() == 0x10)
return QString("+%1").arg(triplet.data());
2020-09-06 16:47:38 +01:00
else
return QVariant();
2020-09-06 16:47:38 +01:00
}
QString result;
if (role == Qt::DisplayRole) {
if (index.column() == 2)
return (m_modeTripletName[triplet.modeExt()]);
// Column 3 - describe effects of data/address triplet parameters in plain English
2021-06-25 17:48:52 +01:00
switch (triplet.modeExt()) {
case 0x01: // Full row colour
case 0x07: // Address row 0
2021-06-25 17:48:52 +01:00
if ((triplet.data() & 0x60) == 0x60)
result = ", down to bottom";
2021-06-25 17:48:52 +01:00
else if ((triplet.data() & 0x60) == 0x00)
result = ", this row only";
// fall-through
case 0x00: // Full screen colour
2021-06-25 17:48:52 +01:00
if (!(result.isEmpty()) || (triplet.data() & 0x60) == 0x00) {
result.prepend(QString("CLUT %1:%2").arg((triplet.data() & 0x18) >> 3).arg(triplet.data() & 0x07));
return result;
}
break;
case 0x04: // Set Active Position
case 0x10: // Origin Modifier
// For Set Active Position and Origin Modifier, data is the column, so return blank
return QVariant();
case 0x11 ... 0x13: // Invoke object
2021-06-25 17:48:52 +01:00
switch (triplet.address() & 0x18) {
case 0x08:
2021-06-25 17:48:52 +01:00
return QString("Local: d%1 t%2").arg((triplet.data() >> 4) | ((triplet.address() & 0x01) << 3)).arg(triplet.data() & 0x0f);
case 0x10:
result = "POP";
break;
case 0x18:
result = "GPOP";
break;
// case 0x00: shouldn't happen since that would make a column triplet, not a row triplet
}
2021-06-25 17:48:52 +01:00
result.append(QString(": subpage %1 pkt %2 trplt %3 bits ").arg(triplet.data() & 0x0f).arg((triplet.address() & 0x03) + 1).arg(((triplet.data() & 0x60) >> 5) * 3 + (triplet.modeExt() & 0x03)));
if (triplet.data() & 0x10)
result.append("10-18");
else
result.append("1-9");
return result;
case 0x15 ... 0x17: // Define object
2021-06-25 17:48:52 +01:00
switch (triplet.address() & 0x18) {
case 0x08:
return "Local: L2.5 only";
break;
case 0x10:
return "Local: L3.5 only";
break;
case 0x18:
return "Local: L2.5 and 3.5";
break;
// case 0x00: shouldn't happen since that would make a column triplet, not a row triplet
}
break;
case 0x18: // DRCS mode
2021-06-25 17:48:52 +01:00
result = (triplet.data() & 0x40) == 0x40 ? "Normal" : "Global";
result.append(QString(": subpage %1, ").arg(triplet.data() & 0x0f));
switch (triplet.data() & 0x30) {
case 0x10:
result.append("L2.5 only");
break;
case 0x20:
result.append("L3.5 only");
break;
case 0x30:
result.append("L2.5 and 3.5");
break;
2021-04-06 18:54:51 +01:00
case 0x00:
result.append("Reserved");
break;
}
return result;
case 0x1f: // Termination
2021-06-25 17:48:52 +01:00
switch (triplet.data() & 0x07) {
case 0x00:
return "Intermed (G)POP subpage. End of object, more follows";
break;
case 0x01:
return "Intermed (G)POP subpage. End of last object on page";
break;
case 0x02:
return "Last (G)POP subpage. End of object, more follows";
break;
case 0x03:
return "Last (G)POP subpage. End of last object on page";
break;
case 0x04:
return "Local object definitions. End of object, more follows";
break;
case 0x05:
return "Local object definitions. End of last object on page";
break;
case 0x06:
return "End of local enhance data. Local objects follow";
break;
case 0x07:
return "End of local enhance data. No local objects";
break;
}
break;
case 0x08 ... 0x0d: // PDC
2021-06-25 17:48:52 +01:00
return QString("0x%1").arg(triplet.data(), 2, 16, QChar('0'));
case 0x20: // Foreground colour
case 0x23: // Background colour
2021-06-25 17:48:52 +01:00
if (!(triplet.data() & 0x60))
return QString("CLUT %1:%2").arg((triplet.data() & 0x18) >> 3).arg(triplet.data() & 0x07);
break;
case 0x21: // G1 mosaic character
case 0x22: // G3 mosaic character at level 1.5
case 0x29: // G0 character
case 0x2b: // G3 mosaic character at level >=2.5
case 0x2f ... 0x3f: // G2 character or G0 diacritical mark
2021-06-25 17:48:52 +01:00
if (triplet.data() >= 0x20)
return QString("0x%1").arg(triplet.data(), 2, 16);
break;
case 0x27: // Flash functions
2021-06-25 17:48:52 +01:00
if (triplet.data() < 0x18) {
switch (triplet.data() & 0x03) {
case 0x00:
result = "Steady";
break;
case 0x01:
result = "Normal";
break;
case 0x02:
result = "Invert";
2020-09-06 16:47:38 +01:00
break;
case 0x03:
result = "Adj CLUT";
2020-09-06 16:47:38 +01:00
break;
}
2021-06-25 17:48:52 +01:00
switch (triplet.data() & 0x1c) {
case 0x00:
result.append(", 1Hz");
2020-09-06 16:47:38 +01:00
break;
case 0x04:
result.append(", 2Hz ph 1");
2020-09-06 16:47:38 +01:00
break;
case 0x08:
result.append(", 2Hz ph 2");
break;
case 0x0c:
result.append(", 2Hz ph 3");
break;
case 0x10:
result.append(", 2Hz inc");
break;
case 0x14:
result.append(", 2Hz dec");
2020-09-06 16:47:38 +01:00
break;
}
return result;
}
break;
//TODO case 0x28: // G0 and G2 designation
case 0x2c: // Display attributes
2021-06-25 17:48:52 +01:00
if (triplet.data() & 0x02)
result.append("Boxing ");
2021-06-25 17:48:52 +01:00
if (triplet.data() & 0x04)
result.append("Conceal ");
2021-06-25 17:48:52 +01:00
if (triplet.data() & 0x10)
result.append("Invert ");
2021-06-25 17:48:52 +01:00
if (triplet.data() & 0x20)
result.append("Underline ");
if (result.isEmpty())
result = "None";
2020-09-06 16:47:38 +01:00
else
// Chop off the last space
result.chop(1);
2021-06-25 17:48:52 +01:00
switch (triplet.data() & 0x41) {
case 0x00:
result.append(", normal size");
break;
case 0x01:
result.append(", double height");
break;
case 0x40:
result.append(", double width");
break;
case 0x41:
result.append(", double size");
break;
}
return result;
case 0x2d: // DRCS character
2021-06-25 17:48:52 +01:00
result = (triplet.data() & 0x40) == 0x40 ? "Normal" : "Global";
result.append(QString(": %1").arg(triplet.data() & 0x3f));
return result;
case 0x2e: // Font style
2021-06-25 17:48:52 +01:00
if (triplet.data() & 0x01)
result.append("Proportional ");
2021-06-25 17:48:52 +01:00
if (triplet.data() & 0x02)
result.append("Bold ");
2021-06-25 17:48:52 +01:00
if (triplet.data() & 0x04)
result.append("Italic ");
if (result.isEmpty())
result = "None";
2020-09-06 16:47:38 +01:00
else
// Chop off the last space
result.chop(1);
2021-06-25 17:48:52 +01:00
result.append(QString(", %1 row(s)").arg(triplet.data() >> 4));
return result;
case 0x28: // Modified G0 and G2 character set
case 0x26: // PDC
2021-06-25 17:48:52 +01:00
return QString("0x%1").arg(triplet.data(), 2, 16, QChar('0'));
default: // Reserved
2021-06-25 17:48:52 +01:00
return QString("Reserved 0x%1").arg(triplet.data(), 2, 16, QChar('0'));
2020-09-06 16:47:38 +01:00
}
// Reserved mode or data
2021-06-25 17:48:52 +01:00
return QString("Reserved 0x%1").arg(triplet.data(), 2, 16, QChar('0'));
}
if (role == Qt::DecorationRole && index.column() == 3)
2021-06-25 17:48:52 +01:00
switch (triplet.modeExt()) {
case 0x00: // Full screen colour
case 0x20: // Foreground colour
case 0x23: // Background colour
if (!(triplet.data() & 0x60))
return m_parentMainWidget->document()->currentSubPage()->CLUTtoQColor(triplet.data());
break;
case 0x01: // Full row colour
case 0x07: // Address row 0
if (((triplet.data() & 0x60) == 0x00) || ((triplet.data() & 0x60) == 0x60))
return m_parentMainWidget->document()->currentSubPage()->CLUTtoQColor(triplet.data() & 0x1f);
break;
case 0x21: // G1 mosaic character
2021-06-25 17:48:52 +01:00
if (triplet.data() & 0x20)
return m_fontBitmap.rawBitmap()->copy((triplet.data()-32)*12, 24*10, 12, 10);
break;
case 0x22: // G3 mosaic character at level 1.5
case 0x2b: // G3 mosaic character at level >=2.5
2021-06-25 17:48:52 +01:00
if (triplet.data() >= 0x20)
return m_fontBitmap.rawBitmap()->copy((triplet.data()-32)*12, 26*10, 12, 10);
break;
case 0x2f: // G2 character
// TODO non-Latin G2 character sets
2021-06-25 17:48:52 +01:00
if (triplet.data() >= 0x20)
return m_fontBitmap.rawBitmap()->copy((triplet.data()-32)*12, 7*10, 12, 10);
break;
case 0x29: // G0 character
case 0x30 ... 0x3f: // G0 diacritical mark
// TODO non-Latin G0 character sets
2021-06-25 17:48:52 +01:00
if (triplet.data() >= 0x20)
return m_fontBitmap.rawBitmap()->copy((triplet.data()-32)*12, 0, 12, 10);
break;
};
2021-06-25 17:48:52 +01:00
if (role == Qt::EditRole && index.column() == 2)
return triplet.modeExt();
2021-07-04 16:03:51 +01:00
if (role < Qt::UserRole)
return QVariant();
switch (triplet.modeExt()) {
case 0x01: // Full row colour
case 0x07: // Address row 0
if (role == Qt::UserRole+2) // "this row only" or "down to bottom"
return (triplet.data() & 0x60) == 0x60;
// fall-through
case 0x00: // Full screen colour
case 0x20: // Foreground colour
case 0x23: // Background colour
if (role == Qt::UserRole+1) // Colour index
return triplet.data() & 0x1f;
break;
2021-07-04 16:03:51 +01:00
case 0x11 ... 0x13: // Invoke object
switch (role) {
case Qt::UserRole+1: // Object source: Local, POP or GPOP
return ((triplet.address() & 0x18) >> 3) - 1;
case Qt::UserRole+2:
if ((triplet.address() & 0x18) == 0x08)
// Local object: Designation code
2021-06-25 17:48:52 +01:00
return ((triplet.address() & 0x01) << 3) | ((triplet.data() & 0x70) >> 4);
else
// (G)POP object: Subpage
2021-06-25 17:48:52 +01:00
return triplet.data() & 0x0f;
2021-07-04 16:03:51 +01:00
case Qt::UserRole+3:
2021-06-25 17:48:52 +01:00
if ((triplet.address() & 0x08) == 0x08)
// Local object: Triplet number
2021-06-25 17:48:52 +01:00
return triplet.data() & 0x0f;
else
// (G)POP object: Pointer location
2021-06-25 17:48:52 +01:00
return (triplet.address() & 0x03) + 1;
2021-07-04 16:03:51 +01:00
case Qt::UserRole+4: // (G)POP object: Triplet number
return triplet.data() >> 5;
case Qt::UserRole+5: // (G)POP object: Pointer position
return (triplet.data() & 0x10) >> 4;
}
break;
case 0x15 ... 0x17: // Define object
switch (role) {
case Qt::UserRole+1: // Required at which levels
return ((triplet.address() & 0x18) >> 3) - 1;
case Qt::UserRole+2: // Local object: Designation code
return ((triplet.address() & 0x01) << 3) | ((triplet.data() & 0x70) >> 4);
case Qt::UserRole+3: // Local object: Triplet number
2021-06-25 17:48:52 +01:00
return triplet.data() & 0x0f;
}
break;
2021-07-04 16:03:51 +01:00
case 0x18: // DRCS mode
switch (role) {
case Qt::UserRole+1: // Required at which levels
return ((triplet.data() & 0x30) >> 4) - 1;
case Qt::UserRole+3: // Normal or Global
return (triplet.data() & 0x40) == 0x40;
case Qt::UserRole+4: // Subpage
2021-06-25 17:48:52 +01:00
return triplet.data() & 0x0f;
}
break;
2021-07-04 16:03:51 +01:00
case 0x1f: // Termination
switch (role) {
case Qt::UserRole+1: // Intermed POP subpage|Last POP subpage|Local Object|Local enhance
return ((triplet.data() & 0x06) >> 1);
case Qt::UserRole+2: // More follows/Last
return (triplet.data() & 0x01) == 0x01;
}
break;
case 0x27: // Flash functions
switch (role) {
case Qt::UserRole+1: // Flash mode
return triplet.data() & 0x03;
case Qt::UserRole+2: // Flash rate and phase
return triplet.data() >> 2;
}
break;
case 0x2c: // Display attributes
switch (role) {
case Qt::UserRole+1: // Text size
return (triplet.data() & 0x01) | ((triplet.data() & 0x40) >> 5);
case Qt::UserRole+2: // Boxing/window
return (triplet.data() & 0x02) == 0x02;
case Qt::UserRole+3: // Conceal
return (triplet.data() & 0x04) == 0x04;
case Qt::UserRole+4: // Invert
return (triplet.data() & 0x10) == 0x10;
case Qt::UserRole+5: // Underline/Separated
2021-06-25 17:48:52 +01:00
return (triplet.data() & 0x20) == 0x20;
}
break;
2021-07-04 16:03:51 +01:00
case 0x2d: // DRCS character
switch (role) {
case Qt::UserRole+1: // Normal or Global
return (triplet.data() & 0x40) == 0x40;
case Qt::UserRole+2: // Character number
return triplet.data() & 0x3f;
}
break;
case 0x2e: // Font style
switch (role) {
case Qt::UserRole+1: // Proportional
return (triplet.data() & 0x01) == 0x01;
case Qt::UserRole+2: // Bold
return (triplet.data() & 0x02) == 0x02;
case Qt::UserRole+3: // Italic
return (triplet.data() & 0x04) == 0x04;
case Qt::UserRole+4: // Number of rows
return triplet.data() >> 4;
}
break;
};
// Fpr other triplet modes, return the complete data value
if (role == Qt::UserRole+1)
return triplet.data();
2020-09-06 16:47:38 +01:00
return QVariant();
}
bool X26Model::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid())
return false;
2021-06-25 17:48:52 +01:00
if (!value.canConvert<int>())
return false;
const int intValue = value.toInt();
if (intValue < 0)
return false;
// Raw address, mode and data values
2021-06-25 17:48:52 +01:00
if (role == Qt::UserRole && index.column() <= 2) {
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), index.column(), 0x00, intValue, role));
2020-09-06 16:47:38 +01:00
return true;
}
2021-06-25 17:48:52 +01:00
const X26Triplet triplet = m_parentMainWidget->document()->currentSubPage()->enhancements()->at(index.row());
// Cooked row, column and triplet mode
2021-06-25 17:48:52 +01:00
if (role == Qt::EditRole) {
2020-09-06 16:47:38 +01:00
switch (index.column()) {
case 0: // Cooked row
// Maximum row is 24
2020-09-06 16:47:38 +01:00
if (intValue > 24)
return false;
// Set Active Position and Full Row Colour can't select row 0
2021-06-25 17:48:52 +01:00
if (((triplet.modeExt() == 0x04) || (triplet.modeExt() == 0x01)) && intValue == 0)
return false;
// For Origin Modifier address of 40 refers to same row
2021-06-25 17:48:52 +01:00
if (triplet.modeExt() == 0x10 && intValue == 24) {
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x00, 40, role));
return true;
}
// Others use address 40 for row 24
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x00, (intValue == 24) ? 40 : intValue+40, role));
return true;
case 1: // Cooked column
// Origin modifier allows columns up to 71
2021-06-25 17:48:52 +01:00
if (intValue > (triplet.modeExt() == 0x10 ? 71 : 39))
2020-09-06 16:47:38 +01:00
return false;
// For Set Active Position and Origin Modifier, data is the column
2021-06-25 17:48:52 +01:00
if (triplet.modeExt() == 0x04 || triplet.modeExt() == 0x10)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x00, intValue, role));
2020-09-06 16:47:38 +01:00
else
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x00, intValue, role));
return true;
case 2: // Cooked triplet mode
2021-06-25 17:48:52 +01:00
if (intValue < 0x20 && !triplet.isRowTriplet()) {
2020-09-06 16:47:38 +01:00
// Changing mode from column triplet to row triplet
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x00, 41, role));
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x00, 0, role));
2020-09-06 16:47:38 +01:00
}
2021-06-25 17:48:52 +01:00
if (intValue >= 0x20 && triplet.isRowTriplet()) {
2020-09-06 16:47:38 +01:00
// Changing mode from row triplet to column triplet
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x00, 0, role));
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x00, 0, role));
2020-09-06 16:47:38 +01:00
}
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETmode, 0x00, intValue & 0x1f, role));
// Now set data values to avoid reserved bits if we need to
// FIXME this can rather messily push multiple EditTripletCommands
// that rely on mergeWith to tidy them up afterwards
// Also this just flips bits, where we could use default values
switch (intValue) {
case 0x00: // Full screen colour
case 0x20: // Foreground colour
case 0x23: // Background colour
// Both S1 and S0 reserved bits must be clear
2021-06-25 17:48:52 +01:00
if (triplet.data() & 0x60)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x1f, 0x00, role));
break;
case 0x07: // Address row 0
// Address locked to 63
2021-06-25 17:48:52 +01:00
if (triplet.address() != 63)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x00, 63, role));
// fall-through
case 0x01: // Full row colour
// S1 and S0 bits need to be the same
2021-06-25 17:48:52 +01:00
if ((triplet.data() & 0x60) != 0x00 && (triplet.data() & 0x60) != 0x60)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x1f, 0x00, role));
break;
case 0x04: // Set Active Position
// Data range 0-39
2021-06-25 17:48:52 +01:00
if (triplet.data() >= 40)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x00, 0, role));
break;
case 0x10: // Origin modifier
// Data range 0-71
2021-06-25 17:48:52 +01:00
if (triplet.data() >= 72)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x00, 0, role));
break;
case 0x11: // Invoke Active Object
case 0x12: // Invoke Adaptive Object
case 0x13: // Invoke Passive Object
case 0x15: // Define Active Object
case 0x16: // Define Adaptive Object
case 0x17: // Define Passive Object
// Bit 3 of Address is reserved
2021-06-25 17:48:52 +01:00
if ((triplet.address() & 0x04) == 0x04)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x7b, 0x00, role));
// BUG we're only dealing with Local Object Definitions at the moment!
// If source is Local, triplet number must be in range 0-12
2021-06-25 17:48:52 +01:00
if (((triplet.address() & 0x18) == 0x08) && ((triplet.data() & 0x0f) >= 12))
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x70, 0x00, role));
break;
case 0x18: // DRCS mode
// At least one of the L1 and L0 bits must be set
2021-06-25 17:48:52 +01:00
if ((triplet.data() & 0x30) == 0x00)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x4f, 0x30, role));
break;
case 0x1f: // Termination marker
// Address locked to 63
2021-06-25 17:48:52 +01:00
if (triplet.address() != 63)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x00, 63, role));
// Clear reserved bits D6-D3
2021-06-25 17:48:52 +01:00
if (triplet.data() & 0x78)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x07, 0x00, role));
break;
case 0x21: // G1 mosaic character
case 0x22: // G3 mosaic character at level 1.5
case 0x29: // G0 character
case 0x2b: // G3 mosaic character at level >=2.5
case 0x2f ... 0x3f: // G2 character or G0 diacritical mark
// Data range 0x20-0x7f
2021-06-25 17:48:52 +01:00
if (triplet.data() < 0x20)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x00, 0x20, role));
break;
case 0x27: // Additional flash functions
// D6 and D5 must be clear, D4 and D3 set is reserved phase
2021-06-25 17:48:52 +01:00
if (triplet.data() >= 0x18)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x00, 0, role));
break;
case 0x28: // Display attributes
case 0x2e: // Font style
// Clear reserved bit D3
2021-06-25 17:48:52 +01:00
if (triplet.data() & 0x08)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x77, 0x00, role));
break;
case 0x2d: // DRCS character
// D5-D0 range 0-47
2021-06-25 17:48:52 +01:00
if ((triplet.data() & 0x3f) >= 48)
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x40, 0x77, role));
break;
2021-07-04 16:03:51 +01:00
}
return true;
2020-09-06 16:47:38 +01:00
}
return false;
2020-09-06 16:47:38 +01:00
}
2021-07-04 16:03:51 +01:00
if (role < Qt::UserRole)
return false;
switch (triplet.modeExt()) {
case 0x01: // Full row colour
case 0x07: // Address row 0
switch (role) {
case Qt::UserRole+1: // Colour index
2021-06-25 17:48:52 +01:00
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x60, intValue, role));
2021-07-04 16:03:51 +01:00
return true;
case Qt::UserRole+2: // "this row only" or "down to bottom"
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x1f, intValue * 0x60, role));
break;
}
break;
2021-07-04 16:03:51 +01:00
case 0x11 ... 0x13: // Invoke object
switch (role) {
case Qt::UserRole+1: // Object source: Local, POP or GPOP
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x27, (intValue+1) << 3, role));
return true;
case Qt::UserRole+2:
if ((triplet.address() & 0x18) == 0x08) {
// Local object: Designation code
2021-06-25 17:48:52 +01:00
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x0f, (intValue & 0x07) << 4, role));
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x38, intValue >> 3, role));
} else
// (G)POP object: Subpage
2021-06-25 17:48:52 +01:00
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x30, intValue, role));
2021-07-04 16:03:51 +01:00
return true;
case Qt::UserRole+3: // Invoke object
if ((triplet.address() & 0x18) == 0x08)
// Local object: triplet number
2021-06-25 17:48:52 +01:00
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x70, intValue, role));
else
// (G)POP object: Pointer location
2021-06-25 17:48:52 +01:00
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x7c, intValue - 1, role));
2021-07-04 16:03:51 +01:00
return true;
case Qt::UserRole+4: // (G)POP object: Triplet number
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x1f, intValue << 5, role));
return true;
case Qt::UserRole+5: // (G)POP object: Pointer position
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x6f, intValue << 4, role));
return true;
}
break;
case 0x15 ... 0x17: // Define object
switch (role) {
case Qt::UserRole+1: // Required at which levels
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x27, (intValue+1) << 3, role));
return true;
case Qt::UserRole+2: // Local object: Designation code
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x0f, (intValue & 0x07) << 4, role));
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETaddress, 0x38, intValue >> 3, role));
return true;
case Qt::UserRole+3: // Local object: triplet number
2021-06-25 17:48:52 +01:00
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x70, intValue, role));
break;
}
break;
2021-07-04 16:03:51 +01:00
case 0x18: // DRCS Mode
switch (role) {
case Qt::UserRole+1: // Required at which levels
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x4f, (intValue+1) << 4, role));
return true;
case Qt::UserRole+3: // Normal or Global
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x3f, intValue << 6, role));
return true;
case Qt::UserRole+4: // Subpage
2021-06-25 17:48:52 +01:00
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x70, intValue, role));
2021-07-04 16:03:51 +01:00
return true;
}
break;
case 0x1f: // Termination
switch (role) {
case Qt::UserRole+1: // Intermed POP subpage|Last POP subpage|Local Object|Local enhance
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x01, intValue << 1, role));
return true;
case Qt::UserRole+2: // More follows/Last
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x06, intValue, role));
return true;
}
break;
case 0x27: // Flash functions
switch (role) {
case Qt::UserRole+1: // Flash mode
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x1c, intValue, role));
return true;
case Qt::UserRole+2: // Flash rate and phase
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x03, intValue << 2, role));
break;
}
break;
2021-07-04 16:03:51 +01:00
case 0x2c: // Display attributes
switch (role) {
case Qt::UserRole+1: // Text size
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x36, ((intValue & 0x02) << 5) | (intValue & 0x01), role));
return true;
case Qt::UserRole+2: // Boxing/window
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x7d, intValue << 1, role));
return true;
case Qt::UserRole+3: // Conceal
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x7b, intValue << 2, role));
return true;
case Qt::UserRole+4: // Invert
2021-06-25 17:48:52 +01:00
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x6f, intValue << 4, role));
2021-07-04 16:03:51 +01:00
return true;
case Qt::UserRole+5: // Underline/Separated
2021-06-25 17:48:52 +01:00
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x5f, intValue << 5, role));
2021-07-04 16:03:51 +01:00
return true;
}
break;
case 0x2d: // DRCS character
switch (role) {
case Qt::UserRole+1: // Normal or Global
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x3f, intValue << 6, role));
return true;
case Qt::UserRole+2: // Character number
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x40, intValue, role));
break;
}
break;
2021-07-04 16:03:51 +01:00
case 0x2e: // Font style
switch (role) {
case Qt::UserRole+1: // Proportional
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x7e, intValue, role));
return true;
case Qt::UserRole+2: // Bold
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x7d, intValue << 1, role));
return true;
case Qt::UserRole+3: // Italic
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x7b, intValue << 2, role));
return true;
case Qt::UserRole+4: // Number of rows
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x07, intValue << 4, role));
return true;
}
break;
}
2021-07-04 16:03:51 +01:00
// Fpr other triplet modes, set the complete data value
if (role == Qt::UserRole+1) {
m_parentMainWidget->document()->undoStack()->push(new EditTripletCommand(m_parentMainWidget->document(), this, index.row(), EditTripletCommand::ETdata, 0x00, intValue, role));
return true;
}
2021-07-04 16:03:51 +01:00
2021-06-25 17:48:52 +01:00
return false;
2020-09-06 16:47:38 +01:00
}
QVariant X26Model::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
switch (section) {
case 0:
return tr("Row");
case 1:
return tr("Col");
case 2:
return tr("Mode");
case 3:
return tr("Data");
default:
return QVariant();
2020-09-06 16:47:38 +01:00
}
} else if (orientation == Qt::Vertical)
return QString("d%1 t%2").arg(section / 13).arg(section % 13);
}
return QVariant();
}
bool X26Model::insertRows(int row, int count, const QModelIndex &parent)
2020-09-06 16:47:38 +01:00
{
Q_UNUSED(parent);
if (m_parentMainWidget->document()->currentSubPage()->enhancements()->size() + count > m_parentMainWidget->document()->currentSubPage()->maxEnhancements())
return false;
2020-09-06 16:47:38 +01:00
m_parentMainWidget->document()->undoStack()->push(new InsertTripletCommand(m_parentMainWidget->document(), this, row, count, m_parentMainWidget->document()->currentSubPage()->enhancements()->at(row)));
2020-09-06 16:47:38 +01:00
return true;
}
bool X26Model::insertRows(int row, int count, const QModelIndex &parent, X26Triplet triplet)
2020-09-06 16:47:38 +01:00
{
Q_UNUSED(parent);
if (m_parentMainWidget->document()->currentSubPage()->enhancements()->size() + count > m_parentMainWidget->document()->currentSubPage()->maxEnhancements())
return false;
m_parentMainWidget->document()->undoStack()->push(new InsertTripletCommand(m_parentMainWidget->document(), this, row, count, triplet));
2020-09-06 16:47:38 +01:00
return true;
}
bool X26Model::removeRows(int row, int count, const QModelIndex &index)
2020-09-06 16:47:38 +01:00
{
Q_UNUSED(index);
m_parentMainWidget->document()->undoStack()->push(new DeleteTripletCommand(m_parentMainWidget->document(), this, row, count));
2020-09-06 16:47:38 +01:00
return true;
}
2020-09-06 16:47:38 +01:00
/*
Qt::ItemFlags X26Model::flags(const QModelIndex &index) const
{
if (!index.isValid())
return QAbstractItemModel::flags(index);
if (index.column() <= 1)
return QAbstractItemModel::flags(index);
if (index.column() >= 2)
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
return QAbstractItemModel::flags(index);
}
*/