Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
dd0f2f18
Commit
dd0f2f18
authored
14 years ago
by
ck
Browse files
Options
Downloads
Patches
Plain Diff
BinEditor: Add a bit of value interpretation.
parent
ae38de5c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/plugins/bineditor/bineditor.cpp
+79
-7
79 additions, 7 deletions
src/plugins/bineditor/bineditor.cpp
src/plugins/bineditor/bineditor.h
+3
-0
3 additions, 0 deletions
src/plugins/bineditor/bineditor.h
with
82 additions
and
7 deletions
src/plugins/bineditor/bineditor.cpp
+
79
−
7
View file @
dd0f2f18
...
...
@@ -40,10 +40,12 @@
#include
<QtGui/QAction>
#include
<QtGui/QClipboard>
#include
<QtGui/QFontMetrics>
#include
<QtGui/QHelpEvent>
#include
<QtGui/QMenu>
#include
<QtGui/QMessageBox>
#include
<QtGui/QPainter>
#include
<QtGui/QScrollBar>
#include
<QtGui/QToolTip>
#include
<QtGui/QWheelEvent>
using
namespace
BINEditor
;
...
...
@@ -1030,7 +1032,64 @@ bool BinEditor::event(QEvent *e) {
break
;
default
:
;
}
}
else
if
(
e
->
type
()
==
QEvent
::
ToolTip
)
{
bool
hide
=
true
;
int
selStart
=
selectionStart
();
int
selEnd
=
selectionEnd
();
int
byteCount
=
selEnd
-
selStart
;
if
(
byteCount
<=
0
)
{
selStart
=
m_cursorPosition
;
selEnd
=
selStart
+
1
;
byteCount
=
1
;
}
if
(
byteCount
<=
8
)
{
const
QPoint
&
startPoint
=
offsetToPos
(
selStart
);
const
QPoint
&
endPoint
=
offsetToPos
(
selEnd
);
const
QPoint
expandedEndPoint
=
QPoint
(
endPoint
.
x
(),
endPoint
.
y
()
+
m_lineHeight
);
const
QRect
selRect
(
startPoint
,
expandedEndPoint
);
const
QHelpEvent
*
const
helpEvent
=
static_cast
<
QHelpEvent
*>
(
e
);
const
QPoint
&
mousePos
=
helpEvent
->
pos
();
if
(
selRect
.
contains
(
mousePos
))
{
quint64
beValue
,
leValue
;
asIntegers
(
selStart
,
byteCount
,
beValue
,
leValue
);
QString
leSigned
;
QString
beSigned
;
switch
(
byteCount
)
{
case
8
:
case
7
:
case
6
:
case
5
:
leSigned
=
QString
::
number
(
static_cast
<
qint64
>
(
leValue
));
beSigned
=
QString
::
number
(
static_cast
<
qint64
>
(
beValue
));
break
;
case
4
:
case
3
:
leSigned
=
QString
::
number
(
static_cast
<
qint32
>
(
leValue
));
beSigned
=
QString
::
number
(
static_cast
<
qint32
>
(
beValue
));
break
;
case
2
:
leSigned
=
QString
::
number
(
static_cast
<
qint16
>
(
leValue
));
beSigned
=
QString
::
number
(
static_cast
<
qint16
>
(
beValue
));
break
;
case
1
:
leSigned
=
QString
::
number
(
static_cast
<
qint8
>
(
leValue
));
beSigned
=
QString
::
number
(
static_cast
<
qint8
>
(
beValue
));
break
;
}
hide
=
false
;
QToolTip
::
showText
(
helpEvent
->
globalPos
(),
tr
(
"Decimal unsigned value (little endian): %1
\n
"
"Decimal unsigned value (big endian): %2
\n
"
"Decimal signed value (little endian): %3
\n
"
"Decimal signed value (big endian): %4"
)
.
arg
(
QString
::
number
(
leValue
))
.
arg
(
QString
::
number
(
beValue
))
.
arg
(
leSigned
).
arg
(
beSigned
));
}
}
if
(
hide
)
QToolTip
::
hideText
();
e
->
accept
();
return
true
;
}
return
QAbstractScrollArea
::
event
(
e
);
}
...
...
@@ -1271,13 +1330,7 @@ void BinEditor::contextMenuEvent(QContextMenuEvent *event)
quint64
beAddress
=
0
;
quint64
leAddress
=
0
;
if
(
byteCount
<=
8
)
{
const
QByteArray
&
data
=
dataMid
(
selStart
,
byteCount
);
for
(
int
pos
=
0
;
pos
<
byteCount
;
++
pos
)
{
const
quint64
val
=
static_cast
<
quint64
>
(
data
.
at
(
pos
))
&
0xff
;
beAddress
+=
val
<<
(
pos
*
8
);
leAddress
+=
val
<<
((
byteCount
-
pos
-
1
)
*
8
);
}
asIntegers
(
selStart
,
byteCount
,
beAddress
,
leAddress
);
setupJumpToMenuAction
(
&
contextMenu
,
&
jumpToBeAddressHere
,
&
jumpToBeAddressNewWindow
,
beAddress
);
...
...
@@ -1335,3 +1388,22 @@ void BinEditor::setNewWindowRequestAllowed()
{
m_canRequestNewWindow
=
true
;
}
QPoint
BinEditor
::
offsetToPos
(
int
offset
)
{
const
int
x
=
m_labelWidth
+
(
offset
%
16
)
*
m_columnWidth
;
const
int
y
=
(
offset
/
16
)
*
m_lineHeight
;
return
QPoint
(
x
,
y
);
}
void
BinEditor
::
asIntegers
(
int
offset
,
int
count
,
quint64
&
beValue
,
quint64
&
leValue
)
{
beValue
=
leValue
=
0
;
const
QByteArray
&
data
=
dataMid
(
offset
,
count
);
for
(
int
pos
=
0
;
pos
<
count
;
++
pos
)
{
const
quint64
val
=
static_cast
<
quint64
>
(
data
.
at
(
pos
))
&
0xff
;
beValue
+=
val
<<
(
pos
*
8
);
leValue
+=
val
<<
((
count
-
pos
-
1
)
*
8
);
}
}
This diff is collapsed.
Click to expand it.
src/plugins/bineditor/bineditor.h
+
3
−
0
View file @
dd0f2f18
...
...
@@ -169,6 +169,9 @@ private:
QByteArray
dataMid
(
int
from
,
int
length
)
const
;
QByteArray
blockData
(
int
block
)
const
;
QPoint
offsetToPos
(
int
offset
);
void
asIntegers
(
int
offset
,
int
count
,
quint64
&
beValue
,
quint64
&
leValue
);
int
m_unmodifiedState
;
int
m_readOnly
;
int
m_margin
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment