コード例 #1
0
ファイル: PointerEvent.cpp プロジェクト: ZappoMan/hifi
/**jsdoc
 * <p>A KeyboardModifiers value is used to specify which modifier keys on the keyboard are pressed. The value is the sum 
 * (bitwise OR) of the relevant combination of values from the following table:</p>
 * <table>
 *   <thead>
 *     <tr><th>Key</th><th>Hexadecimal value</th><th>Decimal value</th><th>Description</th></tr>
 *   </thead>
 *   <tbody>
 *     <tr><td>Shift</td><td><code>0x02000000</code></td><td><code>33554432</code></td>
 *         <td>A Shift key on the keyboard is pressed.</td></tr>
 *     <tr><td>Control</td><td><code>0x04000000</code></td><td><code>67108864</code></td>
 *         <td>A Control key on the keyboard is pressed.</td></tr>
 *     <tr><td>Alt</td><td><code>0x08000000</code></td><td><code>134217728</code></td>
 *         <td>An Alt key on the keyboard is pressed.</td></tr>
 *     <tr><td>Meta</td><td><code>0x10000000</code></td><td><code>268435456</code></td>
 *         <td>A Meta or Windows key on the keyboard is pressed.</td></tr>
 *     <tr><td>Keypad</td><td><code>0x20000000</code></td><td><code>536870912</code></td>
 *         <td>A keypad button is pressed.</td></tr>
 *     <tr><td>Group</td><td><code>0x40000000</code></td><td><code>1073741824</code></td>
 *         <td>X11 operating system only: An AltGr / Mode_switch key on the keyboard is pressed.</td></tr>
 *   </tbody>
 * </table>
 * @typedef {number} KeyboardModifiers
 */
QScriptValue PointerEvent::toScriptValue(QScriptEngine* engine, const PointerEvent& event) {
    QScriptValue obj = engine->newObject();

    switch (event._type) {
    case Press:
        obj.setProperty("type", "Press");
        break;
    case DoublePress:
        obj.setProperty("type", "DoublePress");
        break;
    case Release:
        obj.setProperty("type", "Release");
        break;
    default:
    case Move:
        obj.setProperty("type", "Move");
        break;
    };

    obj.setProperty("id", event._id);

    QScriptValue pos2D = engine->newObject();
    pos2D.setProperty("x", event._pos2D.x);
    pos2D.setProperty("y", event._pos2D.y);
    obj.setProperty("pos2D", pos2D);

    QScriptValue pos3D = engine->newObject();
    pos3D.setProperty("x", event._pos3D.x);
    pos3D.setProperty("y", event._pos3D.y);
    pos3D.setProperty("z", event._pos3D.z);
    obj.setProperty("pos3D", pos3D);

    QScriptValue normal = engine->newObject();
    normal.setProperty("x", event._normal.x);
    normal.setProperty("y", event._normal.y);
    normal.setProperty("z", event._normal.z);
    obj.setProperty("normal", normal);

    QScriptValue direction = engine->newObject();
    direction.setProperty("x", event._direction.x);
    direction.setProperty("y", event._direction.y);
    direction.setProperty("z", event._direction.z);
    obj.setProperty("direction", direction);

    bool isPrimaryButton = false;
    bool isSecondaryButton = false;
    bool isTertiaryButton = false;
    switch (event._button) {
    case NoButtons:
        obj.setProperty("button", "None");
        break;
    case PrimaryButton:
        obj.setProperty("button", "Primary");
        isPrimaryButton = true;
        break;
    case SecondaryButton:
        obj.setProperty("button", "Secondary");
        isSecondaryButton = true;
        break;
    case TertiaryButton:
        obj.setProperty("button", "Tertiary");
        isTertiaryButton = true;
        break;
    }

    if (isPrimaryButton) {
        obj.setProperty("isPrimaryButton", isPrimaryButton);
        obj.setProperty("isLeftButton", isPrimaryButton);
    }
    if (isSecondaryButton) {
        obj.setProperty("isSecondaryButton", isSecondaryButton);
        obj.setProperty("isRightButton", isSecondaryButton);
    }
    if (isTertiaryButton) {
        obj.setProperty("isTertiaryButton", isTertiaryButton);
        obj.setProperty("isMiddleButton", isTertiaryButton);
    }

    obj.setProperty("isPrimaryHeld", areFlagsSet(event._buttons, PrimaryButton));
    obj.setProperty("isSecondaryHeld", areFlagsSet(event._buttons, SecondaryButton));
    obj.setProperty("isTertiaryHeld", areFlagsSet(event._buttons, TertiaryButton));

    obj.setProperty("keyboardModifiers", QScriptValue(event.getKeyboardModifiers()));

    return obj;
}
コード例 #2
0
ファイル: Web3DOverlay.cpp プロジェクト: cozza13/hifi
void Web3DOverlay::handlePointerEventAsTouch(const PointerEvent& event) {
    if (!_webSurface) {
        return;
    }

    //do not send secondary button events to tablet
    if (event.getButton() == PointerEvent::SecondaryButton ||
        //do not block composed events
        event.getButtons() == PointerEvent::SecondaryButton) {
        return;
    }


    QPointF windowPoint;
    {
        glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi);
        windowPoint = QPointF(windowPos.x, windowPos.y);
    }

    Qt::TouchPointState state = Qt::TouchPointStationary;
    if (event.getType() == PointerEvent::Press && event.getButton() == PointerEvent::PrimaryButton) {
        state = Qt::TouchPointPressed;
    } else if (event.getType() == PointerEvent::Release) {
        state = Qt::TouchPointReleased;
    } else if (_activeTouchPoints.count(event.getID()) && windowPoint != _activeTouchPoints[event.getID()].pos()) {
        state = Qt::TouchPointMoved;
    }

    QEvent::Type touchType = QEvent::TouchUpdate;
    if (_activeTouchPoints.empty()) {
        // If the first active touch point is being created, send a begin
        touchType = QEvent::TouchBegin;
    } if (state == Qt::TouchPointReleased && _activeTouchPoints.size() == 1 && _activeTouchPoints.count(event.getID())) {
        // If the last active touch point is being released, send an end
        touchType = QEvent::TouchEnd;
    } 

    {
        QTouchEvent::TouchPoint point;
        point.setId(event.getID());
        point.setState(state);
        point.setPos(windowPoint);
        point.setScreenPos(windowPoint);
        _activeTouchPoints[event.getID()] = point;
    }

    QTouchEvent touchEvent(touchType, &_touchDevice, event.getKeyboardModifiers());
    {
        QList<QTouchEvent::TouchPoint> touchPoints;
        Qt::TouchPointStates touchPointStates;
        for (const auto& entry : _activeTouchPoints) {
            touchPointStates |= entry.second.state();
            touchPoints.push_back(entry.second);
        }

        touchEvent.setWindow(_webSurface->getWindow());
        touchEvent.setTarget(_webSurface->getRootItem());
        touchEvent.setTouchPoints(touchPoints);
        touchEvent.setTouchPointStates(touchPointStates);
    }

    // Send mouse events to the Web surface so that HTML dialog elements work with mouse press and hover.
    // FIXME: Scroll bar dragging is a bit unstable in the tablet (content can jump up and down at times).
    // This may be improved in Qt 5.8. Release notes: "Cleaned up touch and mouse event delivery".
    //
    // In Qt 5.9 mouse events must be sent before touch events to make sure some QtQuick components will
    // receive mouse events
    Qt::MouseButton button = Qt::NoButton;
    Qt::MouseButtons buttons = Qt::NoButton;
    if (event.getButton() == PointerEvent::PrimaryButton) {
        button = Qt::LeftButton;
    }
    if (event.getButtons() & PointerEvent::PrimaryButton) {
        buttons |= Qt::LeftButton;
    }

#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
    if (event.getType() == PointerEvent::Move) {
        QMouseEvent mouseEvent(QEvent::MouseMove, windowPoint, windowPoint, windowPoint, button, buttons, Qt::NoModifier);
        QCoreApplication::sendEvent(_webSurface->getWindow(), &mouseEvent);
    }
#endif

    if (touchType == QEvent::TouchBegin) {
        _touchBeginAccepted = QCoreApplication::sendEvent(_webSurface->getWindow(), &touchEvent);
    } else if (_touchBeginAccepted) {
        QCoreApplication::sendEvent(_webSurface->getWindow(), &touchEvent);
    }

    // If this was a release event, remove the point from the active touch points
    if (state == Qt::TouchPointReleased) {
        _activeTouchPoints.erase(event.getID());
    }

#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
    if (event.getType() == PointerEvent::Move) {
        QMouseEvent mouseEvent(QEvent::MouseMove, windowPoint, windowPoint, windowPoint, button, buttons, Qt::NoModifier);
        QCoreApplication::sendEvent(_webSurface->getWindow(), &mouseEvent);
    }
#endif
}