void QmlMapControl::touchEvent(QTouchEvent *evnt) { const QList<QTouchEvent::TouchPoint> & touchs = evnt->touchPoints(); if( touchs.count() != 2 ) { QQuickPaintedItem::touchEvent(evnt); } else { evnt->accept(); const QTouchEvent::TouchPoint & t0 = touchs.first(); const QTouchEvent::TouchPoint & t1 = touchs.last(); if( last_t0_startPos.isNull() ) last_t0_startPos = t0.startPos(); if( last_t1_startPos.isNull() ) last_t1_startPos = t1.startPos(); qreal startW = qPow( qPow(last_t0_startPos.x()-last_t1_startPos.x(),2)+qPow(last_t0_startPos.y()-last_t1_startPos.y(),2), 0.5 ); qreal endW = qPow( qPow(t0.pos().x()-t1.pos().x(),2)+qPow(t0.pos().y()-t1.pos().y(),2), 0.5 ); if( startW*4/3<endW ) { QPoint pnt( last_t0_startPos.x()/2+last_t1_startPos.x()/2, last_t0_startPos.y()/2+last_t1_startPos.y()/2 ); QPoint newPoint( width()-pnt.x(), height()-pnt.y() ); setView(clickToWorldCoordinate(pnt)); zoomIn(pnt); setView(clickToWorldCoordinate(newPoint)); last_t0_startPos = t0.pos(); last_t1_startPos = t1.pos(); } else if( startW*3/4>endW ) { QPoint pnt( t0.pos().x()/2+t1.pos().x()/2, t0.pos().y()/2+t1.pos().y()/2 ); QPoint newPoint( width()-pnt.x(), height()-pnt.y() ); setView(clickToWorldCoordinate(pnt)); zoomOut(pnt); setView(clickToWorldCoordinate(newPoint)); last_t0_startPos = t0.pos(); last_t1_startPos = t1.pos(); } } }
void MapControl::mouseReleaseEvent(QMouseEvent* evnt) { mousepressed = false; if (mymousemode == Dragging) { QPointF ulCoord = clickToWorldCoordinate(pre_click_px); QPointF lrCoord = clickToWorldCoordinate(current_mouse_pos); QRectF coordinateBB = QRectF(ulCoord, QSizeF( (lrCoord-ulCoord).x(), (lrCoord-ulCoord).y())); emit(boxDragged(coordinateBB)); } emit(mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos()))); }
void MapControl::mouseMoveEvent(QMouseEvent* evnt) { layermanager->mouseEvent(evnt); emit(mouseEvent(evnt)); /* // rotating QMouseEvent* me = new QMouseEvent(evnt->type(), qm.map(QPoint(evnt->x(),evnt->y())), evnt->button(), evnt->buttons(), evnt->modifiers()); evnt = me; */ if (mousepressed && mymousemode == Panning) { QPoint offset = pre_click_px - QPoint(evnt->x(), evnt->y()); layermanager->scrollView(offset); pre_click_px = QPoint(evnt->x(), evnt->y()); } else if (mousepressed && mymousemode == Dragging) { current_mouse_pos = QPoint(evnt->x(), evnt->y()); } // emit(mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos()))); currentWorldCoordinate = clickToWorldCoordinate(evnt->pos()); emit(mouseMoveCoordinateEvent(currentWorldCoordinate)); update(); //emit(mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos()))); }
// mouse events void MapControl::mousePressEvent(QMouseEvent* evnt) { //rotating (experimental) // QMouseEvent* me = new QMouseEvent(evnt->type(), qm.map(QPoint(evnt->x(),evnt->y())), evnt->button(), evnt->buttons(), evnt->modifiers()); // evnt = me; // qDebug() << "evnt: " << evnt->x() << ", " << evnt->y() << ", " << evnt->pos(); layermanager->mouseEvent(evnt); if (layermanager->layers().size()>0) { if (evnt->button() == 1) { mousepressed = true; pre_click_px = QPoint(evnt->x(), evnt->y()); } else if (evnt->button() == 2 && mymousemode != None) // zoom in { zoomIn(); } else if (evnt->button() == 4 && mymousemode != None) // zoom out { zoomOut(); } } // emit(mouseEvent(evnt)); emit(mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos()))); }
void MapControl::wheelEvent(QWheelEvent *evnt) { if(mouse_wheel_events && evnt->orientation() == Qt::Vertical) { if(evnt->delta() > 0) { if( currentZoom() == layermanager->maxZoom() ) { return; } setView(clickToWorldCoordinate(evnt->pos())); //zoom in under mouse cursor zoomIn(); } else { if( currentZoom() == layermanager->minZoom() ) { return; } zoomOut(); } evnt->accept(); } else { evnt->ignore(); } }
// mouse events void MapControl::mousePressEvent(QMouseEvent* evnt) { layermanager->mouseEvent(evnt); if (layermanager->layers().size()>0) { if (evnt->button() == 1) { mousepressed = true; pre_click_px = QPoint(evnt->x(), evnt->y()); } // else if ( evnt->button() == 2 && // mouseWheelEventsEnabled() && // mymousemode != None) // zoom in // { // zoomIn(); // } // else if ( evnt->button() == 4 && // mouseWheelEventsEnabled() && // mymousemode != None) // zoom out // { // zoomOut(); // } } // emit(mouseEvent(evnt)); emit(mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos()))); }
void QmlMapControl::wheelEvent(QWheelEvent *evnt) { if(mouse_wheel_events && evnt->orientation() == Qt::Vertical) { if(evnt->delta() > 0) { if( currentZoom() == 17 ) { return; } QPoint pnt = evnt->pos(); QPoint newPoint( width()-pnt.x(), height()-pnt.y() ); setView(clickToWorldCoordinate(pnt)); zoomIn(pnt); setView(clickToWorldCoordinate(newPoint)); } else { if( currentZoom() == 0 ) { return; } QPoint pnt = evnt->pos(); QPoint newPoint( width()-pnt.x(), height()-pnt.y() ); setView(clickToWorldCoordinate(pnt)); zoomOut(pnt); setView(clickToWorldCoordinate(newPoint)); } evnt->accept(); } else { evnt->ignore(); } }