diff --git a/x26dockwidget.cpp b/x26dockwidget.cpp index 3e67f33..f07849a 100644 --- a/x26dockwidget.cpp +++ b/x26dockwidget.cpp @@ -17,6 +17,7 @@ * along with QTeletextMaker. If not, see . */ +#include #include #include #include @@ -34,8 +35,42 @@ #include #include +#include "render.h" #include "x26dockwidget.h" +CharacterListModel::CharacterListModel(QObject *parent): QAbstractListModel(parent) +{ + m_characterSet = 0; +} + +int CharacterListModel::rowCount(const QModelIndex & /*parent*/) const +{ + return 96; +} + +QVariant CharacterListModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role == Qt::DisplayRole) + return QString("0x%1").arg(index.row()+0x20, 2, 16); + + if (role == Qt::DecorationRole) + return m_fontBitmap.rawBitmap()->copy(index.row()*12, m_characterSet*10, 12, 10); + + return QVariant(); +} + +void CharacterListModel::setCharacterSet(int characterSet) +{ + if (characterSet != m_characterSet) { + m_characterSet = characterSet; + emit dataChanged(createIndex(0, 0), createIndex(95, 0), QVector(Qt::DecorationRole)); + } +} + + X26DockWidget::X26DockWidget(TeletextWidget *parent): QDockWidget(parent) { QVBoxLayout *x26Layout = new QVBoxLayout; @@ -181,8 +216,7 @@ X26DockWidget::X26DockWidget(TeletextWidget *parent): QDockWidget(parent) QHBoxLayout *characterCodeLayout = new QHBoxLayout; m_characterCodeComboBox = new QComboBox; - for (int i=32; i<128; i++) - m_characterCodeComboBox->addItem(QString("0x%1").arg(i, 2, 16), i); + m_characterCodeComboBox->setModel(&m_characterListModel); characterCodeLayout->addWidget(m_characterCodeComboBox); connect(m_characterCodeComboBox, QOverload::of(&QComboBox::activated), this, [=](const int value) { updateModelFromCookedWidget(value+32, Qt::UserRole+1); } ); @@ -705,7 +739,16 @@ void X26DockWidget::updateCookedTripletParameters(const QModelIndex &index) case 0x29: // G0 character case 0x2b: // G3 character at Level 2.5 case 0x2f ... 0x3f: // G2 character, G0 character with diacritical + // TODO non-Latin G0 and G2 character sets m_characterCodeComboBox->blockSignals(true); + if (modeExt == 0x22 || modeExt == 0x2b) + m_characterListModel.setCharacterSet(26); + else if (modeExt == 0x2f) + m_characterListModel.setCharacterSet(7); + else if (modeExt == 0x21) + m_characterListModel.setCharacterSet(24); + else + m_characterListModel.setCharacterSet(0); m_characterCodeComboBox->setCurrentIndex(index.model()->data(index.model()->index(index.row(), 0), Qt::UserRole+1).toInt()-32); m_characterCodeComboBox->blockSignals(false); m_tripletParameterStackedLayout->setCurrentIndex(2); diff --git a/x26dockwidget.h b/x26dockwidget.h index 674349f..3453ab0 100644 --- a/x26dockwidget.h +++ b/x26dockwidget.h @@ -20,6 +20,7 @@ #ifndef X26DOCKWIDGET_H #define X26DOCKWIDGET_H +#include #include #include #include @@ -31,8 +32,25 @@ #include #include "mainwidget.h" +#include "render.h" #include "x26model.h" +class CharacterListModel : public QAbstractListModel +{ + Q_OBJECT + +public: + CharacterListModel(QObject *parent = 0); + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + void setCharacterSet(int); + +private: + TeletextFontBitmap m_fontBitmap; + int m_characterSet; +}; + class X26DockWidget : public QDockWidget { Q_OBJECT @@ -63,6 +81,7 @@ public slots: protected: void keyPressEvent(QKeyEvent *event) override; + CharacterListModel m_characterListModel; private: QTableView *m_x26View; diff --git a/x26model.cpp b/x26model.cpp index d2125b8..aec8f99 100644 --- a/x26model.cpp +++ b/x26model.cpp @@ -21,6 +21,7 @@ #include +#include "render.h" #include "x26commands.h" X26Model::X26Model(TeletextWidget *parent): QAbstractListModel(parent) @@ -309,15 +310,36 @@ QVariant X26Model::data(const QModelIndex &index, int role) const return QString("Reserved 0x%1").arg(m_parentMainWidget->document()->currentSubPage()->enhancements()->at(index.row()).data(), 2, 16, QChar('0')); } + if (role == Qt::DecorationRole && index.column() == 3) + switch (mode) { + case 0x21: // G1 mosaic character + if (m_parentMainWidget->document()->currentSubPage()->enhancements()->at(index.row()).data() & 0x20) + return m_fontBitmap.rawBitmap()->copy((m_parentMainWidget->document()->currentSubPage()->enhancements()->at(index.row()).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 + if (m_parentMainWidget->document()->currentSubPage()->enhancements()->at(index.row()).data() >= 0x20) + return m_fontBitmap.rawBitmap()->copy((m_parentMainWidget->document()->currentSubPage()->enhancements()->at(index.row()).data()-32)*12, 26*10, 12, 10); + break; + case 0x2f: // G2 character + // TODO non-Latin G2 character sets + if (m_parentMainWidget->document()->currentSubPage()->enhancements()->at(index.row()).data() >= 0x20) + return m_fontBitmap.rawBitmap()->copy((m_parentMainWidget->document()->currentSubPage()->enhancements()->at(index.row()).data()-32)*12, 7*10, 12, 10); + break; + case 0x29: // G0 character + case 0x30 ... 0x3f: // G0 diacritical mark + // TODO non-Latin G0 character sets + if (m_parentMainWidget->document()->currentSubPage()->enhancements()->at(index.row()).data() >= 0x20) + return m_fontBitmap.rawBitmap()->copy((m_parentMainWidget->document()->currentSubPage()->enhancements()->at(index.row()).data()-32)*12, 0, 12, 10); + break; + }; + if (role == Qt::EditRole && index.column() == 2) { if (!m_parentMainWidget->document()->currentSubPage()->enhancements()->at(index.row()).isRowTriplet()) mode |= 0x20; return mode; } - if (role <= Qt::UserRole) - return QVariant(); - switch (role) { case Qt::UserRole+1: switch (mode) { diff --git a/x26model.h b/x26model.h index 6fa2f56..bf4eee8 100644 --- a/x26model.h +++ b/x26model.h @@ -22,6 +22,7 @@ #include #include "mainwidget.h" +#include "render.h" class X26Model : public QAbstractListModel { @@ -49,6 +50,7 @@ public: private: TeletextWidget *m_parentMainWidget; bool m_listLoaded; + TeletextFontBitmap m_fontBitmap; }; static const QString modeTripletName[64] {