2020-07-16 08:05:10 +00:00
|
|
|
#ifndef CUTTER_GRAPHVIEW_H
|
|
|
|
#define CUTTER_GRAPHVIEW_H
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QShortcut>
|
|
|
|
#include <QLabel>
|
|
|
|
|
2020-11-03 06:23:12 +00:00
|
|
|
#include <QGestureEvent>
|
|
|
|
|
2020-07-16 08:05:10 +00:00
|
|
|
#include "widgets/GraphView.h"
|
|
|
|
#include "common/CachedFontMetrics.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Common Cutter specific graph functionality.
|
|
|
|
*/
|
|
|
|
class CutterGraphView : public GraphView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
CutterGraphView(QWidget *parent);
|
|
|
|
virtual bool event(QEvent *event) override;
|
|
|
|
|
|
|
|
enum class GraphExportType {
|
2021-01-24 14:50:13 +00:00
|
|
|
Png,
|
|
|
|
Jpeg,
|
|
|
|
Svg,
|
|
|
|
GVDot,
|
|
|
|
GVJson,
|
|
|
|
GVGif,
|
|
|
|
GVPng,
|
|
|
|
GVJpeg,
|
|
|
|
GVPostScript,
|
|
|
|
GVSvg,
|
2023-02-18 05:35:49 +00:00
|
|
|
GVPdf,
|
2021-01-24 14:50:13 +00:00
|
|
|
RzGml,
|
|
|
|
RzJson
|
2020-07-16 08:05:10 +00:00
|
|
|
};
|
|
|
|
/**
|
|
|
|
* @brief Export graph to a file in the specified format
|
2023-02-18 05:35:49 +00:00
|
|
|
* @param filePath - output file path
|
|
|
|
* @param exportType - export type, GV* and Rz* types require \p graphCommand
|
|
|
|
* @param graphType - graph type, example RZ_CORE_GRAPH_TYPE_FUNCALL or
|
|
|
|
* RZ_CORE_GRAPH_TYPE_IMPORT
|
|
|
|
* @param address - object address (if global set it to RVA_INVALID)
|
2020-07-16 08:05:10 +00:00
|
|
|
*/
|
2023-02-18 05:35:49 +00:00
|
|
|
void exportGraph(QString filePath, GraphExportType exportType, RzCoreGraphType graphType,
|
2020-11-03 06:23:12 +00:00
|
|
|
RVA address = RVA_INVALID);
|
2023-02-18 05:35:49 +00:00
|
|
|
|
2020-07-16 08:05:10 +00:00
|
|
|
/**
|
2020-12-16 10:59:23 +00:00
|
|
|
* @brief Export graph in one of the text formats supported by rizin json, gml, SDB key-value
|
2023-02-18 05:35:49 +00:00
|
|
|
* @param filePath - output file path
|
|
|
|
* @param type - graph type, example RZ_CORE_GRAPH_TYPE_FUNCALL or RZ_CORE_GRAPH_TYPE_IMPORT
|
|
|
|
* @param format - graph format, example RZ_CORE_GRAPH_FORMAT_DOT or RZ_CORE_GRAPH_FORMAT_GML
|
|
|
|
* @param address - object address (if global set it to RVA_INVALID)
|
2020-07-16 08:05:10 +00:00
|
|
|
*/
|
2023-02-18 05:35:49 +00:00
|
|
|
void exportRzTextGraph(QString filePath, RzCoreGraphType type, RzCoreGraphFormat format,
|
|
|
|
RVA address);
|
2020-07-16 08:05:10 +00:00
|
|
|
static bool graphIsBitamp(GraphExportType type);
|
|
|
|
/**
|
|
|
|
* @brief Show graph export dialog.
|
|
|
|
* @param defaultName - default file name in the export dialog
|
2023-02-18 05:35:49 +00:00
|
|
|
* @param type - graph type, example RZ_CORE_GRAPH_TYPE_FUNCALL or RZ_CORE_GRAPH_TYPE_IMPORT
|
|
|
|
* @param address - object address (if global set it to RVA_INVALID)
|
2020-07-16 08:05:10 +00:00
|
|
|
*/
|
2023-02-18 05:35:49 +00:00
|
|
|
void showExportGraphDialog(QString defaultName, RzCoreGraphType type,
|
2020-07-16 08:05:10 +00:00
|
|
|
RVA address = RVA_INVALID);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
virtual void refreshView();
|
|
|
|
void updateColors();
|
|
|
|
void fontsUpdatedSlot();
|
|
|
|
|
|
|
|
void zoom(QPointF mouseRelativePos, double velocity);
|
|
|
|
void setZoom(QPointF mouseRelativePos, double scale);
|
|
|
|
void zoomIn();
|
|
|
|
void zoomOut();
|
|
|
|
void zoomReset();
|
|
|
|
|
|
|
|
/**
|
2020-12-16 10:59:23 +00:00
|
|
|
* @brief Show the export file dialog. Override this to support rizin based export formats.
|
2020-07-16 08:05:10 +00:00
|
|
|
*/
|
|
|
|
virtual void showExportDialog();
|
|
|
|
signals:
|
|
|
|
void viewRefreshed();
|
|
|
|
void viewZoomed();
|
|
|
|
void graphMoved();
|
|
|
|
void resized();
|
2021-01-24 14:50:13 +00:00
|
|
|
|
2020-07-16 08:05:10 +00:00
|
|
|
protected:
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
|
|
void wheelEvent(QWheelEvent *event) override;
|
|
|
|
void resizeEvent(QResizeEvent *event) override;
|
2020-11-03 06:23:12 +00:00
|
|
|
bool gestureEvent(QGestureEvent *event) override;
|
2020-07-16 08:05:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Save the the currently viewed or displayed block.
|
2021-01-24 14:50:13 +00:00
|
|
|
* Called before reloading graph. Override to this to implement graph specific logic for what
|
|
|
|
* block is selected. Default implementation does nothing.
|
2020-07-16 08:05:10 +00:00
|
|
|
*/
|
|
|
|
virtual void saveCurrentBlock();
|
|
|
|
/**
|
|
|
|
* @brief Restore view focus and block last saved using saveCurrentBlock().
|
2021-01-24 14:50:13 +00:00
|
|
|
* Called after the graph is reloaded. Default implementation does nothing. Can center the view
|
|
|
|
* if the new graph displays completely different content and the matching node doesn't exist.
|
2020-07-16 08:05:10 +00:00
|
|
|
*/
|
|
|
|
virtual void restoreCurrentBlock();
|
|
|
|
|
|
|
|
void initFont();
|
|
|
|
QPoint getTextOffset(int line) const;
|
|
|
|
GraphLayout::LayoutConfig getLayoutConfig();
|
|
|
|
virtual void updateLayout();
|
|
|
|
|
|
|
|
// Font data
|
|
|
|
std::unique_ptr<CachedFontMetrics<qreal>> mFontMetrics;
|
2021-05-29 14:32:31 +00:00
|
|
|
qreal ACharWidth; // width of character A
|
2020-07-16 08:05:10 +00:00
|
|
|
int charHeight;
|
|
|
|
int charOffset;
|
|
|
|
int baseline;
|
2021-05-29 14:32:31 +00:00
|
|
|
qreal padding;
|
2020-07-16 08:05:10 +00:00
|
|
|
|
|
|
|
// colors
|
|
|
|
QColor disassemblyBackgroundColor;
|
|
|
|
QColor disassemblySelectedBackgroundColor;
|
|
|
|
QColor disassemblySelectionColor;
|
|
|
|
QColor PCSelectionColor;
|
|
|
|
QColor jmpColor;
|
|
|
|
QColor brtrueColor;
|
|
|
|
QColor brfalseColor;
|
|
|
|
QColor retShadowColor;
|
|
|
|
QColor indirectcallShadowColor;
|
|
|
|
QColor mAutoCommentColor;
|
|
|
|
QColor mAutoCommentBackgroundColor;
|
|
|
|
QColor mCommentColor;
|
|
|
|
QColor mCommentBackgroundColor;
|
|
|
|
QColor mLabelColor;
|
|
|
|
QColor mLabelBackgroundColor;
|
|
|
|
QColor graphNodeColor;
|
|
|
|
QColor mAddressColor;
|
|
|
|
QColor mAddressBackgroundColor;
|
|
|
|
QColor mCipColor;
|
|
|
|
QColor mBreakpointColor;
|
|
|
|
QColor mDisabledBreakpointColor;
|
|
|
|
|
|
|
|
QAction actionExportGraph;
|
|
|
|
|
|
|
|
GraphView::Layout graphLayout;
|
|
|
|
QMenu *layoutMenu;
|
|
|
|
QAction *horizontalLayoutAction;
|
2021-01-24 14:50:13 +00:00
|
|
|
|
2020-07-16 08:05:10 +00:00
|
|
|
private:
|
|
|
|
void colorsUpdatedSlot();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CUTTER_GRAPHVIEW_H
|