HexdumpWidget enhancements (#235)

This commit is contained in:
Thomas (nezza-_-) Roth 2018-01-27 11:08:05 +01:00 committed by xarkes
parent 70a361ab91
commit 9847836d73
5 changed files with 788 additions and 514 deletions

View File

@ -120,6 +120,15 @@ namespace qhelpers
widget->setMaximumHeight(max);
}
int getMaxFullyDisplayedLines(QTextEdit *textEdit)
{
QFontMetrics fontMetrics(textEdit->document()->defaultFont());
return (textEdit->height()
- (textEdit->contentsMargins().top()
+ textEdit->contentsMargins().bottom()
+ (int)(textEdit->document()->documentMargin() * 2)))
/ fontMetrics.lineSpacing();
}
int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit)
{

View File

@ -41,7 +41,7 @@ namespace qhelpers
SizePolicyMinMax forceWidth(QWidget *widget, int width);
SizePolicyMinMax forceHeight(QWidget *widget, int height);
int getMaxFullyDisplayedLines(QTextEdit *textEdit);
int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit);
QByteArray applyColorToSvg(const QByteArray &data, QColor color);

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +1,28 @@
#ifndef HEXDUMPWIDGET_H
#define HEXDUMPWIDGET_H
#include <array>
#include <QDebug>
#include <QTextEdit>
#include <QDockWidget>
#include <QTreeWidget>
#include <QTabWidget>
#include <QUrl>
#include <QPlainTextEdit>
#include <QMouseEvent>
#include <array>
#include <memory>
#include "cutter.h"
#include "utils/Highlighter.h"
#include "utils/HexAsciiHighlighter.h"
#include "utils/HexHighlighter.h"
#include "utils/SvgIconEngine.h"
#include "Dashboard.h"
namespace Ui
{
class HexdumpWidget;
}
#include "ui_HexdumpWidget.h"
class HexdumpWidget : public QDockWidget
{
Q_OBJECT
Q_OBJECT
public:
explicit HexdumpWidget(const QString &title, QWidget *parent = nullptr, Qt::WindowFlags flags = 0);
@ -35,16 +31,22 @@ public:
Highlighter *highlighter;
//signals:
// void fontChanged(QFont font);
enum Format {
Hex,
Octal,
// TODO:
// HalfWord,
// Word,
// QuadWord,
// Emoji,
// SignedInt1,
// SignedInt2,
// SignedInt4,
};
public slots:
void initParsing();
QString normalize_addr(QString addr);
QString normalizeAddr(QString addr);
void showOffsets(bool show);
void zoomIn(int range = 1);
@ -55,41 +57,67 @@ protected:
virtual void wheelEvent(QWheelEvent* event) override;
private:
static const int linesMarginMin;
static const int linesMarginDefault;
static const int linesMarginMax;
static const int linesMarginMin = 32;
static const int linesMarginDefault = 48;
static const int linesMarginMax = 64;
enum Format format = Format::Hex;
std::unique_ptr<Ui::HexdumpWidget> ui;
RVA topOffset;
RVA bottomOffset;
bool sent_seek = false;
bool scroll_disabled = false;
RVA first_loaded_address = RVA_INVALID;
RVA last_loaded_address = RVA_INVALID;
void refresh(RVA addr = RVA_INVALID);
void appendHexdumpLines(int lines, bool top);
void removeHexdumpLines(int lines, bool top);
void selectHexPreview();
void updateHeaders();
void updateHeaders();
std::array<QString, 3> fetchHexdump(RVA offset, RVA bytes);
std::array<QString, 3> fetchHexdump(RVA addr, int lines);
void connectScroll(bool disconnect);
void connectScroll(bool disconnect_);
void setupScrollSync();
void setupFonts();
// If bottom = false gets the FIRST displayed line, otherwise the LAST displayed
// line.
int getDisplayedLined(QTextEdit *textEdit, bool bottom = false);
static void removeTopLinesWithoutScroll(QTextEdit *textEdit, int lines);
static void removeBottomLinesWithoutScroll(QTextEdit *textEdit, int lines);
static void prependWithoutScroll(QTextEdit *textEdit, QString text);
static void appendWithoutScroll(QTextEdit *textEdit, QString text);
static void setTextEditPosition(QTextEdit *textEdit, int position);
RVA hexPositionToAddress(int position);
RVA asciiPositionToAddress(int position);
int hexAddressToPosition(RVA address);
int asciiAddressToPosition(RVA address);
void updateWidths();
void updateParseWindow(RVA start_address, int size);
void clearParseWindow();
int bufferLines;
private slots:
void on_seekChanged(RVA addr);
void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type);
void highlightHexCurrentLine();
// Currently unused/untested
// void highlightHexCurrentLine();
// void highlightHexWords(const QString &str);
void highlightHexWords(const QString &str);
void on_actionHideHexdump_side_panel_triggered();
void showHexdumpContextMenu(const QPoint &pt);
void showHexASCIIContextMenu(const QPoint &pt);
void on_hexHexText_selectionChanged();
void selectionChanged();
void scrollChanged();
void on_parseArchComboBox_currentTextChanged(const QString &arg1);
void on_parseBitsComboBox_currentTextChanged(const QString &arg1);
@ -104,7 +132,8 @@ private slots:
void on_action32columns_triggered();
void on_action64columns_triggered();
void adjustHexdumpLines();
void on_actionFormatHex_triggered();
void on_actionFormatOctal_triggered();
void fontsUpdated();
void colorsUpdatedSlot();

View File

@ -152,47 +152,10 @@ QToolTip {
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QPlainTextEdit" name="hexOffsetText">
<item row="1" column="2">
<widget class="QTextEdit" name="hexHexText">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPlainTextEdit" name="hexHexText">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -228,17 +191,92 @@ QToolTip {
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
<property name="cursorWidth">
<number>3</number>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPlainTextEdit" name="hexASCIIText">
<item row="1" column="3">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="hexHeaderLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>0 1 2 3 ...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTextEdit" name="hexOffsetText">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="asciiHeaderLabel">
<property name="text">
<string>0123...</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="offsetHeaderLabel">
<property name="text">
<string>Offset</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QTextEdit" name="hexASCIIText">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -280,31 +318,23 @@ QToolTip {
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
<property name="cursorWidth">
<number>3</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="offsetHeaderLabel">
<property name="text">
<string>Offset</string>
<item row="1" column="5">
<widget class="QTextEdit" name="hexSpacerText">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="hexHeaderLabel">
<property name="text">
<string>0 1 2 3 ...</string>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="asciiHeaderLabel">
<property name="text">
<string>0123...</string>
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget>
</item>
@ -974,6 +1004,60 @@ QToolTip {
<string>Insert String</string>
</property>
</action>
<action name="actionFormatHex">
<property name="text">
<string>Hex</string>
</property>
</action>
<action name="actionFormatOctal">
<property name="text">
<string>Octal</string>
</property>
</action>
<action name="actionFormatHalfWord">
<property name="text">
<string>Half-word</string>
</property>
</action>
<action name="actionFormatWord">
<property name="text">
<string>Word</string>
</property>
</action>
<action name="actionFormatQuadWord">
<property name="text">
<string>Quad-word</string>
</property>
</action>
<action name="actionFormatEmoji">
<property name="text">
<string>Emoji</string>
</property>
</action>
<action name="actionFormatSignedInt1">
<property name="text">
<string>1 byte</string>
</property>
<property name="toolTip">
<string>1 byte</string>
</property>
</action>
<action name="actionFormatSignedInt2">
<property name="text">
<string>2 bytes</string>
</property>
<property name="toolTip">
<string>2 bytes</string>
</property>
</action>
<action name="actionFormatSignedInt4">
<property name="text">
<string>4 bytes</string>
</property>
<property name="toolTip">
<string>4 bytes</string>
</property>
</action>
</widget>
<resources>
<include location="../resources.qrc"/>