本文整理汇总了C++中QPanGesture类的典型用法代码示例。如果您正苦于以下问题:C++ QPanGesture类的具体用法?C++ QPanGesture怎么用?C++ QPanGesture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPanGesture类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reset
void QPanGestureRecognizer::reset(QGesture *state)
{
QPanGesture *pan = static_cast<QPanGesture*>(state);
QPanGesturePrivate *d = pan->d_func();
d->lastOffset = d->offset = QPointF();
d->acceleration = 0;
QGestureRecognizer::reset(state);
}
示例2: recognize
QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state,
QObject *,
QEvent *event)
{
QPanGesture *q = static_cast<QPanGesture *>(state);
QPanGesturePrivate *d = q->d_func();
QGestureRecognizer::Result result = QGestureRecognizer::Ignore;
switch (event->type()) {
case QEvent::TouchBegin: {
const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
result = QGestureRecognizer::MayBeGesture;
QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
d->lastOffset = d->offset = QPointF();
d->pointCount = m_pointCount;
break;
}
case QEvent::TouchEnd: {
if (q->state() != Qt::NoGesture) {
const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
if (ev->touchPoints().size() == d->pointCount) {
d->lastOffset = d->offset;
d->offset = panOffset(ev->touchPoints(), d->pointCount);
}
result = QGestureRecognizer::FinishGesture;
} else {
result = QGestureRecognizer::CancelGesture;
}
break;
}
case QEvent::TouchUpdate: {
const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
if (ev->touchPoints().size() >= d->pointCount) {
d->lastOffset = d->offset;
d->offset = panOffset(ev->touchPoints(), d->pointCount);
if (d->offset.x() > 10 || d->offset.y() > 10 ||
d->offset.x() < -10 || d->offset.y() < -10) {
q->setHotSpot(ev->touchPoints().first().startScreenPos());
result = QGestureRecognizer::TriggerGesture;
} else {
result = QGestureRecognizer::MayBeGesture;
}
}
break;
}
default:
break;
}
return result;
}
示例3: if
bool View::gestureEvent(QGestureEvent* event)
{
//
// pinch has precedence
if (QGesture *pinchEvent = event->gesture(Qt::PinchGesture)) {
QPinchGesture* pinch = static_cast<QPinchGesture*>(pinchEvent);
//
// only pinch if the fingers have already moved a significant amount
qreal totalScaleFactor = pinch->totalScaleFactor();
if((totalScaleFactor < 0.66) || (totalScaleFactor > 1.5)){
qreal zoomDelta = pinch->scaleFactor();
qreal resultZoom = m_zoomFactor * zoomDelta;
if(resultZoom > s_maxZoomFactor){
zoomDelta = s_maxZoomFactor / m_zoomFactor;
}else if(resultZoom < s_minZoomFactor){
zoomDelta = s_minZoomFactor / m_zoomFactor;
}
// scale the view
scale(zoomDelta,zoomDelta);
m_zoomFactor *= zoomDelta;
return true;
}
}
//
// pan
if (QGesture *panEvent = event->gesture(Qt::PanGesture)) {
QPanGesture* pan = static_cast<QPanGesture*>(panEvent);
QPointF delta = pan->delta();
qreal factor = (1.0 / m_zoomFactor) * 0.9;
QScrollBar* vScrollBar = verticalScrollBar();
vScrollBar->setValue(vScrollBar->value() - int(delta.y()/factor));
QScrollBar* hScrollBar = horizontalScrollBar();
hScrollBar->setValue(hScrollBar->value() - int(delta.x()/factor));
}
return true;
}
示例4: reset
void MousePanGestureRecognizer::reset(QGesture *state)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
g->setLastOffset(QPointF());
g->setOffset(QPointF());
g->setAcceleration(0);
g->setProperty("startPos", QVariant());
g->setProperty("pressed", QVariant::fromValue<bool>(false));
g->setProperty("ignoreMousePress", QVariant::fromValue<bool>(false));
QGestureRecognizer::reset(state);
}
示例5: gestureEvent
void gestureEvent(QGestureEvent *event)
{
QPanGesture *pan = static_cast<QPanGesture *>(event->gesture(Qt::PanGesture));
if (pan) {
switch(pan->state()) {
case Qt::GestureStarted: qDebug() << this << "Pan: started"; break;
case Qt::GestureFinished: qDebug() << this << "Pan: finished"; break;
case Qt::GestureCanceled: qDebug() << this << "Pan: canceled"; break;
case Qt::GestureUpdated: break;
default: qDebug() << this << "Pan: <unknown state>"; break;
}
if (pan->state() == Qt::GestureStarted)
outside = false;
event->ignore();
event->ignore(pan);
if (outside)
return;
const QPointF delta = pan->delta();
const QPointF totalOffset = pan->offset();
QScrollBar *vbar = verticalScrollBar();
QScrollBar *hbar = horizontalScrollBar();
if ((vbar->value() == vbar->minimum() && totalOffset.y() > 10) ||
(vbar->value() == vbar->maximum() && totalOffset.y() < -10)) {
outside = true;
return;
}
if ((hbar->value() == hbar->minimum() && totalOffset.x() > 10) ||
(hbar->value() == hbar->maximum() && totalOffset.x() < -10)) {
outside = true;
return;
}
vbar->setValue(vbar->value() - delta.y());
hbar->setValue(hbar->value() - delta.x());
event->accept(pan);
}
}
示例6: recognize
QGestureRecognizer::Result QWinNativePanGestureRecognizer::recognize(QGesture *state,
QObject *,
QEvent *event)
{
QPanGesture *q = static_cast<QPanGesture*>(state);
QPanGesturePrivate *d = q->d_func();
QGestureRecognizer::Result result = QGestureRecognizer::Ignore;
if (event->type() == QEvent::NativeGesture) {
QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event);
switch(ev->gestureType) {
case QNativeGestureEvent::GestureBegin:
break;
case QNativeGestureEvent::Pan:
result = QGestureRecognizer::TriggerGesture;
event->accept();
break;
case QNativeGestureEvent::GestureEnd:
if (q->state() == Qt::NoGesture)
return QGestureRecognizer::Ignore; // some other gesture has ended
result = QGestureRecognizer::FinishGesture;
break;
default:
return QGestureRecognizer::Ignore;
}
if (q->state() == Qt::NoGesture) {
d->lastOffset = d->offset = QPointF();
d->startPosition = ev->position;
} else {
d->lastOffset = d->offset;
d->offset = QPointF(ev->position.x() - d->startPosition.x(),
ev->position.y() - d->startPosition.y());
}
}
return result;
}
示例7: recognize
QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
QPoint globalPos;
switch (event->type()) {
case QEvent::GraphicsSceneMousePress:
case QEvent::GraphicsSceneMouseDoubleClick:
case QEvent::GraphicsSceneMouseMove:
case QEvent::GraphicsSceneMouseRelease:
globalPos = static_cast<QGraphicsSceneMouseEvent *>(event)->screenPos();
break;
case QEvent::MouseButtonPress:
case QEvent::MouseMove:
case QEvent::MouseButtonRelease:
globalPos = static_cast<QMouseEvent *>(event)->globalPos();
break;
default:
break;
}
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick
|| event->type() == QEvent::GraphicsSceneMousePress || event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
g->setHotSpot(globalPos);
g->setProperty("startPos", globalPos);
g->setProperty("pressed", QVariant::fromValue<bool>(true));
return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
} else if (event->type() == QEvent::MouseMove || event->type() == QEvent::GraphicsSceneMouseMove) {
if (g->property("pressed").toBool()) {
QPoint offset = globalPos - g->property("startPos").toPoint();
g->setLastOffset(g->offset());
g->setOffset(QPointF(offset.x(), offset.y()));
return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
}
return QGestureRecognizer::CancelGesture;
} else if (event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::GraphicsSceneMouseRelease) {
return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
}
return QGestureRecognizer::Ignore;
}
示例8: FlipAnimationStart
bool ModelSelectionPane::event(QEvent *event)
{
#if 0
if(event->type() == QEvent::Gesture) {
LogManagerInst << LogManager::LogDegreeType_Normal << "QEvent::Gesture";
QGestureEvent* gestureEvent = static_cast<QGestureEvent*>(event);
QGesture *gesture = gestureEvent->gesture(Qt::PanGesture);
if(NULL == gestureEvent) {
LogManagerInst << LogManager::LogDegreeType_Error << "QEvent::Gesture is NULL";
}else {
QList<QGesture *> gestures = gestureEvent->gestures();
QList<QGesture *> activeGestures = gestureEvent->activeGestures();
LogManagerInst << "Gesture Value" << QString::number((int)gesture, 16);
LogManagerInst << LogManager::LogDegreeType_Normal << "Gesture Count" << QString::number(gestures.count()) << "activeGestures Count" << QString::number(activeGestures.count());
LogManagerInst << LogManager::LogDegreeType_Normal
<< (gestureEvent->gesture(Qt::TapGesture) != NULL?"TapGesture":"")
<< (gestureEvent->gesture(Qt::TapAndHoldGesture) != NULL?"TapAndHoldGesture":"")
<< ((NULL != gesture)?"PanGesture":"")
<< (gestureEvent->gesture(Qt::PinchGesture) != NULL?"PinchGesture":"")
<< (gestureEvent->gesture(Qt::SwipeGesture) != NULL?"SwipeGesture":"") ;
}
LogManagerInst << (gesture == NULL?"PanGesture == NULL":"PanGesture != NULL");
if(gesture != NULL) {
LogManagerInst << LogManager::LogDegreeType_Normal << "Handle Pan Gesture";
QPanGesture* panGesture = static_cast<QPanGesture*>(gesture);
LogManagerInst << LogManager::LogDegreeType_Normal << "Acceleration" << QString::number(panGesture->acceleration());
LogManagerInst << LogManager::LogDegreeType_Normal << "delta" << QString::number(panGesture->delta().x());
LogManagerInst << LogManager::LogDegreeType_Normal << "State" << QString::number(gesture->state());
if(gesture->state() == Qt::GestureFinished) {
if((panGesture->acceleration() > 2) || (panGesture->delta().x() > width()/2)) {
FlipAnimationStart(panGesture->delta().x() > 0 ? FlipDirection_Right : FlipDirection_Left);
}
} else {
LogManagerInst << LogManager::LogDegreeType_Normal << "Position" << QString::number(ui->itemsetpane->x());
QPoint targetPos = ui->itemsetpane->pos()+QPoint(panGesture->delta().x(),0);
if(targetPos.x() > width()/4) {
targetPos.setX(width()/4);
} else if(targetPos.x() < width() - m_itemSetPaneSize.width() - width()/4) {
targetPos.setX(width() - m_itemSetPaneSize.width() - width()/4);
} else {
}
ui->itemsetpane->move(targetPos);
}
}
}
#endif
#if 1
/*****
* 外面是阴天,我也成了阴天
* 狗屎的Gesture
* Document明明图示QPanGesture是一个手指
* 源码里却他妈的是3个
* 你他妈的逗我么
* 我就是个秀逗
* 明天dota只能用秀逗了
* 悲剧啊悲剧啊
* 我的时间
* 如同我的身体老去
*****/
bool flipAction = false;
static float last_x = 0.0f;
static float touchBeginLastX = 0.0f;
int deltaX = 0;
float acceleration = 0.0f;
switch(event->type()) {
#if 1
case QEvent::TouchBegin: {
LogManagerInst << LogManager::LogDegreeType_Normal << "TouchBegin";
flipAction = true;
m_time.start();
const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event);
QTouchEvent::TouchPoint touchPoint = touchEvent->touchPoints().first();
last_x = touchPoint.pos().x();
touchBeginLastX = touchPoint.pos().x();
}
break;
case QEvent::TouchUpdate: {
LogManagerInst << LogManager::LogDegreeType_Normal << "TouchUpdate";
flipAction = true;
const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event);
QTouchEvent::TouchPoint touchPoint = touchEvent->touchPoints().first();
deltaX = touchPoint.pos().x() - last_x;
last_x = touchPoint.pos().x();
}
break;
case QEvent::TouchEnd: {
LogManagerInst << LogManager::LogDegreeType_Normal << "TouchEnd";
flipAction = true;
const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event);
QTouchEvent::TouchPoint touchPoint = touchEvent->touchPoints().first();
int elapseTime = m_time.elapsed();
//.........这里部分代码省略.........
示例9: recognize
QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state,
QObject *,
QEvent *event)
{
QPanGesture *q = static_cast<QPanGesture *>(state);
QPanGesturePrivate *d = q->d_func();
const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
QGestureRecognizer::Result result;
switch (event->type()) {
case QEvent::TouchBegin: {
result = QGestureRecognizer::MayBeGesture;
QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
d->lastOffset = d->offset = QPointF();
break;
}
case QEvent::TouchEnd: {
if (q->state() != Qt::NoGesture) {
if (ev->touchPoints().size() == 2) {
QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
d->lastOffset = d->offset;
d->offset =
QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(),
p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2;
}
result = QGestureRecognizer::FinishGesture;
} else {
result = QGestureRecognizer::CancelGesture;
}
break;
}
case QEvent::TouchUpdate: {
if (ev->touchPoints().size() >= 2) {
QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
d->lastOffset = d->offset;
d->offset =
QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(),
p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2;
if (d->offset.x() > 10 || d->offset.y() > 10 ||
d->offset.x() < -10 || d->offset.y() < -10) {
q->setHotSpot(p1.startScreenPos());
result = QGestureRecognizer::TriggerGesture;
} else {
result = QGestureRecognizer::MayBeGesture;
}
}
break;
}
case QEvent::MouseButtonPress:
case QEvent::MouseMove:
case QEvent::MouseButtonRelease:
result = QGestureRecognizer::Ignore;
break;
default:
result = QGestureRecognizer::Ignore;
break;
}
return result;
}
示例10: recognize
QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
if (event->type() == QEvent::TouchBegin) {
// ignore the following mousepress event
g->setProperty("ignoreMousePress", QVariant::fromValue<bool>(true));
} else if (event->type() == QEvent::TouchEnd) {
g->setProperty("ignoreMousePress", QVariant::fromValue<bool>(false));
}
QMouseEvent *me = static_cast<QMouseEvent *>(event);
if (event->type() == QEvent::MouseButtonPress) {
if (g->property("ignoreMousePress").toBool())
return QGestureRecognizer::Ignore;
g->setHotSpot(me->globalPos());
g->setProperty("startPos", me->globalPos());
g->setProperty("pressed", QVariant::fromValue<bool>(true));
return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
} else if (event->type() == QEvent::MouseMove) {
if (g->property("pressed").toBool()) {
QPoint offset = me->globalPos() - g->property("startPos").toPoint();
g->setLastOffset(g->offset());
g->setOffset(QPointF(offset.x(), offset.y()));
return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
}
return QGestureRecognizer::CancelGesture;
} else if (event->type() == QEvent::MouseButtonRelease) {
if (g->property("pressed").toBool())
return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
}
return QGestureRecognizer::Ignore;
}
示例11: cos
//===============================================================
bool MousePanNZoomNavigator::eventFilter(QObject *widget, QEvent *e) {
// according to Qt's doc, this constant has been defined by wheel mouse vendors
// we need it to interpret the value of QWheelEvent->delta()
#define WHEEL_DELTA 120
if (e->type() == QEvent::Wheel &&
(((QWheelEvent *) e)->orientation() == Qt::Vertical)) {
GlMainWidget *g = (GlMainWidget *) widget;
if(((QWheelEvent *) e)->delta() < 0 && g->getScene()->getCamera().getZoomFactor() < 0.5f) {
return true;
}
g->getScene()->zoomXY(((QWheelEvent *) e)->delta() / WHEEL_DELTA,
((QWheelEvent *) e)->x(), ((QWheelEvent *) e)->y());
g->draw(false);
return true;
}
if(e->type() == QEvent::Gesture) {
GlMainWidget *g = (GlMainWidget *) widget;
QGestureEvent* gesture = (QGestureEvent*)e;
QPointF center;
//swipe events and pan events are never fired, known Qt bug
/*if(gesture->gesture(Qt::SwipeGesture)) {
QSwipeGesture* swipe = (QSwipeGesture*)gesture->gesture(Qt::SwipeGesture);
int x = cos(swipe->swipeAngle()) * swipe->property("velocity").toFloat();
int y = sin(swipe->swipeAngle()) * swipe->property("velocity").toFloat();
g->getScene()->translateCamera(x, y, 0);
}*/
if(gesture->gesture(Qt::PinchGesture)) {
QPinchGesture* pinch = (QPinchGesture*)gesture->gesture(Qt::PinchGesture);
Camera& camera = g->getScene()->getCamera();
//store the camera scale factor when starting the gesture
if(pinch->state() == Qt::GestureStarted) {
cameraScaleFactor = camera.getZoomFactor();
isGesturing = true;
}
if(pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) {
//only set the zoom factor if two events in a row were in the same direction (zoom in or out) to smooth a bit the effect.
if((pinch->lastScaleFactor() > 1 && pinch->scaleFactor() > 1) || (pinch->lastScaleFactor() <= 1 && pinch->scaleFactor() <= 1)) {
camera.setZoomFactor(cameraScaleFactor * pinch->totalScaleFactor());
}
}
if(pinch->changeFlags() & QPinchGesture::RotationAngleChanged) {
/*//backup the current camera center
Coord oldCenter = camera.getCenter();
Coord oldEye = camera.getEyes();
//sets the camera center to the center of the pich gesture
Coord rotationCenter(g->mapFromGlobal(pinch->centerPoint().toPoint()).x(), g->mapFromGlobal(pinch->centerPoint().toPoint()).y(), oldCenter.getZ());
Coord rotationEye=camera.getEyes()+(rotationCenter-oldCenter);
camera.setCenter(rotationCenter);
camera.setEyes(rotationEye);*/
//rotates the camera
camera.rotate((pinch->rotationAngle() - pinch->lastRotationAngle())/180*M_PI, 0, 0, 1);
/*
//restore old camera center and eyes
camera.setCenter(oldCenter);
camera.setEyes(oldEye); */
}
if(pinch->state() == Qt::GestureFinished) {
isGesturing = false;
}
if(gesture->gesture(Qt::PanGesture)) {
QPanGesture* pan = (QPanGesture*)gesture->gesture(Qt::PanGesture);
if(pan->state() == Qt::GestureStarted) {
isGesturing = true;
}
if(pan->state() == Qt::GestureFinished) {
isGesturing = false;
}
center = pan->delta();
g->getScene()->translateCamera(pan->delta().x(), -pan->delta().y(), 0);
}
}
g->draw(false);
return true;
}
return false;
}