GUI: also use the Calculator to calculate from hex, signed int, unsigned int, octal, binary, ascii, unicode to the others
This commit is contained in:
parent
0f0a2b3f71
commit
91ee4ca292
|
@ -10,6 +10,9 @@ CalculatorDialog::CalculatorDialog(QWidget *parent) : QDialog(parent), ui(new Ui
|
|||
connect(ui->txtExpression,SIGNAL(textChanged(QString)),this,SLOT(answerExpression(QString)));
|
||||
connect(this,SIGNAL(validAddress(bool)),ui->btnGoto,SLOT(setEnabled(bool)));
|
||||
emit validAddress(false);
|
||||
ui->txtBin->setInputMask(QString("bbbb ").repeated(sizeof(uint_t)*2));
|
||||
ui->txtExpression->setText("0");
|
||||
ui->txtExpression->selectAll();
|
||||
ui->txtExpression->setFocus();
|
||||
}
|
||||
|
||||
|
@ -20,52 +23,65 @@ CalculatorDialog::~CalculatorDialog()
|
|||
|
||||
void CalculatorDialog::setExpressionFocus()
|
||||
{
|
||||
ui->txtExpression->selectAll();
|
||||
ui->txtExpression->setFocus();
|
||||
}
|
||||
|
||||
void CalculatorDialog::answerExpression(QString expression)
|
||||
{
|
||||
|
||||
ui->txtHex->setStyleSheet("");
|
||||
ui->txtSignedDec->setStyleSheet("");
|
||||
ui->txtUnsignedDec->setStyleSheet("");
|
||||
ui->txtOct->setStyleSheet("");
|
||||
ui->txtBin->setStyleSheet("");
|
||||
ui->txtAscii->setStyleSheet("");
|
||||
ui->txtUnicode->setStyleSheet("");
|
||||
if(!DbgIsValidExpression(expression.toUtf8().constData()))
|
||||
{
|
||||
ui->txtBin->setText("");
|
||||
ui->txtDec->setText("");
|
||||
ui->txtSignedDec->setText("");
|
||||
ui->txtUnsignedDec->setText("");
|
||||
ui->txtHex->setText("");
|
||||
ui->txtOct->setText("");
|
||||
ui->txtAscii->setText("");
|
||||
ui->txtUnicode->setText("");
|
||||
ui->txtExpression->setStyleSheet("border: 2px solid red");
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->txtExpression->setStyleSheet("");
|
||||
uint_t ans = DbgValFromString(expression.toUtf8().constData());
|
||||
ui->txtHex->setText(inFormat(ans,N_HEX));
|
||||
ui->txtDec->setText(inFormat(ans,N_DEC));
|
||||
ui->txtSignedDec->setText(inFormat(ans,N_SDEC));
|
||||
ui->txtUnsignedDec->setText(inFormat(ans,N_UDEC));
|
||||
int cursorpos=ui->txtBin->cursorPosition();
|
||||
ui->txtBin->setText(inFormat(ans,N_BIN));
|
||||
ui->txtBin->setCursorPosition(cursorpos);
|
||||
ui->txtOct->setText(inFormat(ans,N_OCT));
|
||||
if((ans == (ans & 0xFF)) )
|
||||
{
|
||||
QChar c = QChar((char)ans);
|
||||
if(c.isPrint())
|
||||
ui->txtAscii->setText(QString(c));
|
||||
ui->txtAscii->setText("'"+QString(c)+"'");
|
||||
else
|
||||
ui->txtAscii->setText("???");
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->txtAscii->setText("???");
|
||||
if((ans == (ans & 0xFFF)) ) //UNICODE?
|
||||
{
|
||||
QChar c = QChar((wchar_t)ans);
|
||||
if(c.isPrint())
|
||||
ui->txtUnicode->setText(QString(c));
|
||||
else
|
||||
ui->txtUnicode->setText("???");
|
||||
}
|
||||
ui->txtAscii->setCursorPosition(1);
|
||||
if((ans == (ans & 0xFFF)) ) //UNICODE?
|
||||
{
|
||||
QChar c = QChar((wchar_t)ans);
|
||||
if(c.isPrint())
|
||||
ui->txtUnicode->setText("L'"+QString(c)+"'");
|
||||
else
|
||||
{
|
||||
ui->txtUnicode->setText("???");
|
||||
}
|
||||
ui->txtUnicode->setText("????");
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->txtUnicode->setText("????");
|
||||
}
|
||||
ui->txtUnicode->setCursorPosition(2);
|
||||
emit validAddress(DbgMemIsValidReadPtr(ans));
|
||||
}
|
||||
}
|
||||
|
@ -76,29 +92,25 @@ QString CalculatorDialog::inFormat(const uint_t val, CalculatorDialog::NUMBERFOR
|
|||
{
|
||||
default:
|
||||
case N_HEX:
|
||||
// 0,...,9 in hex is the same as in dec
|
||||
if(val<10 && val>=0)
|
||||
return QString("%1").arg(val,1,16,QChar('0')).toUpper();
|
||||
return QString("%1").arg(val,1,16,QChar('0')).toUpper()+"h";
|
||||
case N_DEC:
|
||||
// 0,...,9 in hex is the same as in dec
|
||||
if(val<10 && val>=0)
|
||||
return QString("%1").arg(val);
|
||||
return QString("%1").arg(val, 1, 16, QChar('0')).toUpper();
|
||||
case N_SDEC:
|
||||
return QString("%1").arg((int_t)val);
|
||||
case N_UDEC:
|
||||
return QString("%1").arg(val);
|
||||
case N_BIN:
|
||||
{
|
||||
QString binary = QString("%1").arg(val,8*4,2,QChar('0')).toUpper();
|
||||
QString binary = QString("%1").arg(val, 8*sizeof(uint_t), 2, QChar('0')).toUpper();
|
||||
QString ans = "";
|
||||
for(int i=0; i<4*8; i++)
|
||||
for(int i=0; i<sizeof(uint_t)*8; i++)
|
||||
{
|
||||
ans += binary[i];
|
||||
if((i%4==0) && (i!=0))
|
||||
ans += " ";
|
||||
ans += binary[i];
|
||||
}
|
||||
return ans +"b";
|
||||
return ans;
|
||||
}
|
||||
case N_OCT:
|
||||
return QString("%1").arg(val,1,8,QChar('0')).toUpper()+"o";
|
||||
return QString("%1").arg(val, 1, 8, QChar('0')).toUpper();
|
||||
case N_ASCII:
|
||||
return QString("'%1'").arg((char)val);
|
||||
}
|
||||
|
@ -109,3 +121,98 @@ void CalculatorDialog::on_btnGoto_clicked()
|
|||
DbgCmdExecDirect(QString("disasm " + ui->txtExpression->text()).toUtf8().constData());
|
||||
emit showCpu();
|
||||
}
|
||||
|
||||
void CalculatorDialog::on_txtHex_textEdited(const QString &arg1)
|
||||
{
|
||||
bool ok=false;
|
||||
ULONGLONG val = arg1.toULongLong(&ok, 16);
|
||||
if(!ok)
|
||||
{
|
||||
ui->txtHex->setStyleSheet("border: 2px solid red");
|
||||
return;
|
||||
}
|
||||
ui->txtHex->setStyleSheet("");
|
||||
ui->txtExpression->setText(QString("%1").arg(val, 1, 16, QChar('0')).toUpper());
|
||||
}
|
||||
|
||||
void CalculatorDialog::on_txtSignedDec_textEdited(const QString &arg1)
|
||||
{
|
||||
bool ok=false;
|
||||
LONGLONG val = arg1.toLongLong(&ok, 10);
|
||||
if(!ok)
|
||||
{
|
||||
ui->txtUnsignedDec->setStyleSheet("border: 2px solid red");
|
||||
return;
|
||||
}
|
||||
ui->txtUnsignedDec->setStyleSheet("");
|
||||
ui->txtExpression->setText(QString("%1").arg(val, 1, 16, QChar('0')).toUpper());
|
||||
}
|
||||
|
||||
void CalculatorDialog::on_txtUnsignedDec_textEdited(const QString &arg1)
|
||||
{
|
||||
bool ok=false;
|
||||
LONGLONG val = arg1.toULongLong(&ok, 10);
|
||||
if(!ok)
|
||||
{
|
||||
ui->txtUnsignedDec->setStyleSheet("border: 2px solid red");
|
||||
return;
|
||||
}
|
||||
ui->txtUnsignedDec->setStyleSheet("");
|
||||
ui->txtExpression->setText(QString("%1").arg(val, 1, 16, QChar('0')).toUpper());
|
||||
}
|
||||
|
||||
void CalculatorDialog::on_txtOct_textEdited(const QString &arg1)
|
||||
{
|
||||
bool ok=false;
|
||||
ULONGLONG val = arg1.toULongLong(&ok, 8);
|
||||
if(!ok)
|
||||
{
|
||||
ui->txtOct->setStyleSheet("border: 2px solid red");
|
||||
return;
|
||||
}
|
||||
ui->txtOct->setStyleSheet("");
|
||||
ui->txtExpression->setText(QString("%1").arg(val, 1, 16, QChar('0')).toUpper());
|
||||
}
|
||||
|
||||
void CalculatorDialog::on_txtBin_textEdited(const QString &arg1)
|
||||
{
|
||||
bool ok=false;
|
||||
QString text = arg1;
|
||||
text = text.replace(" ", "");
|
||||
ULONGLONG val = text.toULongLong(&ok, 2);
|
||||
if(!ok)
|
||||
{
|
||||
ui->txtBin->setStyleSheet("border: 2px solid red");
|
||||
return;
|
||||
}
|
||||
ui->txtBin->setStyleSheet("");
|
||||
ui->txtExpression->setText(QString("%1").arg(val, 1, 16, QChar('0')).toUpper());
|
||||
}
|
||||
|
||||
void CalculatorDialog::on_txtAscii_textEdited(const QString &arg1)
|
||||
{
|
||||
QString text = arg1;
|
||||
text = text.replace("'", "");
|
||||
if(text.length() > 1)
|
||||
{
|
||||
ui->txtAscii->setStyleSheet("border: 2px solid red");
|
||||
return;
|
||||
}
|
||||
ui->txtAscii->setStyleSheet("");
|
||||
ui->txtExpression->setText(QString().sprintf("%X", text[0].toAscii()));
|
||||
ui->txtAscii->setCursorPosition(1);
|
||||
}
|
||||
|
||||
void CalculatorDialog::on_txtUnicode_textEdited(const QString &arg1)
|
||||
{
|
||||
QString text = arg1;
|
||||
text = text.replace("L'", "").replace("'", "");
|
||||
if(text.length() > 1)
|
||||
{
|
||||
ui->txtUnicode->setStyleSheet("border: 2px solid red");
|
||||
return;
|
||||
}
|
||||
ui->txtUnicode->setStyleSheet("");
|
||||
ui->txtExpression->setText(QString().sprintf("%X", text[0].unicode()));
|
||||
ui->txtUnicode->setCursorPosition(2);
|
||||
}
|
||||
|
|
|
@ -15,23 +15,35 @@ class CalculatorDialog : public QDialog
|
|||
enum NUMBERFORMAT
|
||||
{
|
||||
N_HEX=16,
|
||||
N_DEC=10,
|
||||
N_SDEC=10,
|
||||
N_UDEC=11,
|
||||
N_BIN=2,
|
||||
N_OCT=8,
|
||||
N_ASCII=0,
|
||||
N_UNKNOWN=-1
|
||||
};
|
||||
|
||||
public:
|
||||
explicit CalculatorDialog(QWidget *parent = 0);
|
||||
~CalculatorDialog();
|
||||
void setExpressionFocus();
|
||||
|
||||
signals:
|
||||
bool validAddress(bool valid);
|
||||
void showCpu();
|
||||
|
||||
public slots:
|
||||
void answerExpression(QString expression);
|
||||
|
||||
private slots:
|
||||
void on_btnGoto_clicked();
|
||||
void on_txtHex_textEdited(const QString &arg1);
|
||||
void on_txtSignedDec_textEdited(const QString &arg1);
|
||||
void on_txtUnsignedDec_textEdited(const QString &arg1);
|
||||
void on_txtOct_textEdited(const QString &arg1);
|
||||
void on_txtBin_textEdited(const QString &arg1);
|
||||
void on_txtAscii_textEdited(const QString &arg1);
|
||||
void on_txtUnicode_textEdited(const QString &arg1);
|
||||
|
||||
private:
|
||||
Ui::CalculatorDialog *ui;
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>402</width>
|
||||
<height>242</height>
|
||||
<width>502</width>
|
||||
<height>254</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -27,7 +27,7 @@
|
|||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>210</y>
|
||||
<y>220</y>
|
||||
<width>141</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
|
@ -41,102 +41,167 @@
|
|||
<rect>
|
||||
<x>11</x>
|
||||
<y>8</y>
|
||||
<width>381</width>
|
||||
<height>191</height>
|
||||
<width>481</width>
|
||||
<height>201</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="8" column="1">
|
||||
<widget class="QLineEdit" name="txtUnicode">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="inputMask">
|
||||
<string>XXXX</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Expression</string>
|
||||
<string>Expression:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="txtExpression"/>
|
||||
<widget class="QLineEdit" name="txtExpression">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Hex:</string>
|
||||
<string>Octal:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Unsigned:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="txtUnsignedDec">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="txtHex">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Dec:</string>
|
||||
<string>Hexadecimal:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="txtDec">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Oct:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="txtOct">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Bin:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="txtBin">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>ASCII</string>
|
||||
<string>ASCII:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLineEdit" name="txtAscii">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
<widget class="QLineEdit" name="txtOct">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Unicode</string>
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLineEdit" name="txtUnicode">
|
||||
<widget class="QLineEdit" name="txtBin">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Lucida Console</family>
|
||||
<pointsize>7</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001 0010</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Binary:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QLineEdit" name="txtAscii">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="inputMask">
|
||||
<string>XXX</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Unicode:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Signed:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="txtSignedDec">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -145,8 +210,8 @@
|
|||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>320</x>
|
||||
<y>210</y>
|
||||
<x>417</x>
|
||||
<y>220</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
|
@ -156,6 +221,17 @@
|
|||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>txtExpression</tabstop>
|
||||
<tabstop>txtHex</tabstop>
|
||||
<tabstop>txtUnsignedDec</tabstop>
|
||||
<tabstop>txtOct</tabstop>
|
||||
<tabstop>txtBin</tabstop>
|
||||
<tabstop>txtAscii</tabstop>
|
||||
<tabstop>txtUnicode</tabstop>
|
||||
<tabstop>btnGoto</tabstop>
|
||||
<tabstop>pushButton</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../resource.qrc"/>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue