Qt / QML-创建自定义QTouch3DInputHandler

时间:2018-08-21 08:38:44

标签: c++ qt inheritance qml

我正在尝试为要在触摸屏上运行的应用程序创建自定义输入处理程序。根据Q3DInputHandler的源代码,鼠标右键可以处理旋转。我想将旋转处理绑定到左侧按钮,因为我们的触摸屏只能处理单个右键单击,而不能单击并按住。

custominputhandler.h

class Q3DInputHandlerPrivate;
class custominputhandler : public QtDataVisualization::Q3DInputHandler
{
Q_OBJECT

public:
custominputhandler(QObject* src, QObject* parent = nullptr);
void mousePressEvent(QMouseEvent *event, const QPoint &mousePos);

private:
Q_DISABLE_COPY(custominputhandler)

QScopedPointer<Q3DInputHandlerPrivate> d_ptr;

和.cpp文件

custominputhandler.cpp
void custominputhandler::mousePressEvent(QMouseEvent *event, const QPoint &mousePos)
{
#if defined(Q_OS_IOS)
Q_UNUSED(event);
Q_UNUSED(mousePos);
#else
if (Qt::RightButton == event->button()){
    if (scene()->isSlicingActive()) {
        if (scene()->isPointInPrimarySubView(mousePos))
            setInputView(InputViewOnPrimary);
        else if (scene()->isPointInSecondarySubView(mousePos))
            setInputView(InputViewOnSecondary);
        else
            setInputView(InputViewNone);
    } else {
        // update mouse positions to prevent jumping when releasing or repressing a button
        setInputPosition(mousePos);
        scene()->setSelectionQueryPosition(mousePos);
        setInputView(InputViewOnPrimary);
        d_ptr->m_inputState = QAbstract3DInputHandlerPrivate::InputStateSelecting;
    }


    if (Qt::LeftButton == event->button()) {
        if (isRotationEnabled()) {
            // disable rotating when in slice view
            if (!scene()->isSlicingActive())
                d_ptr->m_inputState = QAbstract3DInputHandlerPrivate::InputStateRotating;
            // update mouse positions to prevent jumping when releasing or repressing a button
            setInputPosition(mousePos);
        }
    }
#endif
}
}

这有一些问题,即d_ptr包含来自私有头文件的对象。我的理解是,私有头文件永远不会被用户弄乱。

更改QML中的默认行为是否应该这么乏味?我感谢所有答案。

0 个答案:

没有答案