I am working on a text editor written with C++ engine and Qt for UI. I want to allow the user to write with any of the input source ( keyboard of any language ). It was all good till the time I was supporting languages which has 1-1 keyboard mapping ( e.g. French/Russian keyboard ). I had an eventFilter
installed on my Qwidget
on which I was rendering the text and was capturing the keyboard inputs in QEvent::InputMethod
But when I started up with Asian languages ( like Japanese/Chinese ) I am not able to support all the features required for text editing with such language, a typical example of such case is the split underline when user writes some text with Japanese( Hiragana IME ) and presses space key which helps user in determining what all characters are to be replaced with the content on prediction dialog.See Image below: :
after struggling a while I figured out that Qt does not provide enough information about the splits or length of the string which is being replaced and I give up the idea to create all these visual appearance myself.
But then I discovered that some of the applications uses some OS specific input method to handle such complex text. An example is the OSX Finder, if we change the input method to Japanese ( Hiragana ) and start typing when a finder window is in focus, it pops up a floating window which accepts all my inputs and passes it to finder. See the image below
I dig more and I figured out that there was such a framework which was available earlier as Text Services Manager with a lot of documentation ( "http://mirror.informatimago.com/next/developer.apple.com/technotes/te/te_27.html#Downloads" ) which could have done this trick very easily for me BUT this API has been deprecated and no more available.
What I am looking for now is an alternative for this deprecated API. Do we have a cocoa API which can help me with bringing this operating system input method component for the easy text input?
Ok, I found the solution. I was ignorant to say that Qt does not provide enough information about these splits. Qt has a way to provide this support by using the caret position. So to conclude, the information of the text to be displayed can be easily retrieved by:
for( auto value : inEvent->attributes() )
{
if( value.type == QInputMethodEvent::Cursor )
{
std::cout<<" length "<< value.length;
std::cout<<" start "<< value.start;
}
}
Here, start is the position of the cursor. Once this position is clear, it is easy to determine how much length of text should be underlined so as to give clear indication to the user.