/* * MyInputMethod.cpp * * Created on: Jun 23, 2013 * Author: yiyu * QQ:1036184468 * Descriptoin: */ #include "MyInputMethod.h" #include #include #include #include #include #include #include #include #include #include "Public.h" #include #include #include #include "InkJetPrinter.h" extern InkJetPrinter *pInkJectPrinter; MyInputMethod::MyInputMethod(QWidget *parent) :QObject(parent) { InputMethod *input = new InputMethod(this,parent); QString filename = Public::readLanguageType(); input->initInputMethod(filename); inputMethod = input; digitalInput = new DigitalInput(this,parent); } void MyInputMethod::SetInputFile(QString filename){ inputMethod->initInputMethod(filename); } InputMethod* MyInputMethod::getInputMethod() { return inputMethod; } //bool MyInputMethod::filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ){ // qDebug() << "MyInputMethod::filter "; // return true; //} MyInputMethod::~MyInputMethod(){ delete inputMethod; delete digitalInput; } void MyInputMethod::sendString(QString &str){ #ifndef Q_OS_WIN32 QWidget *watched = QApplication::focusWidget(); QSpinBox *qsb=qobject_cast(watched); QLineEdit *qle=qobject_cast(watched); QTextEdit *qte=qobject_cast(watched); if(qle)qle->insert(str); if(qte)qte->insertPlainText(str); if(qsb) { const QObjectList objectList=qsb->children(); foreach (QObject * const obj, objectList) { if(QLineEdit * const qcle=qobject_cast(obj)) { qcle->insert(str); break; } } } #endif } void MyInputMethod::updateHandler ( int type ){ QWidget *widget = QApplication::focusWidget(); #ifndef Q_OS_WIN32 switch(type){ case 0:break; case 1: if (widget && dynamic_cast(widget)) { int a = 0; } 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)); //全局坐标 QPoint topLeft=pInkJectPrinter->pos(); if(point.y() < rec.height()/2) /*如果组件在上,则将输入法放在上面,否则放在下面*/ inputMethod->setGeometry(topLeft.x(),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->setGeometry(topLeft.x(),30,myRec.width(),myRec.height()); inputMethod->show(); } } } break; case 2://QWSInputMethod::FocusOut: inputMethod->hide(); digitalInput->hide(); inputMethod->onHiden(); break; } #endif } void MyInputMethod::switchBangalInput(bool flag){ inputMethod->switchKeyBoardBengalDisply(flag); } #ifdef EnableArabic void MyInputMethod::getArabicFlag(bool flag){ inputMethod->setArabicDisplay(flag); } void MyInputMethod::getArabicPage(int page){ emit selectArabicPage(page); } void MyInputMethod::getEnglishOrAarbic(bool flag){ emit switchEnglishOrArabic(flag); } void MyInputMethod::switchArabicFlag(bool flag){ inputMethod->setSwitchArabicFlag(flag); } #endif void MyInputMethod::sendEvent(int key,Qt::KeyboardModifiers modifiers) { QKeyEvent pressEvent(QEvent::KeyPress, key, modifiers); QKeyEvent releaseEvent(QEvent::KeyRelease, key, modifiers); QCoreApplication::sendEvent(QApplication::focusWidget(), &pressEvent); QCoreApplication::sendEvent(QApplication::focusWidget(), &releaseEvent); }