Exemplo n.º 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();
        }
    }
}
Exemplo n.º 2
0
void WindPlot::mouseMoveEvent(
        QMouseEvent *event)
{
    if (QCPCurve *curve = qobject_cast<QCPCurve *>(plottable(0)))
    {
        QSharedPointer<QCPCurveDataContainer> data = curve->data();

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

        for (QCPCurveDataContainer::const_iterator it = data->constBegin();
             it != data->constEnd() && (it + 1) != data->constEnd();
             ++ it)
        {
            QPointF pt1 = QPointF(xAxis->coordToPixel(it->key),
                                  yAxis->coordToPixel(it->value));
            QPointF pt2 = QPointF(xAxis->coordToPixel((it + 1)->key),
                                  yAxis->coordToPixel((it + 1)->value));

            double mu;
            double dist = sqrt(distSqrToLine(pt1, pt2, event->pos(), mu));

            if (dist < resultDistance)
            {
                double t1 = it->t;
                double t2 = (it + 1)->t;

                resultTime = t1 + mu * (t2 - t1);
                resultDistance = dist;
            }
        }

        if (resultDistance < selectionTolerance())
        {
            mMainWindow->setMark(resultTime);
        }
        else
        {
            mMainWindow->clearMark();
        }
    }
}