本文整理汇总了C++中qtouchevent::TouchPoint类的典型用法代码示例。如果您正苦于以下问题:C++ TouchPoint类的具体用法?C++ TouchPoint怎么用?C++ TouchPoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TouchPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateTouchPoint
void GestureEngine::updateTouchPoint(QTouchEvent::TouchPoint e)
{
gwc::touchpoint updated_point;
updated_point.init(e.id(), e.pos().x() / 1920, e.pos().y()/ 1080, 0, 1, 1);
updated_point.status = gwc::TOUCHUPDATE;
addEvent(updated_point);
}
示例2: update
bool QtPinchGestureRecognizer::update(const QTouchEvent::TouchPoint& point1, const QTouchEvent::TouchPoint& point2)
{
const qreal currentFingerDistance = QLineF(point1.screenPos(), point2.screenPos()).length();
switch (m_state) {
case NoGesture:
m_initialFingerDistance = currentFingerDistance;
m_state = GestureRecognitionStarted;
return false;
case GestureRecognitionStarted: {
const qreal pinchDistance = qAbs(currentFingerDistance - m_initialFingerDistance);
if (pinchDistance < pinchInitialTriggerDistanceThreshold)
return false;
m_state = GestureRecognized;
if (viewportController())
viewportController()->pinchGestureStarted(computePinchCenter(point1, point2));
// We reset the initial span distance to the current distance of the
// touch points in order to avoid the jump caused by the events which
// were skipped between the recognition start and the actual recognition.
m_initialFingerDistance = currentFingerDistance;
// fall through
}
case GestureRecognized:
const qreal totalScaleFactor = currentFingerDistance / m_initialFingerDistance;
const QPointF touchCenterInViewCoordinates = computePinchCenter(point1, point2);
if (viewportController())
viewportController()->pinchGestureRequestUpdate(touchCenterInViewCoordinates, totalScaleFactor);
return true;
break;
}
ASSERT_NOT_REACHED();
return false;
}
示例3: sceneEvent
bool PuzzleBoardItem::sceneEvent(QEvent *event)
{
if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd)
{
QTouchEvent *te = static_cast<QTouchEvent*>(event);
if (te->touchPoints().count() == 1)
{
QTouchEvent::TouchPoint tp = te->touchPoints().first();
QPointF diff = tp.screenPos() - this->game()->rotationGuideCoordinates();
if (abs(diff.x()) < 32 && abs(diff.y()) < 32)
{
event->ignore();
return false;
}
}
event->accept();
_game->handleTouchEvent(te);
if (!_autoRepainter->isActive())
update();
return true;
}
return QDeclarativeItem::sceneEvent(event);
}
示例4: removeTouchPoint
void GestureEngine::removeTouchPoint(QTouchEvent::TouchPoint e)
{
gwc::touchpoint removed_point;
removed_point.init(e.id(), e.pos().x() / 1920, e.pos().y()/ 1080, 0, 1, 1);
removed_point.status = gwc::TOUCHREMOVED;
addEvent(removed_point);
}
示例5: addTouchPoint
void GestureEngine::addTouchPoint(QTouchEvent::TouchPoint e)
{
gwc::touchpoint new_point;
new_point.init(e.id(), e.pos().x() / 1920, e.pos().y() / 1080, 0, 1920, 1080);
new_point.status = gwc::TOUCHADDED;
addEvent(new_point);
qDebug() << "Added to Gestureworks";
}
示例6: event
bool TreeViewTouch::event(QEvent *event) {
#if QT_VERSION >= 0x050000
if (event->type() == QEvent::TouchBegin && ((QTouchEvent*)event)->device()->type()==QTouchDevice::TouchScreen) {
#else
if (event->type() == QEvent::TouchBegin && ((QTouchEvent*)event)->deviceType()==QTouchEvent::TouchScreen) {
#endif
// Register that we may be scrolling, set the scroll mode to scroll-per-pixel
// and accept the event (return true) so that we will receive TouchUpdate and TouchEnd/TouchCancel
_touchScrollInProgress = true;
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
return true;
}
if (event->type() == QEvent::TouchUpdate && _touchScrollInProgress) {
QTouchEvent::TouchPoint p = ((QTouchEvent*)event)->touchPoints().at(0);
if (!_firstTouchUpdateHappened) {
// After the first movement of a Touch-Point, calculate the distance in both axis
// and if the point moved more horizontally abort scroll.
double dx = qAbs(p.lastPos().x() - p.pos().x());
double dy = qAbs(p.lastPos().y() - p.pos().y());
if (dx > dy) {
_touchScrollInProgress = false;
}
_firstTouchUpdateHappened = true;
}
// Apply touch movement to scrollbar
verticalScrollBar()->setValue(verticalScrollBar()->value() - (p.pos().y() - p.lastPos().y()));
return true;
}
#if QT_VERSION >= 0x050000
if (event->type() == QEvent::TouchEnd || event->type() == QEvent::TouchCancel) {
#else
if (event->type() == QEvent::TouchEnd) {
#endif
// End scroll and reset variables
_touchScrollInProgress = false;
_firstTouchUpdateHappened = false;
return true;
}
return QTreeView::event(event);
}
void TreeViewTouch::mousePressEvent(QMouseEvent *event) {
if (!_touchScrollInProgress)
QTreeView::mousePressEvent(event);
}
void TreeViewTouch::mouseMoveEvent(QMouseEvent *event) {
if (!_touchScrollInProgress)
QTreeView::mouseMoveEvent(event);
};
示例7: processTouchEvent
void MainGraphicsView::processTouchEvent(QTouchEvent *touchEvent) {
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
//qDebug("touch event %d count %d", event->type(), touchPoints.count());
if( touchPoints.count() > 1 ) {
this->has_kinetic_scroll = false;
this->single_left_mouse_down = false;
// can't trust last mouse position if more that one touch!
this->has_last_mouse = false;
}
#if QT_VERSION >= 0x050000
#ifdef Q_OS_ANDROID
// on Android with Qt 5, mouse events are never received, instead it's done purely via touch events
if( touchPoints.count() == 1 ) {
QTouchEvent::TouchPoint touchPoint = touchPoints.at(0);
int m_x = touchPoint.pos().x();
int m_y = touchPoint.pos().y();
if( touchEvent->type() == QEvent::TouchBegin ) {
this->mousePress(m_x, m_y);
}
else if( touchEvent->type() == QEvent::TouchEnd ) {
this->mouseRelease(m_x, m_y);
}
else if( touchEvent->type() == QEvent::TouchUpdate ) {
this->mouseMove(m_x, m_y);
}
}
#endif
#endif
if( touchPoints.count() == 2 ) {
// determine scale factor
const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
/*float scale_factor =
QLineF(touchPoint0.pos(), touchPoint1.pos()).length()
/ QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length();*/
QPointF touch_centre = (touchPoint0.pos() + touchPoint1.pos())*0.5;
QPointF zoom_centre = this->mapToScene(QPoint(touch_centre.x(), touch_centre.y()));
float scale_factor =
QLineF(touchPoint0.pos(), touchPoint1.pos()).length()
/ QLineF(touchPoint0.lastPos(), touchPoint1.lastPos()).length();
/*if (touchEvent->touchPointStates() & Qt::TouchPointReleased) {
// if one of the fingers is released, remember the current scale
// factor so that adding another finger later will continue zooming
// by adding new scale factor to the existing remembered value.
totalScaleFactor *= currentScaleFactor;
currentScaleFactor = 1;
}*/
/*setTransform(QTransform().scale(totalScaleFactor * currentScaleFactor,
totalScaleFactor * currentScaleFactor));*/
float n_scale = c_scale *scale_factor;
//LOG("multitouch scale: %f : %f\n", scale_factor, n_scale);
this->setScale(zoom_centre, n_scale);
}
}
示例8: activateTapHighlight
void QtWebPageEventHandler::activateTapHighlight(const QTouchEvent::TouchPoint& point)
{
#if ENABLE(TOUCH_EVENTS)
ASSERT(!point.pos().toPoint().isNull());
ASSERT(!m_isTapHighlightActive);
m_isTapHighlightActive = true;
QTransform fromItemTransform = m_webPage->transformFromItem();
m_webPageProxy->handlePotentialActivation(IntPoint(fromItemTransform.map(point.pos()).toPoint()), IntSize(point.rect().size().toSize()));
#else
Q_UNUSED(point);
#endif
}
示例9: createWebGestureEvent
WebGestureEvent WebEventFactory::createWebGestureEvent(const QTouchEvent::TouchPoint& point, const WebEvent::Type& gestureType, const QTransform& fromItemTransform)
{
WebEvent::Type type = gestureType;
IntPoint position = fromItemTransform.map(point.pos()).toPoint();
IntPoint screenPosition = point.screenPos().toPoint();
WebEvent::Modifiers modifiers = WebEvent::Modifiers(0);
double timestamp = 0;
IntSize area = IntSize(point.rect().size().toSize());
FloatPoint delta = FloatPoint(0, 0);
return WebGestureEvent(type, position, screenPosition, modifiers, timestamp, area, delta);
}
示例10: switch
QGestureRecognizer::Result
WebosTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object,
QEvent *event)
{
QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture;
WebosTapAndHoldGesture *q = static_cast<WebosTapAndHoldGesture *>(state);
if (object == state && event->type() == QEvent::Timer) {
q->stopTapTimer();
if (q->state() != Qt::NoGesture && q->state() != Qt::GestureCanceled) {
result = QGestureRecognizer::FinishGesture;
}
return result | QGestureRecognizer::ConsumeEventHint;
}
const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
//Todo Here use a const value to set up the timer interval but maybe need to use the Timeout value
//enum { TimerInterval = 700 };
enum { TapRadius = 40 };
switch (event->type()) {
case QEvent::TouchBegin:
q->setPosition(ev->touchPoints().at(0).startScreenPos());
q->setHotSpot(q->position());
q->stopTapTimer();
q->startTapTimer();
return QGestureRecognizer::TriggerGesture;
case QEvent::TouchEnd:
result = QGestureRecognizer::CancelGesture;
q->stopTapTimer();
break;
case QEvent::TouchUpdate:
if (q->tapTimerId() && ev->touchPoints().size() == 1) {
QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
QPoint delta = p.pos().toPoint() - p.startPos().toPoint();
if (delta.manhattanLength() > TapRadius) {
result = QGestureRecognizer::CancelGesture;
q->stopTapTimer();
} else {
result = QGestureRecognizer::Ignore;
}
} else if (ev->touchPoints().size() > 1) {
result = QGestureRecognizer::CancelGesture;
q->stopTapTimer();
} else {
result = QGestureRecognizer::Ignore;
}
break;
default:
return QGestureRecognizer::Ignore;
}
return result;
}
示例11: switch
QGestureRecognizer::Result
QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object,
QEvent *event)
{
QTapAndHoldGesture *q = static_cast<QTapAndHoldGesture *>(state);
QTapAndHoldGesturePrivate *d = q->d_func();
if (object == state && event->type() == QEvent::Timer) {
q->killTimer(d->timerId);
d->timerId = 0;
return QGestureRecognizer::Ignore | QGestureRecognizer::ConsumeEventHint;
}
const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture;
enum { TimerInterval = 2000 };
enum { TapRadius = 40 };
switch (event->type()) {
case QEvent::TouchBegin:
d->position = ev->touchPoints().at(0).pos();
if (d->timerId)
q->killTimer(d->timerId);
d->timerId = q->startTimer(TimerInterval);
result = QGestureRecognizer::TriggerGesture;
break;
case QEvent::TouchEnd:
if (d->timerId)
result = QGestureRecognizer::CancelGesture;
else
result = QGestureRecognizer::FinishGesture;
break;
case QEvent::TouchUpdate:
if (q->state() != Qt::NoGesture && ev->touchPoints().size() == 1) {
QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
QPoint delta = p.pos().toPoint() - p.startPos().toPoint();
if (delta.manhattanLength() <= TapRadius)
result = QGestureRecognizer::TriggerGesture;
}
break;
case QEvent::MouseButtonPress:
case QEvent::MouseMove:
case QEvent::MouseButtonRelease:
result = QGestureRecognizer::Ignore;
break;
default:
result = QGestureRecognizer::Ignore;
break;
}
return result;
}
示例12: touchStateToString
QDebug operator<<(QDebug dbg, const QTouchEvent::TouchPoint &s)
{
dbg.nospace() << "\"TouchPoint\":"
<< "{ \"id\":" << s.id()
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
<< ", \"primary\":\"" << (s.isPrimary() ? "true" : "false") << "\""
#endif
<< ", \"state\":" << touchStateToString(s.state())
<< ", \"pos\":\"" << s.pos() << "\""
<< ", \"pressure\":\"" << s.pressure() << "\""
<< " }";
return dbg.space();
}
示例13: switch
PlatformTouchPoint::PlatformTouchPoint(const QTouchEvent::TouchPoint& point)
{
// The QTouchEvent::TouchPoint API states that ids will be >= 0.
m_id = static_cast<unsigned>(point.id());
switch (point.state()) {
case Qt::TouchPointReleased: m_state = TouchReleased; break;
case Qt::TouchPointMoved: m_state = TouchMoved; break;
case Qt::TouchPointPressed: m_state = TouchPressed; break;
case Qt::TouchPointStationary: m_state = TouchStationary; break;
}
m_screenPos = point.screenPos().toPoint();
m_pos = point.pos().toPoint();
}
示例14: handlePotentialSingleTapEvent
void QtWebPageEventHandler::handlePotentialSingleTapEvent(const QTouchEvent::TouchPoint& point)
{
#if ENABLE(TOUCH_EVENTS)
if (point.pos() == QPointF()) {
// An empty point deactivates the highlighting.
m_webPageProxy->handlePotentialActivation(IntPoint(), IntSize());
} else {
QTransform fromItemTransform = m_webPage->transformFromItem();
m_webPageProxy->handlePotentialActivation(IntPoint(fromItemTransform.map(point.pos()).toPoint()), IntSize(point.rect().size().toSize()));
}
#else
Q_UNUSED(point);
#endif
}
示例15: buildWebSurface
bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) {
if (_currentWebCount >= MAX_CONCURRENT_WEB_VIEWS) {
qWarning() << "Too many concurrent web views to create new view";
return false;
}
qDebug() << "Building web surface";
++_currentWebCount;
// Save the original GL context, because creating a QML surface will create a new context
QOpenGLContext * currentContext = QOpenGLContext::currentContext();
QSurface * currentSurface = currentContext->surface();
_webSurface = new OffscreenQmlSurface();
_webSurface->create(currentContext);
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/controls/"));
_webSurface->load("WebView.qml");
_webSurface->resume();
_webSurface->getRootItem()->setProperty("url", _sourceUrl);
_webSurface->getRootContext()->setContextProperty("desktop", QVariant());
_connection = QObject::connect(_webSurface, &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) {
_texture = textureId;
});
// Restore the original GL context
currentContext->makeCurrent(currentSurface);
auto forwardPointerEvent = [=](const EntityItemID& entityItemID, const PointerEvent& event) {
if (entityItemID == getID()) {
handlePointerEvent(event);
}
};
_mousePressConnection = QObject::connect(renderer, &EntityTreeRenderer::mousePressOnEntity, forwardPointerEvent);
_mouseReleaseConnection = QObject::connect(renderer, &EntityTreeRenderer::mouseReleaseOnEntity, forwardPointerEvent);
_mouseMoveConnection = QObject::connect(renderer, &EntityTreeRenderer::mouseMoveOnEntity, forwardPointerEvent);
_hoverLeaveConnection = QObject::connect(renderer, &EntityTreeRenderer::hoverLeaveEntity, [=](const EntityItemID& entityItemID, const PointerEvent& event) {
if (this->_pressed && this->getID() == entityItemID) {
// If the user mouses off the entity while the button is down, simulate a touch end.
QTouchEvent::TouchPoint point;
point.setId(event.getID());
point.setState(Qt::TouchPointReleased);
glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi);
QPointF windowPoint(windowPos.x, windowPos.y);
point.setPos(windowPoint);
QList<QTouchEvent::TouchPoint> touchPoints;
touchPoints.push_back(point);
QTouchEvent* touchEvent = new QTouchEvent(QEvent::TouchEnd, nullptr, Qt::NoModifier, Qt::TouchPointReleased, touchPoints);
QCoreApplication::postEvent(_webSurface->getWindow(), touchEvent);
}
});
return true;
}