summaryrefslogtreecommitdiff
path: root/externals/qhexedit
diff options
context:
space:
mode:
authorGravatar ShizZy2013-08-29 23:35:09 -0400
committerGravatar ShizZy2013-08-29 23:35:09 -0400
commit27474060e1287a67c45cd790d29b9095b35b2bdf (patch)
treefcbc56f1182617c01597f13e1a18dbec147d4216 /externals/qhexedit
parentInitial commit (diff)
downloadyuzu-27474060e1287a67c45cd790d29b9095b35b2bdf.tar.gz
yuzu-27474060e1287a67c45cd790d29b9095b35b2bdf.tar.xz
yuzu-27474060e1287a67c45cd790d29b9095b35b2bdf.zip
adding initial project layout
Diffstat (limited to 'externals/qhexedit')
-rw-r--r--externals/qhexedit/CMakeLists.txt13
-rw-r--r--externals/qhexedit/commands.cpp115
-rw-r--r--externals/qhexedit/commands.h70
-rw-r--r--externals/qhexedit/license.txt502
-rw-r--r--externals/qhexedit/qhexedit.cpp180
-rw-r--r--externals/qhexedit/qhexedit.h240
-rw-r--r--externals/qhexedit/qhexedit_p.cpp859
-rw-r--r--externals/qhexedit/qhexedit_p.h125
-rw-r--r--externals/qhexedit/xbytearray.cpp167
-rw-r--r--externals/qhexedit/xbytearray.h66
10 files changed, 2337 insertions, 0 deletions
diff --git a/externals/qhexedit/CMakeLists.txt b/externals/qhexedit/CMakeLists.txt
new file mode 100644
index 000000000..cfe168ef3
--- /dev/null
+++ b/externals/qhexedit/CMakeLists.txt
@@ -0,0 +1,13 @@
1set(SRCS
2 commands.cpp
3 qhexedit.cpp
4 qhexedit_p.cpp
5 xbytearray.cpp)
6
7qt4_wrap_cpp(MOC_SRCS
8 qhexedit.h
9 qhexedit_p.h)
10
11include_directories(${CMAKE_CURRENT_BINARY_DIR})
12
13add_library(qhexedit STATIC ${SRCS} ${MOC_SRCS})
diff --git a/externals/qhexedit/commands.cpp b/externals/qhexedit/commands.cpp
new file mode 100644
index 000000000..303091d1d
--- /dev/null
+++ b/externals/qhexedit/commands.cpp
@@ -0,0 +1,115 @@
1#include "commands.h"
2
3CharCommand::CharCommand(XByteArray * xData, Cmd cmd, int charPos, char newChar, QUndoCommand *parent)
4 : QUndoCommand(parent)
5{
6 _xData = xData;
7 _charPos = charPos;
8 _newChar = newChar;
9 _cmd = cmd;
10}
11
12bool CharCommand::mergeWith(const QUndoCommand *command)
13{
14 const CharCommand *nextCommand = static_cast<const CharCommand *>(command);
15 bool result = false;
16
17 if (_cmd != remove)
18 {
19 if (nextCommand->_cmd == replace)
20 if (nextCommand->_charPos == _charPos)
21 {
22 _newChar = nextCommand->_newChar;
23 result = true;
24 }
25 }
26 return result;
27}
28
29void CharCommand::undo()
30{
31 switch (_cmd)
32 {
33 case insert:
34 _xData->remove(_charPos, 1);
35 break;
36 case replace:
37 _xData->replace(_charPos, _oldChar);
38 _xData->setDataChanged(_charPos, _wasChanged);
39 break;
40 case remove:
41 _xData->insert(_charPos, _oldChar);
42 _xData->setDataChanged(_charPos, _wasChanged);
43 break;
44 }
45}
46
47void CharCommand::redo()
48{
49 switch (_cmd)
50 {
51 case insert:
52 _xData->insert(_charPos, _newChar);
53 break;
54 case replace:
55 _oldChar = _xData->data()[_charPos];
56 _wasChanged = _xData->dataChanged(_charPos);
57 _xData->replace(_charPos, _newChar);
58 break;
59 case remove:
60 _oldChar = _xData->data()[_charPos];
61 _wasChanged = _xData->dataChanged(_charPos);
62 _xData->remove(_charPos, 1);
63 break;
64 }
65}
66
67
68
69ArrayCommand::ArrayCommand(XByteArray * xData, Cmd cmd, int baPos, QByteArray newBa, int len, QUndoCommand *parent)
70 : QUndoCommand(parent)
71{
72 _cmd = cmd;
73 _xData = xData;
74 _baPos = baPos;
75 _newBa = newBa;
76 _len = len;
77}
78
79void ArrayCommand::undo()
80{
81 switch (_cmd)
82 {
83 case insert:
84 _xData->remove(_baPos, _newBa.length());
85 break;
86 case replace:
87 _xData->replace(_baPos, _oldBa);
88 _xData->setDataChanged(_baPos, _wasChanged);
89 break;
90 case remove:
91 _xData->insert(_baPos, _oldBa);
92 _xData->setDataChanged(_baPos, _wasChanged);
93 break;
94 }
95}
96
97void ArrayCommand::redo()
98{
99 switch (_cmd)
100 {
101 case insert:
102 _xData->insert(_baPos, _newBa);
103 break;
104 case replace:
105 _oldBa = _xData->data().mid(_baPos, _len);
106 _wasChanged = _xData->dataChanged(_baPos, _len);
107 _xData->replace(_baPos, _newBa);
108 break;
109 case remove:
110 _oldBa = _xData->data().mid(_baPos, _len);
111 _wasChanged = _xData->dataChanged(_baPos, _len);
112 _xData->remove(_baPos, _len);
113 break;
114 }
115}
diff --git a/externals/qhexedit/commands.h b/externals/qhexedit/commands.h
new file mode 100644
index 000000000..9931b3fb5
--- /dev/null
+++ b/externals/qhexedit/commands.h
@@ -0,0 +1,70 @@
1#ifndef COMMANDS_H
2#define COMMANDS_H
3
4/** \cond docNever */
5
6#include <QUndoCommand>
7
8#include "xbytearray.h"
9
10/*! CharCommand is a class to prived undo/redo functionality in QHexEdit.
11A QUndoCommand represents a single editing action on a document. CharCommand
12is responsable for manipulations on single chars. It can insert. replace and
13remove characters. A manipulation stores allways to actions
141. redo (or do) action
152. undo action.
16
17CharCommand also supports command compression via mergeWidht(). This allows
18the user to execute a undo command contation e.g. 3 steps in a single command.
19If you for example insert a new byt "34" this means for the editor doing 3
20steps: insert a "00", replace it with "03" and the replace it with "34". These
213 steps are combined into a single step, insert a "34".
22*/
23class CharCommand : public QUndoCommand
24{
25public:
26 enum { Id = 1234 };
27 enum Cmd {insert, remove, replace};
28
29 CharCommand(XByteArray * xData, Cmd cmd, int charPos, char newChar,
30 QUndoCommand *parent=0);
31
32 void undo();
33 void redo();
34 bool mergeWith(const QUndoCommand *command);
35 int id() const { return Id; }
36
37private:
38 XByteArray * _xData;
39 int _charPos;
40 bool _wasChanged;
41 char _newChar;
42 char _oldChar;
43 Cmd _cmd;
44};
45
46/*! ArrayCommand provides undo/redo functionality for handling binary strings. It
47can undo/redo insert, replace and remove binary strins (QByteArrays).
48*/
49class ArrayCommand : public QUndoCommand
50{
51public:
52 enum Cmd {insert, remove, replace};
53 ArrayCommand(XByteArray * xData, Cmd cmd, int baPos, QByteArray newBa=QByteArray(), int len=0,
54 QUndoCommand *parent=0);
55 void undo();
56 void redo();
57
58private:
59 Cmd _cmd;
60 XByteArray * _xData;
61 int _baPos;
62 int _len;
63 QByteArray _wasChanged;
64 QByteArray _newBa;
65 QByteArray _oldBa;
66};
67
68/** \endcond docNever */
69
70#endif // COMMANDS_H
diff --git a/externals/qhexedit/license.txt b/externals/qhexedit/license.txt
new file mode 100644
index 000000000..f166cc57b
--- /dev/null
+++ b/externals/qhexedit/license.txt
@@ -0,0 +1,502 @@
1 GNU LESSER GENERAL PUBLIC LICENSE
2 Version 2.1, February 1999
3
4 Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 Everyone is permitted to copy and distribute verbatim copies
7 of this license document, but changing it is not allowed.
8
9[This is the first released version of the Lesser GPL. It also counts
10 as the successor of the GNU Library Public License, version 2, hence
11 the version number 2.1.]
12
13 Preamble
14
15 The licenses for most software are designed to take away your
16freedom to share and change it. By contrast, the GNU General Public
17Licenses are intended to guarantee your freedom to share and change
18free software--to make sure the software is free for all its users.
19
20 This license, the Lesser General Public License, applies to some
21specially designated software packages--typically libraries--of the
22Free Software Foundation and other authors who decide to use it. You
23can use it too, but we suggest you first think carefully about whether
24this license or the ordinary General Public License is the better
25strategy to use in any particular case, based on the explanations below.
26
27 When we speak of free software, we are referring to freedom of use,
28not price. Our General Public Licenses are designed to make sure that
29you have the freedom to distribute copies of free software (and charge
30for this service if you wish); that you receive source code or can get
31it if you want it; that you can change the software and use pieces of
32it in new free programs; and that you are informed that you can do
33these things.
34
35 To protect your rights, we need to make restrictions that forbid
36distributors to deny you these rights or to ask you to surrender these
37rights. These restrictions translate to certain responsibilities for
38you if you distribute copies of the library or if you modify it.
39
40 For example, if you distribute copies of the library, whether gratis
41or for a fee, you must give the recipients all the rights that we gave
42you. You must make sure that they, too, receive or can get the source
43code. If you link other code with the library, you must provide
44complete object files to the recipients, so that they can relink them
45with the library after making changes to the library and recompiling
46it. And you must show them these terms so they know their rights.
47
48 We protect your rights with a two-step method: (1) we copyright the
49library, and (2) we offer you this license, which gives you legal
50permission to copy, distribute and/or modify the library.
51
52 To protect each distributor, we want to make it very clear that
53there is no warranty for the free library. Also, if the library is
54modified by someone else and passed on, the recipients should know
55that what they have is not the original version, so that the original
56author's reputation will not be affected by problems that might be
57introduced by others.
58
59 Finally, software patents pose a constant threat to the existence of
60any free program. We wish to make sure that a company cannot
61effectively restrict the users of a free program by obtaining a
62restrictive license from a patent holder. Therefore, we insist that
63any patent license obtained for a version of the library must be
64consistent with the full freedom of use specified in this license.
65
66 Most GNU software, including some libraries, is covered by the
67ordinary GNU General Public License. This license, the GNU Lesser
68General Public License, applies to certain designated libraries, and
69is quite different from the ordinary General Public License. We use
70this license for certain libraries in order to permit linking those
71libraries into non-free programs.
72
73 When a program is linked with a library, whether statically or using
74a shared library, the combination of the two is legally speaking a
75combined work, a derivative of the original library. The ordinary
76General Public License therefore permits such linking only if the
77entire combination fits its criteria of freedom. The Lesser General
78Public License permits more lax criteria for linking other code with
79the library.
80
81 We call this license the "Lesser" General Public License because it
82does Less to protect the user's freedom than the ordinary General
83Public License. It also provides other free software developers Less
84of an advantage over competing non-free programs. These disadvantages
85are the reason we use the ordinary General Public License for many
86libraries. However, the Lesser license provides advantages in certain
87special circumstances.
88
89 For example, on rare occasions, there may be a special need to
90encourage the widest possible use of a certain library, so that it becomes
91a de-facto standard. To achieve this, non-free programs must be
92allowed to use the library. A more frequent case is that a free
93library does the same job as widely used non-free libraries. In this
94case, there is little to gain by limiting the free library to free
95software only, so we use the Lesser General Public License.
96
97 In other cases, permission to use a particular library in non-free
98programs enables a greater number of people to use a large body of
99free software. For example, permission to use the GNU C Library in
100non-free programs enables many more people to use the whole GNU
101operating system, as well as its variant, the GNU/Linux operating
102system.
103
104 Although the Lesser General Public License is Less protective of the
105users' freedom, it does ensure that the user of a program that is
106linked with the Library has the freedom and the wherewithal to run
107that program using a modified version of the Library.
108
109 The precise terms and conditions for copying, distribution and
110modification follow. Pay close attention to the difference between a
111"work based on the library" and a "work that uses the library". The
112former contains code derived from the library, whereas the latter must
113be combined with the library in order to run.
114
115 GNU LESSER GENERAL PUBLIC LICENSE
116 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117
118 0. This License Agreement applies to any software library or other
119program which contains a notice placed by the copyright holder or
120other authorized party saying it may be distributed under the terms of
121this Lesser General Public License (also called "this License").
122Each licensee is addressed as "you".
123
124 A "library" means a collection of software functions and/or data
125prepared so as to be conveniently linked with application programs
126(which use some of those functions and data) to form executables.
127
128 The "Library", below, refers to any such software library or work
129which has been distributed under these terms. A "work based on the
130Library" means either the Library or any derivative work under
131copyright law: that is to say, a work containing the Library or a
132portion of it, either verbatim or with modifications and/or translated
133straightforwardly into another language. (Hereinafter, translation is
134included without limitation in the term "modification".)
135
136 "Source code" for a work means the preferred form of the work for
137making modifications to it. For a library, complete source code means
138all the source code for all modules it contains, plus any associated
139interface definition files, plus the scripts used to control compilation
140and installation of the library.
141
142 Activities other than copying, distribution and modification are not
143covered by this License; they are outside its scope. The act of
144running a program using the Library is not restricted, and output from
145such a program is covered only if its contents constitute a work based
146on the Library (independent of the use of the Library in a tool for
147writing it). Whether that is true depends on what the Library does
148and what the program that uses the Library does.
149
150 1. You may copy and distribute verbatim copies of the Library's
151complete source code as you receive it, in any medium, provided that
152you conspicuously and appropriately publish on each copy an
153appropriate copyright notice and disclaimer of warranty; keep intact
154all the notices that refer to this License and to the absence of any
155warranty; and distribute a copy of this License along with the
156Library.
157
158 You may charge a fee for the physical act of transferring a copy,
159and you may at your option offer warranty protection in exchange for a
160fee.
161
162 2. You may modify your copy or copies of the Library or any portion
163of it, thus forming a work based on the Library, and copy and
164distribute such modifications or work under the terms of Section 1
165above, provided that you also meet all of these conditions:
166
167 a) The modified work must itself be a software library.
168
169 b) You must cause the files modified to carry prominent notices
170 stating that you changed the files and the date of any change.
171
172 c) You must cause the whole of the work to be licensed at no
173 charge to all third parties under the terms of this License.
174
175 d) If a facility in the modified Library refers to a function or a
176 table of data to be supplied by an application program that uses
177 the facility, other than as an argument passed when the facility
178 is invoked, then you must make a good faith effort to ensure that,
179 in the event an application does not supply such function or
180 table, the facility still operates, and performs whatever part of
181 its purpose remains meaningful.
182
183 (For example, a function in a library to compute square roots has
184 a purpose that is entirely well-defined independent of the
185 application. Therefore, Subsection 2d requires that any
186 application-supplied function or table used by this function must
187 be optional: if the application does not supply it, the square
188 root function must still compute square roots.)
189
190These requirements apply to the modified work as a whole. If
191identifiable sections of that work are not derived from the Library,
192and can be reasonably considered independent and separate works in
193themselves, then this License, and its terms, do not apply to those
194sections when you distribute them as separate works. But when you
195distribute the same sections as part of a whole which is a work based
196on the Library, the distribution of the whole must be on the terms of
197this License, whose permissions for other licensees extend to the
198entire whole, and thus to each and every part regardless of who wrote
199it.
200
201Thus, it is not the intent of this section to claim rights or contest
202your rights to work written entirely by you; rather, the intent is to
203exercise the right to control the distribution of derivative or
204collective works based on the Library.
205
206In addition, mere aggregation of another work not based on the Library
207with the Library (or with a work based on the Library) on a volume of
208a storage or distribution medium does not bring the other work under
209the scope of this License.
210
211 3. You may opt to apply the terms of the ordinary GNU General Public
212License instead of this License to a given copy of the Library. To do
213this, you must alter all the notices that refer to this License, so
214that they refer to the ordinary GNU General Public License, version 2,
215instead of to this License. (If a newer version than version 2 of the
216ordinary GNU General Public License has appeared, then you can specify
217that version instead if you wish.) Do not make any other change in
218these notices.
219
220 Once this change is made in a given copy, it is irreversible for
221that copy, so the ordinary GNU General Public License applies to all
222subsequent copies and derivative works made from that copy.
223
224 This option is useful when you wish to copy part of the code of
225the Library into a program that is not a library.
226
227 4. You may copy and distribute the Library (or a portion or
228derivative of it, under Section 2) in object code or executable form
229under the terms of Sections 1 and 2 above provided that you accompany
230it with the complete corresponding machine-readable source code, which
231must be distributed under the terms of Sections 1 and 2 above on a
232medium customarily used for software interchange.
233
234 If distribution of object code is made by offering access to copy
235from a designated place, then offering equivalent access to copy the
236source code from the same place satisfies the requirement to
237distribute the source code, even though third parties are not
238compelled to copy the source along with the object code.
239
240 5. A program that contains no derivative of any portion of the
241Library, but is designed to work with the Library by being compiled or
242linked with it, is called a "work that uses the Library". Such a
243work, in isolation, is not a derivative work of the Library, and
244therefore falls outside the scope of this License.
245
246 However, linking a "work that uses the Library" with the Library
247creates an executable that is a derivative of the Library (because it
248contains portions of the Library), rather than a "work that uses the
249library". The executable is therefore covered by this License.
250Section 6 states terms for distribution of such executables.
251
252 When a "work that uses the Library" uses material from a header file
253that is part of the Library, the object code for the work may be a
254derivative work of the Library even though the source code is not.
255Whether this is true is especially significant if the work can be
256linked without the Library, or if the work is itself a library. The
257threshold for this to be true is not precisely defined by law.
258
259 If such an object file uses only numerical parameters, data
260structure layouts and accessors, and small macros and small inline
261functions (ten lines or less in length), then the use of the object
262file is unrestricted, regardless of whether it is legally a derivative
263work. (Executables containing this object code plus portions of the
264Library will still fall under Section 6.)
265
266 Otherwise, if the work is a derivative of the Library, you may
267distribute the object code for the work under the terms of Section 6.
268Any executables containing that work also fall under Section 6,
269whether or not they are linked directly with the Library itself.
270
271 6. As an exception to the Sections above, you may also combine or
272link a "work that uses the Library" with the Library to produce a
273work containing portions of the Library, and distribute that work
274under terms of your choice, provided that the terms permit
275modification of the work for the customer's own use and reverse
276engineering for debugging such modifications.
277
278 You must give prominent notice with each copy of the work that the
279Library is used in it and that the Library and its use are covered by
280this License. You must supply a copy of this License. If the work
281during execution displays copyright notices, you must include the
282copyright notice for the Library among them, as well as a reference
283directing the user to the copy of this License. Also, you must do one
284of these things:
285
286 a) Accompany the work with the complete corresponding
287 machine-readable source code for the Library including whatever
288 changes were used in the work (which must be distributed under
289 Sections 1 and 2 above); and, if the work is an executable linked
290 with the Library, with the complete machine-readable "work that
291 uses the Library", as object code and/or source code, so that the
292 user can modify the Library and then relink to produce a modified
293 executable containing the modified Library. (It is understood
294 that the user who changes the contents of definitions files in the
295 Library will not necessarily be able to recompile the application
296 to use the modified definitions.)
297
298 b) Use a suitable shared library mechanism for linking with the
299 Library. A suitable mechanism is one that (1) uses at run time a
300 copy of the library already present on the user's computer system,
301 rather than copying library functions into the executable, and (2)
302 will operate properly with a modified version of the library, if
303 the user installs one, as long as the modified version is
304 interface-compatible with the version that the work was made with.
305
306 c) Accompany the work with a written offer, valid for at
307 least three years, to give the same user the materials
308 specified in Subsection 6a, above, for a charge no more
309 than the cost of performing this distribution.
310
311 d) If distribution of the work is made by offering access to copy
312 from a designated place, offer equivalent access to copy the above
313 specified materials from the same place.
314
315 e) Verify that the user has already received a copy of these
316 materials or that you have already sent this user a copy.
317
318 For an executable, the required form of the "work that uses the
319Library" must include any data and utility programs needed for
320reproducing the executable from it. However, as a special exception,
321the materials to be distributed need not include anything that is
322normally distributed (in either source or binary form) with the major
323components (compiler, kernel, and so on) of the operating system on
324which the executable runs, unless that component itself accompanies
325the executable.
326
327 It may happen that this requirement contradicts the license
328restrictions of other proprietary libraries that do not normally
329accompany the operating system. Such a contradiction means you cannot
330use both them and the Library together in an executable that you
331distribute.
332
333 7. You may place library facilities that are a work based on the
334Library side-by-side in a single library together with other library
335facilities not covered by this License, and distribute such a combined
336library, provided that the separate distribution of the work based on
337the Library and of the other library facilities is otherwise
338permitted, and provided that you do these two things:
339
340 a) Accompany the combined library with a copy of the same work
341 based on the Library, uncombined with any other library
342 facilities. This must be distributed under the terms of the
343 Sections above.
344
345 b) Give prominent notice with the combined library of the fact
346 that part of it is a work based on the Library, and explaining
347 where to find the accompanying uncombined form of the same work.
348
349 8. You may not copy, modify, sublicense, link with, or distribute
350the Library except as expressly provided under this License. Any
351attempt otherwise to copy, modify, sublicense, link with, or
352distribute the Library is void, and will automatically terminate your
353rights under this License. However, parties who have received copies,
354or rights, from you under this License will not have their licenses
355terminated so long as such parties remain in full compliance.
356
357 9. You are not required to accept this License, since you have not
358signed it. However, nothing else grants you permission to modify or
359distribute the Library or its derivative works. These actions are
360prohibited by law if you do not accept this License. Therefore, by
361modifying or distributing the Library (or any work based on the
362Library), you indicate your acceptance of this License to do so, and
363all its terms and conditions for copying, distributing or modifying
364the Library or works based on it.
365
366 10. Each time you redistribute the Library (or any work based on the
367Library), the recipient automatically receives a license from the
368original licensor to copy, distribute, link with or modify the Library
369subject to these terms and conditions. You may not impose any further
370restrictions on the recipients' exercise of the rights granted herein.
371You are not responsible for enforcing compliance by third parties with
372this License.
373
374 11. If, as a consequence of a court judgment or allegation of patent
375infringement or for any other reason (not limited to patent issues),
376conditions are imposed on you (whether by court order, agreement or
377otherwise) that contradict the conditions of this License, they do not
378excuse you from the conditions of this License. If you cannot
379distribute so as to satisfy simultaneously your obligations under this
380License and any other pertinent obligations, then as a consequence you
381may not distribute the Library at all. For example, if a patent
382license would not permit royalty-free redistribution of the Library by
383all those who receive copies directly or indirectly through you, then
384the only way you could satisfy both it and this License would be to
385refrain entirely from distribution of the Library.
386
387If any portion of this section is held invalid or unenforceable under any
388particular circumstance, the balance of the section is intended to apply,
389and the section as a whole is intended to apply in other circumstances.
390
391It is not the purpose of this section to induce you to infringe any
392patents or other property right claims or to contest validity of any
393such claims; this section has the sole purpose of protecting the
394integrity of the free software distribution system which is
395implemented by public license practices. Many people have made
396generous contributions to the wide range of software distributed
397through that system in reliance on consistent application of that
398system; it is up to the author/donor to decide if he or she is willing
399to distribute software through any other system and a licensee cannot
400impose that choice.
401
402This section is intended to make thoroughly clear what is believed to
403be a consequence of the rest of this License.
404
405 12. If the distribution and/or use of the Library is restricted in
406certain countries either by patents or by copyrighted interfaces, the
407original copyright holder who places the Library under this License may add
408an explicit geographical distribution limitation excluding those countries,
409so that distribution is permitted only in or among countries not thus
410excluded. In such case, this License incorporates the limitation as if
411written in the body of this License.
412
413 13. The Free Software Foundation may publish revised and/or new
414versions of the Lesser General Public License from time to time.
415Such new versions will be similar in spirit to the present version,
416but may differ in detail to address new problems or concerns.
417
418Each version is given a distinguishing version number. If the Library
419specifies a version number of this License which applies to it and
420"any later version", you have the option of following the terms and
421conditions either of that version or of any later version published by
422the Free Software Foundation. If the Library does not specify a
423license version number, you may choose any version ever published by
424the Free Software Foundation.
425
426 14. If you wish to incorporate parts of the Library into other free
427programs whose distribution conditions are incompatible with these,
428write to the author to ask for permission. For software which is
429copyrighted by the Free Software Foundation, write to the Free
430Software Foundation; we sometimes make exceptions for this. Our
431decision will be guided by the two goals of preserving the free status
432of all derivatives of our free software and of promoting the sharing
433and reuse of software generally.
434
435 NO WARRANTY
436
437 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
439EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
440OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
441KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
442IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
443PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
444LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
445THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
446
447 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
448WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
449AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
450FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
451CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
452LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
453RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
454FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456DAMAGES.
457
458 END OF TERMS AND CONDITIONS
459
460 How to Apply These Terms to Your New Libraries
461
462 If you develop a new library, and you want it to be of the greatest
463possible use to the public, we recommend making it free software that
464everyone can redistribute and change. You can do so by permitting
465redistribution under these terms (or, alternatively, under the terms of the
466ordinary General Public License).
467
468 To apply these terms, attach the following notices to the library. It is
469safest to attach them to the start of each source file to most effectively
470convey the exclusion of warranty; and each file should have at least the
471"copyright" line and a pointer to where the full notice is found.
472
473 <one line to give the library's name and a brief idea of what it does.>
474 Copyright (C) <year> <name of author>
475
476 This library is free software; you can redistribute it and/or
477 modify it under the terms of the GNU Lesser General Public
478 License as published by the Free Software Foundation; either
479 version 2.1 of the License, or (at your option) any later version.
480
481 This library is distributed in the hope that it will be useful,
482 but WITHOUT ANY WARRANTY; without even the implied warranty of
483 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
484 Lesser General Public License for more details.
485
486 You should have received a copy of the GNU Lesser General Public
487 License along with this library; if not, write to the Free Software
488 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
489
490Also add information on how to contact you by electronic and paper mail.
491
492You should also get your employer (if you work as a programmer) or your
493school, if any, to sign a "copyright disclaimer" for the library, if
494necessary. Here is a sample; alter the names:
495
496 Yoyodyne, Inc., hereby disclaims all copyright interest in the
497 library `Frob' (a library for tweaking knobs) written by James Random Hacker.
498
499 <signature of Ty Coon>, 1 April 1990
500 Ty Coon, President of Vice
501
502That's all there is to it! \ No newline at end of file
diff --git a/externals/qhexedit/qhexedit.cpp b/externals/qhexedit/qhexedit.cpp
new file mode 100644
index 000000000..b12624e08
--- /dev/null
+++ b/externals/qhexedit/qhexedit.cpp
@@ -0,0 +1,180 @@
1#include <QtGui>
2
3#include "qhexedit.h"
4
5
6QHexEdit::QHexEdit(QWidget *parent) : QScrollArea(parent)
7{
8 qHexEdit_p = new QHexEditPrivate(this);
9 setWidget(qHexEdit_p);
10 setWidgetResizable(true);
11
12 connect(qHexEdit_p, SIGNAL(currentAddressChanged(int)), this, SIGNAL(currentAddressChanged(int)));
13 connect(qHexEdit_p, SIGNAL(currentSizeChanged(int)), this, SIGNAL(currentSizeChanged(int)));
14 connect(qHexEdit_p, SIGNAL(dataChanged()), this, SIGNAL(dataChanged()));
15 connect(qHexEdit_p, SIGNAL(overwriteModeChanged(bool)), this, SIGNAL(overwriteModeChanged(bool)));
16 setFocusPolicy(Qt::NoFocus);
17}
18
19int QHexEdit::indexOf(const QByteArray & ba, int from) const
20{
21 return qHexEdit_p->indexOf(ba, from);
22}
23
24void QHexEdit::insert(int i, const QByteArray & ba)
25{
26 qHexEdit_p->insert(i, ba);
27}
28
29void QHexEdit::insert(int i, char ch)
30{
31 qHexEdit_p->insert(i, ch);
32}
33
34int QHexEdit::lastIndexOf(const QByteArray & ba, int from) const
35{
36 return qHexEdit_p->lastIndexOf(ba, from);
37}
38
39void QHexEdit::remove(int pos, int len)
40{
41 qHexEdit_p->remove(pos, len);
42}
43
44void QHexEdit::replace( int pos, int len, const QByteArray & after)
45{
46 qHexEdit_p->replace(pos, len, after);
47}
48
49QString QHexEdit::toReadableString()
50{
51 return qHexEdit_p->toRedableString();
52}
53
54QString QHexEdit::selectionToReadableString()
55{
56 return qHexEdit_p->selectionToReadableString();
57}
58
59void QHexEdit::setAddressArea(bool addressArea)
60{
61 qHexEdit_p->setAddressArea(addressArea);
62}
63
64void QHexEdit::redo()
65{
66 qHexEdit_p->redo();
67}
68
69void QHexEdit::undo()
70{
71 qHexEdit_p->undo();
72}
73
74void QHexEdit::setAddressWidth(int addressWidth)
75{
76 qHexEdit_p->setAddressWidth(addressWidth);
77}
78
79void QHexEdit::setAsciiArea(bool asciiArea)
80{
81 qHexEdit_p->setAsciiArea(asciiArea);
82}
83
84void QHexEdit::setHighlighting(bool mode)
85{
86 qHexEdit_p->setHighlighting(mode);
87}
88
89void QHexEdit::setAddressOffset(int offset)
90{
91 qHexEdit_p->setAddressOffset(offset);
92}
93
94int QHexEdit::addressOffset()
95{
96 return qHexEdit_p->addressOffset();
97}
98
99void QHexEdit::setCursorPosition(int cursorPos)
100{
101 // cursorPos in QHexEditPrivate is the position of the textcoursor without
102 // blanks, means bytePos*2
103 qHexEdit_p->setCursorPos(cursorPos*2);
104}
105
106int QHexEdit::cursorPosition()
107{
108 return qHexEdit_p->cursorPos() / 2;
109}
110
111
112void QHexEdit::setData(const QByteArray &data)
113{
114 qHexEdit_p->setData(data);
115}
116
117QByteArray QHexEdit::data()
118{
119 return qHexEdit_p->data();
120}
121
122void QHexEdit::setAddressAreaColor(const QColor &color)
123{
124 qHexEdit_p->setAddressAreaColor(color);
125}
126
127QColor QHexEdit::addressAreaColor()
128{
129 return qHexEdit_p->addressAreaColor();
130}
131
132void QHexEdit::setHighlightingColor(const QColor &color)
133{
134 qHexEdit_p->setHighlightingColor(color);
135}
136
137QColor QHexEdit::highlightingColor()
138{
139 return qHexEdit_p->highlightingColor();
140}
141
142void QHexEdit::setSelectionColor(const QColor &color)
143{
144 qHexEdit_p->setSelectionColor(color);
145}
146
147QColor QHexEdit::selectionColor()
148{
149 return qHexEdit_p->selectionColor();
150}
151
152void QHexEdit::setOverwriteMode(bool overwriteMode)
153{
154 qHexEdit_p->setOverwriteMode(overwriteMode);
155}
156
157bool QHexEdit::overwriteMode()
158{
159 return qHexEdit_p->overwriteMode();
160}
161
162void QHexEdit::setReadOnly(bool readOnly)
163{
164 qHexEdit_p->setReadOnly(readOnly);
165}
166
167bool QHexEdit::isReadOnly()
168{
169 return qHexEdit_p->isReadOnly();
170}
171
172void QHexEdit::setFont(const QFont &font)
173{
174 qHexEdit_p->setFont(font);
175}
176
177const QFont & QHexEdit::font() const
178{
179 return qHexEdit_p->font();
180}
diff --git a/externals/qhexedit/qhexedit.h b/externals/qhexedit/qhexedit.h
new file mode 100644
index 000000000..15b6d7603
--- /dev/null
+++ b/externals/qhexedit/qhexedit.h
@@ -0,0 +1,240 @@
1// Original author: Winfried Simon
2// See http://code.google.com/p/qhexedit2/
3// Huge thanks!
4
5#ifndef QHEXEDIT_H
6#define QHEXEDIT_H
7
8#include <QtGui>
9#include "qhexedit_p.h"
10
11/** \mainpage
12QHexEdit is a binary editor widget for Qt.
13
14\version Version 0.6.3
15\image html hexedit.png
16*/
17
18
19/*! QHexEdit is a hex editor widget written in C++ for the Qt (Qt4) framework.
20It is a simple editor for binary data, just like QPlainTextEdit is for text
21data. There are sip configuration files included, so it is easy to create
22bindings for PyQt and you can use this widget also in python.
23
24QHexEdit takes the data of a QByteArray (setData()) and shows it. You can use
25the mouse or the keyboard to navigate inside the widget. If you hit the keys
26(0..9, a..f) you will change the data. Changed data is highlighted and can be
27accessed via data().
28
29Normaly QHexEdit works in the overwrite Mode. You can set overwriteMode(false)
30and insert data. In this case the size of data() increases. It is also possible
31to delete bytes (del or backspace), here the size of data decreases.
32
33You can select data with keyboard hits or mouse movements. The copy-key will
34copy the selected data into the clipboard. The cut-key copies also but delets
35it afterwards. In overwrite mode, the paste function overwrites the content of
36the (does not change the length) data. In insert mode, clipboard data will be
37inserted. The clipboard content is expected in ASCII Hex notation. Unknown
38characters will be ignored.
39
40QHexEdit comes with undo/redo functionality. All changes can be undone, by
41pressing the undo-key (usually ctr-z). They can also be redone afterwards.
42The undo/redo framework is cleared, when setData() sets up a new
43content for the editor. You can search data inside the content with indexOf()
44and lastIndexOf(). The replace() function is to change located subdata. This
45'replaced' data can also be undone by the undo/redo framework.
46
47This widget can only handle small amounts of data. The size has to be below 10
48megabytes, otherwise the scroll sliders ard not shown and you can't scroll any
49more.
50*/
51 class QHexEdit : public QScrollArea
52{
53 Q_OBJECT
54 /*! Property data holds the content of QHexEdit. Call setData() to set the
55 content of QHexEdit, data() returns the actual content.
56 */
57 Q_PROPERTY(QByteArray data READ data WRITE setData)
58
59 /*! Property addressOffset is added to the Numbers of the Address Area.
60 A offset in the address area (left side) is sometimes usefull, whe you show
61 only a segment of a complete memory picture. With setAddressOffset() you set
62 this property - with addressOffset() you get the actual value.
63 */
64 Q_PROPERTY(int addressOffset READ addressOffset WRITE setAddressOffset)
65
66 /*! Property address area color sets (setAddressAreaColor()) the backgorund
67 color of address areas. You can also read the color (addressaAreaColor()).
68 */
69 Q_PROPERTY(QColor addressAreaColor READ addressAreaColor WRITE setAddressAreaColor)
70
71 /*! Porperty cursorPosition sets or gets the position of the editor cursor
72 in QHexEdit.
73 */
74 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition)
75
76 /*! Property highlighting color sets (setHighlightingColor()) the backgorund
77 color of highlighted text areas. You can also read the color
78 (highlightingColor()).
79 */
80 Q_PROPERTY(QColor highlightingColor READ highlightingColor WRITE setHighlightingColor)
81
82 /*! Property selection color sets (setSelectionColor()) the backgorund
83 color of selected text areas. You can also read the color
84 (selectionColor()).
85 */
86 Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor)
87
88 /*! Porperty overwrite mode sets (setOverwriteMode()) or gets (overwriteMode()) the mode
89 in which the editor works. In overwrite mode the user will overwrite existing data. The
90 size of data will be constant. In insert mode the size will grow, when inserting
91 new data.
92 */
93 Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
94
95 /*! Porperty readOnly sets (setReadOnly()) or gets (isReadOnly) the mode
96 in which the editor works. In readonly mode the the user can only navigate
97 through the data and select data; modifying is not possible. This
98 property's default is false.
99 */
100 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
101
102 /*! Set the font of the widget. Please use fixed width fonts like Mono or Courier.*/
103 Q_PROPERTY(QFont font READ font WRITE setFont)
104
105
106public:
107 /*! Creates an instance of QHexEdit.
108 \param parent Parent widget of QHexEdit.
109 */
110 QHexEdit(QWidget *parent = 0);
111
112 /*! Returns the index position of the first occurrence
113 of the byte array ba in this byte array, searching forward from index position
114 from. Returns -1 if ba could not be found. In addition to this functionality
115 of QByteArray the cursorposition is set to the end of found bytearray and
116 it will be selected.
117
118 */
119 int indexOf(const QByteArray & ba, int from = 0) const;
120
121 /*! Inserts a byte array.
122 \param i Index position, where to insert
123 \param ba byte array, which is to insert
124 In overwrite mode, the existing data will be overwritten, in insertmode ba will be
125 inserted and size of data grows.
126 */
127 void insert(int i, const QByteArray & ba);
128
129 /*! Inserts a char.
130 \param i Index position, where to insert
131 \param ch Char, which is to insert
132 In overwrite mode, the existing data will be overwritten, in insertmode ba will be
133 inserted and size of data grows.
134 */
135 void insert(int i, char ch);
136
137 /*! Returns the index position of the last occurrence
138 of the byte array ba in this byte array, searching backwards from index position
139 from. Returns -1 if ba could not be found. In addition to this functionality
140 of QByteArray the cursorposition is set to the beginning of found bytearray and
141 it will be selected.
142
143 */
144 int lastIndexOf(const QByteArray & ba, int from = 0) const;
145
146 /*! Removes len bytes from the content.
147 \param pos Index position, where to remove
148 \param len Amount of bytes to remove
149 In overwrite mode, the existing bytes will be overwriten with 0x00.
150 */
151 void remove(int pos, int len=1);
152
153 /*! Replaces len bytes from index position pos with the byte array after.
154 */
155 void replace( int pos, int len, const QByteArray & after);
156
157 /*! Gives back a formatted image of the content of QHexEdit
158 */
159 QString toReadableString();
160
161 /*! Gives back a formatted image of the selected content of QHexEdit
162 */
163 QString selectionToReadableString();
164
165 /*! \cond docNever */
166 void setAddressOffset(int offset);
167 int addressOffset();
168 void setCursorPosition(int cusorPos);
169 int cursorPosition();
170 void setData(QByteArray const &data);
171 QByteArray data();
172 void setAddressAreaColor(QColor const &color);
173 QColor addressAreaColor();
174 void setHighlightingColor(QColor const &color);
175 QColor highlightingColor();
176 void setSelectionColor(QColor const &color);
177 QColor selectionColor();
178 void setOverwriteMode(bool);
179 bool overwriteMode();
180 void setReadOnly(bool);
181 bool isReadOnly();
182 const QFont &font() const;
183 void setFont(const QFont &);
184 /*! \endcond docNever */
185
186public slots:
187 /*! Redoes the last operation. If there is no operation to redo, i.e.
188 there is no redo step in the undo/redo history, nothing happens.
189 */
190 void redo();
191
192 /*! Set the minimum width of the address area.
193 \param addressWidth Width in characters.
194 */
195 void setAddressWidth(int addressWidth);
196
197 /*! Switch the address area on or off.
198 \param addressArea true (show it), false (hide it).
199 */
200 void setAddressArea(bool addressArea);
201
202 /*! Switch the ascii area on or off.
203 \param asciiArea true (show it), false (hide it).
204 */
205 void setAsciiArea(bool asciiArea);
206
207 /*! Switch the highlighting feature on or of.
208 \param mode true (show it), false (hide it).
209 */
210 void setHighlighting(bool mode);
211
212 /*! Undoes the last operation. If there is no operation to undo, i.e.
213 there is no undo step in the undo/redo history, nothing happens.
214 */
215 void undo();
216
217signals:
218
219 /*! Contains the address, where the cursor is located. */
220 void currentAddressChanged(int address);
221
222 /*! Contains the size of the data to edit. */
223 void currentSizeChanged(int size);
224
225 /*! The signal is emited every time, the data is changed. */
226 void dataChanged();
227
228 /*! The signal is emited every time, the overwrite mode is changed. */
229 void overwriteModeChanged(bool state);
230
231private:
232 /*! \cond docNever */
233 QHexEditPrivate *qHexEdit_p;
234 QHBoxLayout *layout;
235 QScrollArea *scrollArea;
236 /*! \endcond docNever */
237};
238
239#endif
240
diff --git a/externals/qhexedit/qhexedit_p.cpp b/externals/qhexedit/qhexedit_p.cpp
new file mode 100644
index 000000000..c16f4ce4d
--- /dev/null
+++ b/externals/qhexedit/qhexedit_p.cpp
@@ -0,0 +1,859 @@
1#include <QtGui>
2
3#include "qhexedit_p.h"
4#include "commands.h"
5
6const int HEXCHARS_IN_LINE = 47;
7const int GAP_ADR_HEX = 10;
8const int GAP_HEX_ASCII = 16;
9const int BYTES_PER_LINE = 16;
10
11QHexEditPrivate::QHexEditPrivate(QScrollArea *parent) : QWidget(parent)
12{
13 _undoStack = new QUndoStack(this);
14
15 _scrollArea = parent;
16 setAddressWidth(4);
17 setAddressOffset(0);
18 setAddressArea(true);
19 setAsciiArea(true);
20 setHighlighting(true);
21 setOverwriteMode(true);
22 setReadOnly(false);
23 setAddressAreaColor(QColor(0xd4, 0xd4, 0xd4, 0xff));
24 setHighlightingColor(QColor(0xff, 0xff, 0x99, 0xff));
25 setSelectionColor(QColor(0x6d, 0x9e, 0xff, 0xff));
26 setFont(QFont("Courier", 10));
27
28 _size = 0;
29 resetSelection(0);
30
31 setFocusPolicy(Qt::StrongFocus);
32
33 connect(&_cursorTimer, SIGNAL(timeout()), this, SLOT(updateCursor()));
34 _cursorTimer.setInterval(500);
35 _cursorTimer.start();
36}
37
38void QHexEditPrivate::setAddressOffset(int offset)
39{
40 _xData.setAddressOffset(offset);
41 adjust();
42}
43
44int QHexEditPrivate::addressOffset()
45{
46 return _xData.addressOffset();
47}
48
49void QHexEditPrivate::setData(const QByteArray &data)
50{
51 _xData.setData(data);
52 _undoStack->clear();
53 adjust();
54 setCursorPos(0);
55}
56
57QByteArray QHexEditPrivate::data()
58{
59 return _xData.data();
60}
61
62void QHexEditPrivate::setAddressAreaColor(const QColor &color)
63{
64 _addressAreaColor = color;
65 update();
66}
67
68QColor QHexEditPrivate::addressAreaColor()
69{
70 return _addressAreaColor;
71}
72
73void QHexEditPrivate::setHighlightingColor(const QColor &color)
74{
75 _highlightingColor = color;
76 update();
77}
78
79QColor QHexEditPrivate::highlightingColor()
80{
81 return _highlightingColor;
82}
83
84void QHexEditPrivate::setSelectionColor(const QColor &color)
85{
86 _selectionColor = color;
87 update();
88}
89
90QColor QHexEditPrivate::selectionColor()
91{
92 return _selectionColor;
93}
94
95void QHexEditPrivate::setReadOnly(bool readOnly)
96{
97 _readOnly = readOnly;
98}
99
100bool QHexEditPrivate::isReadOnly()
101{
102 return _readOnly;
103}
104
105XByteArray & QHexEditPrivate::xData()
106{
107 return _xData;
108}
109
110int QHexEditPrivate::indexOf(const QByteArray & ba, int from)
111{
112 if (from > (_xData.data().length() - 1))
113 from = _xData.data().length() - 1;
114 int idx = _xData.data().indexOf(ba, from);
115 if (idx > -1)
116 {
117 int curPos = idx*2;
118 setCursorPos(curPos + ba.length()*2);
119 resetSelection(curPos);
120 setSelection(curPos + ba.length()*2);
121 ensureVisible();
122 }
123 return idx;
124}
125
126void QHexEditPrivate::insert(int index, const QByteArray & ba)
127{
128 if (ba.length() > 0)
129 {
130 if (_overwriteMode)
131 {
132 QUndoCommand *arrayCommand= new ArrayCommand(&_xData, ArrayCommand::replace, index, ba, ba.length());
133 _undoStack->push(arrayCommand);
134 emit dataChanged();
135 }
136 else
137 {
138 QUndoCommand *arrayCommand= new ArrayCommand(&_xData, ArrayCommand::insert, index, ba, ba.length());
139 _undoStack->push(arrayCommand);
140 emit dataChanged();
141 }
142 }
143}
144
145void QHexEditPrivate::insert(int index, char ch)
146{
147 QUndoCommand *charCommand = new CharCommand(&_xData, CharCommand::insert, index, ch);
148 _undoStack->push(charCommand);
149 emit dataChanged();
150}
151
152int QHexEditPrivate::lastIndexOf(const QByteArray & ba, int from)
153{
154 from -= ba.length();
155 if (from < 0)
156 from = 0;
157 int idx = _xData.data().lastIndexOf(ba, from);
158 if (idx > -1)
159 {
160 int curPos = idx*2;
161 setCursorPos(curPos);
162 resetSelection(curPos);
163 setSelection(curPos + ba.length()*2);
164 ensureVisible();
165 }
166 return idx;
167}
168
169void QHexEditPrivate::remove(int index, int len)
170{
171 if (len > 0)
172 {
173 if (len == 1)
174 {
175 if (_overwriteMode)
176 {
177 QUndoCommand *charCommand = new CharCommand(&_xData, CharCommand::replace, index, char(0));
178 _undoStack->push(charCommand);
179 emit dataChanged();
180 }
181 else
182 {
183 QUndoCommand *charCommand = new CharCommand(&_xData, CharCommand::remove, index, char(0));
184 _undoStack->push(charCommand);
185 emit dataChanged();
186 }
187 }
188 else
189 {
190 QByteArray ba = QByteArray(len, char(0));
191 if (_overwriteMode)
192 {
193 QUndoCommand *arrayCommand = new ArrayCommand(&_xData, ArrayCommand::replace, index, ba, ba.length());
194 _undoStack->push(arrayCommand);
195 emit dataChanged();
196 }
197 else
198 {
199 QUndoCommand *arrayCommand= new ArrayCommand(&_xData, ArrayCommand::remove, index, ba, len);
200 _undoStack->push(arrayCommand);
201 emit dataChanged();
202 }
203 }
204 }
205}
206
207void QHexEditPrivate::replace(int index, char ch)
208{
209 QUndoCommand *charCommand = new CharCommand(&_xData, CharCommand::replace, index, ch);
210 _undoStack->push(charCommand);
211 resetSelection();
212 emit dataChanged();
213}
214
215void QHexEditPrivate::replace(int index, const QByteArray & ba)
216{
217 QUndoCommand *arrayCommand= new ArrayCommand(&_xData, ArrayCommand::replace, index, ba, ba.length());
218 _undoStack->push(arrayCommand);
219 resetSelection();
220 emit dataChanged();
221}
222
223void QHexEditPrivate::replace(int pos, int len, const QByteArray &after)
224{
225 QUndoCommand *arrayCommand= new ArrayCommand(&_xData, ArrayCommand::replace, pos, after, len);
226 _undoStack->push(arrayCommand);
227 resetSelection();
228 emit dataChanged();
229}
230
231void QHexEditPrivate::setAddressArea(bool addressArea)
232{
233 _addressArea = addressArea;
234 adjust();
235
236 setCursorPos(_cursorPosition);
237}
238
239void QHexEditPrivate::setAddressWidth(int addressWidth)
240{
241 _xData.setAddressWidth(addressWidth);
242
243 setCursorPos(_cursorPosition);
244}
245
246void QHexEditPrivate::setAsciiArea(bool asciiArea)
247{
248 _asciiArea = asciiArea;
249 adjust();
250}
251
252void QHexEditPrivate::setFont(const QFont &font)
253{
254 QWidget::setFont(font);
255 adjust();
256}
257
258void QHexEditPrivate::setHighlighting(bool mode)
259{
260 _highlighting = mode;
261 update();
262}
263
264void QHexEditPrivate::setOverwriteMode(bool overwriteMode)
265{
266 _overwriteMode = overwriteMode;
267}
268
269bool QHexEditPrivate::overwriteMode()
270{
271 return _overwriteMode;
272}
273
274void QHexEditPrivate::redo()
275{
276 _undoStack->redo();
277 emit dataChanged();
278 setCursorPos(_cursorPosition);
279 update();
280}
281
282void QHexEditPrivate::undo()
283{
284 _undoStack->undo();
285 emit dataChanged();
286 setCursorPos(_cursorPosition);
287 update();
288}
289
290QString QHexEditPrivate::toRedableString()
291{
292 return _xData.toRedableString();
293}
294
295
296QString QHexEditPrivate::selectionToReadableString()
297{
298 return _xData.toRedableString(getSelectionBegin(), getSelectionEnd());
299}
300
301void QHexEditPrivate::keyPressEvent(QKeyEvent *event)
302{
303 int charX = (_cursorX - _xPosHex) / _charWidth;
304 int posX = (charX / 3) * 2 + (charX % 3);
305 int posBa = (_cursorY / _charHeight) * BYTES_PER_LINE + posX / 2;
306
307
308/*****************************************************************************/
309/* Cursor movements */
310/*****************************************************************************/
311
312 if (event->matches(QKeySequence::MoveToNextChar))
313 {
314 setCursorPos(_cursorPosition + 1);
315 resetSelection(_cursorPosition);
316 }
317 if (event->matches(QKeySequence::MoveToPreviousChar))
318 {
319 setCursorPos(_cursorPosition - 1);
320 resetSelection(_cursorPosition);
321 }
322 if (event->matches(QKeySequence::MoveToEndOfLine))
323 {
324 setCursorPos(_cursorPosition | (2 * BYTES_PER_LINE -1));
325 resetSelection(_cursorPosition);
326 }
327 if (event->matches(QKeySequence::MoveToStartOfLine))
328 {
329 setCursorPos(_cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE)));
330 resetSelection(_cursorPosition);
331 }
332 if (event->matches(QKeySequence::MoveToPreviousLine))
333 {
334 setCursorPos(_cursorPosition - (2 * BYTES_PER_LINE));
335 resetSelection(_cursorPosition);
336 }
337 if (event->matches(QKeySequence::MoveToNextLine))
338 {
339 setCursorPos(_cursorPosition + (2 * BYTES_PER_LINE));
340 resetSelection(_cursorPosition);
341 }
342
343 if (event->matches(QKeySequence::MoveToNextPage))
344 {
345 setCursorPos(_cursorPosition + (((_scrollArea->viewport()->height() / _charHeight) - 1) * 2 * BYTES_PER_LINE));
346 resetSelection(_cursorPosition);
347 }
348 if (event->matches(QKeySequence::MoveToPreviousPage))
349 {
350 setCursorPos(_cursorPosition - (((_scrollArea->viewport()->height() / _charHeight) - 1) * 2 * BYTES_PER_LINE));
351 resetSelection(_cursorPosition);
352 }
353 if (event->matches(QKeySequence::MoveToEndOfDocument))
354 {
355 setCursorPos(_xData.size() * 2);
356 resetSelection(_cursorPosition);
357 }
358 if (event->matches(QKeySequence::MoveToStartOfDocument))
359 {
360 setCursorPos(0);
361 resetSelection(_cursorPosition);
362 }
363
364/*****************************************************************************/
365/* Select commands */
366/*****************************************************************************/
367 if (event->matches(QKeySequence::SelectAll))
368 {
369 resetSelection(0);
370 setSelection(2*_xData.size() + 1);
371 }
372 if (event->matches(QKeySequence::SelectNextChar))
373 {
374 int pos = _cursorPosition + 1;
375 setCursorPos(pos);
376 setSelection(pos);
377 }
378 if (event->matches(QKeySequence::SelectPreviousChar))
379 {
380 int pos = _cursorPosition - 1;
381 setSelection(pos);
382 setCursorPos(pos);
383 }
384 if (event->matches(QKeySequence::SelectEndOfLine))
385 {
386 int pos = _cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE)) + (2 * BYTES_PER_LINE);
387 setCursorPos(pos);
388 setSelection(pos);
389 }
390 if (event->matches(QKeySequence::SelectStartOfLine))
391 {
392 int pos = _cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE));
393 setCursorPos(pos);
394 setSelection(pos);
395 }
396 if (event->matches(QKeySequence::SelectPreviousLine))
397 {
398 int pos = _cursorPosition - (2 * BYTES_PER_LINE);
399 setCursorPos(pos);
400 setSelection(pos);
401 }
402 if (event->matches(QKeySequence::SelectNextLine))
403 {
404 int pos = _cursorPosition + (2 * BYTES_PER_LINE);
405 setCursorPos(pos);
406 setSelection(pos);
407 }
408
409 if (event->matches(QKeySequence::SelectNextPage))
410 {
411 int pos = _cursorPosition + (((_scrollArea->viewport()->height() / _charHeight) - 1) * 2 * BYTES_PER_LINE);
412 setCursorPos(pos);
413 setSelection(pos);
414 }
415 if (event->matches(QKeySequence::SelectPreviousPage))
416 {
417 int pos = _cursorPosition - (((_scrollArea->viewport()->height() / _charHeight) - 1) * 2 * BYTES_PER_LINE);
418 setCursorPos(pos);
419 setSelection(pos);
420 }
421 if (event->matches(QKeySequence::SelectEndOfDocument))
422 {
423 int pos = _xData.size() * 2;
424 setCursorPos(pos);
425 setSelection(pos);
426 }
427 if (event->matches(QKeySequence::SelectStartOfDocument))
428 {
429 int pos = 0;
430 setCursorPos(pos);
431 setSelection(pos);
432 }
433
434/*****************************************************************************/
435/* Edit Commands */
436/*****************************************************************************/
437if (!_readOnly)
438{
439 /* Hex input */
440 int key = int(event->text()[0].toAscii());
441 if ((key>='0' && key<='9') || (key>='a' && key <= 'f'))
442 {
443 if (getSelectionBegin() != getSelectionEnd())
444 {
445 posBa = getSelectionBegin();
446 remove(posBa, getSelectionEnd() - posBa);
447 setCursorPos(2*posBa);
448 resetSelection(2*posBa);
449 }
450
451 // If insert mode, then insert a byte
452 if (_overwriteMode == false)
453 if ((charX % 3) == 0)
454 {
455 insert(posBa, char(0));
456 }
457
458 // Change content
459 if (_xData.size() > 0)
460 {
461 QByteArray hexValue = _xData.data().mid(posBa, 1).toHex();
462 if ((charX % 3) == 0)
463 hexValue[0] = key;
464 else
465 hexValue[1] = key;
466
467 replace(posBa, QByteArray().fromHex(hexValue)[0]);
468
469 setCursorPos(_cursorPosition + 1);
470 resetSelection(_cursorPosition);
471 }
472 }
473
474 /* Cut & Paste */
475 if (event->matches(QKeySequence::Cut))
476 {
477 QString result = QString();
478 for (int idx = getSelectionBegin(); idx < getSelectionEnd(); idx++)
479 {
480 result += _xData.data().mid(idx, 1).toHex() + " ";
481 if ((idx % 16) == 15)
482 result.append("\n");
483 }
484 remove(getSelectionBegin(), getSelectionEnd() - getSelectionBegin());
485 QClipboard *clipboard = QApplication::clipboard();
486 clipboard->setText(result);
487 setCursorPos(getSelectionBegin());
488 resetSelection(getSelectionBegin());
489 }
490
491 if (event->matches(QKeySequence::Paste))
492 {
493 QClipboard *clipboard = QApplication::clipboard();
494 QByteArray ba = QByteArray().fromHex(clipboard->text().toLatin1());
495 insert(_cursorPosition / 2, ba);
496 setCursorPos(_cursorPosition + 2 * ba.length());
497 resetSelection(getSelectionBegin());
498 }
499
500
501 /* Delete char */
502 if (event->matches(QKeySequence::Delete))
503 {
504 if (getSelectionBegin() != getSelectionEnd())
505 {
506 posBa = getSelectionBegin();
507 remove(posBa, getSelectionEnd() - posBa);
508 setCursorPos(2*posBa);
509 resetSelection(2*posBa);
510 }
511 else
512 {
513 if (_overwriteMode)
514 replace(posBa, char(0));
515 else
516 remove(posBa, 1);
517 }
518 }
519
520 /* Backspace */
521 if ((event->key() == Qt::Key_Backspace) && (event->modifiers() == Qt::NoModifier))
522 {
523 if (getSelectionBegin() != getSelectionEnd())
524 {
525 posBa = getSelectionBegin();
526 remove(posBa, getSelectionEnd() - posBa);
527 setCursorPos(2*posBa);
528 resetSelection(2*posBa);
529 }
530 else
531 {
532 if (posBa > 0)
533 {
534 if (_overwriteMode)
535 replace(posBa - 1, char(0));
536 else
537 remove(posBa - 1, 1);
538 setCursorPos(_cursorPosition - 2);
539 }
540 }
541 }
542
543 /* undo */
544 if (event->matches(QKeySequence::Undo))
545 {
546 undo();
547 }
548
549 /* redo */
550 if (event->matches(QKeySequence::Redo))
551 {
552 redo();
553 }
554
555 }
556
557 if (event->matches(QKeySequence::Copy))
558 {
559 QString result = QString();
560 for (int idx = getSelectionBegin(); idx < getSelectionEnd(); idx++)
561 {
562 result += _xData.data().mid(idx, 1).toHex() + " ";
563 if ((idx % 16) == 15)
564 result.append('\n');
565 }
566 QClipboard *clipboard = QApplication::clipboard();
567 clipboard->setText(result);
568 }
569
570 // Switch between insert/overwrite mode
571 if ((event->key() == Qt::Key_Insert) && (event->modifiers() == Qt::NoModifier))
572 {
573 _overwriteMode = !_overwriteMode;
574 setCursorPos(_cursorPosition);
575 overwriteModeChanged(_overwriteMode);
576 }
577
578 ensureVisible();
579 update();
580}
581
582void QHexEditPrivate::mouseMoveEvent(QMouseEvent * event)
583{
584 _blink = false;
585 update();
586 int actPos = cursorPos(event->pos());
587 setCursorPos(actPos);
588 setSelection(actPos);
589}
590
591void QHexEditPrivate::mousePressEvent(QMouseEvent * event)
592{
593 _blink = false;
594 update();
595 int cPos = cursorPos(event->pos());
596 resetSelection(cPos);
597 setCursorPos(cPos);
598}
599
600void QHexEditPrivate::paintEvent(QPaintEvent *event)
601{
602 QPainter painter(this);
603
604 // draw some patterns if needed
605 painter.fillRect(event->rect(), this->palette().color(QPalette::Base));
606 if (_addressArea)
607 painter.fillRect(QRect(_xPosAdr, event->rect().top(), _xPosHex - GAP_ADR_HEX + 2, height()), _addressAreaColor);
608 if (_asciiArea)
609 {
610 int linePos = _xPosAscii - (GAP_HEX_ASCII / 2);
611 painter.setPen(Qt::gray);
612 painter.drawLine(linePos, event->rect().top(), linePos, height());
613 }
614
615 painter.setPen(this->palette().color(QPalette::WindowText));
616
617 // calc position
618 int firstLineIdx = ((event->rect().top()/ _charHeight) - _charHeight) * BYTES_PER_LINE;
619 if (firstLineIdx < 0)
620 firstLineIdx = 0;
621 int lastLineIdx = ((event->rect().bottom() / _charHeight) + _charHeight) * BYTES_PER_LINE;
622 if (lastLineIdx > _xData.size())
623 lastLineIdx = _xData.size();
624 int yPosStart = ((firstLineIdx) / BYTES_PER_LINE) * _charHeight + _charHeight;
625
626 // paint address area
627 if (_addressArea)
628 {
629 for (int lineIdx = firstLineIdx, yPos = yPosStart; lineIdx < lastLineIdx; lineIdx += BYTES_PER_LINE, yPos +=_charHeight)
630 {
631 QString address = QString("%1")
632 .arg(lineIdx + _xData.addressOffset(), _xData.realAddressNumbers(), 16, QChar('0'));
633 painter.drawText(_xPosAdr, yPos, address);
634 }
635 }
636
637 // paint hex area
638 QByteArray hexBa(_xData.data().mid(firstLineIdx, lastLineIdx - firstLineIdx + 1).toHex());
639 QBrush highLighted = QBrush(_highlightingColor);
640 QPen colHighlighted = QPen(this->palette().color(QPalette::WindowText));
641 QBrush selected = QBrush(_selectionColor);
642 QPen colSelected = QPen(Qt::white);
643 QPen colStandard = QPen(this->palette().color(QPalette::WindowText));
644
645 painter.setBackgroundMode(Qt::TransparentMode);
646
647 for (int lineIdx = firstLineIdx, yPos = yPosStart; lineIdx < lastLineIdx; lineIdx += BYTES_PER_LINE, yPos +=_charHeight)
648 {
649 QByteArray hex;
650 int xPos = _xPosHex;
651 for (int colIdx = 0; ((lineIdx + colIdx) < _xData.size() && (colIdx < BYTES_PER_LINE)); colIdx++)
652 {
653 int posBa = lineIdx + colIdx;
654 if ((getSelectionBegin() <= posBa) && (getSelectionEnd() > posBa))
655 {
656 painter.setBackground(selected);
657 painter.setBackgroundMode(Qt::OpaqueMode);
658 painter.setPen(colSelected);
659 }
660 else
661 {
662 if (_highlighting)
663 {
664 // hilight diff bytes
665 painter.setBackground(highLighted);
666 if (_xData.dataChanged(posBa))
667 {
668 painter.setPen(colHighlighted);
669 painter.setBackgroundMode(Qt::OpaqueMode);
670 }
671 else
672 {
673 painter.setPen(colStandard);
674 painter.setBackgroundMode(Qt::TransparentMode);
675 }
676 }
677 }
678
679 // render hex value
680 if (colIdx == 0)
681 {
682 hex = hexBa.mid((lineIdx - firstLineIdx) * 2, 2);
683 painter.drawText(xPos, yPos, hex);
684 xPos += 2 * _charWidth;
685 } else {
686 hex = hexBa.mid((lineIdx + colIdx - firstLineIdx) * 2, 2).prepend(" ");
687 painter.drawText(xPos, yPos, hex);
688 xPos += 3 * _charWidth;
689 }
690
691 }
692 }
693 painter.setBackgroundMode(Qt::TransparentMode);
694 painter.setPen(this->palette().color(QPalette::WindowText));
695
696 // paint ascii area
697 if (_asciiArea)
698 {
699 for (int lineIdx = firstLineIdx, yPos = yPosStart; lineIdx < lastLineIdx; lineIdx += BYTES_PER_LINE, yPos +=_charHeight)
700 {
701 int xPosAscii = _xPosAscii;
702 for (int colIdx = 0; ((lineIdx + colIdx) < _xData.size() && (colIdx < BYTES_PER_LINE)); colIdx++)
703 {
704 painter.drawText(xPosAscii, yPos, _xData.asciiChar(lineIdx + colIdx));
705 xPosAscii += _charWidth;
706 }
707 }
708 }
709
710 // paint cursor
711 if (_blink && !_readOnly && hasFocus())
712 {
713 if (_overwriteMode)
714 painter.fillRect(_cursorX, _cursorY + _charHeight - 2, _charWidth, 2, this->palette().color(QPalette::WindowText));
715 else
716 painter.fillRect(_cursorX, _cursorY, 2, _charHeight, this->palette().color(QPalette::WindowText));
717 }
718
719 if (_size != _xData.size())
720 {
721 _size = _xData.size();
722 emit currentSizeChanged(_size);
723 }
724}
725
726void QHexEditPrivate::setCursorPos(int position)
727{
728 // delete cursor
729 _blink = false;
730 update();
731
732 // cursor in range?
733 if (_overwriteMode)
734 {
735 if (position > (_xData.size() * 2 - 1))
736 position = _xData.size() * 2 - 1;
737 } else {
738 if (position > (_xData.size() * 2))
739 position = _xData.size() * 2;
740 }
741
742 if (position < 0)
743 position = 0;
744
745 // calc position
746 _cursorPosition = position;
747 _cursorY = (position / (2 * BYTES_PER_LINE)) * _charHeight + 4;
748 int x = (position % (2 * BYTES_PER_LINE));
749 _cursorX = (((x / 2) * 3) + (x % 2)) * _charWidth + _xPosHex;
750
751 // immiadately draw cursor
752 _blink = true;
753 update();
754 emit currentAddressChanged(_cursorPosition/2);
755}
756
757int QHexEditPrivate::cursorPos(QPoint pos)
758{
759 int result = -1;
760 // find char under cursor
761 if ((pos.x() >= _xPosHex) && (pos.x() < (_xPosHex + HEXCHARS_IN_LINE * _charWidth)))
762 {
763 int x = (pos.x() - _xPosHex) / _charWidth;
764 if ((x % 3) == 0)
765 x = (x / 3) * 2;
766 else
767 x = ((x / 3) * 2) + 1;
768 int y = ((pos.y() - 3) / _charHeight) * 2 * BYTES_PER_LINE;
769 result = x + y;
770 }
771 return result;
772}
773
774int QHexEditPrivate::cursorPos()
775{
776 return _cursorPosition;
777}
778
779void QHexEditPrivate::resetSelection()
780{
781 _selectionBegin = _selectionInit;
782 _selectionEnd = _selectionInit;
783}
784
785void QHexEditPrivate::resetSelection(int pos)
786{
787 if (pos < 0)
788 pos = 0;
789 pos = pos / 2;
790 _selectionInit = pos;
791 _selectionBegin = pos;
792 _selectionEnd = pos;
793}
794
795void QHexEditPrivate::setSelection(int pos)
796{
797 if (pos < 0)
798 pos = 0;
799 pos = pos / 2;
800 if (pos >= _selectionInit)
801 {
802 _selectionEnd = pos;
803 _selectionBegin = _selectionInit;
804 }
805 else
806 {
807 _selectionBegin = pos;
808 _selectionEnd = _selectionInit;
809 }
810}
811
812int QHexEditPrivate::getSelectionBegin()
813{
814 return _selectionBegin;
815}
816
817int QHexEditPrivate::getSelectionEnd()
818{
819 return _selectionEnd;
820}
821
822
823void QHexEditPrivate::updateCursor()
824{
825 if (_blink)
826 _blink = false;
827 else
828 _blink = true;
829 update(_cursorX, _cursorY, _charWidth, _charHeight);
830}
831
832void QHexEditPrivate::adjust()
833{
834 _charWidth = fontMetrics().width(QLatin1Char('9'));
835 _charHeight = fontMetrics().height();
836
837 _xPosAdr = 0;
838 if (_addressArea)
839 _xPosHex = _xData.realAddressNumbers()*_charWidth + GAP_ADR_HEX;
840 else
841 _xPosHex = 0;
842 _xPosAscii = _xPosHex + HEXCHARS_IN_LINE * _charWidth + GAP_HEX_ASCII;
843
844 // tell QAbstractScollbar, how big we are
845 setMinimumHeight(((_xData.size()/16 + 1) * _charHeight) + 5);
846 if(_asciiArea)
847 setMinimumWidth(_xPosAscii + (BYTES_PER_LINE * _charWidth));
848 else
849 setMinimumWidth(_xPosHex + HEXCHARS_IN_LINE * _charWidth);
850
851 update();
852}
853
854void QHexEditPrivate::ensureVisible()
855{
856 // scrolls to cursorx, cusory (which are set by setCursorPos)
857 // x-margin is 3 pixels, y-margin is half of charHeight
858 _scrollArea->ensureVisible(_cursorX, _cursorY + _charHeight/2, 3, _charHeight/2 + 2);
859}
diff --git a/externals/qhexedit/qhexedit_p.h b/externals/qhexedit/qhexedit_p.h
new file mode 100644
index 000000000..138139b90
--- /dev/null
+++ b/externals/qhexedit/qhexedit_p.h
@@ -0,0 +1,125 @@
1#ifndef QHEXEDIT_P_H
2#define QHEXEDIT_P_H
3
4/** \cond docNever */
5
6
7#include <QtGui>
8#include "xbytearray.h"
9
10class QHexEditPrivate : public QWidget
11{
12Q_OBJECT
13
14public:
15 QHexEditPrivate(QScrollArea *parent);
16
17 void setAddressAreaColor(QColor const &color);
18 QColor addressAreaColor();
19
20 void setAddressOffset(int offset);
21 int addressOffset();
22
23 void setCursorPos(int position);
24 int cursorPos();
25
26 void setData(QByteArray const &data);
27 QByteArray data();
28
29 void setHighlightingColor(QColor const &color);
30 QColor highlightingColor();
31
32 void setOverwriteMode(bool overwriteMode);
33 bool overwriteMode();
34
35 void setReadOnly(bool readOnly);
36 bool isReadOnly();
37
38 void setSelectionColor(QColor const &color);
39 QColor selectionColor();
40
41 XByteArray & xData();
42
43 int indexOf(const QByteArray & ba, int from = 0);
44 void insert(int index, const QByteArray & ba);
45 void insert(int index, char ch);
46 int lastIndexOf(const QByteArray & ba, int from = 0);
47 void remove(int index, int len=1);
48 void replace(int index, char ch);
49 void replace(int index, const QByteArray & ba);
50 void replace(int pos, int len, const QByteArray & after);
51
52 void setAddressArea(bool addressArea);
53 void setAddressWidth(int addressWidth);
54 void setAsciiArea(bool asciiArea);
55 void setHighlighting(bool mode);
56 virtual void setFont(const QFont &font);
57
58 void undo();
59 void redo();
60
61 QString toRedableString();
62 QString selectionToReadableString();
63
64signals:
65 void currentAddressChanged(int address);
66 void currentSizeChanged(int size);
67 void dataChanged();
68 void overwriteModeChanged(bool state);
69
70protected:
71 void keyPressEvent(QKeyEvent * event);
72 void mouseMoveEvent(QMouseEvent * event);
73 void mousePressEvent(QMouseEvent * event);
74
75 void paintEvent(QPaintEvent *event);
76
77 int cursorPos(QPoint pos); // calc cursorpos from graphics position. DOES NOT STORE POSITION
78
79 void resetSelection(int pos); // set selectionStart and selectionEnd to pos
80 void resetSelection(); // set selectionEnd to selectionStart
81 void setSelection(int pos); // set min (if below init) or max (if greater init)
82 int getSelectionBegin();
83 int getSelectionEnd();
84
85
86private slots:
87 void updateCursor();
88
89private:
90 void adjust();
91 void ensureVisible();
92
93 QColor _addressAreaColor;
94 QColor _highlightingColor;
95 QColor _selectionColor;
96 QScrollArea *_scrollArea;
97 QTimer _cursorTimer;
98 QUndoStack *_undoStack;
99
100 XByteArray _xData; // Hält den Inhalt des Hex Editors
101
102 bool _blink; // true: then cursor blinks
103 bool _renderingRequired; // Flag to store that rendering is necessary
104 bool _addressArea; // left area of QHexEdit
105 bool _asciiArea; // medium area
106 bool _highlighting; // highlighting of changed bytes
107 bool _overwriteMode;
108 bool _readOnly; // true: the user can only look and navigate
109
110 int _charWidth, _charHeight; // char dimensions (dpendend on font)
111 int _cursorX, _cursorY; // graphics position of the cursor
112 int _cursorPosition; // character positioin in stream (on byte ends in to steps)
113 int _xPosAdr, _xPosHex, _xPosAscii; // graphics x-position of the areas
114
115 int _selectionBegin; // First selected char
116 int _selectionEnd; // Last selected char
117 int _selectionInit; // That's, where we pressed the mouse button
118
119 int _size;
120};
121
122/** \endcond docNever */
123
124#endif
125
diff --git a/externals/qhexedit/xbytearray.cpp b/externals/qhexedit/xbytearray.cpp
new file mode 100644
index 000000000..09a04cfeb
--- /dev/null
+++ b/externals/qhexedit/xbytearray.cpp
@@ -0,0 +1,167 @@
1#include "xbytearray.h"
2
3XByteArray::XByteArray()
4{
5 _oldSize = -99;
6 _addressNumbers = 4;
7 _addressOffset = 0;
8
9}
10
11int XByteArray::addressOffset()
12{
13 return _addressOffset;
14}
15
16void XByteArray::setAddressOffset(int offset)
17{
18 _addressOffset = offset;
19}
20
21int XByteArray::addressWidth()
22{
23 return _addressNumbers;
24}
25
26void XByteArray::setAddressWidth(int width)
27{
28 if ((width >= 0) && (width<=6))
29 {
30 _addressNumbers = width;
31 }
32}
33
34QByteArray & XByteArray::data()
35{
36 return _data;
37}
38
39void XByteArray::setData(QByteArray data)
40{
41 _data = data;
42 _changedData = QByteArray(data.length(), char(0));
43}
44
45bool XByteArray::dataChanged(int i)
46{
47 return bool(_changedData[i]);
48}
49
50QByteArray XByteArray::dataChanged(int i, int len)
51{
52 return _changedData.mid(i, len);
53}
54
55void XByteArray::setDataChanged(int i, bool state)
56{
57 _changedData[i] = char(state);
58}
59
60void XByteArray::setDataChanged(int i, const QByteArray & state)
61{
62 int length = state.length();
63 int len;
64 if ((i + length) > _changedData.length())
65 len = _changedData.length() - i;
66 else
67 len = length;
68 _changedData.replace(i, len, state);
69}
70
71int XByteArray::realAddressNumbers()
72{
73 if (_oldSize != _data.size())
74 {
75 // is addressNumbers wide enought?
76 QString test = QString("%1")
77 .arg(_data.size() + _addressOffset, _addressNumbers, 16, QChar('0'));
78 _realAddressNumbers = test.size();
79 }
80 return _realAddressNumbers;
81}
82
83int XByteArray::size()
84{
85 return _data.size();
86}
87
88QByteArray & XByteArray::insert(int i, char ch)
89{
90 _data.insert(i, ch);
91 _changedData.insert(i, char(1));
92 return _data;
93}
94
95QByteArray & XByteArray::insert(int i, const QByteArray & ba)
96{
97 _data.insert(i, ba);
98 _changedData.insert(i, QByteArray(ba.length(), char(1)));
99 return _data;
100}
101
102QByteArray & XByteArray::remove(int i, int len)
103{
104 _data.remove(i, len);
105 _changedData.remove(i, len);
106 return _data;
107}
108
109QByteArray & XByteArray::replace(int index, char ch)
110{
111 _data[index] = ch;
112 _changedData[index] = char(1);
113 return _data;
114}
115
116QByteArray & XByteArray::replace(int index, const QByteArray & ba)
117{
118 int len = ba.length();
119 return replace(index, len, ba);
120}
121
122QByteArray & XByteArray::replace(int index, int length, const QByteArray & ba)
123{
124 int len;
125 if ((index + length) > _data.length())
126 len = _data.length() - index;
127 else
128 len = length;
129 _data.replace(index, len, ba.mid(0, len));
130 _changedData.replace(index, len, QByteArray(len, char(1)));
131 return _data;
132}
133
134QChar XByteArray::asciiChar(int index)
135{
136 char ch = _data[index];
137 if ((ch < 0x20) || (ch > 0x7e))
138 ch = '.';
139 return QChar(ch);
140}
141
142QString XByteArray::toRedableString(int start, int end)
143{
144 int adrWidth = realAddressNumbers();
145 if (_addressNumbers > adrWidth)
146 adrWidth = _addressNumbers;
147 if (end < 0)
148 end = _data.size();
149
150 QString result;
151 for (int i=start; i < end; i += 16)
152 {
153 QString adrStr = QString("%1").arg(_addressOffset + i, adrWidth, 16, QChar('0'));
154 QString hexStr;
155 QString ascStr;
156 for (int j=0; j<16; j++)
157 {
158 if ((i + j) < _data.size())
159 {
160 hexStr.append(" ").append(_data.mid(i+j, 1).toHex());
161 ascStr.append(asciiChar(i+j));
162 }
163 }
164 result += adrStr + " " + QString("%1").arg(hexStr, -48) + " " + QString("%1").arg(ascStr, -17) + "\n";
165 }
166 return result;
167}
diff --git a/externals/qhexedit/xbytearray.h b/externals/qhexedit/xbytearray.h
new file mode 100644
index 000000000..2b67c61b8
--- /dev/null
+++ b/externals/qhexedit/xbytearray.h
@@ -0,0 +1,66 @@
1#ifndef XBYTEARRAY_H
2#define XBYTEARRAY_H
3
4/** \cond docNever */
5
6#include <QtCore>
7
8/*! XByteArray represents the content of QHexEcit.
9XByteArray comprehend the data itself and informations to store if it was
10changed. The QHexEdit component uses these informations to perform nice
11rendering of the data
12
13XByteArray also provides some functionality to insert, replace and remove
14single chars and QByteArras. Additionally some functions support rendering
15and converting to readable strings.
16*/
17class XByteArray
18{
19public:
20 explicit XByteArray();
21
22 int addressOffset();
23 void setAddressOffset(int offset);
24
25 int addressWidth();
26 void setAddressWidth(int width);
27
28 QByteArray & data();
29 void setData(QByteArray data);
30
31 bool dataChanged(int i);
32 QByteArray dataChanged(int i, int len);
33 void setDataChanged(int i, bool state);
34 void setDataChanged(int i, const QByteArray & state);
35
36 int realAddressNumbers();
37 int size();
38
39 QByteArray & insert(int i, char ch);
40 QByteArray & insert(int i, const QByteArray & ba);
41
42 QByteArray & remove(int pos, int len);
43
44 QByteArray & replace(int index, char ch);
45 QByteArray & replace(int index, const QByteArray & ba);
46 QByteArray & replace(int index, int length, const QByteArray & ba);
47
48 QChar asciiChar(int index);
49 QString toRedableString(int start=0, int end=-1);
50
51signals:
52
53public slots:
54
55private:
56 QByteArray _data;
57 QByteArray _changedData;
58
59 int _addressNumbers; // wanted width of address area
60 int _addressOffset; // will be added to the real addres inside bytearray
61 int _realAddressNumbers; // real width of address area (can be greater then wanted width)
62 int _oldSize; // size of data
63};
64
65/** \endcond docNever */
66#endif // XBYTEARRAY_H