void Graph:: mouseMoveEvent(QMouseEvent* event) { if(dragging||scaling||operationCode){ int newx=event->x(),newy=event->y(); //std::cerr<<"new "<<newx<<" "<<newy<<std::endl; float newx0,newy0,oldx0,oldy0,dx,dy; xforminv(newx,newy,newx0,newy0); xforminv(lastcx,lastcy,oldx0,oldy0); dx=newx0-oldx0;dy=newy0-oldy0; if(dragging){ //std::cerr<<"dx "<<dx<<" "<<dy<<std::endl; xmin-=dx;xmax-=dx; ymin-=dy;ymax-=dy; }else if(scaling){ float width=(xmax-xmin)/2.,height=(ymax-ymin)/2.; float xcenter=(xmax+xmin)/2.,ycenter=(ymax+ymin)/2.; width*=pow(10.,-dx/(xmax-xmin)); height*=pow(10.,-dy/(ymax-ymin)); xmin=xcenter-width; ymin=ycenter-height; xmax=xcenter+width; ymax=ycenter+height; }else if(operationCode){ boundEnd=newx0; } lastcx=newx;lastcy=newy; repaint(); } }
void Graph::mousePressEvent(QMouseEvent* event) { lastcx = event->x(); lastcy = event->y(); if (event->button() == Qt::MidButton) dragging = true; else if (event->button() == Qt::RightButton) { scaling = true; } if (operationCode && Qt::LeftButton) { float x, y; xforminv(lastcx, lastcy, x, y); boundStart = x; } }
void Graph:: mouseReleaseEvent(QMouseEvent* event) {dragging=false;scaling=false; if(operationCode){ float x,y; xforminv(event->x(),event->y(),x,y); switch(operationCode){ case NONE: break; case FIND_ROOT: solveRoot(functionIndex,x); break; case FIND_MIN: solveMin(functionIndex,boundStart,x); break; case FIND_MAX: solveMax(functionIndex,boundStart,x); break; } status->showMessage(""); operationCode=NONE; } }