mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-08 20:20:44 +00:00
Cap selection area to screen and graph bounds
This commit is contained in:
parent
58f1933dcd
commit
f8f9ae59af
@ -344,6 +344,8 @@ void gGraph::mouseMoveEvent(QMouseEvent * event)
|
|||||||
qDebug() << m_title << "Moved" << x << y << left << right << top << bottom << m_width << m_height;
|
qDebug() << m_title << "Moved" << x << y << left << right << top << bottom << m_width << m_height;
|
||||||
int a1=MIN(x,x2);
|
int a1=MIN(x,x2);
|
||||||
int a2=MAX(x,x2);
|
int a2=MAX(x,x2);
|
||||||
|
if (a1<m_marginleft+left) a1=m_marginleft+left;
|
||||||
|
if (a2>w) a2=w;
|
||||||
m_selecting_area=true;
|
m_selecting_area=true;
|
||||||
m_selection=QRect(a1-m_marginleft,0,a2-a1,m_height);
|
m_selection=QRect(a1-m_marginleft,0,a2-a1,m_height);
|
||||||
m_graphview->updateGL();
|
m_graphview->updateGL();
|
||||||
@ -380,20 +382,15 @@ void gGraph::mouseReleaseEvent(QMouseEvent * event)
|
|||||||
int w=m_width-(m_graphview->titleWidth+m_marginleft+left+right+m_marginright);
|
int w=m_width-(m_graphview->titleWidth+m_marginleft+left+right+m_marginright);
|
||||||
int h=m_height-(bottom+m_marginbottom);
|
int h=m_height-(bottom+m_marginbottom);
|
||||||
int x2=m_graphview->pointClicked().x(),y2=m_graphview->pointClicked().y();
|
int x2=m_graphview->pointClicked().x(),y2=m_graphview->pointClicked().y();
|
||||||
|
if (m_selecting_area) {
|
||||||
m_selecting_area=false;
|
m_selecting_area=false;
|
||||||
m_selection.setWidth(0);
|
m_selection.setWidth(0);
|
||||||
if (x>left+m_marginleft && x<w+m_marginleft+left && y>top+m_margintop && y<h) { // main area
|
|
||||||
if (event->button() & Qt::RightButton) {
|
|
||||||
ZoomX(2,x);
|
|
||||||
// zoom out.
|
|
||||||
} else if (event->button() & Qt::LeftButton) {
|
|
||||||
if (abs(x-x2)<4) {
|
|
||||||
ZoomX(0.5,x);
|
|
||||||
} else {
|
|
||||||
x-=left+m_marginleft;
|
x-=left+m_marginleft;
|
||||||
y-=top+m_margintop;
|
y-=top+m_margintop;
|
||||||
x2-=left+m_marginleft;
|
x2-=left+m_marginleft;
|
||||||
y2-=top+m_margintop;
|
y2-=top+m_margintop;
|
||||||
|
if (x<0) x=0;
|
||||||
|
if (x>w) x=w;
|
||||||
if (!m_blockzoom) {
|
if (!m_blockzoom) {
|
||||||
double xx=max_x-min_x;
|
double xx=max_x-min_x;
|
||||||
double xmult=xx/double(w);
|
double xmult=xx/double(w);
|
||||||
@ -401,6 +398,7 @@ void gGraph::mouseReleaseEvent(QMouseEvent * event)
|
|||||||
qint64 j2=min_x+xmult*x2;
|
qint64 j2=min_x+xmult*x2;
|
||||||
qint64 a1=MIN(j1,j2)
|
qint64 a1=MIN(j1,j2)
|
||||||
qint64 a2=MAX(j1,j2)
|
qint64 a2=MAX(j1,j2)
|
||||||
|
if (a2>rmax_x) a2=rmax_x;
|
||||||
m_graphview->SetXBounds(a1,a2);
|
m_graphview->SetXBounds(a1,a2);
|
||||||
} else {
|
} else {
|
||||||
double xx=rmax_x-rmin_x;
|
double xx=rmax_x-rmin_x;
|
||||||
@ -409,8 +407,19 @@ void gGraph::mouseReleaseEvent(QMouseEvent * event)
|
|||||||
qint64 j2=rmin_x+xmult*x2;
|
qint64 j2=rmin_x+xmult*x2;
|
||||||
qint64 a1=MIN(j1,j2)
|
qint64 a1=MIN(j1,j2)
|
||||||
qint64 a2=MAX(j1,j2)
|
qint64 a2=MAX(j1,j2)
|
||||||
|
if (a2>rmax_x) a2=rmax_x;
|
||||||
m_graphview->SetXBounds(a1,a2);
|
m_graphview->SetXBounds(a1,a2);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (x>left+m_marginleft && x<w+m_marginleft+left && y>top+m_margintop && y<h) { // main area
|
||||||
|
if (event->button() & Qt::RightButton) {
|
||||||
|
ZoomX(2,x);
|
||||||
|
// zoom out.
|
||||||
|
} else if (event->button() & Qt::LeftButton) {
|
||||||
|
if (abs(x-x2)<4) {
|
||||||
|
ZoomX(0.5,x);
|
||||||
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug() << m_title << "Released" << min_x << max_x << x << y << x2 << y2 << left << right << top << bottom << m_width << m_height;
|
qDebug() << m_title << "Released" << min_x << max_x << x << y << x2 << y2 << left << right << top << bottom << m_width << m_height;
|
||||||
@ -932,6 +941,7 @@ void gGraphView::mouseMoveEvent(QMouseEvent * event)
|
|||||||
this->setCursor(Qt::ArrowCursor);
|
this->setCursor(Qt::ArrowCursor);
|
||||||
QPoint p(x-titleWidth,y-py);
|
QPoint p(x-titleWidth,y-py);
|
||||||
QMouseEvent e(event->type(),p,event->button(),event->buttons(),event->modifiers());
|
QMouseEvent e(event->type(),p,event->button(),event->buttons(),event->modifiers());
|
||||||
|
|
||||||
m_graphs[i]->mouseMoveEvent(&e);
|
m_graphs[i]->mouseMoveEvent(&e);
|
||||||
} else {
|
} else {
|
||||||
this->setCursor(Qt::OpenHandCursor);
|
this->setCursor(Qt::OpenHandCursor);
|
||||||
|
Loading…
Reference in New Issue
Block a user