423QPointF QEventPoint::normalizedPosition()
const
428 auto geom = d->device->availableVirtualGeometry();
431 const QPointF p = globalPosition() - geom.topLeft();
432 return QPointF(p.x() / geom.width(), p.y() / geom.height());
509void QMutableEventPoint::update(
const QEventPoint &other, QEventPoint &target)
512 setPressure(target, other.pressure());
514 switch (other.state()) {
515 case QEventPoint::State::Pressed:
516 setGlobalPressPosition(target, other.globalPosition());
517 setGlobalLastPosition(target, other.globalPosition());
518 if (target.pressure() < 0)
519 setPressure(target, 1);
522 case QEventPoint::State::Released:
523 if (target.globalPosition() != other.globalPosition())
524 setGlobalLastPosition(target, target.globalPosition());
525 setPressure(target, 0);
529 if (target.globalPosition() != other.globalPosition())
530 setGlobalLastPosition(target, target.globalPosition());
531 if (target.pressure() < 0)
532 setPressure(target, 1);
536 setState(target, other.state());
537 setPosition(target, other.position());
538 setScenePosition(target, other.scenePosition());
539 setGlobalPosition(target, other.globalPosition());
540 setEllipseDiameters(target, other.ellipseDiameters());
541 setRotation(target, other.rotation());
542 setVelocity(target, other.velocity());
543 setUniqueId(target, other.uniqueId());
564void QMutableEventPoint::setTimestamp(QEventPoint &p, ulong t)
572 if (p.state() == QEventPoint::State::Pressed) {
573 p.d->pressTimestamp = t;
574 p.d->globalPressPos = p.d->globalPos;
576 if (p.d->timestamp == t)
583 QEventPointPrivate *pd = QPointingDevicePrivate::get(
584 const_cast<QPointingDevice *>(p.d->device))->pointById(p.id())->eventPoint.d.get();
585 if (t > pd->timestamp) {
586 pd->lastTimestamp = pd->timestamp;
588 if (p.state() == QEventPoint::State::Pressed)
589 pd->pressTimestamp = t;
590 if (pd->lastTimestamp > 0 && !p.device()->capabilities().testFlag(QInputDevice::Capability::Velocity)) {
592 QVector2D newVelocity = QVector2D(pd->globalPos - pd->globalLastPos) / (t - pd->lastTimestamp) * 1000;
595 static const float KalmanGain = 0.7f;
596 pd->velocity = newVelocity * KalmanGain + pd->velocity * (1.0f - KalmanGain);
597 qCDebug(lcPointerVel) <<
"velocity" << newVelocity <<
"filtered" << pd->velocity <<
598 "based on movement" << pd->globalLastPos <<
"->" << pd->globalPos <<
599 "over time" << pd->lastTimestamp <<
"->" << pd->timestamp;
602 p.d->lastTimestamp = pd->lastTimestamp;
603 p.d->velocity = pd->velocity;