*** apps/konsole/src/TerminalDisplay.h.old	2009-10-13 16:01:21.000000000 +0900
--- apps/konsole/src/TerminalDisplay.h	2009-10-13 14:50:56.000000000 +0900
***************
*** 775,780 ****
--- 775,786 ----
      {
          QString preeditString;
          QRect previousPreeditRect;
+ #ifndef	ORIGINAL_CODE
+         int im_cursor;
+         int im_cursorlen;
+         QColor im_cursor_bg;
+ 	QColor im_cursor_ebg;
+ #endif
      };
      InputMethodData _inputMethodData;
  
*** apps/konsole/src/TerminalDisplay.cpp.old	2009-10-13 16:01:13.000000000 +0900
--- apps/konsole/src/TerminalDisplay.cpp	2009-10-13 15:59:04.000000000 +0900
***************
*** 40,45 ****
--- 40,48 ----
  #include <QtGui/QStyle>
  #include <QtCore/QTimer>
  #include <QtGui/QToolTip>
+ #ifndef	ORIGINAL_CODE
+ #include <QTextFormat>
+ #endif
  
  // KDE
  #include <kshell.h>
***************
*** 1227,1236 ****
--- 1237,1257 ----
      if ( preeditLength == 0 )
          return QRect();
  
+ #ifdef	ORIGINAL_CODE
      return QRect(_leftMargin + _fontWidth*cursorPosition().x(),
                   _topMargin + _fontHeight*cursorPosition().y(),
                   _fontWidth*preeditLength,
                   _fontHeight);
+ #else
+     QPoint tL  = contentsRect().topLeft();
+     int    tLx = tL.x();
+     int    tLy = tL.y();
+ 
+     return QRect(_leftMargin + tLx + _fontWidth*cursorPosition().x(),
+                  _topMargin + tLy + _fontHeight*cursorPosition().y(),
+                  _fontWidth*preeditLength,
+                  _fontHeight);
+ #endif
  }   
  
  void TerminalDisplay::drawInputMethodPreeditString(QPainter& painter , const QRect& rect)
***************
*** 1245,1255 ****
--- 1266,1321 ----
      const QColor foreground = _colorTable[DEFAULT_FORE_COLOR].color;
      const Character* style = &_image[loc(cursorPos.x(),cursorPos.y())];
  
+ #ifdef	ORIGINAL_CODE
      drawBackground(painter,rect,background,true);
      drawCursor(painter,rect,foreground,background,invertColors);
      drawCharacters(painter,rect,_inputMethodData.preeditString,style,invertColors);
  
      _inputMethodData.previousPreeditRect = rect; 
+ #else
+ 
+     QPoint tL  = contentsRect().topLeft();
+     int    tLx = tL.x();
+     int    tLy = tL.y();
+ 
+     Character pstyle = *style;
+     pstyle.rendition &= ~RE_BLINK;
+     pstyle.rendition |= RE_UNDERLINE;
+     drawBackground(painter, rect, background, true);
+     _inputMethodData.previousPreeditRect = rect;
+ 
+     // Yes, I know, it's stupid to draw a character one by one.
+     // Because some font width problems exists for Asian characters,
+     // we need to do it.
+     int preeditLength = string_width(_inputMethodData.preeditString);
+     for (int i = 0, pos = 0; i < preeditLength; i ++)
+     {
+        QString tmpstr = _inputMethodData.preeditString.mid(i, 1);
+        int charlen = string_width(tmpstr); 
+        QRect CharRect = QRect(_leftMargin + tLx + 
+                  _fontWidth*(cursorPosition().x() + pos),
+                  _topMargin + tLy + _fontHeight*cursorPosition().y(),
+                  _fontWidth * charlen,
+                  _fontHeight);
+        pos += charlen;
+   
+        invertColors = false;
+        if (i >= _inputMethodData.im_cursor && 
+            i < _inputMethodData.im_cursor + _inputMethodData.im_cursorlen)
+        {
+ 	       if (_inputMethodData.im_cursor_bg.isValid() == false)
+ 			_inputMethodData.im_cursor_bg = Qt::yellow;
+ 	       if (style->foregroundColor.color(_colorTable) == _inputMethodData.im_cursor_bg)
+ 		       invertColors = true;
+ 	       drawBackground(painter, CharRect, _inputMethodData.im_cursor_bg, true);
+        }
+        else
+ 	       drawBackground(painter, CharRect, background, true);
+ 
+        drawCharacters(painter, CharRect, tmpstr, &pstyle, invertColors);
+        _inputMethodData.previousPreeditRect |= CharRect;
+     }
+ #endif
  }
  
  FilterChain* TerminalDisplay::filterChain() const
***************
*** 2533,2538 ****
--- 2599,2643 ----
      emit keyPressedSignal(&keyEvent);
  
      _inputMethodData.preeditString = event->preeditString();
+ 
+ #ifndef	ORIGINAL_CODE
+     _inputMethodData.im_cursor = 0;
+     _inputMethodData.im_cursorlen = 0;
+     int decorationColumn = 0;
+     foreach (const QInputMethodEvent::Attribute &a, event->attributes()) 
+     {
+       if (a.type == QInputMethodEvent::Cursor) 
+       {
+ 	_inputMethodData.im_cursor = a.start;
+ 	if (a.length > 0)
+ 	   _inputMethodData.im_cursorlen = 1;
+       } 
+       else  if (a.type == QInputMethodEvent::TextFormat) 
+       {
+ 	// A special service for our UIM.
+ 	  QTextFormat f(qvariant_cast<QTextFormat>(a.value));
+ 	  QColor bg = f.background().color();
+ 	  if (_inputMethodData.im_cursor_ebg.isValid() == false &&
+     	      bg.isValid())
+ 		  _inputMethodData.im_cursor_ebg = bg;
+ 		
+           if (decorationColumn <= a.start)
+           {
+     		if (bg.isValid() &&
+ 		    bg != _inputMethodData.im_cursor_ebg)
+ 		{
+ 			_inputMethodData.im_cursor = a.start;
+ 			_inputMethodData.im_cursorlen = a.length;
+ 			_inputMethodData.im_cursor_bg = bg;
+ 			break;
+ 		}
+                 decorationColumn = a.start + a.length;
+           }
+       }
+     }
+ //    printf("cursor: %d\n", _inputMethodData.im_cursor);
+ #endif
+ 
      update(preeditRect() | _inputMethodData.previousPreeditRect);
      
      event->accept();
