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