Use last codepage conveniently (#1023)
This commit is contained in:
parent
6e0f34a79a
commit
f2cf0ac0b1
|
|
@ -192,12 +192,32 @@ void CPUDump::setupContextMenu()
|
|||
MenuBuilder* wHexMenu = new MenuBuilder(this);
|
||||
wHexMenu->addAction(makeAction(DIcon("ascii.png"), tr("&ASCII"), SLOT(hexAsciiSlot())));
|
||||
wHexMenu->addAction(makeAction(DIcon("ascii-extended.png"), tr("&Extended ASCII"), SLOT(hexUnicodeSlot())));
|
||||
QAction* wHexLastCodepage = makeAction(DIcon("codepage.png"), "?", SLOT(hexLastCodepageSlot()));
|
||||
wHexMenu->addAction(wHexLastCodepage, [wHexLastCodepage](QMenu*)
|
||||
{
|
||||
duint lastCodepage;
|
||||
auto allCodecs = QTextCodec::availableCodecs();
|
||||
if(!BridgeSettingGetUint("Misc", "LastCodepage", &lastCodepage) || lastCodepage >= duint(allCodecs.size()))
|
||||
return false;
|
||||
wHexLastCodepage->setText(QString::fromLocal8Bit(allCodecs.at(lastCodepage)));
|
||||
return true;
|
||||
});
|
||||
wHexMenu->addAction(makeAction(DIcon("codepage.png"), tr("&Codepage..."), SLOT(hexCodepageSlot())));
|
||||
mMenuBuilder->addMenu(makeMenu(DIcon("hex.png"), tr("&Hex")), wHexMenu);
|
||||
|
||||
MenuBuilder* wTextMenu = new MenuBuilder(this);
|
||||
wTextMenu->addAction(makeAction(DIcon("ascii.png"), tr("&ASCII"), SLOT(textAsciiSlot())));
|
||||
wTextMenu->addAction(makeAction(DIcon("ascii-extended.png"), tr("&Extended ASCII"), SLOT(textUnicodeSlot())));
|
||||
QAction* wTextLastCodepage = makeAction(DIcon("codepage.png"), "?", SLOT(textLastCodepageSlot()));
|
||||
wTextMenu->addAction(wTextLastCodepage, [wTextLastCodepage](QMenu*)
|
||||
{
|
||||
duint lastCodepage;
|
||||
auto allCodecs = QTextCodec::availableCodecs();
|
||||
if(!BridgeSettingGetUint("Misc", "LastCodepage", &lastCodepage) || lastCodepage >= duint(allCodecs.size()))
|
||||
return false;
|
||||
wTextLastCodepage->setText(QString::fromLocal8Bit(allCodecs.at(lastCodepage)));
|
||||
return true;
|
||||
});
|
||||
wTextMenu->addAction(makeAction(DIcon("codepage.png"), tr("&Codepage..."), SLOT(textCodepageSlot())));
|
||||
mMenuBuilder->addMenu(makeMenu(DIcon("strings.png"), tr("&Text")), wTextMenu);
|
||||
|
||||
|
|
@ -575,6 +595,57 @@ void CPUDump::hexCodepageSlot()
|
|||
reloadData();
|
||||
}
|
||||
|
||||
void CPUDump::hexLastCodepageSlot()
|
||||
{
|
||||
int charwidth = getCharWidth();
|
||||
ColumnDescriptor_t wColDesc;
|
||||
DataDescriptor_t dDesc;
|
||||
duint lastCodepage;
|
||||
auto allCodecs = QTextCodec::availableCodecs();
|
||||
if(!BridgeSettingGetUint("Misc", "LastCodepage", &lastCodepage) || lastCodepage >= duint(allCodecs.size()))
|
||||
return;
|
||||
|
||||
wColDesc.isData = true; //hex byte
|
||||
wColDesc.itemCount = 16;
|
||||
wColDesc.separator = 4;
|
||||
dDesc.itemSize = Byte;
|
||||
dDesc.byteMode = HexByte;
|
||||
wColDesc.data = dDesc;
|
||||
appendResetDescriptor(8 + charwidth * 47, tr("Hex"), false, wColDesc);
|
||||
|
||||
wColDesc.isData = true; //text (in code page)
|
||||
wColDesc.itemCount = 16;
|
||||
wColDesc.separator = 0;
|
||||
wColDesc.textCodec = QTextCodec::codecForName(allCodecs.at(lastCodepage));
|
||||
dDesc.itemSize = Byte;
|
||||
dDesc.byteMode = AsciiByte;
|
||||
wColDesc.data = dDesc;
|
||||
appendDescriptor(0, allCodecs.at(lastCodepage), false, wColDesc);
|
||||
|
||||
reloadData();
|
||||
}
|
||||
|
||||
void CPUDump::textLastCodepageSlot()
|
||||
{
|
||||
ColumnDescriptor_t wColDesc;
|
||||
DataDescriptor_t dDesc;
|
||||
duint lastCodepage;
|
||||
auto allCodecs = QTextCodec::availableCodecs();
|
||||
if(!BridgeSettingGetUint("Misc", "LastCodepage", &lastCodepage) || lastCodepage >= duint(allCodecs.size()))
|
||||
return;
|
||||
|
||||
wColDesc.isData = true; //text (in code page)
|
||||
wColDesc.itemCount = 64;
|
||||
wColDesc.separator = 0;
|
||||
wColDesc.textCodec = QTextCodec::codecForName(allCodecs.at(lastCodepage));
|
||||
dDesc.itemSize = Byte;
|
||||
dDesc.byteMode = AsciiByte;
|
||||
wColDesc.data = dDesc;
|
||||
appendResetDescriptor(0, allCodecs.at(lastCodepage), false, wColDesc);
|
||||
|
||||
reloadData();
|
||||
}
|
||||
|
||||
void CPUDump::textAsciiSlot()
|
||||
{
|
||||
Config()->setUint("HexDump", "DefaultView", (duint)ViewTextAscii);
|
||||
|
|
|
|||
|
|
@ -52,10 +52,12 @@ public slots:
|
|||
void hexAsciiSlot();
|
||||
void hexUnicodeSlot();
|
||||
void hexCodepageSlot();
|
||||
void hexLastCodepageSlot();
|
||||
|
||||
void textAsciiSlot();
|
||||
void textUnicodeSlot();
|
||||
void textCodepageSlot();
|
||||
void textLastCodepageSlot();
|
||||
|
||||
void integerSignedByteSlot();
|
||||
void integerSignedShortSlot();
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ QString CPUInfoBox::getSymbolicName(dsint addr)
|
|||
}
|
||||
else if(addr == (addr & 0xFFF)) //UNICODE?
|
||||
{
|
||||
QChar c = QChar::fromLatin1((wchar_t)addr);
|
||||
QChar c = QChar((ushort)addr);
|
||||
if(c.isPrint())
|
||||
finalText += " L'" + QString(c) + "'";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ void CalculatorDialog::expressionChanged(bool validExpression, bool validPointer
|
|||
ui->txtAscii->setCursorPosition(1);
|
||||
if((value == (value & 0xFFF))) //UNICODE?
|
||||
{
|
||||
QChar c = QChar::fromLatin1((wchar_t)value);
|
||||
QChar c = QChar((ushort)value);
|
||||
if(c.isPrint())
|
||||
ui->txtUnicode->setText("L'" + QString(c) + "'");
|
||||
else
|
||||
|
|
@ -233,7 +233,7 @@ void CalculatorDialog::on_txtAscii_textEdited(const QString & arg1)
|
|||
return;
|
||||
}
|
||||
ui->txtAscii->setStyleSheet("");
|
||||
ui->txtExpression->setText(QString().sprintf("%X", text[0].toLatin1()));
|
||||
ui->txtExpression->setText(QString().sprintf("%X", text[0].unicode()));
|
||||
ui->txtAscii->setCursorPosition(1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -143,6 +143,12 @@ void HexEditDialog::on_btnCodepage_clicked()
|
|||
return;
|
||||
LineEditDialog lineEdit(this);
|
||||
lineEdit.setWindowTitle(tr("Enter text to convert..."));
|
||||
QString oldText;
|
||||
oldText = textCodec->toUnicode(mHexEdit->data());
|
||||
for(auto & i : oldText)
|
||||
if(!i.isPrint())
|
||||
i = QChar('.');
|
||||
lineEdit.setText(oldText);
|
||||
if(lineEdit.exec() != QDialog::Accepted)
|
||||
return;
|
||||
mHexEdit->setData(resizeData(textCodec->fromUnicode(lineEdit.editText)));
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ void HexLineEdit::keyPressEvent(QKeyEvent* event)
|
|||
switch(mEncoding)
|
||||
{
|
||||
case Encoding::Ascii:
|
||||
keyText = event->text().toLatin1();
|
||||
keyText = event->text().toLocal8Bit();
|
||||
break;
|
||||
case Encoding::Unicode:
|
||||
keyText = event->text();
|
||||
|
|
@ -71,22 +71,16 @@ void HexLineEdit::setData(const QByteArray & data)
|
|||
switch(mEncoding)
|
||||
{
|
||||
case Encoding::Ascii:
|
||||
for(int i = 0; i < data.size(); i++)
|
||||
{
|
||||
QChar ch(data.constData()[i]);
|
||||
if(ch >= 0 && ch <= 255)
|
||||
text += ch.toLatin1();
|
||||
}
|
||||
text = QString::fromLocal8Bit(data);
|
||||
break;
|
||||
|
||||
case Encoding::Unicode:
|
||||
for(int i = 0, j = 0; i < data.size(); i += sizeof(wchar_t), j++)
|
||||
{
|
||||
QChar wch(((wchar_t*)data.constData())[j]);
|
||||
text += wch;
|
||||
}
|
||||
text = QString::fromUtf16((const ushort *)data.constData());
|
||||
break;
|
||||
}
|
||||
for(auto & i : text)
|
||||
if(!i.isPrint())
|
||||
i = QChar(' ');
|
||||
|
||||
mData = toEncodedData(text);
|
||||
setText(text);
|
||||
|
|
@ -162,8 +156,7 @@ QByteArray HexLineEdit::toEncodedData(const QString & text)
|
|||
switch(mEncoding)
|
||||
{
|
||||
case Encoding::Ascii:
|
||||
for(int i = 0; i < text.length(); i++)
|
||||
data.append(text[i].toLatin1());
|
||||
data = text.toLocal8Bit();
|
||||
break;
|
||||
|
||||
case Encoding::Unicode:
|
||||
|
|
|
|||
Loading…
Reference in New Issue