/* * MyInputMethod.cpp * * Created on: Jun 23, 2013 * Author: yiyu * QQ:1036184468 * Descriptoin: */ #include "MyInputMethod.h" #include #include #include #include #include #include #include #include #include "Public.h" MyInputMethod::MyInputMethod(QWidget *parent){ InputMethod *input = new InputMethod(this,parent); //QString filename = "WINPY_utf8.txt"; //qDebug()<<"File1:MyInputMethod";//; QString filename = Public::readLanguageType(); //qDebug()<<"File2:"<initInputMethod(filename); //qDebug()<<"File3:"<initInputMethod(filename); //qDebug()<<"SetInputFile:"<sendCommitString(str); #endif } void MyInputMethod::updateHandler ( int type ){ QWidget *widget = QApplication::focusWidget(); #ifndef Q_OS_WIN32 switch(type){ case QWSInputMethod::Update: case QWSInputMethod::FocusIn: if(widget && dynamic_cast(widget)){ if(digitalInput->isHidden()){ QRect rec = QApplication::desktop()->screenGeometry(); QPoint point = widget->mapToGlobal (QPoint(0,0)); //全局坐标 QRect myRec = digitalInput->geometry(); digitalInput->setGeometry((point.x() > rec.width()/2)?(point.x() - myRec.width() - 20):(point.x() + 20), (point.y() > rec.height()/2)?(point.y() - myRec.height() - 20):(point.y() + 20), myRec.width(),myRec.height()); digitalInput->show(); } } else { if(inputMethod->isHidden()){ //QCursor cursor(Qt::PointingHandCursor); //inputMethod->setCursor(cursor); QRect rec = QApplication::desktop()->screenGeometry(); QRect myRec = inputMethod->geometry(); if(widget){ QPoint point = widget->mapToGlobal (QPoint(0,0)); //全局坐标 if(point.y() < rec.height()/2) /*如果组件在上,则将输入法放在上面,否则放在下面*/ inputMethod->setGeometry(0,rec.height() - myRec.height(),myRec.width(),myRec.height()); // inputMethod->setGeometry(0,rec.height() - myRec.height()-12,myRec.width(),myRec.height()); else inputMethod->setGeometry(0,0,myRec.width(),myRec.height()); inputMethod->show(); } } } break; case QWSInputMethod::FocusOut: inputMethod->hide(); digitalInput->hide(); inputMethod->onHiden(); break; } #endif }