Ejemplo n.º 1
0
QIBusPlatformInputContext::QIBusPlatformInputContext ()
    : d(new QIBusPlatformInputContextPrivate())
{
    if (d->context) {
        connect(d->context, SIGNAL(CommitText(QDBusVariant)), SLOT(commitText(QDBusVariant)));
        connect(d->context, SIGNAL(UpdatePreeditText(QDBusVariant,uint,bool)), this, SLOT(updatePreeditText(QDBusVariant,uint,bool)));
    }
QIBusPlatformInputContext::QIBusPlatformInputContext ()
    : d(new QIBusPlatformInputContextPrivate())
{
    if (d->context) {
        connect(d->context, SIGNAL(CommitText(QDBusVariant)), SLOT(commitText(QDBusVariant)));
        connect(d->context, SIGNAL(UpdatePreeditText(QDBusVariant,uint,bool)), this, SLOT(updatePreeditText(QDBusVariant,uint,bool)));
        connect(d->context, SIGNAL(DeleteSurroundingText(int,uint)), this, SLOT(deleteSurroundingText(int,uint)));
        connect(d->context, SIGNAL(RequireSurroundingText()), this, SLOT(surroundingTextRequired()));
    }
Ejemplo n.º 3
0
void Template::compileInclude(const std::string &_filename) {
	if ( m_cnt_include_depth >= INCLUDE_DEPTH_MAX )
	{
		commitText("\nTemplater error: max include depth reached (loop?)\n");
	} else {

		// Open new file and compile it recursively
		fir::ds::StaticCache::DataTagged &file = m_filecache.getData( fir::str::BuffPtr(_filename.c_str(), _filename.size()) );
		if ( ! file.exists ) {
			commitText("\nTEMPLATER ERROR: INCLUDE ERROR: CANNOT INCLUDE FILE: \"");
			commitText(_filename.c_str(), _filename.size());
			commitText("\"\n");
			return;
		}

		++ m_cnt_include_depth;
		compile( file.data );
		-- m_cnt_include_depth;
	}
}
void QHangulPlatformInputContext::reset() {
    if (m_candidateList != NULL && m_candidateList->isVisible()) {
	m_candidateList->close();
    }

    const ucschar *flushed = hangul_ic_flush(m_hic);

    // we do not send preedit update IMEvent
    // because commit() send InputMethodEnd event and it remove preedit string

    QString commitString = ucsToQString(flushed);
    if (!commitString.isEmpty()) {
	commitText(commitString);
    } else {
	updatePreedit("");
    }
}
bool QComposeInputContext::checkComposeTable()
{
    QVector<QComposeTableElement>::const_iterator it =
            std::lower_bound(m_composeTable.constBegin(), m_composeTable.constEnd(), m_composeBuffer, Compare());

    // prevent dereferencing an 'end' iterator, which would result in a crash
    if (it == m_composeTable.constEnd())
        it -= 1;

    QComposeTableElement elem = *it;
    // would be nicer if qLowerBound had API that tells if the item was actually found
    if (m_composeBuffer[0] != elem.keys[0]) {
#ifdef DEBUG_COMPOSING
        qDebug( "### no match ###" );
#endif
        reset();
        return false;
    }
    // check if compose buffer is matched
    for (int i=0; i < QT_KEYSEQUENCE_MAX_LEN; i++) {

        // check if partial match
        if (m_composeBuffer[i] == 0 && elem.keys[i]) {
#ifdef DEBUG_COMPOSING
            qDebug("### partial match ###");
#endif
            return true;
        }

        if (m_composeBuffer[i] != elem.keys[i]) {
#ifdef DEBUG_COMPOSING
            qDebug("### different entry ###");
#endif
            reset();
            return i != 0;
        }
    }
#ifdef DEBUG_COMPOSING
    qDebug("### match exactly ###");
#endif

    // check if the key sequence is overwriten - see the comment in
    // TableGenerator::orderComposeTable()
    int next = 1;
    do {
        // if we are at the end of the table, then we have nothing to do here
        if (it + next != m_composeTable.end()) {
            QComposeTableElement nextElem = *(it + next);
            if (isDuplicate(elem, nextElem)) {
                elem = nextElem;
                next++;
                continue;
            } else {
                break;
            }
        }
        break;
    } while (true);

    commitText(elem.value);
    reset();

    return true;
}
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;
}
Ejemplo n.º 7
0
bool Template::compile(fir::str::BuffPtr &_file)
{
	std::vector<Element*> stack_elem;

	if ( 0 == _file.ptr )
		return true;

	const char *p = _file.ptr;
	const char *end = _file.ptr + _file.size;
	const char *text_begin = p;

	for ( ; p < end; )
	{
		if ( '{' == *p ) {
			if ( (p + 1) < end && '{' == *(p + 1)) {

				bool token_end = false;
				//bool token_error = false;
				const char *text_end = p;


				p += 2;

				// skip mistaken '{'s (so, any number of { allowed)
				while( (p < end) && ('{' == *p) )
					++p;

				// Skip begin spaces
				while( (p < end) && (' ' == *p) )
					++p;

				if ( '}' == *p && (p + 1 < end) && '}' == p[1] ) {
					p += 2;
					token_end = true; //continue;
				}

				Element *new_element = nullptr;
				std::string include_filename;

				if ( ! token_end ) {
					// todo '}}' right here!
					auto new_p = parseToken(p, end, &new_element, include_filename);

					// no valid token found:
					// treat this as a text.
					if ( 0 == new_p ) {
						continue;
					}
					p = new_p;


					// Skip end spaces
					while( (p < end) && (' ' == *p) )
						++p;

					if ( '}' == *p && (p + 1 < end) && '}' == p[1] ) {
						p += 2;

						// skip mistaken '}'s
						while( (p < end) && ('}' == *p) )
							++p;

						//elem_end = p;
					} else {
						continue;
					}
				}




				commitText(text_begin, text_end - text_begin);
				text_begin = p;

				if ( include_filename.size() ) {
					compileInclude(include_filename);
				} else {
					commitElement(new_element, stack_elem);
				}
			}
		}

		++ p;
	}

	commitText(text_begin, p - text_begin);

	return true;
}
Ejemplo n.º 8
0
void Template::commitText(const char *_text)
{
	commitText(_text, strlen(_text));
}