160 lines
5.0 KiB
C++
160 lines
5.0 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 <QTableWidget>
|
|
#include "Public.h"
|
|
#include<iostream>
|
|
#include<string>
|
|
#include<QLineEdit>
|
|
#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<QSpinBox*>(watched);
|
|
QLineEdit *qle=qobject_cast<QLineEdit*>(watched);
|
|
QTextEdit *qte=qobject_cast<QTextEdit*>(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<QLineEdit *const >(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<QTableWidget *>(widget)) {
|
|
int a = 0;
|
|
}
|
|
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)); //全局坐标
|
|
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);
|
|
}
|