mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-23 05:16:11 +00:00
f8cebe0e30
* Replace scroll algorithm with just using offset * WIP * Text is now shown properly on each node * WIP * Scaling well WIP * Fix positioning for Graph * Overview properly displays Rect WIP * Rect in overview moves along with the mouse WIP * Overview rect properly moves WIP * mouse properly moves WIP * in middle of fixing resizing WIP * scaling issue WIP * Properly zooms * almost done * Edge width fixed for the overview * Fixed a small bug * Clean up
113 lines
4.5 KiB
C++
113 lines
4.5 KiB
C++
#include "MainWindow.h"
|
|
#include "GraphWidget.h"
|
|
#include "DisassemblerGraphView.h"
|
|
#include "WidgetShortcuts.h"
|
|
#include "OverviewView.h"
|
|
|
|
GraphWidget::GraphWidget(MainWindow *main, OverviewWidget *overview, QAction *action) :
|
|
CutterDockWidget(main, action)
|
|
{
|
|
this->setObjectName("Graph");
|
|
this->setAllowedAreas(Qt::AllDockWidgetAreas);
|
|
this->graphView = new DisassemblerGraphView(this);
|
|
this->setWidget(graphView);
|
|
this->overviewWidget = overview;
|
|
|
|
// getting the name of the class is implementation defined, and cannot be
|
|
// used reliably across different compilers.
|
|
//QShortcut *toggle_shortcut = new QShortcut(widgetShortcuts[typeid(this).name()], main);
|
|
QShortcut *toggle_shortcut = new QShortcut(widgetShortcuts["GraphWidget"], main);
|
|
connect(toggle_shortcut, &QShortcut::activated, this, [ = ]() {
|
|
toggleDockWidget(true);
|
|
main->updateDockActionChecked(action);
|
|
});
|
|
|
|
connect(this, &QDockWidget::visibilityChanged, this, [ = ](bool visibility) {
|
|
toggleOverview(visibility);
|
|
if (visibility) {
|
|
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Graph);
|
|
this->graphView->refreshView();
|
|
}
|
|
});
|
|
|
|
connect(graphView, &DisassemblerGraphView::viewRefreshed, this, [ = ]() {
|
|
overviewWidget->graphView->setData(graphView->getWidth(), graphView->getHeight(), graphView->getBlocks());
|
|
});
|
|
|
|
connect(Core(), &CutterCore::raisePrioritizedMemoryWidget,
|
|
this, [ = ](CutterCore::MemoryWidgetType type) {
|
|
bool emptyGraph = (type == CutterCore::MemoryWidgetType::Graph && Core()->isGraphEmpty());
|
|
if (type == CutterCore::MemoryWidgetType::Graph && !emptyGraph) {
|
|
this->raise();
|
|
this->graphView->setFocus();
|
|
}
|
|
});
|
|
}
|
|
|
|
GraphWidget::~GraphWidget() {}
|
|
|
|
void GraphWidget::toggleOverview(bool visibility)
|
|
{
|
|
if (!overviewWidget) {
|
|
return;
|
|
}
|
|
if (visibility) {
|
|
connect(graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOverview()));
|
|
connect(graphView, SIGNAL(viewZoomed()), this, SLOT(adjustOverview()));
|
|
connect(overviewWidget->graphView, SIGNAL(mouseMoved()), this, SLOT(adjustGraph()));
|
|
connect(overviewWidget, &QDockWidget::dockLocationChanged, this, &GraphWidget::adjustOverview);
|
|
connect(overviewWidget, &OverviewWidget::resized, this, &GraphWidget::adjustOverview);
|
|
} else {
|
|
disconnect(graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOverview()));
|
|
disconnect(graphView, SIGNAL(viewZoomed()), this, SLOT(adjustOverview()));
|
|
disconnect(overviewWidget->graphView, SIGNAL(mouseMoved()), this, SLOT(adjustGraph()));
|
|
disconnect(overviewWidget, &QDockWidget::dockLocationChanged, this, &GraphWidget::adjustOverview);
|
|
disconnect(overviewWidget, &OverviewWidget::resized, this, &GraphWidget::adjustOverview);
|
|
disableOverviewRect();
|
|
}
|
|
}
|
|
|
|
void GraphWidget::disableOverviewRect()
|
|
{
|
|
if (!overviewWidget) {
|
|
return;
|
|
}
|
|
overviewWidget->graphView->rangeRect = QRectF(0, 0, 0, 0);
|
|
overviewWidget->graphView->viewport()->update();
|
|
}
|
|
|
|
void GraphWidget::adjustOverview()
|
|
{
|
|
if (!overviewWidget) {
|
|
return;
|
|
}
|
|
qreal curScale = overviewWidget->graphView->current_scale;
|
|
qreal baseScale = graphView->current_scale;
|
|
qreal w = graphView->viewport()->width() * curScale / baseScale;
|
|
qreal h = graphView->viewport()->height() * curScale / baseScale;
|
|
int graph_offset_x = graphView->offset_x;
|
|
int graph_offset_y = graphView->offset_y;
|
|
int overview_offset_x = overviewWidget->graphView->offset_x;
|
|
int overview_offset_y = overviewWidget->graphView->offset_y;
|
|
int rangeRectX = graph_offset_x * curScale - overview_offset_x * curScale;
|
|
int rangeRectY = graph_offset_y * curScale - overview_offset_y * curScale;
|
|
|
|
overviewWidget->graphView->rangeRect = QRectF(rangeRectX, rangeRectY, w, h);
|
|
overviewWidget->graphView->viewport()->update();
|
|
}
|
|
|
|
void GraphWidget::adjustGraph()
|
|
{
|
|
if (!overviewWidget) {
|
|
return;
|
|
}
|
|
qreal curScale = overviewWidget->graphView->current_scale;
|
|
int rectx = overviewWidget->graphView->rangeRect.x();
|
|
int recty = overviewWidget->graphView->rangeRect.y();
|
|
int overview_offset_x = overviewWidget->graphView->offset_x;
|
|
int overview_offset_y = overviewWidget->graphView->offset_y;
|
|
graphView->offset_x = rectx /curScale + overview_offset_x;
|
|
graphView->offset_y = recty /curScale + overview_offset_y;
|
|
graphView->viewport()->update();
|
|
}
|