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 "CalculatorDialog.h"
#include "ui_CalculatorDialog.h" #include "ui_CalculatorDialog.h"
#include <QString> #include <QString>
CalculatorDialog::CalculatorDialog(QWidget *parent) : CalculatorDialog::CalculatorDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CalculatorDialog)
QDialog(parent), {
ui(new Ui::CalculatorDialog) ui->setupUi(this);
{ setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
ui->setupUi(this); setFixedSize(this->size()); //fixed size
setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint); connect(ui->txtExpression,SIGNAL(textChanged(QString)),this,SLOT(answerExpression(QString)));
setFixedSize(this->size()); //fixed size connect(this,SIGNAL(validAddress(bool)),ui->btnGoto,SLOT(setEnabled(bool)));
connect(ui->txtExpression,SIGNAL(textChanged(QString)),this,SLOT(answerExpression(QString))); emit validAddress(false);
connect(this,SIGNAL(validAddress(bool)),ui->btnGoto,SLOT(setEnabled(bool))); ui->txtExpression->setFocus();
emit validAddress(false); }
ui->txtExpression->setFocus();
CalculatorDialog::~CalculatorDialog()
} {
delete ui;
CalculatorDialog::~CalculatorDialog() }
{
delete ui; void CalculatorDialog::setExpressionFocus()
} {
ui->txtExpression->setFocus();
}
void CalculatorDialog::answerExpression(QString expression){
void CalculatorDialog::answerExpression(QString expression)
if(!DbgIsValidExpression(expression.toUtf8().constData())){ {
ui->txtBin->setText("");
ui->txtDec->setText(""); if(!DbgIsValidExpression(expression.toUtf8().constData()))
ui->txtHex->setText(""); {
ui->txtOct->setText(""); ui->txtBin->setText("");
ui->txtAscii->setText(""); ui->txtDec->setText("");
ui->txtUnicode->setText(""); ui->txtHex->setText("");
}else{ ui->txtOct->setText("");
uint_t ans = DbgValFromString(expression.toUtf8().constData()); ui->txtAscii->setText("");
ui->txtHex->setText(inFormat(ans,N_HEX)); ui->txtUnicode->setText("");
ui->txtDec->setText(inFormat(ans,N_DEC)); }
ui->txtBin->setText(inFormat(ans,N_BIN)); else
ui->txtOct->setText(inFormat(ans,N_OCT)); {
if((ans == (ans & 0xFF)) ) uint_t ans = DbgValFromString(expression.toUtf8().constData());
{ ui->txtHex->setText(inFormat(ans,N_HEX));
QChar c = QChar((char)ans); ui->txtDec->setText(inFormat(ans,N_DEC));
if(c.isPrint()) ui->txtBin->setText(inFormat(ans,N_BIN));
ui->txtAscii->setText(QString(c)); ui->txtOct->setText(inFormat(ans,N_OCT));
else if((ans == (ans & 0xFF)) )
ui->txtAscii->setText("???"); {
}else{ QChar c = QChar((char)ans);
ui->txtAscii->setText("???"); if(c.isPrint())
if((ans == (ans & 0xFFF)) ) //UNICODE? ui->txtAscii->setText(QString(c));
{ else
QChar c = QChar((wchar_t)ans); ui->txtAscii->setText("???");
if(c.isPrint()) }
ui->txtUnicode->setText(QString(c)); else
else {
ui->txtUnicode->setText("???"); ui->txtAscii->setText("???");
}else{ if((ans == (ans & 0xFFF)) ) //UNICODE?
ui->txtUnicode->setText("???"); {
} QChar c = QChar((wchar_t)ans);
} if(c.isPrint())
ui->txtUnicode->setText(QString(c));
else
emit validAddress(DbgMemIsValidReadPtr(ans)); ui->txtUnicode->setText("???");
} }
} else
{
QString CalculatorDialog::inFormat(const uint_t val, CalculatorDialog::NUMBERFORMAT NF) const ui->txtUnicode->setText("???");
{ }
switch(NF){ }
default: emit validAddress(DbgMemIsValidReadPtr(ans));
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(); QString CalculatorDialog::inFormat(const uint_t val, CalculatorDialog::NUMBERFORMAT NF) const
return QString("%1").arg(val,1,16,QChar('0')).toUpper()+"h"; {
case N_DEC: switch(NF)
// 0,...,9 in hex is the same as in dec {
if(val<10 && val>=0) default:
return QString("%1").arg(val); case N_HEX:
return QString("%1").arg(val); // 0,...,9 in hex is the same as in dec
case N_BIN:{ if(val<10 && val>=0)
QString binary = QString("%1").arg(val,8*4,2,QChar('0')).toUpper(); return QString("%1").arg(val,1,16,QChar('0')).toUpper();
QString ans = ""; return QString("%1").arg(val,1,16,QChar('0')).toUpper()+"h";
for(int i=0;i<4*8;i++){ case N_DEC:
ans += binary[i]; // 0,...,9 in hex is the same as in dec
if((i%4==0) && (i!=0)) if(val<10 && val>=0)
ans += " "; return QString("%1").arg(val);
} return QString("%1").arg(val);
return ans +"b";} case N_BIN:
case N_OCT: {
return QString("%1").arg(val,1,8,QChar('0')).toUpper()+"o"; QString binary = QString("%1").arg(val,8*4,2,QChar('0')).toUpper();
case N_ASCII: QString ans = "";
return QString("'%1'").arg((char)val); 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 #ifndef CALCULATORDIALOG_H
#define CALCULATORDIALOG_H #define CALCULATORDIALOG_H
#include <QDialog> #include <QDialog>
#include "Bridge.h" #include "Bridge.h"
namespace Ui { namespace Ui
class CalculatorDialog; {
} class CalculatorDialog;
}
class CalculatorDialog : public QDialog
{ class CalculatorDialog : public QDialog
Q_OBJECT {
Q_OBJECT
enum NUMBERFORMAT{N_HEX=16,N_DEC=10,N_BIN=2,N_OCT=8,N_ASCII=0,N_UNKNOWN=-1};
public: enum NUMBERFORMAT
explicit CalculatorDialog(QWidget *parent = 0); {
~CalculatorDialog(); N_HEX=16,
signals: N_DEC=10,
bool validAddress(bool valid); N_BIN=2,
public slots: N_OCT=8,
void answerExpression(QString expression); N_ASCII=0,
private: N_UNKNOWN=-1
Ui::CalculatorDialog *ui; };
QString inFormat(const uint_t val, CalculatorDialog::NUMBERFORMAT NF) const; public:
}; explicit CalculatorDialog(QWidget *parent = 0);
~CalculatorDialog();
#endif // CALCULATORDIALOG_H 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> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>402</width>
<height>254</height> <height>242</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -17,48 +17,32 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>Calculator</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset resource="../../resource.qrc"> <iconset resource="../../resource.qrc">
<normaloff>:/icons/images/calculator.png</normaloff>:/icons/images/calculator.png</iconset> <normaloff>:/icons/images/calculator.png</normaloff>:/icons/images/calculator.png</iconset>
</property> </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"> <widget class="QPushButton" name="btnGoto">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>10</x>
<y>210</y> <y>210</y>
<width>101</width> <width>141</width>
<height>23</height> <height>23</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>goto Expression</string> <string>&amp;Follow in Disassembler</string>
</property> </property>
</widget> </widget>
<widget class="QWidget" name=""> <widget class="QWidget" name="layoutWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>11</x> <x>11</x>
<y>21</y> <y>8</y>
<width>371</width> <width>381</width>
<height>178</height> <height>191</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
@ -158,40 +142,37 @@
</item> </item>
</layout> </layout>
</widget> </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> </widget>
<resources> <resources>
<include location="../../resource.qrc"/> <include location="../../resource.qrc"/>
</resources> </resources>
<connections> <connections>
<connection> <connection>
<sender>buttonBox</sender> <sender>pushButton</sender>
<signal>accepted()</signal> <signal>clicked()</signal>
<receiver>CalculatorDialog</receiver> <receiver>CalculatorDialog</receiver>
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>248</x> <x>347</x>
<y>254</y> <y>216</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>157</x> <x>284</x>
<y>274</y> <y>215</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>
</hint> </hint>
</hints> </hints>
</connection> </connection>

View File

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

View File

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

View File

@ -158,10 +158,9 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionStrings"/> <addaction name="actionStrings"/>
<addaction name="actionCalls"/> <addaction name="actionCalls"/>
<addaction name="actionCalculator"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionDonate"/>
<addaction name="actionCheckUpdates"/> <addaction name="actionCheckUpdates"/>
<addaction name="actionCalculator"/>
</widget> </widget>
<widget class="QStatusBar" name="statusBar"/> <widget class="QStatusBar" name="statusBar"/>
<widget class="QToolBar" name="cmdBar"> <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("ActionAbortScript", Shortcut(tr("Actions -> Abort Script"), "Esc"));
defaultShortcuts.insert("ActionExecuteCommandScript", Shortcut(tr("Actions -> Execute Script Command"), "X")); defaultShortcuts.insert("ActionExecuteCommandScript", Shortcut(tr("Actions -> Execute Script Command"), "X"));
Shortcuts = defaultShortcuts; Shortcuts = defaultShortcuts;
load(); load();
@ -541,7 +539,7 @@ const Configuration::Shortcut Configuration::getShortcut(const QString key_id) c
msg.setWindowIcon(QIcon(":/icons/images/compile-warning.png")); msg.setWindowIcon(QIcon(":/icons/images/compile-warning.png"));
msg.setWindowFlags(msg.windowFlags()&(~Qt::WindowContextHelpButtonHint)); msg.setWindowFlags(msg.windowFlags()&(~Qt::WindowContextHelpButtonHint));
msg.exec(); msg.exec();
return QKeySequence(); return Shortcut();
} }
void Configuration::setShortcut(const QString key_id, const QKeySequence key_sequence) void Configuration::setShortcut(const QString key_id, const QKeySequence key_sequence)

View File

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