mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-21 04:16:12 +00:00
Fix an wrong positioning of the rect of Overview (#1171)
* Fix an wrong positioning of the rect of Overview * Fix commenting and a resizing issue
This commit is contained in:
parent
9778cdf2d6
commit
1a132ecf83
@ -59,6 +59,8 @@ void GraphWidget::toggleOverview(bool visibility)
|
|||||||
connect(graphView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjustOverview()));
|
connect(graphView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjustOverview()));
|
||||||
connect(overviewWidget->graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOffset()));
|
connect(overviewWidget->graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOffset()));
|
||||||
connect(overviewWidget->graphView, SIGNAL(mouseMoved()), this, SLOT(adjustGraph()));
|
connect(overviewWidget->graphView, SIGNAL(mouseMoved()), this, SLOT(adjustGraph()));
|
||||||
|
connect(overviewWidget, &QDockWidget::dockLocationChanged, this, &GraphWidget::adjustOverview);
|
||||||
|
connect(overviewWidget, &OverviewWidget::resized, this, &GraphWidget::adjustOverview);
|
||||||
} else {
|
} else {
|
||||||
disconnect(graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOverview()));
|
disconnect(graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOverview()));
|
||||||
disconnect(graphView, SIGNAL(viewZoomed()), this, SLOT(adjustOverview()));
|
disconnect(graphView, SIGNAL(viewZoomed()), this, SLOT(adjustOverview()));
|
||||||
@ -66,6 +68,8 @@ void GraphWidget::toggleOverview(bool visibility)
|
|||||||
disconnect(graphView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjustOverview()));
|
disconnect(graphView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjustOverview()));
|
||||||
disconnect(overviewWidget->graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOffset()));
|
disconnect(overviewWidget->graphView, SIGNAL(refreshBlock()), this, SLOT(adjustOffset()));
|
||||||
disconnect(overviewWidget->graphView, SIGNAL(mouseMoved()), this, SLOT(adjustGraph()));
|
disconnect(overviewWidget->graphView, SIGNAL(mouseMoved()), this, SLOT(adjustGraph()));
|
||||||
|
disconnect(overviewWidget, &QDockWidget::dockLocationChanged, this, &GraphWidget::adjustOverview);
|
||||||
|
disconnect(overviewWidget, &OverviewWidget::resized, this, &GraphWidget::adjustOverview);
|
||||||
disableOverviewRect();
|
disableOverviewRect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,6 +88,8 @@ void GraphWidget::adjustOverview()
|
|||||||
if (!overviewWidget) {
|
if (!overviewWidget) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
overviewWidget->graphView->h_offset = 0;
|
||||||
|
overviewWidget->graphView->v_offset = 0;
|
||||||
bool scrollXVisible = graphView->horizontalScrollBar()->isVisible();
|
bool scrollXVisible = graphView->horizontalScrollBar()->isVisible();
|
||||||
bool scrollYVisible = graphView->verticalScrollBar()->isVisible();
|
bool scrollYVisible = graphView->verticalScrollBar()->isVisible();
|
||||||
if (!scrollXVisible && !scrollYVisible) {
|
if (!scrollXVisible && !scrollYVisible) {
|
||||||
@ -92,25 +98,29 @@ void GraphWidget::adjustOverview()
|
|||||||
}
|
}
|
||||||
qreal x = 0;
|
qreal x = 0;
|
||||||
qreal y = 0;
|
qreal y = 0;
|
||||||
qreal w = overviewWidget->graphView->viewport()->width();
|
qreal w = graphView->viewport()->width();
|
||||||
qreal h = overviewWidget->graphView->viewport()->height();
|
qreal h = graphView->viewport()->height();
|
||||||
qreal curScale = overviewWidget->graphView->current_scale;
|
qreal curScale = overviewWidget->graphView->current_scale;
|
||||||
qreal baseScale = graphView->current_scale;
|
qreal baseScale = graphView->current_scale;
|
||||||
|
|
||||||
w = graphView->viewport()->width();
|
w *= curScale / baseScale;
|
||||||
h = graphView->viewport()->height();
|
h *= curScale / baseScale;
|
||||||
|
|
||||||
if (scrollXVisible) {
|
if (scrollXVisible) {
|
||||||
x = graphView->horizontalScrollBar()->value();
|
x = graphView->horizontalScrollBar()->value();
|
||||||
w *= curScale / baseScale;
|
x *= curScale;
|
||||||
|
} else {
|
||||||
|
x = (overviewWidget->graphView->viewport()->width() - w) / 2;
|
||||||
|
overviewWidget->graphView->h_offset = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scrollYVisible) {
|
if (scrollYVisible) {
|
||||||
y = graphView->verticalScrollBar()->value();
|
y = graphView->verticalScrollBar()->value();
|
||||||
h *= curScale / baseScale;
|
y *= curScale;
|
||||||
|
} else {
|
||||||
|
y = (overviewWidget->graphView->viewport()->height() - h) / 2;
|
||||||
|
overviewWidget->graphView->v_offset = y;
|
||||||
}
|
}
|
||||||
x *= curScale;
|
|
||||||
y *= curScale;
|
|
||||||
overviewWidget->graphView->rangeRect = QRectF(x + overviewWidget->graphView->unscrolled_render_offset_x,
|
overviewWidget->graphView->rangeRect = QRectF(x + overviewWidget->graphView->unscrolled_render_offset_x,
|
||||||
y + overviewWidget->graphView->unscrolled_render_offset_y, w, h);
|
y + overviewWidget->graphView->unscrolled_render_offset_y, w, h);
|
||||||
overviewWidget->graphView->viewport()->update();
|
overviewWidget->graphView->viewport()->update();
|
||||||
@ -123,8 +133,8 @@ void GraphWidget::adjustGraph()
|
|||||||
}
|
}
|
||||||
int x1 = overviewWidget->graphView->horizontalScrollBar()->value();
|
int x1 = overviewWidget->graphView->horizontalScrollBar()->value();
|
||||||
int y1 = overviewWidget->graphView->verticalScrollBar()->value();
|
int y1 = overviewWidget->graphView->verticalScrollBar()->value();
|
||||||
qreal x2 = (overviewWidget->graphView->rangeRect.x() - (qreal)overviewWidget->graphView->unscrolled_render_offset_x)/ overviewWidget->graphView->current_scale;
|
qreal x2 = (overviewWidget->graphView->rangeRect.x() - (qreal)overviewWidget->graphView->unscrolled_render_offset_x) / overviewWidget->graphView->current_scale;
|
||||||
qreal y2 = (overviewWidget->graphView->rangeRect.y() - (qreal)overviewWidget->graphView->unscrolled_render_offset_y)/ overviewWidget->graphView->current_scale;
|
qreal y2 = (overviewWidget->graphView->rangeRect.y() - (qreal)overviewWidget->graphView->unscrolled_render_offset_y) / overviewWidget->graphView->current_scale;
|
||||||
|
|
||||||
graphView->horizontalScrollBar()->setValue(x1 + x2);
|
graphView->horizontalScrollBar()->setValue(x1 + x2);
|
||||||
graphView->verticalScrollBar()->setValue(y1 + y2);
|
graphView->verticalScrollBar()->setValue(y1 + y2);
|
||||||
|
@ -91,8 +91,8 @@ void OverviewView::mousePressEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
qreal w = rangeRect.width();
|
qreal w = rangeRect.width();
|
||||||
qreal h = rangeRect.height();
|
qreal h = rangeRect.height();
|
||||||
qreal x = event->localPos().x() - w/2;
|
qreal x = event->localPos().x() - w/2 + h_offset;
|
||||||
qreal y = event->localPos().y() - h/2;
|
qreal y = event->localPos().y() - h/2 + v_offset;
|
||||||
rangeRect = QRectF(x, y, w, h);
|
rangeRect = QRectF(x, y, w, h);
|
||||||
viewport()->update();
|
viewport()->update();
|
||||||
emit mouseMoved();
|
emit mouseMoved();
|
||||||
@ -132,6 +132,8 @@ void OverviewView::mouseMoveEvent(QMouseEvent *event)
|
|||||||
if (y <= unscrolled_render_offset_y) {
|
if (y <= unscrolled_render_offset_y) {
|
||||||
y = unscrolled_render_offset_y;
|
y = unscrolled_render_offset_y;
|
||||||
}
|
}
|
||||||
|
x += h_offset;
|
||||||
|
y += v_offset;
|
||||||
rangeRect = QRectF(x, y, w, h);
|
rangeRect = QRectF(x, y, w, h);
|
||||||
viewport()->update();
|
viewport()->update();
|
||||||
emit mouseMoved();
|
emit mouseMoved();
|
||||||
|
@ -11,8 +11,8 @@ class OverviewView : public GraphView
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/*
|
||||||
* @brief signal when mouse is pressed or moved so that
|
* \brief signal when mouse is pressed or moved so that
|
||||||
* Graph can refresh its contents corresponded with Overview
|
* Graph can refresh its contents corresponded with Overview
|
||||||
*/
|
*/
|
||||||
void mouseMoved();
|
void mouseMoved();
|
||||||
@ -21,13 +21,20 @@ public:
|
|||||||
OverviewView(QWidget *parent);
|
OverviewView(QWidget *parent);
|
||||||
~OverviewView() override;
|
~OverviewView() override;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @brief a rect on Overview to show where you are on Graph
|
* \brief a rect on Overview to show where you are on Graph
|
||||||
*/
|
*/
|
||||||
QRectF rangeRect;
|
QRectF rangeRect;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @brief Graph access this function to set minimum set of the data
|
* \brief offset for the rect which is put when either of the scrollbar of
|
||||||
|
* Graph is not visible.
|
||||||
|
*/
|
||||||
|
qreal h_offset = 0;
|
||||||
|
qreal v_offset = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Graph access this function to set minimum set of the data
|
||||||
* @param baseWidth width of Graph when it computed the blocks
|
* @param baseWidth width of Graph when it computed the blocks
|
||||||
* @param baseHeigh height of Graph when it computed the blocks
|
* @param baseHeigh height of Graph when it computed the blocks
|
||||||
* @param baseBlocks computed blocks passed by Graph
|
* @param baseBlocks computed blocks passed by Graph
|
||||||
@ -35,81 +42,81 @@ public:
|
|||||||
void setData(int baseWidth, int baseHeight, std::unordered_map<ut64, GraphBlock> baseBlocks);
|
void setData(int baseWidth, int baseHeight, std::unordered_map<ut64, GraphBlock> baseBlocks);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/*
|
||||||
* @brief refresh the view and adjust the scale
|
* \brief refresh the view and adjust the scale
|
||||||
*/
|
*/
|
||||||
void refreshView();
|
void refreshView();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
/**
|
/*
|
||||||
* @brief update Colors.
|
* \brief update Colors.
|
||||||
* for example this will be called when the theme is changed.
|
* for example this will be called when the theme is changed.
|
||||||
*/
|
*/
|
||||||
void colorsUpdatedSlot();
|
void colorsUpdatedSlot();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/*
|
||||||
* @brief mousePressEvent to start moving the rect.
|
* \brief mousePressEvent to start moving the rect.
|
||||||
*/
|
*/
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
/**
|
/*
|
||||||
* @brief mouseReleaseEvent to tell not to move the rect anymore.
|
* \brief mouseReleaseEvent to tell not to move the rect anymore.
|
||||||
*/
|
*/
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
/**
|
/*
|
||||||
* @brief mouseMoveEvent to move the rect.
|
* \brief mouseMoveEvent to move the rect.
|
||||||
*/
|
*/
|
||||||
void mouseMoveEvent(QMouseEvent *event) override;
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/*
|
||||||
* @brief this will be handled in mouse events to move the rect properly
|
* \brief this will be handled in mouse events to move the rect properly
|
||||||
* along with the mouse.
|
* along with the mouse.
|
||||||
*/
|
*/
|
||||||
bool mouseActive = false;
|
bool mouseActive = false;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @brief save the initial distance
|
* \brief save the initial distance
|
||||||
* between the point where the mouse was pressed and the point of the rect
|
* between the point where the mouse was pressed and the point of the rect
|
||||||
* so as to change the rect point properly along with mouse.
|
* so as to change the rect point properly along with mouse.
|
||||||
*/
|
*/
|
||||||
QPointF initialDiff;
|
QPointF initialDiff;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @brief draw the computed blocks passed by Graph
|
* \brief draw the computed blocks passed by Graph
|
||||||
*/
|
*/
|
||||||
virtual void drawBlock(QPainter &p, GraphView::GraphBlock &block) override;
|
virtual void drawBlock(QPainter &p, GraphView::GraphBlock &block) override;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @brief override the edgeConfiguration so as to
|
* \brief override the edgeConfiguration so as to
|
||||||
* adjust the width of the edges by the scale
|
* adjust the width of the edges by the scale
|
||||||
* @return EdgeConfiguration
|
* @return EdgeConfiguration
|
||||||
*/
|
*/
|
||||||
virtual GraphView::EdgeConfiguration edgeConfiguration(GraphView::GraphBlock &from,
|
virtual GraphView::EdgeConfiguration edgeConfiguration(GraphView::GraphBlock &from,
|
||||||
GraphView::GraphBlock *to) override;
|
GraphView::GraphBlock *to) override;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @brief override the paintEvent to draw the rect on Overview
|
* \brief override the paintEvent to draw the rect on Overview
|
||||||
*/
|
*/
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @brief apply scale properly on the view
|
* \brief apply scale properly on the view
|
||||||
*/
|
*/
|
||||||
void adjustScale();
|
void adjustScale();
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @brief if the mouse is in the rect in Overview.
|
* \brief if the mouse is in the rect in Overview.
|
||||||
*/
|
*/
|
||||||
bool mouseContainsRect(QMouseEvent *event);
|
bool mouseContainsRect(QMouseEvent *event);
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @brief base background color changing depending on the theme
|
* \brief base background color changing depending on the theme
|
||||||
*/
|
*/
|
||||||
QColor disassemblyBackgroundColor;
|
QColor disassemblyBackgroundColor;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @brief color for each node changing depending on the theme
|
* \brief color for each node changing depending on the theme
|
||||||
*/
|
*/
|
||||||
QColor graphNodeColor;
|
QColor graphNodeColor;
|
||||||
};
|
};
|
||||||
|
@ -28,6 +28,7 @@ void OverviewWidget::resizeEvent(QResizeEvent *event)
|
|||||||
{
|
{
|
||||||
graphView->refreshView();
|
graphView->refreshView();
|
||||||
QDockWidget::resizeEvent(event);
|
QDockWidget::resizeEvent(event);
|
||||||
|
emit resized();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverviewWidget::updateContents()
|
void OverviewWidget::updateContents()
|
||||||
|
@ -17,16 +17,22 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
RefreshDeferrer *refreshDeferrer;
|
RefreshDeferrer *refreshDeferrer;
|
||||||
/**
|
/*
|
||||||
* @brief this takes care of scaling the overview when the widget is resized
|
* \brief this takes care of scaling the overview when the widget is resized
|
||||||
*/
|
*/
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
/**
|
/*
|
||||||
* @brief update the overview
|
* \brief update the overview
|
||||||
*/
|
*/
|
||||||
void updateContents();
|
void updateContents();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/*
|
||||||
|
* \brief emit signal to update the rect
|
||||||
|
*/
|
||||||
|
void resized();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // OverviewWIDGET_H
|
#endif // OverviewWIDGET_H
|
||||||
|
Loading…
Reference in New Issue
Block a user