void ScreenshotsWidget::updateMouseShape(const QPoint &point) { switch(currentShotState){ case initShot: case beginShot: setCursor(Qt::CrossCursor); break; case beginMoveShot: setCursor(Qt::OpenHandCursor); break; case finishShot: case finishMoveShot: case finishControl: if(getSelectedRect().contains(point)) setCursor(Qt::OpenHandCursor); else updateMoveControlMouseShape(getMoveControlState(point)); break; case beginControl: updateMoveControlMouseShape(controlValue); //调用函数对移动8个控制点进行鼠标状态的改变 break; default: setCursor(Qt::ArrowCursor); break; } }
bool ScreenshotsWidget::isInSelectedRect(const QPoint &point) { int x,y; QRect selectedRect; if(currentShotState == initShot || currentShotState == beginShot) return false; selectedRect = getSelectedRect(); x = point.x(); y = point.y(); return selectedRect.contains(x,y); }
void SelectionView::mouseReleaseEvent( QMouseEvent *e ) { if ( _drawLine ) { QPainter painter( getPix() ); painter.setPen(QPen(Qt::red, 12, Qt::DashDotLine, Qt::RoundCap)); painter.drawPath( *linePath ); pixItem->setPixmap( *getPix() ); // scene()->addPixmap( *getPix() ); _drawLineHold = false; return; } //!* self-defined pixel if ( _snapRatio == -1.0) { if (_isFromCenter) { _originPoint.rx() = e ->pos().x() - int(_snapWidth*_zoomRatio/2+0.5); _originPoint.ry() = e ->pos().y() - int(_snapHeight*_zoomRatio/2+0.5); _terminalPoint.rx() = e ->pos().x() + int(_snapWidth*_zoomRatio/2+0.5); _terminalPoint.ry() = e ->pos().y() + int(_snapHeight*_zoomRatio/2+0.5); } else { _originPoint = e->pos(); _terminalPoint.rx() = e ->pos().x() + int(_snapWidth*_zoomRatio+0.5) - 1; _terminalPoint.ry() = e ->pos().y() + int(_snapHeight*_zoomRatio+0.5) - 1; } } //!* specify ratio else { if (_isFromCenter) { _originPoint = _originPoint + _originPoint - _terminalPoint; } } QRect selectedRect = getSelectedRect(); QPoint topLeft = selectedRect.topLeft() / _zoomRatio; QPoint bottomRight = selectedRect.bottomRight() / _zoomRatio; if ( qAbs(bottomRight.x()-topLeft.x()) > 2 && qAbs(bottomRight.y()-topLeft.y()) > 2 ) emit rubberBandSelectionFinished(); _selectionFinished = true; }