From 2f8c2cfd598e38190ac4ac73e16f8ebc8fe28a14 Mon Sep 17 00:00:00 2001 From: Mark Long Date: Mon, 24 Oct 2016 00:41:35 -0500 Subject: [PATCH] Updates to CharacterSetExplorer in CharSetViewer --- src/ui/viewers/charsetviewer.cpp | 26 +++++++++ src/ui/viewers/charsetviewer.h | 7 +++ src/ui/widgets/CharacterSetExplorer.cpp | 72 +++++++++++++++++++++++++ src/ui/widgets/CharacterSetExplorer.h | 13 +++++ src/ui/widgets/CharacterSetExplorer.ui | 36 ++++++++++++- src/ui/widgets/HiresScreenWidget.cpp | 28 +++++----- src/util/charset.h | 3 +- 7 files changed, 167 insertions(+), 18 deletions(-) diff --git a/src/ui/viewers/charsetviewer.cpp b/src/ui/viewers/charsetviewer.cpp index cb720e6..305c31b 100644 --- a/src/ui/viewers/charsetviewer.cpp +++ b/src/ui/viewers/charsetviewer.cpp @@ -7,6 +7,7 @@ CharSetViewer::CharSetViewer(QWidget *parent) : FileViewerInterface(parent) { m_file = Q_NULLPTR; + m_cse = Q_NULLPTR; QGridLayout *qgl = new QGridLayout(this); setLayout(qgl); @@ -14,6 +15,10 @@ CharSetViewer::CharSetViewer(QWidget *parent) : FileViewerInterface(parent) setWindowTitle(title); } +CharSetViewer::~CharSetViewer() +{ +} + void CharSetViewer::setFile(GenericFile *file) { if (dynamic_cast(file)) @@ -73,9 +78,30 @@ bool CharSetViewer::optionsMenuItems(QMenu *menu) connect(action, SIGNAL(toggled(bool)),SLOT(enableBitShift(bool))); menu->addAction(action); + menu->addSeparator(); + + action = new QAction("&Character Set Explorer..."); + connect(action, SIGNAL(triggered(bool)), SLOT(showExplorer())); + menu->addAction(action); + return true; } +void CharSetViewer::showExplorer() +{ + if (!m_cse) { + m_cse = new CharacterSetExplorer(this); + connect(m_cse, SIGNAL(destroyed(QObject*)), SLOT(cleanupExplorer())); + m_cse->setCharSet(m_charset); + } + m_cse->show(); + m_cse->raise(); +} + +void CharSetViewer::cleanupExplorer() +{ + m_cse = Q_NULLPTR; +} QList CharSetViewer::getChildren() { diff --git a/src/ui/viewers/charsetviewer.h b/src/ui/viewers/charsetviewer.h index 3674afa..7b65411 100644 --- a/src/ui/viewers/charsetviewer.h +++ b/src/ui/viewers/charsetviewer.h @@ -4,6 +4,7 @@ #include "binaryfile.h" #include "characterwidget.h" #include "fileviewerinterface.h" +#include "CharacterSetExplorer.h" #include @@ -12,6 +13,7 @@ class CharSetViewer : public FileViewerInterface Q_OBJECT public: explicit CharSetViewer(QWidget *parent = 0); + virtual ~CharSetViewer(); void setFile(GenericFile *file); void setFile(BinaryFile *file); @@ -26,12 +28,16 @@ public slots: void showGrid(bool show); void enableBitShift(bool enable); + void showExplorer(); signals: protected: QList getChildren(); +protected slots: + void cleanupExplorer(); + private: BinaryFile *m_file; @@ -39,6 +45,7 @@ private: CharacterSet m_charset; + CharacterSetExplorer *m_cse; }; #endif // CHARSETVIEWER_H diff --git a/src/ui/widgets/CharacterSetExplorer.cpp b/src/ui/widgets/CharacterSetExplorer.cpp index 52fcffe..c175231 100644 --- a/src/ui/widgets/CharacterSetExplorer.cpp +++ b/src/ui/widgets/CharacterSetExplorer.cpp @@ -5,10 +5,82 @@ CharacterSetExplorer::CharacterSetExplorer(QWidget *parent) : QDialog(parent), ui(new Ui::CharacterSetExplorer) { + m_unpackedScreen.fill(0,8192); ui->setupUi(this); + connect(ui->drawButton, SIGNAL(clicked(bool)), SLOT(handleDrawButton())); + connect(ui->insertChar, SIGNAL(clicked(bool)), SLOT(handleInsertCharButton())); + connect(ui->inputText, SIGNAL(textChanged(QString)), SLOT(handleTextChanged(QString))); +} + +void CharacterSetExplorer::setCharSet(CharacterSet &charset) +{ + m_charset = charset; } CharacterSetExplorer::~CharacterSetExplorer() { delete ui; } + +void CharacterSetExplorer::handleDrawButton() +{ + handleTextChanged(ui->inputText->text()); +} + +void CharacterSetExplorer::handleInsertCharButton() +{ + +} + +void CharacterSetExplorer::handleTextChanged(QString string) +{ + int currCursorX = 0; + int currCursorY = 0; + m_unpackedScreen.fill(0x00,8192); + + foreach (QChar character, string) + { + if (character.unicode() < 128) + { + if (character.unicode() < 32) + { + // Handle control character + } + else + { + // Handle ASCII value + if (m_charset.contains(character.unicode())) + { + QByteArray chardata = m_charset[character.unicode()].data(); + + for (int idx = 0; idx < 8; idx++) + { + int baseY = (currCursorY * 8 + idx) * 40; + quint8 chr = chardata[idx]; + m_unpackedScreen[baseY + currCursorX] = chr; + } + currCursorX++; + + if (currCursorX >= 40) { + currCursorY++; + currCursorX = 0; + } + if (currCursorY >= 24) + { + currCursorX = 0; + currCursorY = 0; + } + } + else + { + qDebug() << "Character" << character.unicode() << "not defined in char set"; + } + } + } + else + { + qDebug() << "Unhandled character: " << character.unicode(); + } + } + ui->drawWidget->setUnpackedData(m_unpackedScreen); +} diff --git a/src/ui/widgets/CharacterSetExplorer.h b/src/ui/widgets/CharacterSetExplorer.h index 4b52663..6911847 100644 --- a/src/ui/widgets/CharacterSetExplorer.h +++ b/src/ui/widgets/CharacterSetExplorer.h @@ -3,6 +3,8 @@ #include +#include "charset.h" + namespace Ui { class CharacterSetExplorer; } @@ -15,8 +17,19 @@ public: explicit CharacterSetExplorer(QWidget *parent = 0); ~CharacterSetExplorer(); + void setCharSet(CharacterSet &charset); + +public slots: + void handleDrawButton(); + void handleInsertCharButton(); + void handleTextChanged(QString string); + private: Ui::CharacterSetExplorer *ui; + + QByteArray m_unpackedScreen; + + CharacterSet m_charset; }; #endif // CHARACTERSETEXPLORER_H diff --git a/src/ui/widgets/CharacterSetExplorer.ui b/src/ui/widgets/CharacterSetExplorer.ui index 527f891..5e9cef3 100644 --- a/src/ui/widgets/CharacterSetExplorer.ui +++ b/src/ui/widgets/CharacterSetExplorer.ui @@ -10,12 +10,31 @@ 352 + + + 0 + 0 + + Dialog + + true + + + + - + + + + 561 + 384 + + + @@ -29,6 +48,13 @@ + + + + Insert Char... + + + @@ -40,6 +66,14 @@ + + + HiresScreenWidget + QWidget +
HiresScreenWidget.h
+ 1 +
+
diff --git a/src/ui/widgets/HiresScreenWidget.cpp b/src/ui/widgets/HiresScreenWidget.cpp index d3cd799..c564ee7 100644 --- a/src/ui/widgets/HiresScreenWidget.cpp +++ b/src/ui/widgets/HiresScreenWidget.cpp @@ -120,8 +120,8 @@ void HiresScreenWidget::resizeEvent(QResizeEvent *) } -void HiresScreenWidget::drawPixmap() { - +void HiresScreenWidget::drawPixmap() +{ QPainter pmpainter(&m_pixmap); pmpainter.setBrush(Qt::black); @@ -207,7 +207,7 @@ void HiresScreenWidget::drawPixmap() { int xoff = cr.col() * 7; int yoff = cr.row() * 2; - quint8 cOffset = 0;// highBit?1:0; + quint8 cOffset = highBit?1:0; quint8 doubleScan = 0; if (!m_showScanLines) @@ -276,7 +276,11 @@ QByteArray HiresScreenWidget::packData(QByteArray unpackedData) for (int idx = 0; idx < qMin(unpackedData.count(),8192); idx++) { ColRow cr = getColRowFromRawAddress(idx); - packedData[cr.appleAddress()] = unpackedData[idx]; + + if (cr.isDefined()) + { + packedData[cr.appleAddress()] = unpackedData[idx]; + } } return packedData; @@ -303,20 +307,17 @@ int HiresScreenWidget::getLineAddressOffset(int line) void HiresScreenWidget::setData(QByteArray data) { m_data = data; - drawPixmap(); + repaint(); } void HiresScreenWidget::drawMonoLine(QPainter &painter, int lineNum, QBitArray data) { + painter.setPen(Qt::black); + painter.drawLine(0,lineNum,data.count(),lineNum); + painter.setPen(Qt::white); for (int idx = 0; idx < data.count(); idx++) { if (data.at(idx)) - { - painter.setPen(Qt::white); - } else { - painter.setPen(Qt::black); - } - - painter.drawPoint(idx,lineNum); + painter.drawPoint(idx,lineNum); } } @@ -402,7 +403,6 @@ QColor HiresScreenWidget::getColorFromBits(QBitArray bits, quint8 phase) if (bitval == 7 && phase == 3) return lightBlueColor; return whiteColor; - } void HiresScreenWidget::drawNtscLine(QPainter &painter, int lineNum, QBitArray data) { @@ -479,7 +479,6 @@ HiresScreenWidget::ColRow HiresScreenWidget::getColRowFromRawAddress(quint16 add void HiresScreenWidget::makeAddressTables() { - qDebug() << " ****** makeAddressTables()"; m_rawAddressToColRowList.resize(8192); m_appleAddressToColRowList.resize(8192); @@ -488,7 +487,6 @@ void HiresScreenWidget::makeAddressTables() for (int col = 0; col < 40; col++) { ColRow cr(col,row); - // qDebug() << "Col: " << col << "Row: " << row << "Raw: " << cr.rawAddress() << " Apple: " << cr.appleAddress(); m_rawAddressToColRowList[cr.rawAddress()] = cr; m_appleAddressToColRowList[cr.appleAddress()] = cr; diff --git a/src/util/charset.h b/src/util/charset.h index f68dc59..fd34de5 100644 --- a/src/util/charset.h +++ b/src/util/charset.h @@ -24,14 +24,13 @@ private: }; - - class CharacterSet { public: void buildSetFromSetBlob(QByteArray data); CharSetCharacter operator[](int asciival) const { return m_charmap[asciival]; } QList allCharacters() const; + bool contains(int asciival) { return m_charmap.keys().contains(asciival); } private: QMap m_charmap;