135 lines
3.8 KiB
C++
135 lines
3.8 KiB
C++
/*
|
|
* MyInputMethod.cpp
|
|
*
|
|
* Created on: Jun 23, 2013
|
|
* Author: yiyu
|
|
* QQ:1036184468
|
|
* Descriptoin:
|
|
|
|
*/
|
|
|
|
|
|
#include "MyInputMethod.h"
|
|
#include <QDebug>
|
|
#include <QDesktopWidget>
|
|
#include <QCursor>
|
|
#include <QWidget>
|
|
#include <QPoint>
|
|
#include <QApplication>
|
|
#include <QSpinBox>
|
|
#include <QFile>
|
|
#include "Public.h"
|
|
#include<iostream>
|
|
#include<string>
|
|
|
|
MyInputMethod::MyInputMethod(QWidget *parent){
|
|
InputMethod *input = new InputMethod(this,parent);
|
|
//QString filename = "WINPY_utf8.txt";
|
|
//qDebug()<<"File1:MyInputMethod";//;
|
|
QString filename = Public::readLanguageType();
|
|
//qDebug()<<"File2:"<<filename;//;
|
|
input->initInputMethod(filename);
|
|
//qDebug()<<"File3:"<<filename;//;
|
|
inputMethod = input;
|
|
digitalInput = new DigitalInput(this,parent);
|
|
}
|
|
void MyInputMethod::SetInputFile(QString filename){
|
|
//InputMethod *input = new InputMethod(this,parent);
|
|
//QString filename = "WINPY_utf8.txt";
|
|
//QString filename = Public::readLanguageType();
|
|
inputMethod->initInputMethod(filename);
|
|
//qDebug()<<"SetInputFile:"<<filename;//;
|
|
//inputMethod = input;
|
|
}
|
|
|
|
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
|
|
this->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<QSpinBox *>(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->setGeometry(0,30,myRec.width(),myRec.height());
|
|
inputMethod->show();
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case 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
|