示例#1
0
void MInputContext::update(Qt::InputMethodQueries queries)
{
    if (debug) qDebug() << InputContextName << "in" << __PRETTY_FUNCTION__;

    Q_UNUSED(queries) // fetching everything

    if (queries & Qt::ImPlatformData) {
        updateInputMethodExtensions();
    }

    bool effectiveFocusChange = false;
    if (queries & Qt::ImEnabled) {
        bool newAcceptance = inputMethodAccepted();
        if (newAcceptance && !active) {
            setFocusObject(QGuiApplication::focusObject());
            return;
        }

        if (newAcceptance != currentFocusAcceptsInput) {
            currentFocusAcceptsInput = newAcceptance;
            effectiveFocusChange = true;
        }
    }
    // get the state information of currently focused widget, and pass it to input method server
    QMap<QString, QVariant> stateInformation = getStateInformation();
    imServer->updateWidgetInformation(stateInformation, effectiveFocusChange);
}
void MInputContext::setFocusObject(QObject *focused)
{
    if (debug) qDebug() << InputContextName << "in" << __PRETTY_FUNCTION__ << focused;

    updateInputMethodExtensions();

    QWindow *newFocusWindow = qGuiApp->focusWindow();
    if (newFocusWindow != window.data()) {
       if (window) {
           disconnect(window.data(), SIGNAL(contentOrientationChanged(Qt::ScreenOrientation)),
                      this, SLOT(updateServerOrientation(Qt::ScreenOrientation)));
       }

       window = newFocusWindow;
       if (window) {
           connect(window.data(), SIGNAL(contentOrientationChanged(Qt::ScreenOrientation)),
                   this, SLOT(updateServerOrientation(Qt::ScreenOrientation)));
           updateServerOrientation(window->contentOrientation());
       }
    }

    bool oldAcceptInput = currentFocusAcceptsInput;
    currentFocusAcceptsInput = inputMethodAccepted();

    if (!active && currentFocusAcceptsInput) {
        imServer->activateContext();
        active = true;
        updateServerOrientation(newFocusWindow->contentOrientation());
    }

    if (active && (currentFocusAcceptsInput || oldAcceptInput)) {
        const QMap<QString, QVariant> stateInformation = getStateInformation();
        imServer->updateWidgetInformation(stateInformation, true);
    }

    if (inputPanelState == InputPanelShowPending && currentFocusAcceptsInput) {
        sipHideTimer.stop();
        imServer->showInputMethod();
        inputPanelState = InputPanelShown;
    }
}