cutter/src/widgets/HexdumpWidget.h
Nics c4e8a1c178 Small refactor for the widgets of Cutter (#405)
* Small refactor for the widgets of Cutter

This refactor include the following :

* Creation of a new class
Creation of a new class, named CutterWidget, that inherits from QDockWidget and
is used to represent all of the widgets of the main window.
The goal of this class is to regroup all the behaviour shared by the widgets of
Cutter.

For example : in the constructor, instructions corresponding of those
present in the macro **ADD_DOCK** (in MainWindow.cpp) are executed.
This was made because I think that the macro **ADD_DOCK** which is used
to construct the widgets does not take advantage of the object structure.

* Ensure that every widget has a parent
Some widgets were created using the constructor QDockWidget, but using
**nullptr** (default) as argument, thus they haven't got any parent.

The constructor of a CutterWidget takes as argument the MainWindow and an
action (optional) and calls the constructor of QDockWidget with the main
window as argument. This is valid under the assumption that it is mandatory
for every widget to have the main window as a parent.

* Constructors removal
The constructors of some widgets are not used anywhere and does not seem not
fullfill any current usecase. They were removed.

* Renaming CutterWidget to CutterDockWidget
2018-03-16 22:46:57 +01:00

147 lines
3.8 KiB
C++

#ifndef HEXDUMPWIDGET_H
#define HEXDUMPWIDGET_H
#include <QDebug>
#include <QTextEdit>
#include <QMouseEvent>
#include <array>
#include <memory>
#include "Cutter.h"
#include "CutterDockWidget.h"
#include "utils/Highlighter.h"
#include "utils/HexAsciiHighlighter.h"
#include "utils/HexHighlighter.h"
#include "utils/SvgIconEngine.h"
#include "Dashboard.h"
#include "ui_HexdumpWidget.h"
class HexdumpWidget : public CutterDockWidget
{
Q_OBJECT
public:
explicit HexdumpWidget(MainWindow *main, QAction *action = nullptr);
~HexdumpWidget();
Highlighter *highlighter;
enum Format {
Hex,
Octal,
// TODO:
// HalfWord,
// Word,
// QuadWord,
// Emoji,
// SignedInt1,
// SignedInt2,
// SignedInt4,
};
public slots:
void initParsing();
void showOffsets(bool show);
void zoomIn(int range = 1);
void zoomOut(int range = 1);
protected:
virtual void resizeEvent(QResizeEvent *event) override;
virtual void wheelEvent(QWheelEvent* event) override;
private:
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;
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 selectHexPreview();
void updateHeaders();
std::array<QString, 3> fetchHexdump(RVA addr, int lines);
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;
int cols;
private slots:
void on_seekChanged(RVA addr);
void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type);
// Currently unused/untested
// void highlightHexCurrentLine();
// void highlightHexWords(const QString &str);
void on_actionHideHexdump_side_panel_triggered();
void showHexdumpContextMenu(const QPoint &pt);
void showHexASCIIContextMenu(const QPoint &pt);
void selectionChanged();
void scrollChanged();
void on_parseArchComboBox_currentTextChanged(const QString &arg1);
void on_parseBitsComboBox_currentTextChanged(const QString &arg1);
void on_parseTypeComboBox_currentTextChanged(const QString &arg1);
void on_parseEndianComboBox_currentTextChanged(const QString &arg1);
void on_action1column_triggered();
void on_action2columns_triggered();
void on_action4columns_triggered();
void on_action8columns_triggered();
void on_action16columns_triggered();
void on_action32columns_triggered();
void on_action64columns_triggered();
void on_actionFormatHex_triggered();
void on_actionFormatOctal_triggered();
void fontsUpdated();
void colorsUpdatedSlot();
void on_hexSideTab_2_currentChanged(int index);
void on_copyMD5_clicked();
void on_copySHA1_clicked();
};
#endif // HEXDUMPWIDGET_H