Some more cleanup and comments from Iwami and myself.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17682 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-04-01 14:56:55 +00:00
parent ee47f918c2
commit 284e9efab7

View File

@ -607,9 +607,10 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
else else
stopBlinkingCursor(); stopBlinkingCursor();
// if last_width is last length of preedit string. // last_width : for checking if last preedit string was/wasn't empty.
static int last_width = 0; static bool last_width = false;
if (!last_width && preedit_string.empty()) { if (!last_width && preedit_string.empty()) {
// if last_width is last length of preedit string.
e->accept(); e->accept();
return; return;
} }
@ -628,25 +629,24 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
(height + 1) * preedit_lines_); (height + 1) * preedit_lines_);
if (preedit_string.empty()) { if (preedit_string.empty()) {
last_width = 0; last_width = false;
preedit_lines_ = 1; preedit_lines_ = 1;
e->accept(); e->accept();
return; return;
} }
last_width = true;
// FIXME: Describe these variables. // att : stores an IM attribute.
last_width = 1; QList<QInputMethodEvent::Attribute> const & att = e->attributes();
size_t cur_pos = 0;
size_t rStart = 0;
size_t rLength = 0;
int cur_visible = 0;
QList<QInputMethodEvent::Attribute> const & att(e->attributes());
// get attributes of input method cursor. // get attributes of input method cursor.
// cursor_pos : cursor position in preedit string.
size_t cursor_pos = 0;
bool cursor_is_visible = false;
for (int i = 0; i < att.size(); ++i) { for (int i = 0; i < att.size(); ++i) {
if (att.at(i).type == QInputMethodEvent::Cursor) { if (att.at(i).type == QInputMethodEvent::Cursor) {
cur_pos = att.at(i).start; cursor_pos = att.at(i).start;
cur_visible = att.at(i).length; cursor_is_visible = att.at(i).length != 0;
break; break;
} }
} }
@ -655,22 +655,26 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
// get position of selection in input method. // get position of selection in input method.
// FIXME: isn't there a way to do this simplier? // FIXME: isn't there a way to do this simplier?
if (cur_pos < preedit_length) { // rStart : cursor position in selected string in IM.
size_t rStart = 0;
// rLength : selected string length in IM.
size_t rLength = 0;
if (cursor_pos < preedit_length) {
for (int i = 0; i < att.size(); ++i) { for (int i = 0; i < att.size(); ++i) {
if (att.at(i).type == QInputMethodEvent::TextFormat) { if (att.at(i).type == QInputMethodEvent::TextFormat) {
if (att.at(i).start <= int(cur_pos) if (att.at(i).start <= int(cursor_pos)
&& int(cur_pos) < att.at(i).start + att.at(i).length) { && int(cursor_pos) < att.at(i).start + att.at(i).length) {
rStart = att.at(i).start; rStart = att.at(i).start;
rLength = att.at(i).length; rLength = att.at(i).length;
if (cur_visible == 0) if (!cursor_is_visible)
cur_pos += rLength; cursor_pos += rLength;
break; break;
} }
} }
} }
} }
else { else {
rStart = cur_pos; rStart = cursor_pos;
rLength = 0; rLength = 0;
} }
@ -696,11 +700,11 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
// FIXME: should be put out of the loop. // FIXME: should be put out of the loop.
if (pos >= rStart if (pos >= rStart
&& pos < rStart + rLength && pos < rStart + rLength
&& !(cur_pos < rLength && rLength == preedit_length)) && !(cursor_pos < rLength && rLength == preedit_length))
ps = Painter::preedit_selecting; ps = Painter::preedit_selecting;
if (pos == cur_pos if (pos == cursor_pos
&& (cur_pos < rLength && rLength == preedit_length)) && (cursor_pos < rLength && rLength == preedit_length))
ps = Painter::preedit_cursor; ps = Painter::preedit_cursor;
// draw one character and update cur_x. // draw one character and update cur_x.