1 // copyright (c) 2020-2021 hors<horsicq@gmail.com>
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 //
21 #include "xhexviewwidget.h"
22 #include "ui_xhexviewwidget.h"
23
XHexViewWidget(QWidget * pParent)24 XHexViewWidget::XHexViewWidget(QWidget *pParent) :
25 XShortcutsWidget(pParent),
26 ui(new Ui::XHexViewWidget)
27 {
28 ui->setupUi(this);
29
30 connect(ui->scrollAreaHex,SIGNAL(showOffsetDisasm(qint64)),this,SIGNAL(showOffsetDisasm(qint64)));
31 connect(ui->scrollAreaHex,SIGNAL(showOffsetMemoryMap(qint64)),this,SIGNAL(showOffsetMemoryMap(qint64)));
32 connect(ui->scrollAreaHex,SIGNAL(errorMessage(QString)),this,SLOT(errorMessageSlot(QString)));
33 connect(ui->scrollAreaHex,SIGNAL(cursorChanged(qint64)),this,SLOT(cursorChanged(qint64)));
34 connect(ui->scrollAreaHex,SIGNAL(selectionChanged()),this,SLOT(selectionChanged()));
35
36 ui->checkBoxHex->setChecked(true);
37 }
38
~XHexViewWidget()39 XHexViewWidget::~XHexViewWidget()
40 {
41 delete ui;
42 }
43
setShortcuts(XShortcuts * pShortcuts)44 void XHexViewWidget::setShortcuts(XShortcuts *pShortcuts)
45 {
46 ui->scrollAreaHex->setShortcuts(pShortcuts);
47 XShortcutsWidget::setShortcuts(pShortcuts);
48 }
49
setData(QIODevice * pDevice,XHexView::OPTIONS options)50 void XHexViewWidget::setData(QIODevice *pDevice, XHexView::OPTIONS options)
51 {
52 ui->scrollAreaHex->setData(pDevice,options);
53 }
54
reload()55 void XHexViewWidget::reload()
56 {
57 ui->scrollAreaHex->reload(true);
58 }
59
setReadonly(bool bState)60 void XHexViewWidget::setReadonly(bool bState)
61 {
62 Q_UNUSED(bState)
63 // TODO
64 }
65
enableReadOnly(bool bState)66 void XHexViewWidget::enableReadOnly(bool bState)
67 {
68 Q_UNUSED(bState)
69 // TODO
70 }
71
setEdited(bool bState)72 void XHexViewWidget::setEdited(bool bState)
73 {
74 Q_UNUSED(bState)
75 // TODO
76 }
77
getStartAddress()78 qint64 XHexViewWidget::getStartAddress()
79 {
80 return ui->scrollAreaHex->getStartAddress();
81 }
82
setSelection(qint64 nOffset,qint64 nSize)83 void XHexViewWidget::setSelection(qint64 nOffset, qint64 nSize)
84 {
85 ui->scrollAreaHex->setSelection(nOffset,nSize);
86 ui->scrollAreaHex->goToOffset(nOffset);
87 }
88
errorMessageSlot(QString sErrorMessage)89 void XHexViewWidget::errorMessageSlot(QString sErrorMessage)
90 {
91 QMessageBox::critical(this,tr("Error"),sErrorMessage);
92 }
93
cursorChanged(qint64 nOffset)94 void XHexViewWidget::cursorChanged(qint64 nOffset)
95 {
96 Q_UNUSED(nOffset)
97
98 adjust();
99 }
100
selectionChanged()101 void XHexViewWidget::selectionChanged()
102 {
103 adjust();
104 }
105
adjust()106 void XHexViewWidget::adjust()
107 {
108 XAbstractTableView::STATE state=ui->scrollAreaHex->getState();
109
110 QString sCursor;
111 QString sSelectionStart;
112 QString sSelectionSize;
113
114 if(ui->checkBoxHex->isChecked())
115 {
116 sCursor=XBinary::valueToHexEx(state.nCursorOffset);
117 sSelectionStart=XBinary::valueToHexEx(state.nSelectionOffset);
118 sSelectionSize=XBinary::valueToHexEx(state.nSelectionSize);
119 }
120 else
121 {
122 sCursor=QString::number(state.nCursorOffset);
123 sSelectionStart=QString::number(state.nSelectionOffset);
124 sSelectionSize=QString::number(state.nSelectionSize);
125 }
126
127 ui->lineEditCursor->setText(sCursor);
128 ui->lineEditSelectionStart->setText(sSelectionStart);
129 ui->lineEditSelectionSize->setText(sSelectionSize);
130 }
131
registerShortcuts(bool bState)132 void XHexViewWidget::registerShortcuts(bool bState)
133 {
134 Q_UNUSED(bState)
135 }
136
on_checkBoxHex_stateChanged(int nState)137 void XHexViewWidget::on_checkBoxHex_stateChanged(int nState)
138 {
139 Q_UNUSED(nState)
140
141 adjust();
142 }
143