当前位置: 首页>>代码示例>>C++>>正文


C++ QMouseEvent::localPos方法代码示例

本文整理汇总了C++中QMouseEvent::localPos方法的典型用法代码示例。如果您正苦于以下问题:C++ QMouseEvent::localPos方法的具体用法?C++ QMouseEvent::localPos怎么用?C++ QMouseEvent::localPos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QMouseEvent的用法示例。


在下文中一共展示了QMouseEvent::localPos方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: eventFilter

bool OffscreenSurface::eventFilter(QObject* originalDestination, QEvent* event) {
    if (!filterEnabled(originalDestination, event)) {
        return false;
    }
#ifdef DEBUG
    // Don't intercept our own events, or we enter an infinite recursion
    {
        auto rootItem = _sharedObject->getRootItem();
        auto quickWindow = _sharedObject->getWindow();
        QObject* recurseTest = originalDestination;
        while (recurseTest) {
            Q_ASSERT(recurseTest != rootItem && recurseTest != quickWindow);
            recurseTest = recurseTest->parent();
        }
    }
#endif

    switch (event->type()) {
        case QEvent::KeyPress:
        case QEvent::KeyRelease: {
            event->ignore();
            if (QCoreApplication::sendEvent(_sharedObject->getWindow(), event)) {
                return event->isAccepted();
            }
            break;
        }

        case QEvent::Wheel: {
            QWheelEvent* wheelEvent = static_cast<QWheelEvent*>(event);
            QPointF transformedPos = mapToVirtualScreen(wheelEvent->pos());
            QWheelEvent mappedEvent(transformedPos, wheelEvent->delta(), wheelEvent->buttons(), wheelEvent->modifiers(),
                                    wheelEvent->orientation());
            mappedEvent.ignore();
            if (QCoreApplication::sendEvent(_sharedObject->getWindow(), &mappedEvent)) {
                return mappedEvent.isAccepted();
            }
            break;
        }
        case QEvent::MouseMove: {
            QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
            QPointF transformedPos = mapToVirtualScreen(mouseEvent->localPos());
            QMouseEvent mappedEvent(mouseEvent->type(), transformedPos, mouseEvent->screenPos(), mouseEvent->button(),
                                    mouseEvent->buttons(), mouseEvent->modifiers());
            if (event->type() == QEvent::MouseMove) {
                // TODO - this line necessary for the QML Tooltop to work (which is not currently being used), but it causes interface to crash on launch on a fresh install
                // need to investigate into why this crash is happening.
                //_qmlContext->setContextProperty("lastMousePosition", transformedPos);
            }
            mappedEvent.ignore();
            if (QCoreApplication::sendEvent(_sharedObject->getWindow(), &mappedEvent)) {
                return mappedEvent.isAccepted();
            }
            break;
        }
        default:
            break;
    }

    return false;
}
开发者ID:howard-stearns,项目名称:hifi,代码行数:60,代码来源:OffscreenSurface.cpp

示例2: eventFilter

bool DataWindow::eventFilter(QObject *object, QEvent *event)
{    
    //Detect double mouse clicks and move data marker to current mouse position
    if (object == ui->m_tableView_rawTableView->viewport() && event->type() == QEvent::MouseButtonDblClick) {
        QMouseEvent* mouseEventCast = static_cast<QMouseEvent*>(event);
        if(mouseEventCast->button() == Qt::LeftButton) {
            m_pDataMarker->move(mouseEventCast->localPos().x() + ui->m_tableView_rawTableView->verticalHeader()->width() + ui->m_tableView_rawTableView->x(), m_pDataMarker->y());

            //Deselect channel which was selected through the double click -> dirty hack
            //ui->m_tableView_rawTableView->selectionModel()->select(ui->m_tableView_rawTableView->selectionModel()->currentIndex(), QItemSelectionModel::Deselect);
        }
    }

    //Deactivate grabbing gesture when scrollbars or vertical header are selected
    if ((object == ui->m_tableView_rawTableView->horizontalScrollBar() ||
         object == ui->m_tableView_rawTableView->verticalScrollBar() ||
         object == ui->m_tableView_rawTableView->verticalHeader())
        && event->type() == QEvent::Enter) {
        QScroller::ungrabGesture(ui->m_tableView_rawTableView);
        return true;
    }

    //Activate grabbing gesture when scrollbars or vertical header are deselected
    if ((object == ui->m_tableView_rawTableView->horizontalScrollBar() ||
         object == ui->m_tableView_rawTableView->verticalScrollBar() ||
         object == ui->m_tableView_rawTableView->verticalHeader())
        && event->type() == QEvent::Leave) {
        QScroller::grabGesture(ui->m_tableView_rawTableView, QScroller::LeftMouseButtonGesture);
        return true;
    }

    //Look for swipe gesture in order to scale the channels
    if (object == ui->m_tableView_rawTableView && event->type() == QEvent::Gesture) {
        QGestureEvent* gestureEventCast = static_cast<QGestureEvent*>(event);
        return gestureEvent(static_cast<QGestureEvent*>(gestureEventCast));
    }

    return false;
}
开发者ID:BulatSuleymanoff,项目名称:mne-cpp,代码行数:39,代码来源:datawindow.cpp

示例3: eventFilter

bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
{
    if (obj != m_window)
        return false;

    QWaylandInputDevice *input = defaultInputDevice();

    switch (event->type()) {
    case QEvent::Expose:
        m_renderScheduler.start(0);
        if (m_window->isExposed()) {
            // Alt-tabbing away normally results in the alt remaining in
            // pressed state in the clients xkb state. Prevent this by sending
            // a release. This is not an issue in a "real" compositor but
            // is very annoying when running in a regular window on xcb.
            Qt::KeyboardModifiers mods = QGuiApplication::queryKeyboardModifiers();
            if (m_modifiers != mods && input->keyboardFocus()) {
                Qt::KeyboardModifiers stuckMods = m_modifiers ^ mods;
                if (stuckMods & Qt::AltModifier)
                    input->sendKeyReleaseEvent(64); // native scancode for left alt
                m_modifiers = mods;
            }
        }
        break;
    case QEvent::MouseButtonPress: {
        QPointF local;
        QMouseEvent *me = static_cast<QMouseEvent *>(event);
        QWaylandSurface *targetSurface = surfaceAt(me->localPos(), &local);
        if (m_dragKeyIsPressed && targetSurface) {
            m_draggingWindow = targetSurface;
            m_drag_diff = local;
        } else {
            if (targetSurface && input->keyboardFocus() != targetSurface) {
                input->setKeyboardFocus(targetSurface);
                m_surfaces.removeOne(targetSurface);
                m_surfaces.append(targetSurface);
                m_renderScheduler.start(0);
            }
            input->sendMousePressEvent(me->button(), local, me->localPos());
        }
        return true;
    }
    case QEvent::MouseButtonRelease: {
        QWaylandSurface *targetSurface = input->mouseFocus();
        if (m_draggingWindow) {
            m_draggingWindow = 0;
            m_drag_diff = QPointF();
        } else {
            QMouseEvent *me = static_cast<QMouseEvent *>(event);
            QPointF localPos;
            if (targetSurface)
                localPos = toSurface(targetSurface, me->localPos());
            input->sendMouseReleaseEvent(me->button(), localPos, me->localPos());
        }
        return true;
    }
    case QEvent::MouseMove: {
        QMouseEvent *me = static_cast<QMouseEvent *>(event);
        if (m_draggingWindow) {
            m_draggingWindow->setPos(me->localPos() - m_drag_diff);
            m_renderScheduler.start(0);
        } else {
            QPointF local;
            QWaylandSurface *targetSurface = surfaceAt(me->localPos(), &local);
            input->sendMouseMoveEvent(targetSurface, local, me->localPos());
        }
        break;
    }
    case QEvent::Wheel: {
        QWheelEvent *we = static_cast<QWheelEvent *>(event);
        input->sendMouseWheelEvent(we->orientation(), we->delta());
        break;
    }
    case QEvent::KeyPress: {
        QKeyEvent *ke = static_cast<QKeyEvent *>(event);
        if (ke->key() == Qt::Key_Meta || ke->key() == Qt::Key_Super_L) {
            m_dragKeyIsPressed = true;
        }
        m_modifiers = ke->modifiers();
        QWaylandSurface *targetSurface = input->keyboardFocus();
        if (targetSurface)
            input->sendKeyPressEvent(ke->nativeScanCode());
        break;
    }
    case QEvent::KeyRelease: {
        QKeyEvent *ke = static_cast<QKeyEvent *>(event);
        if (ke->key() == Qt::Key_Meta || ke->key() == Qt::Key_Super_L) {
            m_dragKeyIsPressed = false;
        }
        m_modifiers = ke->modifiers();
        QWaylandSurface *targetSurface = input->keyboardFocus();
        if (targetSurface)
            input->sendKeyReleaseEvent(ke->nativeScanCode());
        break;
    }
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    {
        QWaylandSurface *targetSurface = 0;
//.........这里部分代码省略.........
开发者ID:locusf,项目名称:qtwayland,代码行数:101,代码来源:qwindowcompositor.cpp

示例4: eventFilter

bool OffscreenSurface::eventFilter(QObject* originalDestination, QEvent* event) {
    if (!filterEnabled(originalDestination, event)) {
        return false;
    }
#ifdef DEBUG
    // Don't intercept our own events, or we enter an infinite recursion
    {
        auto rootItem = _sharedObject->getRootItem();
        auto quickWindow = _sharedObject->getWindow();
        QObject* recurseTest = originalDestination;
        while (recurseTest) {
            Q_ASSERT(recurseTest != rootItem && recurseTest != quickWindow);
            recurseTest = recurseTest->parent();
        }
    }
#endif

    switch (event->type()) {
        case QEvent::KeyPress:
        case QEvent::KeyRelease: {
            event->ignore();
            if (QCoreApplication::sendEvent(_sharedObject->getWindow(), event)) {
                return event->isAccepted();
            }
            break;
        }

        case QEvent::Wheel: {
            QWheelEvent* wheelEvent = static_cast<QWheelEvent*>(event);
            QPointF transformedPos = mapToVirtualScreen(wheelEvent->pos());
            QWheelEvent mappedEvent(transformedPos, wheelEvent->delta(), wheelEvent->buttons(), wheelEvent->modifiers(),
                                    wheelEvent->orientation());
            mappedEvent.ignore();
            if (QCoreApplication::sendEvent(_sharedObject->getWindow(), &mappedEvent)) {
                return mappedEvent.isAccepted();
            }
            break;
        }
        case QEvent::MouseMove: {
            QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
            QPointF transformedPos = mapToVirtualScreen(mouseEvent->localPos());
            QMouseEvent mappedEvent(mouseEvent->type(), transformedPos, mouseEvent->screenPos(), mouseEvent->button(),
                                    mouseEvent->buttons(), mouseEvent->modifiers());
            mappedEvent.ignore();
            if (QCoreApplication::sendEvent(_sharedObject->getWindow(), &mappedEvent)) {
                return mappedEvent.isAccepted();
            }
            break;
        }

#if defined(Q_OS_ANDROID)
        case QEvent::TouchBegin:
        case QEvent::TouchUpdate:
        case QEvent::TouchEnd: {
            QTouchEvent *originalEvent = static_cast<QTouchEvent *>(event);
            QEvent::Type fakeMouseEventType = QEvent::None;
            Qt::MouseButton fakeMouseButton = Qt::LeftButton;
            Qt::MouseButtons fakeMouseButtons = Qt::NoButton;
            switch (event->type()) {
                case QEvent::TouchBegin:
                    fakeMouseEventType = QEvent::MouseButtonPress;
                    fakeMouseButtons = Qt::LeftButton;
                    break;
                case QEvent::TouchUpdate:
                    fakeMouseEventType = QEvent::MouseMove;
                    fakeMouseButtons = Qt::LeftButton;
                    break;
                case QEvent::TouchEnd:
                    fakeMouseEventType = QEvent::MouseButtonRelease;
                    fakeMouseButtons = Qt::NoButton;
                    break;
            }
            // Same case as OffscreenUi.cpp::eventFilter: touch events are always being accepted so we now use mouse events and consider one touch, touchPoints()[0].
            QMouseEvent fakeMouseEvent(fakeMouseEventType, originalEvent->touchPoints()[0].pos(), fakeMouseButton, fakeMouseButtons, Qt::NoModifier);
            fakeMouseEvent.ignore();
            if (QCoreApplication::sendEvent(_sharedObject->getWindow(), &fakeMouseEvent)) {
                /*qInfo() << __FUNCTION__ << "sent fake touch event:" << fakeMouseEvent.type()
                        << "_quickWindow handled it... accepted:" << fakeMouseEvent.isAccepted();*/
                return fakeMouseEvent.isAccepted();
            }
            break;
        }
        case QEvent::InputMethod:
        case QEvent::InputMethodQuery: {
            auto window = getWindow();
            if (window && window->activeFocusItem()) {
                event->ignore();
                if (QCoreApplication::sendEvent(window->activeFocusItem(), event)) {
                    bool eventAccepted = event->isAccepted();
                    if (event->type() == QEvent::InputMethodQuery) {
                        QInputMethodQueryEvent *imqEvent = static_cast<QInputMethodQueryEvent *>(event);
                        // this block disables the selection cursor in android which appears in
                        // the top-left corner of the screen
                        if (imqEvent->queries() & Qt::ImEnabled) {
                            imqEvent->setValue(Qt::ImEnabled, QVariant(false));
                        }
                    }
                    return eventAccepted;
                }
                return false;
//.........这里部分代码省略.........
开发者ID:binaryking,项目名称:hifi,代码行数:101,代码来源:OffscreenSurface.cpp

示例5: recognize

QGestureRecognizer::Result SingleClickGestureRecognizer::recognize (QGesture* gesture, QObject* watched, QEvent* event)
{
    //g_message("%s", __PRETTY_FUNCTION__);
    QGestureRecognizer::Result result = QGestureRecognizer::Ignore;

    SingleClickGesture* singleClickGesture = static_cast<SingleClickGesture*>(gesture);

    static int s_tapRadius = -1;
    if (G_UNLIKELY(s_tapRadius < 0))
		s_tapRadius = Settings::LunaSettings()->tapRadius;

	static uint32_t s_lastDblClickTime = 0;

    if (watched == singleClickGesture && event->type() == QEvent::Timer) {
	singleClickGesture->stopSingleClickTimer();
	if (singleClickGesture->state() != Qt::GestureCanceled
		&& singleClickGesture->state() != Qt::GestureFinished)
	{
	    if (!singleClickGesture->m_mouseDown) {
		result = QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
	    }
	    else  {
		result |= QGestureRecognizer::ConsumeEventHint;
		singleClickGesture->m_triggerSingleClickOnRelease = true;
	    }
	    // if finger down at the same location for longer than the timer, 
	    // the single tap has to be triggered after the release
	}
	return result;
    }

    switch (event->type()) {
	case QEvent::TouchBegin:
	case QEvent::TouchUpdate:
	case QEvent::TouchEnd:
	    {
		if (singleClickGesture->state() == Qt::GestureStarted
			|| singleClickGesture->state() == Qt::GestureUpdated)
		{
		    QTouchEvent* touchEvent = static_cast<const QTouchEvent *>(event);
		    // this starts the gesture, so dont check existing state
		    if (touchEvent->touchPoints().size() > 1) {
			singleClickGesture->m_triggerSingleClickOnRelease = false;
			singleClickGesture->stopSingleClickTimer();
			result = QGestureRecognizer::CancelGesture;
		    }
		}
		break;
	    }

	case QEvent::MouseButtonPress:
	    {
		QMouseEvent* mouseEvent = static_cast<const QMouseEvent *>(event);
		singleClickGesture->stopSingleClickTimer();
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
        singleClickGesture->m_penDownPos = mouseEvent->posF();
#else
        singleClickGesture->m_penDownPos = mouseEvent->localPos();
#endif
        singleClickGesture->setHotSpot (mouseEvent->globalPos());
		singleClickGesture->m_mouseDown = true;
		singleClickGesture->m_triggerSingleClickOnRelease = false;
		singleClickGesture->m_modifiers = mouseEvent->modifiers();
		result = QGestureRecognizer::TriggerGesture;
		singleClickGesture->startSingleClickTimer();
		break;
	    }

	case QEvent::MouseMove:
	    if (singleClickGesture->state() == Qt::GestureStarted
		    || singleClickGesture->state() == Qt::GestureUpdated)
	    {
		QMouseEvent* mouseEvent = static_cast<const QMouseEvent *>(event);
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
		int moveDistance = (int) qAbs(QLineF (mouseEvent->posF(), singleClickGesture->m_penDownPos).length());
#else
        int moveDistance = (int) qAbs(QLineF (mouseEvent->localPos(), singleClickGesture->m_penDownPos).length());
#endif
		if (moveDistance > s_tapRadius)
		{
		    // move is outside tap radius or multiple fingers are down, so this is not a tap
		    singleClickGesture->stopSingleClickTimer();
		    singleClickGesture->m_triggerSingleClickOnRelease = false;
		    result = QGestureRecognizer::CancelGesture;
		}
	    }
	    break;

	case QEvent::MouseButtonRelease:
	    if (singleClickGesture->state() == Qt::GestureStarted
		    || singleClickGesture->state() == Qt::GestureUpdated) {
		    singleClickGesture->m_mouseDown = false;
		    if (singleClickGesture->m_triggerSingleClickOnRelease)  {
			result = QGestureRecognizer::FinishGesture;
			singleClickGesture->m_triggerSingleClickOnRelease = false;
		    }
	    }

            if(G_UNLIKELY(g_logSingleClick)){
                g_message("SYSMGR PERF: Single Click Occurred time:%d", Time::curTimeMs());
//.........这里部分代码省略.........
开发者ID:halfhalo,项目名称:luna-sysmgr,代码行数:101,代码来源:SingleClickGestureRecognizer.cpp

示例6: eventFilter

bool MainWindow::eventFilter(QObject *, QEvent *event)
{
    //char presentBirdType = myBirdManager->presentBird->getBirdType();

    if(event->type() == QEvent::MouseButtonPress && startPress == 1)
    {
        char presentBirdType = myBirdManager->presentBird->getBirdType();
        if (mousePress == 0  && presentBirdType == 'r'){
            // active the bird
            myBirdManager->bird_1->getBody()->SetActive(true);
            // ignore gravity
            myBirdManager->bird_1->getBody()->SetGravityScale(0);
            mousePress = 1;
            checkRelease = 0;
        }
        if (mousePress == 0  && presentBirdType == 'b'){
            myBirdManager->bird_2->getBody()->SetActive(true);
            myBirdManager->bird_2->getBody()->SetGravityScale(0);
            mousePress = 1;
            checkRelease = 0;
        }
        if (mousePress == 0  && presentBirdType == 'k'){
            myBirdManager->bird_3->getBody()->SetActive(true);
            myBirdManager->bird_3->getBody()->SetGravityScale(0);
            mousePress = 1;
            checkRelease = 0;
        }
        if (mousePress == 0  && presentBirdType == 'y'){
            myBirdManager->bird_4->getBody()->SetActive(true);
            myBirdManager->bird_4->getBody()->SetGravityScale(0);
            mousePress = 1;
            checkRelease = 0;
        }
    }
    if(event->type() == QEvent::MouseMove && startPress == 1)
    {
        char presentBirdType = myBirdManager->presentBird->getBirdType();
        // Move bird according to bird position
        if (mousePress == 1 && presentBirdType == 'r'){
            QMouseEvent *mouse =  (QMouseEvent*)event;
            // transform global QT cordinate to local b2 cordinate
            float32 moveX = mouse->localPos().x()/15;
            float32 moveY = (mouse->localPos().y()*(-1)+540)/15;
            myBirdManager->bird_1->getBody()->SetTransform(b2Vec2(moveX,moveY),0);
        }
        if (mousePress == 1 && presentBirdType == 'b'){
            QMouseEvent *mouse =  (QMouseEvent*)event;
            float32 moveX = mouse->localPos().x()/15;
            float32 moveY = (mouse->localPos().y()*(-1)+540)/15;
            myBirdManager->bird_2->getBody()->SetTransform(b2Vec2(moveX,moveY),0);
        }
        if (mousePress == 1 && presentBirdType == 'k'){
            QMouseEvent *mouse =  (QMouseEvent*)event;
            float32 moveX = mouse->localPos().x()/15;
            float32 moveY = (mouse->localPos().y()*(-1)+540)/15;
            myBirdManager->bird_3->getBody()->SetTransform(b2Vec2(moveX,moveY),0);
        }
        if (mousePress == 1 && presentBirdType == 'y'){
            QMouseEvent *mouse =  (QMouseEvent*)event;
            float32 moveX = mouse->localPos().x()/15;
            float32 moveY = (mouse->localPos().y()*(-1)+540)/15;
            myBirdManager->bird_4->getBody()->SetTransform(b2Vec2(moveX,moveY),0);
        }
    }
    if(event->type() == QEvent::MouseButtonRelease && startPress == 1)
    {
        char presentBirdType = myBirdManager->presentBird->getBirdType();
        if (checkRelease == 0 && presentBirdType == 'r'){
            // restore the gravity
            myBirdManager->bird_1->getBody()->SetGravityScale(1);
            // get bird pos
            int32 birdPosX = myBirdManager->bird_1->getBody()->GetPosition().x;
            int32 birdPosY = myBirdManager->bird_1->getBody()->GetPosition().y;
            // volicity = k * (slingshot center-pos)
            myBirdManager->bird_1->setLinearVelocity(b2Vec2( (11.76-birdPosX)*3, (12.5-birdPosY)*3) );
            mousePress = 0;
            checkRelease = 1;
            // load next bird
            // 2nd : run bird manager process
            myBirdManager->load(myBirdManager->bird_2);
            birdLeft -= 1;


        }
        if (checkRelease == 0 && presentBirdType == 'b'){
            myBirdManager->bird_2->getBody()->SetGravityScale(1);
            int32 birdPosX = myBirdManager->bird_2->getBody()->GetPosition().x;
            int32 birdPosY = myBirdManager->bird_2->getBody()->GetPosition().y;
            myBirdManager->bird_2->setLinearVelocity(b2Vec2( (11.76-birdPosX)*3, (12.5-birdPosY)*3) );
            mousePress = 0;
            checkRelease = 1;
            // load next bird
            // 3nd : run bird manager process
            myBirdManager->load(myBirdManager->bird_3);
            birdLeft -= 1;

        }
        if (checkRelease == 0 && presentBirdType == 'k'){
            myBirdManager->bird_3->getBody()->SetGravityScale(1);
            int32 birdPosX = myBirdManager->bird_3->getBody()->GetPosition().x;
//.........这里部分代码省略.........
开发者ID:cccccroge,项目名称:pd2-Angrybird,代码行数:101,代码来源:mainwindow.cpp


注:本文中的QMouseEvent::localPos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。