-
Notifications
You must be signed in to change notification settings - Fork 120
Minimap for hexedit #266
base: master
Are you sure you want to change the base?
Minimap for hexedit #266
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,10 +48,11 @@ class VisualizationMinimap : public QOpenGLWidget, | |
| ENTROPY | ||
| }; | ||
|
|
||
| explicit VisualizationMinimap(QWidget *parent = 0); | ||
| explicit VisualizationMinimap(bool size_control = true, QWidget *parent = 0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so it is wrong in MinimapPanel , all qt things have it as last argmunet |
||
| ~VisualizationMinimap(); | ||
|
|
||
| void setSampler(util::ISampler * sampler); | ||
| QPair<size_t, size_t> getRange(); | ||
| void setRange(size_t start, size_t end, bool reset_selection = true); | ||
| QPair<size_t, size_t> getSelectedRange(); | ||
| void setSelectedRange(size_t start_address, size_t end_address); | ||
|
|
@@ -153,6 +154,8 @@ class VisualizationMinimap : public QOpenGLWidget, | |
|
|
||
| QOpenGLBuffer square_vertex_; | ||
| QOpenGLVertexArrayObject vao_; | ||
|
|
||
| bool size_control_; | ||
| }; | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,10 @@ HexEditWidget::HexEditWidget(MainWindowWithDetachableDockWidgets *main_window, | |
| connect(hex_edit_, &HexEdit::selectionChanged, | ||
| this, &HexEditWidget::selectionChanged); | ||
|
|
||
| connect(hex_edit_, &HexEdit::visibleRegionChanged, [this] (qint64 start_addr, qint64 region_size) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no space after |
||
| emit updateMinimap(start_addr, region_size); | ||
| }); | ||
|
|
||
| search_dialog_ = new SearchDialog(hex_edit_, this); | ||
|
|
||
| createActions(); | ||
|
|
@@ -176,16 +180,16 @@ void HexEditWidget::createActions() { | |
| connect(show_node_tree_act_, SIGNAL(toggled(bool)), | ||
| this, SIGNAL(showNodeTree(bool))); | ||
|
|
||
| // Currently not implemented | ||
| // show_minimap_act_ = ShortcutsModel::ShortcutsModel::getShortcutsModel()->createQAction( | ||
| // util::settings::shortcuts::SHOW_MINIMAP, | ||
| // this, QIcon(":/images/show_minimap.png"), Qt::WidgetWithChildrenShortcut); | ||
| // show_minimap_act_->setToolTip(tr("Minimap")); | ||
| // show_minimap_act_->setEnabled(true); | ||
| // show_minimap_act_->setCheckable(true); | ||
| // show_minimap_act_->setChecked(false); | ||
| // connect(show_minimap_act_, SIGNAL(toggled(bool)), this, | ||
| // SIGNAL(showMinimap(bool))); | ||
| //Currently not implemented | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after |
||
| show_minimap_act_ = ShortcutsModel::ShortcutsModel::getShortcutsModel()->createQAction( | ||
| util::settings::shortcuts::SHOW_MINIMAP, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indent with 4 spaces |
||
| this, QIcon(":/images/show_minimap.png"), Qt::WidgetWithChildrenShortcut); | ||
| show_minimap_act_->setToolTip(tr("Minimap")); | ||
| show_minimap_act_->setEnabled(true); | ||
| show_minimap_act_->setCheckable(true); | ||
| show_minimap_act_->setChecked(false); | ||
| connect(show_minimap_act_, SIGNAL(toggled(bool)), this, | ||
| SIGNAL(showMinimap(bool))); | ||
|
|
||
| show_hex_edit_act_ = ShortcutsModel::getShortcutsModel()->createQAction( | ||
| util::settings::shortcuts::OPEN_HEX, | ||
|
|
@@ -201,8 +205,8 @@ void HexEditWidget::createToolBars() { | |
| addAction(show_node_tree_act_); | ||
| tools_tool_bar_->addAction(show_node_tree_act_); | ||
| //Disabled until minimap does anything of value in hex-view | ||
| //addAction(show_minimap_act_); | ||
| //tools_tool_bar_->addAction(show_minimap_act_); | ||
| addAction(show_minimap_act_); | ||
| tools_tool_bar_->addAction(show_minimap_act_); | ||
|
|
||
| auto parser_tool_button = new QToolButton(); | ||
| parser_tool_button->setMenu(&parsers_menu_); | ||
|
|
@@ -372,5 +376,9 @@ void HexEditWidget::minimapVisibilityChanged(bool visibility) { | |
| show_minimap_act_->setChecked(visibility); | ||
| } | ||
|
|
||
| void HexEditWidget::minimapSelectionChanged(size_t start, size_t end) { | ||
| hex_edit_->scrollToByte(start); | ||
| } | ||
|
|
||
| } // namespace ui | ||
| } // namespace veles | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,8 @@ | |
| namespace veles { | ||
| namespace ui { | ||
|
|
||
| const float k_minimap_selection_factor = 10; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consts should be in uppercase
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. convention from this component, see trigram.cc
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll refactor this old convention in few days (after fixing Jenkins), so insert new code in Google C++ Style |
||
|
|
||
| /*****************************************************************************/ | ||
| /* Public methods */ | ||
| /*****************************************************************************/ | ||
|
|
@@ -54,7 +56,9 @@ NodeWidget::NodeWidget(MainWindowWithDetachableDockWidgets *main_window, | |
| : View("Hex editor", ":/images/show_hex_edit.png"), | ||
| main_window_(main_window), minimap_(nullptr), | ||
| minimap_dock_(nullptr), data_model_(data_model), | ||
| selection_model_(selection_model), sampler_(nullptr) { | ||
| selection_model_(selection_model), sampler_(nullptr), | ||
| update_minimap_start_(0), update_minimap_size_(0), | ||
| ignore_update_minimap_(false) { | ||
| hex_edit_widget_ = new HexEditWidget( | ||
| main_window, data_model, selection_model); | ||
| addAction(hex_edit_widget_->uploadAction()); | ||
|
|
@@ -79,49 +83,80 @@ NodeWidget::NodeWidget(MainWindowWithDetachableDockWidgets *main_window, | |
| setDockNestingEnabled(true); | ||
| addDockWidget(Qt::LeftDockWidgetArea, node_tree_dock_); | ||
|
|
||
| #if 0 // We do not use minimap for NodeWidget yet, | ||
| minimap_dock_ = new QDockWidget; | ||
| new DockWidgetVisibilityGuard(minimap_dock_); | ||
| minimap_dock_->setWindowTitle("Minimap"); | ||
| minimap_ = new visualization::MinimapPanel(this); | ||
|
|
||
| if(data_model_->binData().size() > 0) { | ||
| loadBinDataToMinimap(); | ||
| } else { | ||
| sampler_data_ = QByteArray(""); | ||
| sampler_ = new util::UniformSampler(sampler_data_); | ||
| sampler_->setSampleSize(4096 * 1024); | ||
| minimap_->setSampler(sampler_); | ||
| } | ||
|
|
||
| minimap_dock_->setWidget(minimap_); | ||
| minimap_dock_->setContextMenuPolicy(Qt::PreventContextMenu); | ||
| minimap_dock_->setAllowedAreas( | ||
| Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); | ||
| addDockWidget(Qt::LeftDockWidgetArea, minimap_dock_); | ||
| MainWindowWithDetachableDockWidgets::splitDockWidget2(this, node_tree_dock_, | ||
| minimap_dock_, Qt::Horizontal); | ||
| #endif | ||
|
|
||
| connect(hex_edit_widget_, &HexEditWidget::showNodeTree, | ||
| node_tree_dock_, &QDockWidget::setVisible); | ||
| connect(node_tree_dock_, &QDockWidget::visibilityChanged, | ||
| hex_edit_widget_, &HexEditWidget::nodeTreeVisibilityChanged); | ||
|
|
||
| #if 0 // We do not use minimap for NodeWidget yet, | ||
| connect(hex_edit_widget_, &HexEditWidget::showMinimap, | ||
| minimap_dock_, &QDockWidget::setVisible); | ||
| connect(data_model_.data(), &FileBlobModel::newBinData, | ||
| this, &NodeWidget::loadBinDataToMinimap); | ||
| connect(minimap_dock_, &QDockWidget::visibilityChanged, | ||
| hex_edit_widget_, &HexEditWidget::minimapVisibilityChanged); | ||
| #endif | ||
| connect(hex_edit_widget_, &HexEditWidget::showMinimap, this, &NodeWidget::showMinimap); | ||
| connect(hex_edit_widget_, &HexEditWidget::updateMinimap, [this](qint64 start, qint64 size) { | ||
| if (!ignore_update_minimap_) { | ||
| update_minimap_start_ = start; | ||
| update_minimap_size_ = size; | ||
| update_minimap_timer_.start(400); | ||
| } | ||
| }); | ||
|
|
||
| update_minimap_timer_.setSingleShot(true); | ||
| connect(&update_minimap_timer_, &QTimer::timeout, this, &NodeWidget::updateMinimap); | ||
| } | ||
|
|
||
| NodeWidget::~NodeWidget() { | ||
| delete sampler_; | ||
| } | ||
|
|
||
| void NodeWidget::showMinimap(bool show) { | ||
| if (minimap_dock_ == nullptr) { | ||
| if (!show) { | ||
| return; | ||
| } | ||
| minimap_dock_ = new QDockWidget; | ||
| new DockWidgetVisibilityGuard(minimap_dock_); | ||
| minimap_dock_->setWindowTitle("Minimap"); | ||
| minimap_ = new visualization::MinimapPanel(this, /*size_control=*/false); | ||
|
|
||
| if(data_model_->binData().size() > 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after |
||
| loadBinDataToMinimap(); | ||
| } else { | ||
| sampler_data_ = QByteArray(""); | ||
| sampler_ = new util::UniformSampler(sampler_data_); | ||
| sampler_->setSampleSize(4096 * 1024); | ||
| minimap_->setSampler(sampler_); | ||
| } | ||
|
|
||
| minimap_dock_->setWidget(minimap_); | ||
| minimap_dock_->setContextMenuPolicy(Qt::PreventContextMenu); | ||
| minimap_dock_->setAllowedAreas( | ||
| Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); | ||
| addDockWidget(Qt::LeftDockWidgetArea, minimap_dock_); | ||
| MainWindowWithDetachableDockWidgets::splitDockWidget2(this, node_tree_dock_, | ||
| minimap_dock_, Qt::Horizontal); | ||
|
|
||
| connect(data_model_.data(), &FileBlobModel::newBinData, | ||
| this, &NodeWidget::loadBinDataToMinimap); | ||
| connect(minimap_dock_, &QDockWidget::visibilityChanged, | ||
| hex_edit_widget_, &HexEditWidget::minimapVisibilityChanged); | ||
| connect(minimap_, &visualization::MinimapPanel::selectionChanged, [this] (size_t start, size_t end) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no space after |
||
| if (!ignore_update_minimap_) { | ||
| ignore_update_minimap_ = true; | ||
| hex_edit_widget_->minimapSelectionChanged(start, end); | ||
| ignore_update_minimap_ = false; | ||
| } | ||
| }); | ||
| } | ||
| minimap_dock_->setVisible(show); | ||
|
|
||
| } | ||
|
|
||
| void NodeWidget::updateMinimap() { | ||
| if (minimap_dock_ == nullptr || sampler_->empty()) { | ||
| return; | ||
| } | ||
| ignore_update_minimap_ = true; | ||
| minimap_->adjustMinimaps(update_minimap_size_, k_minimap_selection_factor, update_minimap_start_); | ||
| ignore_update_minimap_ = false; | ||
| } | ||
|
|
||
| void NodeWidget::loadBinDataToMinimap() { | ||
| delete sampler_; | ||
|
|
||
|
|
@@ -130,6 +165,7 @@ void NodeWidget::loadBinDataToMinimap() { | |
| sampler_ = new util::UniformSampler(sampler_data_); | ||
| sampler_->setSampleSize(4096 * 1024); | ||
| minimap_->setSampler(sampler_); | ||
| updateMinimap(); | ||
| } | ||
|
|
||
| } // namespace ui | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a comment why do we need a timer here (and what it does)