-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhexeditorwidget.cpp
105 lines (84 loc) · 2.51 KB
/
hexeditorwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
///////////////////////////////////////////////////////////////////////
//HardwareExpert. Class connector HexEditorWidget <-> QHexEdit.
//Copyright (C) 2011 Stanislav (f0ma) Ivanov
//
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program. If not, see <http://www.gnu.org/licenses/>.
///////////////////////////////////////////////////////////////////////
#include "hexeditorwidget.h"
#include "intelHexProvider/intelhexprovider.h"
HexEditorWidget::HexEditorWidget(QWidget *parent) :
QHexEdit(parent)
{
connect(this,SIGNAL(currentAddressChanged(int)),SLOT(updateTextBar(int)));
connect(this,SIGNAL(dataChanged()),SLOT(on_dataChanged()));
lbl = NULL;
changed = false;
}
bool HexEditorWidget::loadFromFile(QString filename)
{
QFile f (filename);
if(!f.open(QFile::ReadOnly))return false;
setData(f.readAll());
f.close();
return true;
}
bool HexEditorWidget::loadFromHexFile(QString filename)
{
QByteArray d;
IntelHexProvider p;
p.loadFromHexFile(filename,d);
setData(d);
return true;
}
bool HexEditorWidget::saveToFile(QString filename)
{
Q_UNUSED(filename);
return false ;
}
void HexEditorWidget::updateTextBar(int addr)
{
QString adr; adr.setNum(addr,16); adr = adr.toUpper();
while(adr.length()<8)
{
adr.prepend("0");
}
QString val; val.setNum(this->data()[addr],16); val = val.toUpper();
if(val.length()<2)val.prepend("0");
val = val.mid(val.length()-2,2);
QString bval; bval.setNum(this->data()[addr],2);
while(bval.length()<8)bval.prepend("0");
if(bval.length()>8)
{
bval = bval.mid(bval.length()-8,8);
}
lbl->setText("Address: "+adr+" Value: "+val+" Binary: "+bval);
}
void HexEditorWidget::setLineText(QLabel * label)
{
lbl=label;
lbl->setFont(QFont("Courier", 10));
connect(this,SIGNAL(updateText(QString)),lbl,SLOT(setText(QString)));
}
void HexEditorWidget::on_dataChanged()
{
changed = true;
}
bool HexEditorWidget::isChanged()
{
return changed;
}
void HexEditorWidget::saved()
{
changed = false;
}