1
0
Fork 0

GUI: removed donation button from toolbar + follow in Disassembler in Calculator + title in Calculator + Calculator is not a modal window (still allow working while using the calculator) + AStyle + removed empty resource prefix + fixed a warning in Configuration

This commit is contained in:
Mr. eXoDia 2014-08-02 19:36:09 +02:00
parent 60eeff6124
commit 1e8f1928ab
8 changed files with 188 additions and 177 deletions

View File

@ -1,95 +1,111 @@
#include "CalculatorDialog.h"
#include "ui_CalculatorDialog.h"
#include <QString>
CalculatorDialog::CalculatorDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CalculatorDialog)
{
ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
setFixedSize(this->size()); //fixed size
connect(ui->txtExpression,SIGNAL(textChanged(QString)),this,SLOT(answerExpression(QString)));
connect(this,SIGNAL(validAddress(bool)),ui->btnGoto,SLOT(setEnabled(bool)));
emit validAddress(false);
ui->txtExpression->setFocus();
}
CalculatorDialog::~CalculatorDialog()
{
delete ui;
}
void CalculatorDialog::answerExpression(QString expression){
if(!DbgIsValidExpression(expression.toUtf8().constData())){
ui->txtBin->setText("");
ui->txtDec->setText("");
ui->txtHex->setText("");
ui->txtOct->setText("");
ui->txtAscii->setText("");
ui->txtUnicode->setText("");
}else{
uint_t ans = DbgValFromString(expression.toUtf8().constData());
ui->txtHex->setText(inFormat(ans,N_HEX));
ui->txtDec->setText(inFormat(ans,N_DEC));
ui->txtBin->setText(inFormat(ans,N_BIN));
ui->txtOct->setText(inFormat(ans,N_OCT));
if((ans == (ans & 0xFF)) )
{
QChar c = QChar((char)ans);
if(c.isPrint())
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("???");
}else{
ui->txtUnicode->setText("???");
}
}
emit validAddress(DbgMemIsValidReadPtr(ans));
}
}
QString CalculatorDialog::inFormat(const uint_t val, CalculatorDialog::NUMBERFORMAT NF) const
{
switch(NF){
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);
case N_BIN:{
QString binary = QString("%1").arg(val,8*4,2,QChar('0')).toUpper();
QString ans = "";
for(int i=0;i<4*8;i++){
ans += binary[i];
if((i%4==0) && (i!=0))
ans += " ";
}
return ans +"b";}
case N_OCT:
return QString("%1").arg(val,1,8,QChar('0')).toUpper()+"o";
case N_ASCII:
return QString("'%1'").arg((char)val);
}
}
#include "CalculatorDialog.h"
#include "ui_CalculatorDialog.h"
#include <QString>
CalculatorDialog::CalculatorDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CalculatorDialog)
{
ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
setFixedSize(this->size()); //fixed size
connect(ui->txtExpression,SIGNAL(textChanged(QString)),this,SLOT(answerExpression(QString)));
connect(this,SIGNAL(validAddress(bool)),ui->btnGoto,SLOT(setEnabled(bool)));
emit validAddress(false);
ui->txtExpression->setFocus();
}
CalculatorDialog::~CalculatorDialog()
{
delete ui;
}
void CalculatorDialog::setExpressionFocus()
{
ui->txtExpression->setFocus();
}
void CalculatorDialog::answerExpression(QString expression)
{
if(!DbgIsValidExpression(expression.toUtf8().constData()))
{
ui->txtBin->setText("");
ui->txtDec->setText("");
ui->txtHex->setText("");
ui->txtOct->setText("");
ui->txtAscii->setText("");
ui->txtUnicode->setText("");
}
else
{
uint_t ans = DbgValFromString(expression.toUtf8().constData());
ui->txtHex->setText(inFormat(ans,N_HEX));
ui->txtDec->setText(inFormat(ans,N_DEC));
ui->txtBin->setText(inFormat(ans,N_BIN));
ui->txtOct->setText(inFormat(ans,N_OCT));
if((ans == (ans & 0xFF)) )
{
QChar c = QChar((char)ans);
if(c.isPrint())
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("???");
}
else
{
ui->txtUnicode->setText("???");
}
}
emit validAddress(DbgMemIsValidReadPtr(ans));
}
}
QString CalculatorDialog::inFormat(const uint_t val, CalculatorDialog::NUMBERFORMAT NF) const
{
switch(NF)
{
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);
case N_BIN:
{
QString binary = QString("%1").arg(val,8*4,2,QChar('0')).toUpper();
QString ans = "";
for(int i=0; i<4*8; i++)
{
ans += binary[i];
if((i%4==0) && (i!=0))
ans += " ";
}
return ans +"b";
}
case N_OCT:
return QString("%1").arg(val,1,8,QChar('0')).toUpper()+"o";
case N_ASCII:
return QString("'%1'").arg((char)val);
}
}
void CalculatorDialog::on_btnGoto_clicked()
{
DbgCmdExecDirect(QString("disasm " + ui->txtExpression->text()).toUtf8().constData());
emit showCpu();
}

View File

@ -1,27 +1,41 @@
#ifndef CALCULATORDIALOG_H
#define CALCULATORDIALOG_H
#include <QDialog>
#include "Bridge.h"
namespace Ui {
class CalculatorDialog;
}
class CalculatorDialog : public QDialog
{
Q_OBJECT
enum NUMBERFORMAT{N_HEX=16,N_DEC=10,N_BIN=2,N_OCT=8,N_ASCII=0,N_UNKNOWN=-1};
public:
explicit CalculatorDialog(QWidget *parent = 0);
~CalculatorDialog();
signals:
bool validAddress(bool valid);
public slots:
void answerExpression(QString expression);
private:
Ui::CalculatorDialog *ui;
QString inFormat(const uint_t val, CalculatorDialog::NUMBERFORMAT NF) const;
};
#endif // CALCULATORDIALOG_H
#ifndef CALCULATORDIALOG_H
#define CALCULATORDIALOG_H
#include <QDialog>
#include "Bridge.h"
namespace Ui
{
class CalculatorDialog;
}
class CalculatorDialog : public QDialog
{
Q_OBJECT
enum NUMBERFORMAT
{
N_HEX=16,
N_DEC=10,
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();
private:
Ui::CalculatorDialog *ui;
QString inFormat(const uint_t val, CalculatorDialog::NUMBERFORMAT NF) const;
};
#endif // CALCULATORDIALOG_H

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>254</height>
<width>402</width>
<height>242</height>
</rect>
</property>
<property name="sizePolicy">
@ -17,48 +17,32 @@
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Calculator</string>
</property>
<property name="windowIcon">
<iconset resource="../../resource.qrc">
<normaloff>:/icons/images/calculator.png</normaloff>:/icons/images/calculator.png</iconset>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>40</x>
<y>210</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
<widget class="QPushButton" name="btnGoto">
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<width>101</width>
<width>141</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>goto Expression</string>
<string>&amp;Follow in Disassembler</string>
</property>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>11</x>
<y>21</y>
<width>371</width>
<height>178</height>
<y>8</y>
<width>381</width>
<height>191</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
@ -158,40 +142,37 @@
</item>
</layout>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>320</x>
<y>210</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>&amp;Close</string>
</property>
</widget>
</widget>
<resources>
<include location="../../resource.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>CalculatorDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
<x>347</x>
<y>216</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CalculatorDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
<x>284</x>
<y>215</y>
</hint>
</hints>
</connection>

View File

@ -111,6 +111,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->statusBar->addPermanentWidget(mLastLogLabel, 1);
mPatchDialog = new PatchDialog(this);
mCalculatorDialog = new CalculatorDialog(this);
connect(mCalculatorDialog, SIGNAL(showCpu()), this, SLOT(displayCpuWidget()));
// Setup Signals/Slots
connect(mCmdLineEdit, SIGNAL(returnPressed()), this, SLOT(executeCommand()));
@ -642,8 +644,9 @@ void MainWindow::openAppearance()
void MainWindow::openCalculator()
{
CalculatorDialog calculator(this);
calculator.exec();
mCalculatorDialog->showNormal();
mCalculatorDialog->setFocus();
mCalculatorDialog->setExpressionFocus();
}
void MainWindow::openShortcuts()

View File

@ -111,6 +111,7 @@ private:
ReferenceView* mReferenceView;
ThreadView* mThreadView;
PatchDialog* mPatchDialog;
CalculatorDialog* mCalculatorDialog;
StatusLabel* mStatusLabel;
StatusLabel* mLastLogLabel;

View File

@ -158,10 +158,9 @@
<addaction name="separator"/>
<addaction name="actionStrings"/>
<addaction name="actionCalls"/>
<addaction name="actionCalculator"/>
<addaction name="separator"/>
<addaction name="actionDonate"/>
<addaction name="actionCheckUpdates"/>
<addaction name="actionCalculator"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<widget class="QToolBar" name="cmdBar">

View File

@ -251,8 +251,6 @@ Configuration::Configuration() : QObject()
defaultShortcuts.insert("ActionAbortScript", Shortcut(tr("Actions -> Abort Script"), "Esc"));
defaultShortcuts.insert("ActionExecuteCommandScript", Shortcut(tr("Actions -> Execute Script Command"), "X"));
Shortcuts = defaultShortcuts;
load();
@ -541,7 +539,7 @@ const Configuration::Shortcut Configuration::getShortcut(const QString key_id) c
msg.setWindowIcon(QIcon(":/icons/images/compile-warning.png"));
msg.setWindowFlags(msg.windowFlags()&(~Qt::WindowContextHelpButtonHint));
msg.exec();
return QKeySequence();
return Shortcut();
}
void Configuration::setShortcut(const QString key_id, const QKeySequence key_sequence)

View File

@ -44,5 +44,4 @@
<file>images/donate.png</file>
<file>images/calculator.png</file>
</qresource>
<qresource prefix="/"/>
</RCC>