本文整理汇总了C++中QQuickItem::keepMouseGrab方法的典型用法代码示例。如果您正苦于以下问题:C++ QQuickItem::keepMouseGrab方法的具体用法?C++ QQuickItem::keepMouseGrab怎么用?C++ QQuickItem::keepMouseGrab使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QQuickItem
的用法示例。
在下文中一共展示了QQuickItem::keepMouseGrab方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qInfo
bool
QcMapItem::send_mouse_event(QMouseEvent * event)
{
qInfo() << event;
QPointF local_position = mapFromScene(event->windowPos());
QQuickWindow * _window = window();
QQuickItem * grabber = _window ? _window->mouseGrabberItem() : nullptr;
// Fixme: faster ? / duplicated
bool is_mouse_area = !grabber or QString(grabber->metaObject()->className()).startsWith(QStringLiteral("QQuickMouseArea"));
bool steal_event = m_gesture_area->is_active(); // means pan or pinch is active
// grabber is QQuickMouseArea, steal_event is false first then true
// qInfo() << event << "\ngrabber" << grabber << "\nsteal_event" << steal_event << is_mouse_area;
if (is_mouse_area and (steal_event or contains(local_position)) and (!grabber or !grabber->keepMouseGrab())) {
QScopedPointer<QMouseEvent> mouseEvent(QQuickWindowPrivate::cloneMouseEvent(event, &local_position));
mouseEvent->setAccepted(false);
switch (mouseEvent->type()) {
case QEvent::MouseMove:
m_gesture_area->handle_mouse_move_event(mouseEvent.data());
break;
case QEvent::MouseButtonPress:
m_gesture_area->handle_mouse_press_event(mouseEvent.data());
break;
case QEvent::MouseButtonRelease:
m_gesture_area->handle_mouse_release_event(mouseEvent.data());
break;
default:
break;
}
steal_event = m_gesture_area->is_active(); // recheck value
// Fixme: duplicated code ???
grabber = _window ? _window->mouseGrabberItem() : nullptr;
// qInfo() << "grabber" << grabber << "\nsteal_event" << steal_event;
if (grabber and steal_event and !grabber->keepMouseGrab() and grabber != this) {
// qInfo() << "grab mouse";
grabMouse();
}
if (steal_event) {
event->setAccepted(true);
return true; // do not deliver event
} else
return false; // deliver event
} else {
// ungrab if necessary and deliver event
if (event->type() == QEvent::MouseButtonRelease
and (_window and _window->mouseGrabberItem() == this))
// qInfo() << "ungrab mouse";
ungrabMouse();
return false; // deliver event
}
}
示例2: sendMouseEvent
bool QQuickMouseArea::sendMouseEvent(QMouseEvent *event)
{
Q_D(QQuickMouseArea);
QPointF localPos = mapFromScene(event->windowPos());
QQuickWindow *c = window();
QQuickItem *grabber = c ? c->mouseGrabberItem() : 0;
bool stealThisEvent = d->stealMouse;
if ((stealThisEvent || contains(localPos)) && (!grabber || !grabber->keepMouseGrab())) {
QMouseEvent mouseEvent(event->type(), localPos, event->windowPos(), event->screenPos(),
event->button(), event->buttons(), event->modifiers());
mouseEvent.setAccepted(false);
switch (event->type()) {
case QEvent::MouseMove:
mouseMoveEvent(&mouseEvent);
break;
case QEvent::MouseButtonPress:
mousePressEvent(&mouseEvent);
break;
case QEvent::MouseButtonRelease:
mouseReleaseEvent(&mouseEvent);
stealThisEvent = d->stealMouse;
break;
default:
break;
}
grabber = c ? c->mouseGrabberItem() : 0;
if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this)
grabMouse();
return stealThisEvent;
}
if (event->type() == QEvent::MouseButtonRelease) {
if (d->pressed) {
d->pressed &= ~event->button();
emit pressedButtonsChanged();
if (!d->pressed) {
// no other buttons are pressed
d->stealMouse = false;
if (c && c->mouseGrabberItem() == this)
ungrabMouse();
emit canceled();
emit pressedChanged();
emit containsPressChanged();
if (d->hovered) {
d->hovered = false;
emit hoveredChanged();
}
}
}
}
return false;
}