2018-03-16 21:46:57 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "GraphWidget.h"
|
|
|
|
#include "DisassemblerGraphView.h"
|
2018-10-16 06:25:09 +00:00
|
|
|
#include "WidgetShortcuts.h"
|
2019-01-24 17:13:04 +00:00
|
|
|
#include "OverviewView.h"
|
2018-03-16 21:46:57 +00:00
|
|
|
|
2019-01-24 17:13:04 +00:00
|
|
|
GraphWidget::GraphWidget(MainWindow *main, OverviewWidget *overview, QAction *action) :
|
2018-03-16 21:46:57 +00:00
|
|
|
CutterDockWidget(main, action)
|
|
|
|
{
|
|
|
|
this->setObjectName("Graph");
|
|
|
|
this->setAllowedAreas(Qt::AllDockWidgetAreas);
|
|
|
|
this->graphView = new DisassemblerGraphView(this);
|
|
|
|
this->setWidget(graphView);
|
2019-01-24 17:13:04 +00:00
|
|
|
this->overviewWidget = overview;
|
2018-03-16 21:46:57 +00:00
|
|
|
|
2018-10-16 06:25:09 +00:00
|
|
|
// 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);
|
2018-10-16 14:49:26 +00:00
|
|
|
connect(toggle_shortcut, &QShortcut::activated, this, [ = ]() {
|
2018-10-16 06:25:09 +00:00
|
|
|
toggleDockWidget(true);
|
|
|
|
main->updateDockActionChecked(action);
|
2018-10-16 14:49:26 +00:00
|
|
|
});
|
2018-10-16 06:25:09 +00:00
|
|
|
|
2018-10-16 14:49:26 +00:00
|
|
|
connect(this, &QDockWidget::visibilityChanged, this, [ = ](bool visibility) {
|
2019-01-24 17:13:04 +00:00
|
|
|
toggleOverview(visibility);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (visibility) {
|
2018-03-16 21:46:57 +00:00
|
|
|
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Graph);
|
2019-02-16 17:17:11 +00:00
|
|
|
this->graphView->refreshView();
|
2018-03-16 21:46:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-01-24 17:13:04 +00:00
|
|
|
connect(graphView, &DisassemblerGraphView::viewRefreshed, this, [ = ]() {
|
|
|
|
overviewWidget->graphView->setData(graphView->getWidth(), graphView->getHeight(), graphView->getBlocks());
|
|
|
|
});
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
connect(Core(), &CutterCore::raisePrioritizedMemoryWidget,
|
|
|
|
this, [ = ](CutterCore::MemoryWidgetType type) {
|
2018-09-30 17:46:36 +00:00
|
|
|
bool emptyGraph = (type == CutterCore::MemoryWidgetType::Graph && Core()->isGraphEmpty());
|
|
|
|
if (type == CutterCore::MemoryWidgetType::Graph && !emptyGraph) {
|
2018-03-16 21:46:57 +00:00
|
|
|
this->raise();
|
|
|
|
this->graphView->setFocus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphWidget::~GraphWidget() {}
|
2019-01-24 17:13:04 +00:00
|
|
|
|
|
|
|
void GraphWidget::toggleOverview(bool visibility)
|
|
|
|
{
|
|
|
|
if (!overviewWidget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (visibility) {
|
|
|
|
connect(graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOverview()));
|
2019-01-31 12:14:15 +00:00
|
|
|
connect(graphView, SIGNAL(viewZoomed()), this, SLOT(adjustOverview()));
|
2019-01-24 17:13:04 +00:00
|
|
|
connect(overviewWidget->graphView, SIGNAL(mouseMoved()), this, SLOT(adjustGraph()));
|
2019-02-07 20:39:37 +00:00
|
|
|
connect(overviewWidget, &QDockWidget::dockLocationChanged, this, &GraphWidget::adjustOverview);
|
|
|
|
connect(overviewWidget, &OverviewWidget::resized, this, &GraphWidget::adjustOverview);
|
2019-01-24 17:13:04 +00:00
|
|
|
} else {
|
|
|
|
disconnect(graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOverview()));
|
2019-01-31 12:14:15 +00:00
|
|
|
disconnect(graphView, SIGNAL(viewZoomed()), this, SLOT(adjustOverview()));
|
2019-01-24 17:13:04 +00:00
|
|
|
disconnect(overviewWidget->graphView, SIGNAL(mouseMoved()), this, SLOT(adjustGraph()));
|
2019-02-07 20:39:37 +00:00
|
|
|
disconnect(overviewWidget, &QDockWidget::dockLocationChanged, this, &GraphWidget::adjustOverview);
|
|
|
|
disconnect(overviewWidget, &OverviewWidget::resized, this, &GraphWidget::adjustOverview);
|
2019-01-24 17:13:04 +00:00
|
|
|
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;
|
2019-01-31 12:14:15 +00:00
|
|
|
qreal baseScale = graphView->current_scale;
|
2019-02-16 17:17:11 +00:00
|
|
|
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;
|
2019-01-24 17:13:04 +00:00
|
|
|
|
2019-02-16 17:17:11 +00:00
|
|
|
overviewWidget->graphView->rangeRect = QRectF(rangeRectX, rangeRectY, w, h);
|
2019-01-24 17:13:04 +00:00
|
|
|
overviewWidget->graphView->viewport()->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphWidget::adjustGraph()
|
|
|
|
{
|
|
|
|
if (!overviewWidget) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-16 17:17:11 +00:00
|
|
|
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();
|
2019-01-31 12:14:15 +00:00
|
|
|
}
|