コード例 #1
0
void LiftDragPlot::mouseMoveEvent(
        QMouseEvent *event)
{
    if (event->buttons() & Qt::LeftButton)
    {
        QPoint pos = event->pos();
        QVector2D diff = QVector2D(pos - mBeginPos);

        if (diff.length() > selectionTolerance())
        {
            mDragging = true;
        }

        if (mDragging)
        {
            const double cd = xAxis->pixelToCoord(pos.x());
            const double cl = yAxis->pixelToCoord(pos.y());

            const double c = cd / 2;
            const double a = c / cl / cl;

            mMainWindow->setMinDrag(c);
            mMainWindow->setMaxLD(1 / sqrt(4 * a * c));
        }
    }
    else if (QCPCurve *graph = qobject_cast<QCPCurve *>(plottable(0)))
    {
        const QCPCurveDataMap *data = graph->data();

        double resultTime;
        double resultDistance = std::numeric_limits<double>::max();

        for (QCPCurveDataMap::const_iterator it = data->constBegin();
             it != data->constEnd();
             ++it)
        {
            QVector2D pt = QVector2D(xAxis->coordToPixel(it.value().key),
                                     yAxis->coordToPixel(it.value().value));

            double dist = pt.distanceToPoint(QVector2D(event->pos()));

            if (dist < resultDistance)
            {
                resultTime = it.value().t;
                resultDistance = dist;
            }
        }

        if (resultDistance < selectionTolerance())
        {
            setMark(resultTime);
        }
        else
        {
            mMainWindow->clearMark();
            QToolTip::hideText();
        }
    }
}
コード例 #2
0
ファイル: collider.cpp プロジェクト: jreuss/tudimapper
QPointF Collider::getScaleOrigin(QVector2D vec, QRectF rect)
{
    mIsValidScaleOriginPoint = true;
    if(vec.distanceToPoint (QVector2D(rect.topLeft())) < 10) {
        mScaleXDirection = PosXAxis;
        mScaleYDirection = PosYAxis;
        if(mUniformScaleEnabled){
            mScaleType = Uniform;

        } else {
            mScaleType = BothXY;
        }
        mUniformXScaleVector = QVector2D(QPointF(rect.topLeft().x()-rect.bottomRight().x(),0));
        mUniformYScaleVector = QVector2D(QPointF(0,rect.topLeft().y()-rect.bottomRight().y()));
        setCursor (Qt::SizeFDiagCursor);
        return rect.bottomRight ();
    } else if(vec.distanceToPoint (QVector2D(rect.bottomLeft ())) < 10) {
        mScaleXDirection = PosXAxis;
        mScaleYDirection = NegYAxis;
        if(mUniformScaleEnabled){
            mScaleType = Uniform;
        } else {
            mScaleType = BothXY;
        }
        mUniformXScaleVector = QVector2D(QPointF(rect.bottomLeft().x()-rect.topRight().x(),rect.bottomLeft().y()-rect.topRight().y()));
        setCursor (Qt::SizeBDiagCursor);
        return rect.topRight ();
    } else if(vec.distanceToPoint (QVector2D(rect.topRight ())) < 10) {
        mScaleXDirection = NegXAxis;
        mScaleYDirection = PosYAxis;
        if(mUniformScaleEnabled){
            mScaleType = Uniform;
        } else {
            mScaleType = BothXY;
        }
        setCursor (Qt::SizeBDiagCursor);
        mUniformXScaleVector = QVector2D(QPointF(rect.topRight().x()-rect.bottomLeft().x(),rect.topRight().y()-rect.bottomLeft().y()));
        return rect.bottomLeft ();
    } else if(vec.distanceToPoint (QVector2D(rect.bottomRight ())) < 10) {
        mScaleXDirection = NegXAxis;
        mScaleYDirection = NegYAxis;
        if(mUniformScaleEnabled){
            mScaleType = Uniform;
        } else {
            mScaleType = BothXY;
        }
        mUniformXScaleVector = QVector2D(QPointF(rect.bottomRight().x()-rect.topLeft().x(),rect.bottomRight().y()-rect.topLeft().y()));
        setCursor (Qt::SizeFDiagCursor);
        return rect.topLeft ();
    } else if(vec.distanceToPoint (QVector2D(QPointF(rect.bottomRight ().x()-(rect.width()/2),rect.bottomRight ().y()))) < 10) {
        mScaleYDirection = NegYAxis;
        mScaleType = OnlyY;
        setCursor (Qt::SizeVerCursor);
        return (QPointF(rect.topRight ().x()-(rect.width()/2),rect.topRight ().y()));
    } else if(vec.distanceToPoint (QVector2D(QPointF(rect.topRight ().x()-(rect.width()/2),rect.topRight ().y()))) < 10) {
        mScaleYDirection = PosYAxis;
        mScaleType = OnlyY;
        setCursor (Qt::SizeVerCursor);
        return (QPointF(rect.bottomRight ().x()-(rect.width()/2),rect.bottomRight ().y()));
    } else if(vec.distanceToPoint (QVector2D(QPointF(rect.bottomRight ().x(),rect.bottomRight ().y()-(rect.height()/2)))) < 10) {
        mScaleXDirection = NegXAxis;
        mScaleType = OnlyX;
        setCursor (Qt::SizeHorCursor);
        return (QPointF(rect.bottomLeft ().x(),rect.bottomLeft ().y()-(rect.height()/2)));
    } else if(vec.distanceToPoint (QVector2D(QPointF(rect.bottomLeft ().x(),rect.bottomLeft ().y()-(rect.height()/2)))) < 10) {
        mScaleXDirection = PosXAxis;
        mScaleType = OnlyX;
        setCursor (Qt::SizeHorCursor);
        return (QPointF(rect.bottomRight ().x(),rect.bottomRight ().y()-(rect.height()/2))) ;
    }

    mIsValidScaleOriginPoint = false;
    setCursor (Qt::ArrowCursor);
    return QPointF();
}