GUI: draft HexEditDialog
This commit is contained in:
		
							parent
							
								
									9424054434
								
							
						
					
					
						commit
						bfd165a4fa
					
				|  | @ -71,7 +71,11 @@ SOURCES += \ | |||
|     Src/Gui/AppearanceDialog.cpp \ | ||||
|     Src/Disassembler/BeaTokenizer.cpp \ | ||||
|     Src/Gui/CloseDialog.cpp \ | ||||
|     Src/BasicView/XBytesLineEdit.cpp | ||||
|     Src/Gui/HexEditDialog.cpp \ | ||||
|     Src/QHexEdit/ArrayCommand.cpp \ | ||||
|     Src/QHexEdit/QHexEdit.cpp \ | ||||
|     Src/QHexEdit/QHexEditPrivate.cpp \ | ||||
|     Src/QHexEdit/XByteArray.cpp | ||||
| 
 | ||||
| 
 | ||||
| HEADERS += \ | ||||
|  | @ -121,7 +125,11 @@ HEADERS += \ | |||
|     Src/Gui/AppearanceDialog.h \ | ||||
|     Src/Disassembler/BeaTokenizer.h \ | ||||
|     Src/Gui/CloseDialog.h \ | ||||
|     Src/BasicView/XBytesLineEdit.h | ||||
|     Src/Gui/HexEditDialog.h \ | ||||
|     Src/QHexEdit/ArrayCommand.h \ | ||||
|     Src/QHexEdit/QHexEdit.h \ | ||||
|     Src/QHexEdit/QHexEditPrivate.h \ | ||||
|     Src/QHexEdit/XByteArray.h | ||||
| 
 | ||||
| 
 | ||||
| INCLUDEPATH += \ | ||||
|  | @ -149,7 +157,8 @@ FORMS += \ | |||
|     Src/Gui/ExceptionRangeDialog.ui \ | ||||
|     Src/Gui/CommandHelpView.ui \ | ||||
|     Src/Gui/AppearanceDialog.ui \ | ||||
|     Src/Gui/CloseDialog.ui | ||||
|     Src/Gui/CloseDialog.ui \ | ||||
|     Src/Gui/HexEditDialog.ui | ||||
| 
 | ||||
| INCLUDEPATH += $$PWD/Src/Bridge | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,92 @@ | |||
| #include "HexEditDialog.h" | ||||
| #include "ui_HexEditDialog.h" | ||||
| #include "QHexEdit/QHexEdit.h" | ||||
| 
 | ||||
| HexEditDialog::HexEditDialog(QWidget *parent) : | ||||
|     QDialog(parent), | ||||
|     ui(new Ui::HexEditDialog) | ||||
| { | ||||
|     ui->setupUi(this); | ||||
|     setModal(true); | ||||
|     setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint); | ||||
|     setFixedSize(this->size()); //fixed size
 | ||||
|     setModal(true); //modal window
 | ||||
|     mHexEdit = new QHexEdit(this); | ||||
|     mHexEdit->setHorizontalSpacing(6); | ||||
|     connect(mHexEdit, SIGNAL(dataChanged()), this, SLOT(dataChangedSlot())); | ||||
|     mHexEdit->setData(QString("11223344556677889900aabbccddeeff")); | ||||
|     ui->scrollArea->setWidget(mHexEdit); | ||||
| 
 | ||||
|     QFont font("Monospace", 8); | ||||
|     font.setFixedPitch(true); | ||||
|     font.setStyleHint(QFont::Monospace); | ||||
|     ui->lineEditAscii->setFont(font); | ||||
|     ui->lineEditUnicode->setFont(font); | ||||
|     ui->lineEditAscii->setFocus(); | ||||
| } | ||||
| 
 | ||||
| HexEditDialog::~HexEditDialog() | ||||
| { | ||||
|     delete ui; | ||||
| } | ||||
| 
 | ||||
| void HexEditDialog::on_btnAscii2Hex_clicked() | ||||
| { | ||||
|     QString text = ui->lineEditAscii->text(); | ||||
|     QByteArray data; | ||||
|     for(int i=0; i<text.length(); i++) | ||||
|         data.append(text[i].toAscii()); | ||||
|     if(ui->chkKeepSize->isChecked()) //keep size
 | ||||
|     { | ||||
|         int dataSize = mHexEdit->data().size(); | ||||
|         if(dataSize < data.size()) | ||||
|             data.resize(dataSize); | ||||
|         else if(dataSize > data.size()) | ||||
|             data.append(QByteArray(dataSize-data.size(), 0)); | ||||
|     } | ||||
|     mHexEdit->setData(data); | ||||
| } | ||||
| 
 | ||||
| void HexEditDialog::on_btnUnicode2Hex_clicked() | ||||
| { | ||||
|     QByteArray data =  QTextCodec::codecForName("UTF-16")->makeEncoder(QTextCodec::IgnoreHeader)->fromUnicode(ui->lineEditUnicode->text()); | ||||
|     if(ui->chkKeepSize->isChecked()) //keep size
 | ||||
|     { | ||||
|         int dataSize = mHexEdit->data().size(); | ||||
|         if(dataSize < data.size()) | ||||
|             data.resize(dataSize); | ||||
|         else if(dataSize > data.size()) | ||||
|             data.append(QByteArray(dataSize-data.size(), 0)); | ||||
|     } | ||||
|     mHexEdit->setData(data); | ||||
| } | ||||
| 
 | ||||
| void HexEditDialog::on_chkKeepSize_toggled(bool checked) | ||||
| { | ||||
|     mHexEdit->setKeepSize(checked); | ||||
| } | ||||
| 
 | ||||
| void HexEditDialog::dataChangedSlot() | ||||
| { | ||||
|     QByteArray data = mHexEdit->data(); | ||||
|     QString ascii; | ||||
|     for(int i=0; i<data.size(); i++) | ||||
|     { | ||||
|         QChar ch(data.constData()[i]); | ||||
|         if(ch.isPrint()) | ||||
|             ascii+=ch.toAscii(); | ||||
|         else | ||||
|             ascii+='.'; | ||||
|     } | ||||
|     QString unicode; | ||||
|     for(int i=0,j=0; i<data.size(); i+=2,j++) | ||||
|     { | ||||
|         QChar wch(((wchar_t*)data.constData())[j]); | ||||
|         if(wch.isPrint()) | ||||
|             unicode+=wch; | ||||
|         else | ||||
|             unicode+='.'; | ||||
|     } | ||||
|     ui->lineEditAscii->setText(ascii); | ||||
|     ui->lineEditUnicode->setText(unicode); | ||||
| } | ||||
|  | @ -0,0 +1,30 @@ | |||
| #ifndef HEXEDITDIALOG_H | ||||
| #define HEXEDITDIALOG_H | ||||
| 
 | ||||
| #include <QDialog> | ||||
| #include "QHexEdit/QHexEdit.h" | ||||
| 
 | ||||
| namespace Ui { | ||||
|     class HexEditDialog; | ||||
| } | ||||
| 
 | ||||
| class HexEditDialog : public QDialog | ||||
| { | ||||
|     Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|     explicit HexEditDialog(QWidget *parent = 0); | ||||
|     ~HexEditDialog(); | ||||
| 
 | ||||
| private slots: | ||||
|     void on_btnAscii2Hex_clicked(); | ||||
|     void on_btnUnicode2Hex_clicked(); | ||||
|     void on_chkKeepSize_toggled(bool checked); | ||||
|     void dataChangedSlot(); | ||||
| 
 | ||||
| private: | ||||
|     Ui::HexEditDialog *ui; | ||||
|     QHexEdit* mHexEdit; | ||||
| }; | ||||
| 
 | ||||
| #endif // HEXEDITDIALOG_H
 | ||||
|  | @ -0,0 +1,242 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <ui version="4.0"> | ||||
|  <class>HexEditDialog</class> | ||||
|  <widget class="QDialog" name="HexEditDialog"> | ||||
|   <property name="geometry"> | ||||
|    <rect> | ||||
|     <x>0</x> | ||||
|     <y>0</y> | ||||
|     <width>381</width> | ||||
|     <height>272</height> | ||||
|    </rect> | ||||
|   </property> | ||||
|   <property name="windowTitle"> | ||||
|    <string>HexEdit</string> | ||||
|   </property> | ||||
|   <property name="windowIcon"> | ||||
|    <iconset resource="../../resource.qrc"> | ||||
|     <normaloff>:/icons/images/document-binary.png</normaloff>:/icons/images/document-binary.png</iconset> | ||||
|   </property> | ||||
|   <widget class="QScrollArea" name="scrollArea"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>10</x> | ||||
|      <y>130</y> | ||||
|      <width>361</width> | ||||
|      <height>101</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="focusPolicy"> | ||||
|     <enum>Qt::StrongFocus</enum> | ||||
|    </property> | ||||
|    <property name="widgetResizable"> | ||||
|     <bool>true</bool> | ||||
|    </property> | ||||
|    <property name="alignment"> | ||||
|     <set>Qt::AlignCenter</set> | ||||
|    </property> | ||||
|    <widget class="QWidget" name="scrollAreaWidgetContents"> | ||||
|     <property name="geometry"> | ||||
|      <rect> | ||||
|       <x>0</x> | ||||
|       <y>0</y> | ||||
|       <width>359</width> | ||||
|       <height>99</height> | ||||
|      </rect> | ||||
|     </property> | ||||
|    </widget> | ||||
|   </widget> | ||||
|   <widget class="QLineEdit" name="lineEditUnicode"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>10</x> | ||||
|      <y>80</y> | ||||
|      <width>361</width> | ||||
|      <height>20</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="inputMask"> | ||||
|     <string/> | ||||
|    </property> | ||||
|    <property name="maxLength"> | ||||
|     <number>32767</number> | ||||
|    </property> | ||||
|   </widget> | ||||
|   <widget class="QLineEdit" name="lineEditAscii"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>10</x> | ||||
|      <y>30</y> | ||||
|      <width>361</width> | ||||
|      <height>20</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="inputMask"> | ||||
|     <string/> | ||||
|    </property> | ||||
|    <property name="maxLength"> | ||||
|     <number>32767</number> | ||||
|    </property> | ||||
|   </widget> | ||||
|   <widget class="QLabel" name="labelAscii"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>10</x> | ||||
|      <y>9</y> | ||||
|      <width>32</width> | ||||
|      <height>16</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="text"> | ||||
|     <string>&ASCII:</string> | ||||
|    </property> | ||||
|    <property name="buddy"> | ||||
|     <cstring>lineEditAscii</cstring> | ||||
|    </property> | ||||
|   </widget> | ||||
|   <widget class="QLabel" name="labelUnicode"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>10</x> | ||||
|      <y>59</y> | ||||
|      <width>50</width> | ||||
|      <height>16</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="text"> | ||||
|     <string>&UNICODE:</string> | ||||
|    </property> | ||||
|    <property name="buddy"> | ||||
|     <cstring>lineEditUnicode</cstring> | ||||
|    </property> | ||||
|   </widget> | ||||
|   <widget class="QLabel" name="labelHex"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>10</x> | ||||
|      <y>110</y> | ||||
|      <width>31</width> | ||||
|      <height>16</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="text"> | ||||
|     <string>&Hex:</string> | ||||
|    </property> | ||||
|    <property name="buddy"> | ||||
|     <cstring>scrollArea</cstring> | ||||
|    </property> | ||||
|   </widget> | ||||
|   <widget class="QPushButton" name="btnAscii2Hex"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>297</x> | ||||
|      <y>53</y> | ||||
|      <width>75</width> | ||||
|      <height>23</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="text"> | ||||
|     <string>Ascii2Hex</string> | ||||
|    </property> | ||||
|   </widget> | ||||
|   <widget class="QPushButton" name="btnUnicode2Hex"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>297</x> | ||||
|      <y>103</y> | ||||
|      <width>75</width> | ||||
|      <height>23</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="text"> | ||||
|     <string>Unicode2Hex</string> | ||||
|    </property> | ||||
|   </widget> | ||||
|   <widget class="QPushButton" name="btnOk"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>216</x> | ||||
|      <y>240</y> | ||||
|      <width>75</width> | ||||
|      <height>23</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="text"> | ||||
|     <string>&OK</string> | ||||
|    </property> | ||||
|   </widget> | ||||
|   <widget class="QPushButton" name="btnCancel"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>297</x> | ||||
|      <y>240</y> | ||||
|      <width>75</width> | ||||
|      <height>23</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="text"> | ||||
|     <string>&Cancel</string> | ||||
|    </property> | ||||
|   </widget> | ||||
|   <widget class="QCheckBox" name="chkKeepSize"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>10</x> | ||||
|      <y>240</y> | ||||
|      <width>71</width> | ||||
|      <height>17</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="text"> | ||||
|     <string>&Keep Size</string> | ||||
|    </property> | ||||
|   </widget> | ||||
|  </widget> | ||||
|  <tabstops> | ||||
|   <tabstop>lineEditUnicode</tabstop> | ||||
|   <tabstop>lineEditAscii</tabstop> | ||||
|   <tabstop>btnAscii2Hex</tabstop> | ||||
|   <tabstop>btnUnicode2Hex</tabstop> | ||||
|   <tabstop>scrollArea</tabstop> | ||||
|   <tabstop>chkKeepSize</tabstop> | ||||
|   <tabstop>btnOk</tabstop> | ||||
|   <tabstop>btnCancel</tabstop> | ||||
|  </tabstops> | ||||
|  <resources> | ||||
|   <include location="../../resource.qrc"/> | ||||
|  </resources> | ||||
|  <connections> | ||||
|   <connection> | ||||
|    <sender>btnCancel</sender> | ||||
|    <signal>clicked()</signal> | ||||
|    <receiver>HexEditDialog</receiver> | ||||
|    <slot>reject()</slot> | ||||
|    <hints> | ||||
|     <hint type="sourcelabel"> | ||||
|      <x>335</x> | ||||
|      <y>253</y> | ||||
|     </hint> | ||||
|     <hint type="destinationlabel"> | ||||
|      <x>331</x> | ||||
|      <y>251</y> | ||||
|     </hint> | ||||
|    </hints> | ||||
|   </connection> | ||||
|   <connection> | ||||
|    <sender>btnOk</sender> | ||||
|    <signal>clicked()</signal> | ||||
|    <receiver>HexEditDialog</receiver> | ||||
|    <slot>accept()</slot> | ||||
|    <hints> | ||||
|     <hint type="sourcelabel"> | ||||
|      <x>252</x> | ||||
|      <y>251</y> | ||||
|     </hint> | ||||
|     <hint type="destinationlabel"> | ||||
|      <x>238</x> | ||||
|      <y>251</y> | ||||
|     </hint> | ||||
|    </hints> | ||||
|   </connection> | ||||
|  </connections> | ||||
| </ui> | ||||
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 608 B | 
|  | @ -32,5 +32,6 @@ | |||
|         <file>images/strings.png</file> | ||||
|         <file>images/color-swatches.png</file> | ||||
|         <file>images/call.png</file> | ||||
|         <file>images/document-binary.png</file> | ||||
|     </qresource> | ||||
| </RCC> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue