Show colours in X/26 table and comboboxes
This commit is contained in:
50
document.cpp
50
document.cpp
@@ -17,12 +17,46 @@
|
|||||||
* along with QTeletextMaker. If not, see <https://www.gnu.org/licenses/>.
|
* along with QTeletextMaker. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
|
|
||||||
#include "levelonepage.h"
|
#include "levelonepage.h"
|
||||||
|
|
||||||
|
ClutModel::ClutModel(QObject *parent): QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
m_subPage = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ClutModel::rowCount(const QModelIndex & /*parent*/) const
|
||||||
|
{
|
||||||
|
return 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ClutModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
if (role == Qt::DisplayRole)
|
||||||
|
return QString("CLUT %1:%2").arg(index.row() >> 3).arg(index.row() & 0x07);
|
||||||
|
|
||||||
|
if (role == Qt::DecorationRole && m_subPage != nullptr)
|
||||||
|
return m_subPage->CLUTtoQColor(index.row());
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClutModel::setSubPage(LevelOnePage *subPage)
|
||||||
|
{
|
||||||
|
if (subPage != m_subPage) {
|
||||||
|
m_subPage = subPage;
|
||||||
|
emit dataChanged(createIndex(0, 0), createIndex(31, 0), QVector<int>(Qt::DecorationRole));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TeletextDocument::TeletextDocument()
|
TeletextDocument::TeletextDocument()
|
||||||
{
|
{
|
||||||
m_pageNumber = 0x199;
|
m_pageNumber = 0x199;
|
||||||
@@ -36,10 +70,15 @@ TeletextDocument::TeletextDocument()
|
|||||||
m_cursorColumn = 0;
|
m_cursorColumn = 0;
|
||||||
m_selectionCornerRow = m_selectionCornerColumn = -1;
|
m_selectionCornerRow = m_selectionCornerColumn = -1;
|
||||||
m_selectionSubPage = nullptr;
|
m_selectionSubPage = nullptr;
|
||||||
|
|
||||||
|
m_clutModel = new ClutModel;
|
||||||
|
m_clutModel->setSubPage(m_subPages[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
TeletextDocument::~TeletextDocument()
|
TeletextDocument::~TeletextDocument()
|
||||||
{
|
{
|
||||||
|
delete m_clutModel;
|
||||||
|
|
||||||
for (auto &subPage : m_subPages)
|
for (auto &subPage : m_subPages)
|
||||||
delete(subPage);
|
delete(subPage);
|
||||||
for (auto &recycleSubPage : m_recycleSubPages)
|
for (auto &recycleSubPage : m_recycleSubPages)
|
||||||
@@ -72,7 +111,10 @@ void TeletextDocument::selectSubPageIndex(int newSubPageIndex, bool forceRefresh
|
|||||||
// forceRefresh overrides "beyond the last subpage" check, so inserting a subpage after the last one still shows - dangerous workaround?
|
// forceRefresh overrides "beyond the last subpage" check, so inserting a subpage after the last one still shows - dangerous workaround?
|
||||||
if (forceRefresh || (newSubPageIndex != m_currentSubPageIndex && newSubPageIndex < m_subPages.size())) {
|
if (forceRefresh || (newSubPageIndex != m_currentSubPageIndex && newSubPageIndex < m_subPages.size())) {
|
||||||
emit aboutToChangeSubPage();
|
emit aboutToChangeSubPage();
|
||||||
|
|
||||||
m_currentSubPageIndex = newSubPageIndex;
|
m_currentSubPageIndex = newSubPageIndex;
|
||||||
|
|
||||||
|
m_clutModel->setSubPage(m_subPages[m_currentSubPageIndex]);
|
||||||
emit subPageSelected();
|
emit subPageSelected();
|
||||||
emit selectionMoved();
|
emit selectionMoved();
|
||||||
return;
|
return;
|
||||||
@@ -83,7 +125,10 @@ void TeletextDocument::selectSubPageNext()
|
|||||||
{
|
{
|
||||||
if (m_currentSubPageIndex < m_subPages.size()-1) {
|
if (m_currentSubPageIndex < m_subPages.size()-1) {
|
||||||
emit aboutToChangeSubPage();
|
emit aboutToChangeSubPage();
|
||||||
|
|
||||||
m_currentSubPageIndex++;
|
m_currentSubPageIndex++;
|
||||||
|
|
||||||
|
m_clutModel->setSubPage(m_subPages[m_currentSubPageIndex]);
|
||||||
emit subPageSelected();
|
emit subPageSelected();
|
||||||
emit selectionMoved();
|
emit selectionMoved();
|
||||||
}
|
}
|
||||||
@@ -93,7 +138,10 @@ void TeletextDocument::selectSubPagePrevious()
|
|||||||
{
|
{
|
||||||
if (m_currentSubPageIndex > 0) {
|
if (m_currentSubPageIndex > 0) {
|
||||||
emit aboutToChangeSubPage();
|
emit aboutToChangeSubPage();
|
||||||
|
|
||||||
m_currentSubPageIndex--;
|
m_currentSubPageIndex--;
|
||||||
|
|
||||||
|
m_clutModel->setSubPage(m_subPages[m_currentSubPageIndex]);
|
||||||
emit subPageSelected();
|
emit subPageSelected();
|
||||||
emit selectionMoved();
|
emit selectionMoved();
|
||||||
}
|
}
|
||||||
@@ -116,6 +164,8 @@ void TeletextDocument::insertSubPage(int beforeSubPageIndex, bool copySubPage)
|
|||||||
|
|
||||||
void TeletextDocument::deleteSubPage(int subPageToDelete)
|
void TeletextDocument::deleteSubPage(int subPageToDelete)
|
||||||
{
|
{
|
||||||
|
m_clutModel->setSubPage(nullptr);
|
||||||
|
|
||||||
delete(m_subPages[subPageToDelete]);
|
delete(m_subPages[subPageToDelete]);
|
||||||
m_subPages.erase(m_subPages.begin()+subPageToDelete);
|
m_subPages.erase(m_subPages.begin()+subPageToDelete);
|
||||||
}
|
}
|
||||||
|
|||||||
19
document.h
19
document.h
@@ -20,11 +20,28 @@
|
|||||||
#ifndef DOCUMENT_H
|
#ifndef DOCUMENT_H
|
||||||
#define DOCUMENT_H
|
#define DOCUMENT_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUndoStack>
|
#include <QUndoStack>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "levelonepage.h"
|
#include "levelonepage.h"
|
||||||
|
|
||||||
|
class ClutModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ClutModel(QObject *parent = 0);
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
void setSubPage(LevelOnePage *page);
|
||||||
|
|
||||||
|
private:
|
||||||
|
LevelOnePage *m_subPage;
|
||||||
|
};
|
||||||
|
|
||||||
class TeletextDocument : public QObject
|
class TeletextDocument : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -62,6 +79,7 @@ public:
|
|||||||
void setDescription(QString);
|
void setDescription(QString);
|
||||||
void setFastTextLinkPageNumberOnAllSubPages(int, int);
|
void setFastTextLinkPageNumberOnAllSubPages(int, int);
|
||||||
QUndoStack *undoStack() const { return m_undoStack; }
|
QUndoStack *undoStack() const { return m_undoStack; }
|
||||||
|
ClutModel *clutModel() const { return m_clutModel; }
|
||||||
int cursorRow() const { return m_cursorRow; }
|
int cursorRow() const { return m_cursorRow; }
|
||||||
int cursorColumn() const { return m_cursorColumn; }
|
int cursorColumn() const { return m_cursorColumn; }
|
||||||
void cursorUp(bool shiftKey=false);
|
void cursorUp(bool shiftKey=false);
|
||||||
@@ -104,6 +122,7 @@ private:
|
|||||||
QUndoStack *m_undoStack;
|
QUndoStack *m_undoStack;
|
||||||
int m_cursorRow, m_cursorColumn, m_selectionCornerRow, m_selectionCornerColumn;
|
int m_cursorRow, m_cursorColumn, m_selectionCornerRow, m_selectionCornerColumn;
|
||||||
LevelOnePage *m_selectionSubPage;
|
LevelOnePage *m_selectionSubPage;
|
||||||
|
ClutModel *m_clutModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -47,12 +47,9 @@ PageEnhancementsDockWidget::PageEnhancementsDockWidget(TeletextWidget *parent):
|
|||||||
x28Layout->addWidget(new QLabel(tr("Default screen colour")), 0, 0, 1, 1);
|
x28Layout->addWidget(new QLabel(tr("Default screen colour")), 0, 0, 1, 1);
|
||||||
x28Layout->addWidget(new QLabel(tr("Default row colour")), 1, 0, 1, 1);
|
x28Layout->addWidget(new QLabel(tr("Default row colour")), 1, 0, 1, 1);
|
||||||
m_defaultScreenColourCombo = new QComboBox;
|
m_defaultScreenColourCombo = new QComboBox;
|
||||||
|
m_defaultScreenColourCombo->setModel(m_parentMainWidget->document()->clutModel());
|
||||||
m_defaultRowColourCombo = new QComboBox;
|
m_defaultRowColourCombo = new QComboBox;
|
||||||
for (int r=0; r<=3; r++)
|
m_defaultRowColourCombo->setModel(m_parentMainWidget->document()->clutModel());
|
||||||
for (int c=0; c<=7; c++) {
|
|
||||||
m_defaultScreenColourCombo->addItem(tr("CLUT %1:%2").arg(r).arg(c));
|
|
||||||
m_defaultRowColourCombo->addItem(tr("CLUT %1:%2").arg(r).arg(c));
|
|
||||||
}
|
|
||||||
x28Layout->addWidget(m_defaultScreenColourCombo, 0, 1, 1, 1, Qt::AlignTop);
|
x28Layout->addWidget(m_defaultScreenColourCombo, 0, 1, 1, 1, Qt::AlignTop);
|
||||||
connect(m_defaultScreenColourCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){ m_parentMainWidget->setDefaultScreenColour(index); });
|
connect(m_defaultScreenColourCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){ m_parentMainWidget->setDefaultScreenColour(index); });
|
||||||
x28Layout->addWidget(m_defaultRowColourCombo, 1, 1, 1, 1, Qt::AlignTop);
|
x28Layout->addWidget(m_defaultRowColourCombo, 1, 1, 1, 1, Qt::AlignTop);
|
||||||
|
|||||||
@@ -196,9 +196,7 @@ X26DockWidget::X26DockWidget(TeletextWidget *parent): QDockWidget(parent)
|
|||||||
QHBoxLayout *colourAndRowLayout = new QHBoxLayout;
|
QHBoxLayout *colourAndRowLayout = new QHBoxLayout;
|
||||||
|
|
||||||
m_colourComboBox = new QComboBox;
|
m_colourComboBox = new QComboBox;
|
||||||
for (int c=0; c<=3; c++)
|
m_colourComboBox->setModel(m_parentMainWidget->document()->clutModel());
|
||||||
for (int e=0; e<=7; e++)
|
|
||||||
m_colourComboBox->addItem(tr("CLUT %1:%2").arg(c).arg(e));
|
|
||||||
colourAndRowLayout->addWidget(m_colourComboBox);
|
colourAndRowLayout->addWidget(m_colourComboBox);
|
||||||
connect(m_colourComboBox, QOverload<int>::of(&QComboBox::activated), this, [=](const int value) { updateModelFromCookedWidget(value, Qt::UserRole+1); } );
|
connect(m_colourComboBox, QOverload<int>::of(&QComboBox::activated), this, [=](const int value) { updateModelFromCookedWidget(value, Qt::UserRole+1); } );
|
||||||
|
|
||||||
|
|||||||
11
x26model.cpp
11
x26model.cpp
@@ -318,6 +318,17 @@ QVariant X26Model::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
if (role == Qt::DecorationRole && index.column() == 3)
|
if (role == Qt::DecorationRole && index.column() == 3)
|
||||||
switch (triplet.modeExt()) {
|
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
|
case 0x21: // G1 mosaic character
|
||||||
if (triplet.data() & 0x20)
|
if (triplet.data() & 0x20)
|
||||||
return m_fontBitmap.rawBitmap()->copy((triplet.data()-32)*12, 24*10, 12, 10);
|
return m_fontBitmap.rawBitmap()->copy((triplet.data()-32)*12, 24*10, 12, 10);
|
||||||
|
|||||||
Reference in New Issue
Block a user