예제 #1
0
파일: InputAPI.cpp 프로젝트: katik/naali
void InputAPI::SetMouseCursorVisible(bool visible)
{
    if (framework->IsHeadless())
        return;

    if (mouseCursorVisible == visible)
        return;

    mouseCursorVisible = visible;
    if (mouseCursorVisible)
    {
        // We're showing the previously hidden mouse cursor. Restore the mouse cursor to the position where it
        // was when mouse was hidden.
        QApplication::restoreOverrideCursor();
        QCursor::setPos(mouseFPSModeEnterX, mouseFPSModeEnterY);

        ApplyMouseCursorOverride();
    }
    else
    {
        // Hide the mouse cursor and save up the coordinates where the mouse cursor was hidden.
        QApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
        mouseFPSModeEnterX = QCursor::pos().x();
        mouseFPSModeEnterY = QCursor::pos().y();
    }

    assert(framework->Ui() && framework->Ui()->GraphicsView());
    QGraphicsView *view = framework->Ui()->GraphicsView();
    QPoint mousePos = view->mapFromGlobal(QCursor::pos());
    lastMouseX = mousePos.x();
    lastMouseY = mousePos.y();
}
예제 #2
0
/*!
    Returns the scene-local coordinates if the \a gesturePoint is inside a
    graphics view.

    This functional might be useful when the gesture event is delivered to a
    QGraphicsObject to translate a point in screen coordinates to scene-local
    coordinates.

    \sa QPointF::isNull()
*/
QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const
{
    QWidget *w = widget();
    if (w) // we get the viewport as widget, not the graphics view
        w = w->parentWidget();
    QGraphicsView *view = qobject_cast<QGraphicsView*>(w);
    if (view) {
        return view->mapToScene(view->mapFromGlobal(gesturePoint.toPoint()));
    }
    return QPointF();
}
    QPointF viewportToItemPosition(const QPoint & pos, QWidget * widget)
    {
        QGraphicsView *view = 0;
        if (widget)
            view = qobject_cast<QGraphicsView *>(widget->parentWidget());

        if (view)
        {
            QTransform deviceTransform = item->deviceTransform(view->viewportTransform()).inverted();
            return deviceTransform.map(QPointF(view->mapFromGlobal(pos)));
        }

        return pos;
    }
예제 #4
0
파일: scroller.cpp 프로젝트: fluxer/katie
//Maps screen coordinates to scrollArea coordinates though current m_eventViewport widget 
QPointF ScrollerPrivate::mapToScrollArea(const QPoint &point)
{
    if (!m_scrollArea || !m_eventViewport)
        return point;

    QObject *vparent = m_eventViewport->parent();
    if (!vparent)
        return point;

    QGraphicsView *view = qobject_cast<QGraphicsView*>(vparent);
    if (!view)
        return point;

    QPoint pt = view->mapFromGlobal(point);
    return m_scrollArea->mapFromScene(view->mapToScene(pt));
}
예제 #5
0
/// \bug Due to not being able to restrict the mouse cursor to the window client are in any cross-platform means,
/// it is possible that if the screen is resized to very small and if the mouse is moved very fast, the cursor
/// escapes the window client area and will not get recentered.
void QtInputService::RecenterMouse()
{
    QGraphicsView *view = framework->GetUIView();
    QPoint centeredCursorPosLocal = QPoint(view->size().width()/2, view->size().height()/2);

    lastMouseX = centeredCursorPosLocal.x();
    lastMouseY = centeredCursorPosLocal.y();
    // This call might trigger an immediate mouse move message to the window, so set the mouse coordinates above.
    QPoint centeredCursorPosGlobal = view->mapToGlobal(centeredCursorPosLocal);
    if (centeredCursorPosGlobal == QCursor::pos())
        return; // If the mouse cursor already is at the center, don't do anything.
    QCursor::setPos(centeredCursorPosGlobal);

    // Double-check that the mouse cursor did end up where we wanted it to go.
    QPoint mousePos = view->mapFromGlobal(QCursor::pos());
    lastMouseX = mousePos.x();
    lastMouseY = mousePos.y();
}
예제 #6
0
void SCgInsertMode::activate()
{
    if (mInsertedObjectGroup)
    {
        delete mInsertedObjectGroup;
        mInsertedObjectGroup = 0;
    }

    const QMimeData* data = QApplication::clipboard()->mimeData();
    if (data->hasFormat(SCgWindow::SupportedPasteMimeType))
    {
        QDomDocument document;

        if (!document.setContent(data->data(SCgWindow::SupportedPasteMimeType)))
            return;

        // Read document
        GwfObjectInfoReader reader;
        if (!reader.read(document))
            return;

        //Place objects to scene
        TemplateSCgObjectsBuilder objectBuilder(mScene);
        objectBuilder.buildObjects(reader.objectsInfo());

        QList<SCgObject*> list = objectBuilder.objects();
        QList<QGraphicsItem*> withoutChilds;
        foreach(SCgObject* obj, list)
        {
            if (!obj->parentItem())
                withoutChilds.append(obj);
        }

        if(!withoutChilds.empty())
        {
            mInsertedObjectGroup = mScene->createItemGroup(withoutChilds);

            QGraphicsView* v = mScene->views().at(0);
            QPointF p = v->mapToScene(v->mapFromGlobal(QCursor::pos()));
            mInsertedObjectGroup->setPos(p);
            mInsertedObjectGroup->setOpacity(0.5);
        }
    }