Beispiel #1
0
void QUimInputContext::updatePreedit()
{
    QString newString = getPreeditString();
    int cursor = getPreeditCursorPosition();
    int selLength = getPreeditSelectionLength();

    if ( newString.isEmpty() && ! isComposing() )
        return ;

    // Activating the IM
    if ( ! newString.isEmpty() && ! isComposing() )
        sendIMEvent( QEvent::IMStart );

    if ( ! newString.isEmpty() )
    {
#ifdef ENABLE_DEBUG
        qDebug( "cursor = %d, length = %d", cursor, newString.length() );
#endif
        sendIMEvent( QEvent::IMCompose, newString, cursor, selLength );
    }

    // Preedit's length is Zero, we should deactivate IM and
    // cancel the inputting, that is, sending IMEnd event with
    // empty string.
    if ( newString.isEmpty() && isComposing() )
        sendIMEvent( QEvent::IMEnd );
}
bool QHangulPlatformInputContext::backspace() {
    bool ret = hangul_ic_backspace(m_hic);
    if (ret) {
	QString str = getPreeditString();
	updatePreedit(str);
    }
    return ret;
}
Beispiel #3
0
void
CIMIClassicView::updateWindows(unsigned mask)
{
    if (!m_pWinHandler)
        return;

    if (mask & PREEDIT_MASK) {
        CPreEditString ps;
        getPreeditString (ps);
        m_pWinHandler->updatePreedit (&ps);
    }

    if ((mask & PREEDIT_MASK) || (mask & CANDIDATE_MASK)) {
        unsigned word_num = m_pIC->getBestSentence (m_tailSentence, m_candiFrIdx);
        if (word_num <= 1 || (!m_candiList.empty() && m_tailSentence == m_candiList[0].m_cwstr))
            m_tailSentence.clear ();          
    }

    if (mask & CANDIDATE_MASK) {
        CCandidateList cl;
        getCandidateList (cl, m_candiPageFirst, m_candiWindowSize);
        m_pWinHandler->updateCandidates (&cl);
    }
}
bool QHangulPlatformInputContext::filterEvent(const QEvent *event) {
    if (event->type() != QEvent::KeyPress)
	return false;

    const QKeyEvent *keyevent = static_cast<const QKeyEvent*>(event);
    if (m_candidateList != NULL && m_candidateList->isVisible()) {
	if (m_candidateList->filterEvent(keyevent)) {
	    if (m_candidateList->isSelected()) {
		hangul_ic_reset(m_hic);
		QString candidate(m_candidateList->getCandidate());
		commitText(candidate);
	    }
	    m_candidateList->close();
	}
	return true;
    }

    if (keyevent->key() == Qt::Key_Shift)
	return false;

    if (keyevent->key() == Qt::Key_Backspace)
	return backspace();

    if (isTriggerKey(keyevent)) {
	if (m_mode == MODE_DIRECT) {
	    m_mode = MODE_HANGUL;
	} else {
	    reset();
	    m_mode = MODE_DIRECT;
	}
	setModeInfo(m_mode);

	return true;
    }

    if (isCandidateKey(keyevent)) {
	return popupCandidateList();
    }

    if (keyevent->modifiers() & Qt::ControlModifier ||
	keyevent->modifiers() & Qt::AltModifier ||
	keyevent->modifiers() & Qt::MetaModifier) {
	reset();
	return false;
    }

    if (m_mode == MODE_HANGUL) {
	QString text = keyevent->text();
	if (keyevent->modifiers() & Qt::ShiftModifier)
	    text = text.toUpper();
	else
	    text = text.toLower();

	int ascii = 0;
	if (!text.isEmpty())
	    ascii = text[0].unicode();
	bool ret = hangul_ic_process(m_hic, ascii);

	QString commitString = getCommitString();
	if (!commitString.isEmpty())
	    commitText(commitString);

	QString preeditString = getPreeditString();
	if (!preeditString.isEmpty())
	    updatePreedit(preeditString);

	return ret;
    }

    return false;
}
void
CIMIClassicView::updateWindows(unsigned mask)
{
    if (!m_pWinHandler)
        return;

    if (mask & PREEDIT_MASK) {
        m_uiPreeditString.clear();
        getPreeditString(m_uiPreeditString);
        // m_pWinHandler->updatePreedit(&ps);
        handlerUpdatePreedit(&m_uiPreeditString);
    }

    if ((mask & PREEDIT_MASK) || (mask & CANDIDATE_MASK)) {
        // calculate all possible best sentences
        m_sentences.clear();
        int best_rank = -1;
        for (size_t i = 0; i < m_pIC->getNBest(); i++) {
            wstring sentence;
            unsigned word_num = m_pIC->getBestSentence(sentence, i,
                                                       m_candiFrIdx);
            if (word_num == 0) goto pass;  // when sentence is not worthy of

#ifdef DEBUG
            printf("%d ", i);
            print_wide(sentence.c_str());
            printf("\n");
#endif

            for (size_t j = 0; j < m_sentences.size(); j++) {
                if (sentence == m_sentences[j].second) goto pass;
            }

            if (best_rank < 0 && word_num > 1) {
                best_rank = i;
            }
            m_sentences.push_back(std::make_pair(i, sentence));
        pass:
            continue;
        }
        // build all possible tails with best_rank
        std::vector<CCandidates> tails =
            m_pIC->getBestSentenceTails(best_rank, m_candiFrIdx);
        m_tails.clear();
        for (size_t i = 0; i < tails.size(); i++) {
            CCandidates& tail = tails[i];
            wstring tail_text;
            // translate this tail into text
            for (size_t j = 0; j < tail.size(); j++) {
                tail_text += tail[j].m_cwstr;
            }
            m_tails.push_back(std::make_pair(tail_text, tail));
        }
    }

    if (mask & CANDIDATE_MASK) {
        m_uiCandidateList.clear();
        getCandidateList(m_uiCandidateList, m_candiPageFirst,
                         m_candiWindowSize);
        // m_pWinHandler->updateCandidates(&cl);
        handlerUpdateCandidates(&m_uiPreeditString, &m_uiCandidateList);
    }
}