本文整理汇总了C++中QVector2D::distanceToPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector2D::distanceToPoint方法的具体用法?C++ QVector2D::distanceToPoint怎么用?C++ QVector2D::distanceToPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVector2D
的用法示例。
在下文中一共展示了QVector2D::distanceToPoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mouseMoveEvent
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: getScaleOrigin
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();
}