qskinny/inputcontext/QskInputCompositionModel.cpp

91 lines
2.0 KiB
C++
Raw Normal View History

2018-02-06 13:55:35 +00:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
2017-07-21 16:21:34 +00:00
#include "QskInputCompositionModel.h"
2018-04-04 13:19:51 +00:00
#include "QskInputContext.h"
2017-07-21 16:21:34 +00:00
2018-04-20 06:52:26 +00:00
#include <QInputMethodQueryEvent>
2017-07-21 16:21:34 +00:00
2018-04-20 06:52:26 +00:00
QskInputCompositionModel::QskInputCompositionModel(
Attributes attributes, QskInputContext* context ):
2018-04-04 13:19:51 +00:00
QObject( context ),
2018-04-20 06:52:26 +00:00
m_attributes( attributes )
2017-07-21 16:21:34 +00:00
{
}
QskInputCompositionModel::~QskInputCompositionModel()
{
}
2018-04-04 13:19:51 +00:00
QskInputContext* QskInputCompositionModel::context() const
{
return qobject_cast< QskInputContext* >( parent() );
}
2018-04-20 06:52:26 +00:00
void QskInputCompositionModel::composeKey( const QString& text, int spaceLeft )
{
2018-04-20 06:52:26 +00:00
if ( candidateCount() > 0 )
2017-07-21 16:21:34 +00:00
{
2018-04-20 06:52:26 +00:00
m_preedit += text;
2018-04-20 06:52:26 +00:00
requestCandidates( m_preedit );
context()->sendText( m_preedit, false );
2018-04-20 06:52:26 +00:00
return;
}
2018-04-20 06:52:26 +00:00
requestCandidates( m_preedit );
2018-04-04 13:19:51 +00:00
2018-04-20 06:52:26 +00:00
QString txt;
if ( candidateCount() == 0 )
{
txt = m_preedit.left( spaceLeft );
spaceLeft -= txt.length();
2017-07-21 16:21:34 +00:00
}
2018-04-20 06:52:26 +00:00
else
2017-07-21 16:21:34 +00:00
{
2018-04-20 06:52:26 +00:00
txt = candidate( 0 );
--spaceLeft;
2017-07-21 16:21:34 +00:00
}
2018-04-20 06:52:26 +00:00
context()->sendText( txt, true );
m_preedit.clear();
resetCandidates();
2017-07-21 16:21:34 +00:00
2018-04-20 06:52:26 +00:00
if ( spaceLeft )
2017-07-21 16:21:34 +00:00
{
2018-04-20 06:52:26 +00:00
m_preedit = text;
requestCandidates( m_preedit );
if ( candidateCount() > 0 )
2017-07-21 16:21:34 +00:00
{
2018-04-20 06:52:26 +00:00
context()->sendText( m_preedit, false );
2017-07-21 16:21:34 +00:00
}
else
{
2018-04-20 06:52:26 +00:00
context()->sendText( m_preedit, true );
m_preedit.clear();
resetCandidates();
2017-07-21 16:21:34 +00:00
}
}
}
2018-04-20 06:52:26 +00:00
void QskInputCompositionModel::setPreeditText( const QString& text )
2017-07-21 16:21:34 +00:00
{
2018-04-20 06:52:26 +00:00
if ( text != m_preedit )
{
m_preedit = text;
requestCandidates( m_preedit );
}
2018-03-14 16:30:39 +00:00
}
2018-04-20 06:52:26 +00:00
void QskInputCompositionModel::reset()
2017-07-21 16:21:34 +00:00
{
2018-04-20 06:52:26 +00:00
m_preedit.clear();
resetCandidates();
2017-07-21 16:21:34 +00:00
}
#include "moc_QskInputCompositionModel.cpp"