/* * *2013.9.12 括号错位修复 为了节约cpu最好改用映射方式 &仍未能显示出来 中文模式下小括号还是错位 */ /* Key_Backspace1 = 0x01001003, Key_Return1 = 0x01001004, Key_Enter1 = 0x01001005, Key_Insert1 = 0x01001006, Key_Delete1 = 0x01001007, Key_Clear1 = 0x0100100b, Key_Home1 = 0x01001010, // cursor movement Key_End1 = 0x01001011, Key_Left1 = 0x01001012, Key_Up1 = 0x01001013, Key_Right1 = 0x01001014, Key_Down1 = 0x01001015, Key_PageUp1 = 0x01001016, */ #include #include #include #include #include #include #include #include "MyInputMethod.h" #include "InputMethod.h" #include "ui_InputMethod.h" #include "Public.h" #include #include #include #include QHash *> *InputMethod::pinyinHash = NULL; QList InputMethod::pinyinHashKeys; QStringList InputMethod::pinyinHashQStringList; InputMethod::InputMethod(MyInputMethod *myInputMethod,QWidget *parent) : QWidget(parent,(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool)),//(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool)如果不设置标志,会抢焦点 ui(new Ui::InputMethod),spaceTimer(this) { //setWindowOpacity(0.9); this->myInputMethod = myInputMethod; ui->setupUi(this); currentInputMethodType = INPUT_METHOD_TYPE_ENGLISH; shiftFlag = false; pinyinPage = 0; bengalFlag = false; CapsFlag=false; CtrlFlag=false; #ifdef EnableArabic arabicFlag=false; englishOrArabicFlag=false; #endif /*---------------------------------------------------*/ labelInputTip.setParent(0,(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool)); //QFont font(Public::getFontFamily(24)); //font.setPixelSize(20); //labelInputTip.setFont(font); labelInputTip.setAlignment(Qt::AlignCenter); labelInputTip.setFrameShape(QFrame::Box); labelInputTip.setFrameShadow(QFrame::Sunken); labelInputTip.hide(); /*---------------------------------------------------*/ if(Public::ReadLanguageName() != "Chinese") ui->Key_InputMethodSelect->setEnabled(false); buttonConnect(ui->Key_QuoteLeft,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_one,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_two,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_three,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_four,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_five,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_six,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_seven,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_eight,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_nine,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_zero,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_Minus,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_Equal,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_BracketLeft,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_BracketRight,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_BackSlash,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_Semicolon,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_Apostrophe,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_Comma,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_Period,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_Slash,this,SLOT(onDigitalPunctuationClicked())); buttonConnect(ui->Key_Space,this,SLOT(onDigitalPunctuationClicked())); connect(ui->Key_Space, SIGNAL(pressed()), this, SLOT(spaceKeyPressed())); connect(ui->Key_Space, SIGNAL(released()), this, SLOT(spaceKeyRelease())); connect(&spaceTimer, SIGNAL(timeout()), this, SLOT(spaceKeyLongPressed())); connect(&backtimer, SIGNAL(timeout()), this, SLOT(backKeyLongPressed())); connect(&insertSpaceNumDialog,SIGNAL(accepted()),this,SLOT(onInsertSpaceNumDialogAccepted())); buttonConnect(ui->Key_A,this,SLOT(onCharClicked())); buttonConnect(ui->Key_B,this,SLOT(onCharClicked())); buttonConnect(ui->Key_C,this,SLOT(onCharClicked())); buttonConnect(ui->Key_D,this,SLOT(onCharClicked())); buttonConnect(ui->Key_E,this,SLOT(onCharClicked())); buttonConnect(ui->Key_F,this,SLOT(onCharClicked())); buttonConnect(ui->Key_G,this,SLOT(onCharClicked())); buttonConnect(ui->Key_H,this,SLOT(onCharClicked())); buttonConnect(ui->Key_I,this,SLOT(onCharClicked())); buttonConnect(ui->Key_J,this,SLOT(onCharClicked())); buttonConnect(ui->Key_K,this,SLOT(onCharClicked())); buttonConnect(ui->Key_L,this,SLOT(onCharClicked())); buttonConnect(ui->Key_M,this,SLOT(onCharClicked())); buttonConnect(ui->Key_N,this,SLOT(onCharClicked())); buttonConnect(ui->Key_O,this,SLOT(onCharClicked())); buttonConnect(ui->Key_P,this,SLOT(onCharClicked())); buttonConnect(ui->Key_Q,this,SLOT(onCharClicked())); buttonConnect(ui->Key_R,this,SLOT(onCharClicked())); buttonConnect(ui->Key_S,this,SLOT(onCharClicked())); buttonConnect(ui->Key_T,this,SLOT(onCharClicked())); buttonConnect(ui->Key_U,this,SLOT(onCharClicked())); buttonConnect(ui->Key_V,this,SLOT(onCharClicked())); buttonConnect(ui->Key_W,this,SLOT(onCharClicked())); buttonConnect(ui->Key_X,this,SLOT(onCharClicked())); buttonConnect(ui->Key_Y,this,SLOT(onCharClicked())); buttonConnect(ui->Key_Z,this,SLOT(onCharClicked())); buttonConnect(ui->Key_ShiftLeft,this,SLOT(onShiftClicked())); //buttonConnect(ui->Key_InputMethodSelect,this,SLOT(onInputMethodClicked())); connect(ui->Key_InputMethodSelect,SIGNAL(released()),this,SLOT(onInputMethodClicked())); buttonConnect(ui->Key_Backspace,this,SLOT(onBackspaceClicked())); buttonConnect(ui->Key_Last,this,SLOT(onKeyLastClicked())); buttonConnect(ui->Key_Next,this,SLOT(onKeyNextClicked())); buttonConnect(ui->Key_Enter,this,SLOT(onEnterClicked())); buttonConnect(ui->Key_Left,this,SLOT(onKeyLeftpressed())); buttonConnect(ui->Key_Down,this,SLOT(onKeyDownpressed())); buttonConnect(ui->Key_Up,this,SLOT(onKeyUppressed())); buttonConnect(ui->Key_Right,this,SLOT(onKeyRightpressed())); buttonConnect(ui->Key_Home,this,SLOT(onKeyHomepressed())); buttonConnect(ui->Key_End,this,SLOT(onKeyEndpressed())); buttonConnect(ui->Key_delete,this,SLOT(onKeydeletepressed())); buttonConnect(ui->Key_SpecialChar,this,SLOT(onKeySpecialCharpressed())); //connect(ui->Key_SpecialChar,SIGNAL(pressed()),this,SLOT(onInputMethodClicked())); buttonConnect(ui->Key_Ctrl,this,SLOT(onKeyCtrlpressed())); buttonConnect(ui->pushButtonCaps,this,SLOT(onpushButtonCapspressed())); /*----------------------------------------------------------------------------------------------*/ hanziDisplayLabels[0] = ui->hanzi_1ch; hanziDisplayLabels[1] = ui->hanzi_2ch; hanziDisplayLabels[2] = ui->hanzi_3ch; hanziDisplayLabels[3] = ui->hanzi_4ch; hanziDisplayLabels[4] = ui->hanzi_5ch; for(int i = 0; i < HANZI_SELECT_NUM; i++){ //担心用户改动HANZI_SELECT_NUM却没改动上面 if(!hanziDisplayLabels[i]) QMessageBox::critical((QWidget *)0,tr("错误"),tr("hanziDisplayLabels缺少初始化")); else{ hanziDisplayLabels[i]->setText(""); connect(hanziDisplayLabels[i],SIGNAL(pressed()),this,SLOT(onHanziLabelClicked())); } } userPinyinInputAppending = false; currPinyinList = 0; hide(); hanZiLabelVisibleEnable = true; ctrlAppending = false; setHanziLabelVisible(false); //keyMap.insert("(","("); //keyMap.insert(")",")"); keyMap.insert("(","("); keyMap.insert(")",")"); keyMap.insert("[","["); keyMap.insert("]","]"); keyMap.insert("{","{"); keyMap.insert("}","}"); keyMap.insert("【","【"); keyMap.insert("】","】"); keyMap.insert("『","『"); keyMap.insert("』","』"); //keyMap.insert("《","《"); //keyMap.insert("》","》"); keyMap.insert("《","《"); keyMap.insert("》","》"); //keyMap.insert("<","<"); //keyMap.insert(">",">"); keyMap.insert("<","<"); keyMap.insert(">",">"); keyMap.insert("&","&&"); keyMap.insert("&&","&"); //keyMap.insert("(","("); //keyMap.insert(")",")"); keyMap.insert("(","("); keyMap.insert(")",")"); keyMap.insert("1","1"); keyMap.insert("2","2"); keyMap.insert("3","3"); keyMap.insert("4","4"); keyMap.insert("5","5"); keyMap.insert("6","6"); keyMap.insert("7","7"); keyMap.insert("8","8"); keyMap.insert("9","9"); keyMap.insert("0","0"); keyMap.insert("`","`"); keyMap.insert("~","~"); keyMap.insert("·","·"); keyMap.insert("~","~");//中文 keyMap.insert("!","!"); keyMap.insert("!","!");//中文 keyMap.insert("@","@"); keyMap.insert("#","#"); keyMap.insert("$","$"); keyMap.insert("¥","¥"); keyMap.insert("%","%"); keyMap.insert("^","^"); keyMap.insert("…","…"); keyMap.insert("*","*"); keyMap.insert("-","-"); keyMap.insert("_","_"); keyMap.insert("—","—");//中文 keyMap.insert("+","+"); keyMap.insert("=","="); keyMap.insert("\\","\\"); keyMap.insert("|","|"); keyMap.insert("、","、");//中文 keyMap.insert(";",";"); keyMap.insert(":",":"); keyMap.insert(":",":");//中文 keyMap.insert("'","'"); keyMap.insert("\"","\""); keyMap.insert("‘","‘"); keyMap.insert("“","“"); keyMap.insert(",",","); keyMap.insert(",",",");//中文 keyMap.insert(".","."); keyMap.insert("。","。");//中文 keyMap.insert("/","/"); keyMap.insert("?","?"); keyMap.insert("?","?");//中文 keyMap.insert("1","1"); keyMap.insert("2","2"); keyMap.insert("3","3"); keyMap.insert("4","4"); keyMap.insert("5","5"); keyMap.insert("6","6"); keyMap.insert("7","7"); keyMap.insert("8","8"); keyMap.insert("9","9"); keyMap.insert("0","0"); #ifdef EnableArabic keyMap.insert("11","١"); keyMap.insert("12","٢"); keyMap.insert("13","٣"); keyMap.insert("14","٤"); keyMap.insert("15","٥"); keyMap.insert("16","٦"); keyMap.insert("17","٧"); keyMap.insert("18","٨"); keyMap.insert("19","٩"); keyMap.insert("20","٠"); #endif keyMap.insert("a","a"); keyMap.insert("b","b"); keyMap.insert("c","c"); keyMap.insert("d","d"); keyMap.insert("e","e"); keyMap.insert("f","f"); keyMap.insert("g","g"); keyMap.insert("h","h"); keyMap.insert("i","i"); keyMap.insert("j","j"); keyMap.insert("k","k"); keyMap.insert("l","l"); keyMap.insert("m","m"); keyMap.insert("n","n"); keyMap.insert("o","o"); keyMap.insert("p","p"); keyMap.insert("q","q"); keyMap.insert("r","r"); keyMap.insert("s","s"); keyMap.insert("t","t"); keyMap.insert("u","u"); keyMap.insert("v","v"); keyMap.insert("w","w"); keyMap.insert("x","x"); keyMap.insert("y","y"); keyMap.insert("z","z"); keyMap.insert("a","A"); keyMap.insert("b","B"); keyMap.insert("c","C"); keyMap.insert("d","D"); keyMap.insert("e","E"); keyMap.insert("f","F"); keyMap.insert("g","G"); keyMap.insert("h","H"); keyMap.insert("i","I"); keyMap.insert("j","J"); keyMap.insert("k","K"); keyMap.insert("l","L"); keyMap.insert("m","M"); keyMap.insert("n","N"); keyMap.insert("o","O"); keyMap.insert("p","P"); keyMap.insert("q","Q"); keyMap.insert("r","R"); keyMap.insert("s","S"); keyMap.insert("t","T"); keyMap.insert("u","U"); keyMap.insert("v","V"); keyMap.insert("w","W"); keyMap.insert("x","X"); keyMap.insert("y","Y"); keyMap.insert("z","Z"); } InputMethod::~InputMethod() { delete ui; if(InputMethod::pinyinHash != NULL){ /**/ QHash *>::const_iterator i = InputMethod::pinyinHash->constBegin(); while (i != InputMethod::pinyinHash->constEnd()) { delete (QList *)i.value(); } delete InputMethod::pinyinHash; } } void InputMethod::buttonConnect( QPushButton *sender, const QObject *receiver, const char *member){ sender->setObjectName(sender->text()); connect(sender, SIGNAL(pressed()),receiver, member); connect(sender, SIGNAL(pressed()),this, SLOT(onKeyPressed())); connect(sender, SIGNAL(released()),this, SLOT(onKeyReleased())); } void InputMethod::spaceKeyPressed(){ spaceTimer.start(700); } void InputMethod::spaceKeyRelease(){ spaceTimer.stop(); } void InputMethod::spaceKeyLongPressed(){ spaceTimer.stop(); insertSpaceNumDialog.show(); } void InputMethod::onInsertSpaceNumDialogAccepted(){ int spaceNum = insertSpaceNumDialog.getSpinBoxSpaceNum()->value() - 1; for(int i = 0; i < spaceNum; i++){ userInputed(" "); } } void InputMethod::userInputed(QString str){ if(myInputMethod){ if(bengalFlag){ if(str == "上")str = "A"; else if(str == "下")str = "B"; else if(str == "丌")str = "C"; else if(str == "不")str = "D"; else if(str == "与")str = "E"; else if(str == "义")str = "F"; else if(str == "丐")str = "G"; else if(str == "丑")str = "H"; else if(str == "之")str = "I"; else if(str == "专")str = "J"; else if(str == "且")str = "K"; else if(str == "丕")str = "L"; else if(str == "世")str = "M"; else if(str == "乌")str = "N"; else if(str == "丘")str = "O"; else if(str == "丙")str = "P"; else if(str == "业")str = "Q"; else if(str == "丛")str = "R"; else if(str == "东")str = "S"; else if(str == "丝")str = "T"; else if(str == "丞")str = "U"; else if(str == "乎")str = "V"; else if(str == "乏")str = "W"; else if(str == "乐")str = "X"; else if(str == "丢")str = "Y"; else if(str == "乒")str = "Z"; else if(str == "两")str = "a"; else if(str == "严")str = "b"; else if(str == "乓")str = "c"; else if(str == "丧")str = "d"; else if(str == "丨")str = "e"; else if(str == "乔")str = "f"; else if(str == "个")str = "g"; else if(str == "丫")str = "h"; else if(str == "乖")str = "i"; else if(str == "中")str = "j"; else if(str == "乘")str = "k"; else if(str == "乙")str = "l"; else if(str == "丰")str = "m"; else if(str == "九")str = "n"; else if(str == "串")str = "o"; else if(str == "乞")str = "p"; else if(str == "临")str = "q"; else if(str == "也")str = "r"; else if(str == "习")str = "s"; else if(str == "乡")str = "t"; else if(str == "丸")str = "u"; else if(str == "丹")str = "v"; else if(str == "为")str = "w"; else if(str == "主")str = "x"; else if(str == "书")str = "y"; else if(str == "丽")str = "z"; } myInputMethod->sendString (str); } else{ QMessageBox::warning(this,tr("warning"),tr("myInputMethod is null\n")); } } /* 用来初始化拼音表 */ bool InputMethod::initInputMethod(QString &filename){ QFile file(filename); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){ QMessageBox::critical((QWidget *)0,tr("错误"),tr("找不到输入法初始化文件") + filename); return false; } QTextStream in(&file); if(InputMethod::pinyinHash != NULL){ /*先删除,在添加*/ QHash *>::const_iterator i = InputMethod::pinyinHash->constBegin(); /* while (i != InputMethod::pinyinHash->constEnd()) { QList *pQList = i.value(); if(pQList != NULL) { delete pQList; } }*/ // 是否会有问题呢? delete InputMethod::pinyinHash; } InputMethod::pinyinHash = new QHash *> (); while (!in.atEnd()) { QString line = in.readLine(); QChar *ch = line.data(); QString pinyin = ""; QString hanzi = ""; if(line.size()){ for(int i = 0; i < line.size(); i++){ if(ch[i].unicode() < 0x80) pinyin.append(ch[i]); else hanzi.append(ch[i]); } if(!InputMethod::pinyinHash->contains(pinyin)) InputMethod::pinyinHash->insert(pinyin,new QList()); } QList * list = (QList *)InputMethod::pinyinHash->value(pinyin); list->append(hanzi); //qDebug() << pinyin << ":" << hanzi; } InputMethod::pinyinHashKeys = pinyinHash->keys(); InputMethod::pinyinHashQStringList = QStringList(InputMethod::pinyinHashKeys); InputMethod::pinyinHashQStringList.sort(); file.close(); return true; } /* 用来调试时使用,打印拼音及相关汉字 */ void InputMethod::showPinyinHash(void){ if(!InputMethod::pinyinHash) qDebug() << "拼音哈希表为空\n"; else { QHash *>::const_iterator i = InputMethod::pinyinHash->constBegin(); while (i != InputMethod::pinyinHash->constEnd()) { QList *list = (QList *)i.value(); qDebug() << i.key() << ": "; for (int j = 0; j < list->size(); ++j) { qDebug() << list->at(j) << " "; } qDebug() << endl; ++i; } } } void InputMethod::onDigitalPunctuationClicked(){ QString text; QPushButton * button = qobject_cast(sender()); text = keyMap[button->text()]; if(bengalFlag){ if(button->text() == "一") text = keyMap["1"]; else if(button->text() == "丁") text = keyMap["2"]; else if(button->text() == "举") text = keyMap["3"]; else if(button->text() == "七") text = keyMap["4"]; else if(button->text() == "乃") text = keyMap["5"]; else if(button->text() == "久") text = keyMap["6"]; else if(button->text() == "么") text = keyMap["7"]; else if(button->text() == "万") text = keyMap["8"]; else if(button->text() == "丈") text = keyMap["9"]; else if(button->text() == "三") text = keyMap["0"]; } #ifdef EnableArabic if(arabicFlag){ text = button->objectName(); if(CapsFlag){ if(text==";"){ text=":"; } else if(text=="'"){ text="\""; } else if(text=="."){ text=">"; } else if(text=="/"){ text="?"; } } } #endif //QString text = specialKeyMap(button->text()); if(text.isNull()) text = " "; //处理space // if(text == "(") // { // text = ")"; // }else // if(text == ")") // { // text = "("; // } // if(text == "<") // { // text = ">"; // }else // if(text == ">") // { // text = "<"; // } // if(text == "{") // { // text = "}"; // }else // if(text == "}") // { // text = "{"; // } // if(text == "[") // { // text = "]"; // }else // if(text == "]") // { // text = "["; // } userInputed(text); } void InputMethod::fillPinyinLabel(bool bActFromCharInput){ currPinyins.clear(); matchStartIndex=0; matchEndIndex=0; if(!currPinyinStr.isEmpty()){ QString Fisrt=currPinyinStr.left(1); if(Fisrt=="u"|| Fisrt=="v"|| Fisrt=="i") { //bNotFound=true; ui->pinyin->setText(currPinyinStr); return; } if(currPinyinStr.size() == 1)//首字母,如果只有一个字母,只需要从出现的第一个开始 { QRegExp exp("^" + currPinyinStr); matchStartIndex = InputMethod::pinyinHashQStringList.indexOf(exp); if(matchStartIndex!=-1) { matchEndIndex = InputMethod::pinyinHashQStringList.size()-matchStartIndex-1; } bNotFound=false; ui->pinyin->setText(currPinyinStr); return; } if(!(bNotFound && bActFromCharInput))//如果不是从有拼音输入或者还没确定找不到相应的key,就往下检索 { //if(!pinyinHash->contains(currPinyinStr)) { QRegExp exp("^" + currPinyinStr); //currPinyins = InputMethod::pinyinHashQStringList.filter(exp); matchStartIndex = InputMethod::pinyinHashQStringList.indexOf(exp); if(matchStartIndex!=-1) { bNotFound=false;//此时确定找不到相应的key matchEndIndex = InputMethod::pinyinHashQStringList.lastIndexOf(exp, matchStartIndex); } else { bNotFound=true; } //qDebug()<<"currPinyins size is "<pinyin->setText(currPinyinStr);/*如果没右找到匹配,也要显示出当前的拼音*/ } else{ ui->pinyin->setText(""); } } void InputMethod::onCharClicked(){ QPushButton * button = qobject_cast(sender()); QString text = button->text(); #ifdef EnableArabic if(arabicFlag && CtrlFlag){ text= button->objectName(); } else if(arabicFlag && CapsFlag){ text= button->objectName().toUpper(); } else if(arabicFlag){ text= button->objectName(); } #endif if(ctrlAppending){ qDebug()<<"control append"; #ifndef Q_OS_WIN32 if(button == ui->Key_A){ //似乎进入界面后,要全选两次才生效 //static int init = 0; QWSServer::sendKeyEvent(0,Qt::Key_A,Qt::ControlModifier,true,false); //if(!init) QWSServer::sendKeyEvent(0,Qt::Key_A,Qt::ControlModifier,true,false); //init = 1; } else if(button == ui->Key_C){ QWSServer::sendKeyEvent(0,Qt::Key_C,Qt::ControlModifier,true,false); } else if(button == ui->Key_V){ QWSServer::sendKeyEvent(0,Qt::Key_V,Qt::ControlModifier,true,false); } else if(button == ui->Key_X){ QWSServer::sendKeyEvent(0,Qt::Key_X,Qt::ControlModifier,true,false); } else if(button == ui->Key_Z){ QWSServer::sendKeyEvent(0,Qt::Key_Z,Qt::ControlModifier,true,false); } #endif switchKeyboardDisplay(); if(bengalFlag){ if(CapsFlag) switchKeyBoardBengalCapitalLetters(); else switchKeyBoardBengalLowerLetters(); } } else if((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH) || (CapsFlag /* && (currentInputMethodType != INPUT_METHOD_TYPE_VIETNAM)*/)) { userInputed(text); } else { if(!userPinyinInputAppending) currPinyinStr = text; else currPinyinStr.append(text); fillPinyinLabel(true); currPinyinList = 0; //initial it pinyinPage = 0; displayHanziToLabel(); userPinyinInputAppending = true; } } void InputMethod::onBackspaceClicked(void){ if(userPinyinInputAppending){ currPinyinList = 0; if(currPinyinStr.size()){ currPinyinStr = currPinyinStr.remove(currPinyinStr.size() - 1, 1); fillPinyinLabel(false); } userPinyinInputAppending = currPinyinStr.size(); displayHanziToLabel(); } else { #ifndef Q_OS_WIN32 QWSServer::sendKeyEvent(0,Qt::Key_Backspace,Qt::NoModifier,true,false); //向系统发送键盘事件 QWSServer::sendKeyEvent(0,Qt::Key_Backspace1,Qt::NoModifier,true,false); //向系统发送键盘事件 #endif } } /* 调用此函数前,设置好currPinyinStr,currPinyinList,pinyinPage */ void InputMethod::displayHanziToLabel(void){ static QList s_list; QList *list; bool candicate = false; for(int i = 0; i < HANZI_SELECT_NUM; i++){ hanziDisplayLabels[i]->setText(""); } if(!currPinyinList && pinyinHash && currPinyinStr.size()){ //currPinyinList被置为空,说明需要重新找list if(pinyinHash->contains(currPinyinStr)) currPinyinList = (QList *)pinyinHash->value(currPinyinStr); else { /*如果当前拼音无法找到,找其他备份的词*/ //qDebug()<<"display currPinyins size is "<contains(str)){ list = (QList *)pinyinHash->value(str); for(int k = 0; k < list->size();k++){ s_list.append(list->value(k)); if(s_list.size() >= HANZI_SELECT_NUM) break; } if(s_list.size() >= HANZI_SELECT_NUM) break; } } } candicate = true; } pinyinPage = 0; } if(currPinyinList && currPinyinList->size()){ int begin = MIN(currPinyinList->size() - 1,pinyinPage*HANZI_SELECT_NUM); int end = MIN(currPinyinList->size(),(pinyinPage + 1)*HANZI_SELECT_NUM); //qDebug() << begin << end << currPinyinList->size(); for(int i = begin; i < end; i++){ hanziDisplayLabels[i%HANZI_SELECT_NUM]->setText(currPinyinList->value(i)); //qDebug() << currPinyinList->value(i); } } else if(candicate){ for(int i = 0; i < s_list.size() && i < HANZI_SELECT_NUM; i++){ hanziDisplayLabels[i]->setText(s_list.value(i)); } } } void InputMethod::onHanziLabelClicked(){ ClickLabel * label = qobject_cast(sender()); QString text = label->text(); if(text.size()) userInputed(label->text()); currPinyinStr = ""; userPinyinInputAppending = false; for(int i = 0; i < HANZI_SELECT_NUM; i++){ hanziDisplayLabels[i]->setText(""); } matchStartIndex=0; matchEndIndex=0; //bNotFound=false; currPinyins.clear(); ui->pinyin->setText(""); //setHanziLabelVisible(currentInputMethodType == INPUT_METHOD_TYPE_CHINESE); setHanziLabelVisible(currentInputMethodType != INPUT_METHOD_TYPE_ENGLISH); } void InputMethod::switchKeyboardDisplay(void){ ctrlAppending = false; #if 0 ui->Key_QuoteLeft->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"`":"~"):(!shiftFlag?"·":"~"))); ui->Key_one->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"1":"!"):(!shiftFlag?"1":"!"))); ui->Key_two->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"2":"@"):(!shiftFlag?"2":"@"))); ui->Key_three->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"3":"#"):(!shiftFlag?"3":"#"))); ui->Key_four->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"4":"$"):(!shiftFlag?"4":"¥"))); ui->Key_five->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"5":"%"):(!shiftFlag?"5":"%"))); ui->Key_six->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"6":"^"):(!shiftFlag?"6":"…"))); ui->Key_seven->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"7":"&"):(!shiftFlag?"7":"&"))); ui->Key_eight->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"8":"*"):(!shiftFlag?"8":"*"))); ui->Key_nine->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"9":"("):(!shiftFlag?"9":"("))); ui->Key_zero->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"0":")"):(!shiftFlag?"0":")"))); ui->Key_Minus->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"-":"_"):(!shiftFlag?"-":"—"))); ui->Key_Equal->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"=":"+"):(!shiftFlag?"=":"+"))); ui->Key_BracketLeft->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"[":"{"):(!shiftFlag?"【":"『"))); ui->Key_BracketRight->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"]":"}"):(!shiftFlag?"】":"』"))); ui->Key_BackSlash->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"\\":"|"):(!shiftFlag?"、":"|"))); ui->Key_Semicolon->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?";":":"):(!shiftFlag?";":":"))); ui->Key_Apostrophe->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"'":"\""):(!shiftFlag?"‘":"“"))); ui->Key_Comma->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?",":"<"):(!shiftFlag?",":"《"))); ui->Key_Period->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?".":">"):(!shiftFlag?"。":"》"))); ui->Key_Slash->setText(specialKeyMap((currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?(!shiftFlag?"/":"?"):(!shiftFlag?"/":"?"))); ui->Key_Space->setText(" "); ui->Key_A->setText(!CapsFlag?"a":"A"); ui->Key_B->setText(!CapsFlag?"b":"B"); ui->Key_C->setText(!CapsFlag?"c":"C"); ui->Key_D->setText(!CapsFlag?"d":"D"); ui->Key_E->setText(!CapsFlag?"e":"E"); ui->Key_F->setText(!CapsFlag?"f":"F"); ui->Key_G->setText(!CapsFlag?"g":"G"); ui->Key_H->setText(!CapsFlag?"h":"H"); ui->Key_I->setText(!CapsFlag?"i":"I"); ui->Key_J->setText(!CapsFlag?"j":"J"); ui->Key_K->setText(!CapsFlag?"k":"K"); ui->Key_L->setText(!CapsFlag?"l":"L"); ui->Key_M->setText(!CapsFlag?"m":"M"); ui->Key_N->setText(!CapsFlag?"n":"N"); ui->Key_O->setText(!CapsFlag?"o":"O"); ui->Key_P->setText(!CapsFlag?"p":"P"); ui->Key_Q->setText(!CapsFlag?"q":"Q"); ui->Key_R->setText(!CapsFlag?"r":"R"); ui->Key_S->setText(!CapsFlag?"s":"S"); ui->Key_T->setText(!CapsFlag?"t":"T"); ui->Key_U->setText(!CapsFlag?"u":"U"); ui->Key_V->setText(!CapsFlag?"v":"V"); ui->Key_W->setText(!CapsFlag?"w":"W"); ui->Key_X->setText(!CapsFlag?"x":"X"); ui->Key_Y->setText(!CapsFlag?"y":"Y"); ui->Key_Z->setText(!CapsFlag?"z":"Z"); #elif 1 if(currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH) { if(!shiftFlag) { ui->Key_QuoteLeft->setText(keyMap["`"]); ui->Key_one->setText(keyMap["1"]); ui->Key_two->setText(keyMap["2"]); ui->Key_three->setText(keyMap["3"]); ui->Key_four->setText(keyMap["4"]); ui->Key_five->setText(keyMap["5"]); ui->Key_six->setText(keyMap["6"]); ui->Key_seven->setText(keyMap["7"]); ui->Key_eight->setText(keyMap["8"]); ui->Key_nine->setText(keyMap["9"]); ui->Key_zero->setText(keyMap["0"]); ui->Key_Minus->setText(keyMap["-"]); ui->Key_Equal->setText(keyMap["="]); ui->Key_BracketLeft->setText(keyMap["["]); ui->Key_BracketRight->setText(keyMap["]"]); ui->Key_BackSlash->setText(keyMap["\\"]); ui->Key_Semicolon->setText(keyMap[";"]); ui->Key_Apostrophe->setText(keyMap["'"]); ui->Key_Comma->setText(keyMap[","]); ui->Key_Period->setText(keyMap["."]); ui->Key_Slash->setText(keyMap["/"]); if(bengalFlag){ switchKeyBoardBengalDigit(); return; } } else { ui->Key_QuoteLeft->setText("~"); ui->Key_one->setText(keyMap["!"]); ui->Key_two->setText(keyMap["@"]); ui->Key_three->setText(keyMap["#"]); ui->Key_four->setText(keyMap["$"]); ui->Key_five->setText(keyMap["%"]); ui->Key_six->setText(keyMap["^"]); ui->Key_seven->setText(keyMap["&"]); ui->Key_eight->setText(keyMap["*"]); ui->Key_nine->setText(keyMap["("]); ui->Key_zero->setText(keyMap[")"]); ui->Key_Minus->setText(keyMap["_"]); ui->Key_Equal->setText(keyMap["+"]); ui->Key_BracketLeft->setText(keyMap["{"]); ui->Key_BracketRight->setText(keyMap["}"]); ui->Key_BackSlash->setText(keyMap["|"]); ui->Key_Semicolon->setText(keyMap[":"]); ui->Key_Apostrophe->setText(keyMap["\""]); ui->Key_Comma->setText(keyMap["<"]); ui->Key_Period->setText(keyMap[">"]); ui->Key_Slash->setText(keyMap["?"]); if(bengalFlag){ return; } } } else { if(!shiftFlag) { ui->Key_QuoteLeft->setText(keyMap["·"]); ui->Key_one->setText(keyMap["1"]); ui->Key_two->setText(keyMap["2"]); ui->Key_three->setText(keyMap["3"]); ui->Key_four->setText(keyMap["4"]); ui->Key_five->setText(keyMap["5"]); ui->Key_six->setText(keyMap["6"]); ui->Key_seven->setText(keyMap["7"]); ui->Key_eight->setText(keyMap["8"]); ui->Key_nine->setText(keyMap["9"]); ui->Key_zero->setText(keyMap["0"]); ui->Key_Minus->setText(keyMap["-"]); ui->Key_Equal->setText(keyMap["="]); ui->Key_BracketLeft->setText(keyMap["【"]); ui->Key_BracketRight->setText(keyMap["】"]); ui->Key_BackSlash->setText(keyMap["、"]); ui->Key_Semicolon->setText(keyMap[";"]); ui->Key_Apostrophe->setText(keyMap["‘"]); ui->Key_Comma->setText(keyMap[","]); ui->Key_Period->setText(keyMap["。"]); ui->Key_Slash->setText(keyMap["/"]); } else { ui->Key_QuoteLeft->setText("~"); ui->Key_one->setText(keyMap["!"]); ui->Key_two->setText(keyMap["@"]); ui->Key_three->setText(keyMap["#"]); ui->Key_four->setText(keyMap["¥"]); ui->Key_five->setText(keyMap["%"]); ui->Key_six->setText(keyMap["…"]); ui->Key_seven->setText(keyMap["&"]); ui->Key_eight->setText(keyMap["*"]); ui->Key_nine->setText(keyMap["("]); ui->Key_zero->setText(keyMap[")"]); //ui->Key_nine->setText(keyMap["("]); //ui->Key_zero->setText(keyMap[")"]); ui->Key_Minus->setText(keyMap["—"]); ui->Key_Equal->setText(keyMap["+"]); ui->Key_BracketLeft->setText(keyMap["『"]); ui->Key_BracketRight->setText(keyMap["』"]); ui->Key_BackSlash->setText(keyMap["|"]); ui->Key_Semicolon->setText(keyMap[":"]); ui->Key_Apostrophe->setText(keyMap["“"]); ui->Key_Comma->setText(keyMap["《"]); ui->Key_Period->setText(keyMap["》"]); //ui->Key_Comma->setText(keyMap["》"]); //ui->Key_Period->setText(keyMap["《"]); ui->Key_Slash->setText(keyMap["?"]); } } ui->Key_Space->setText(" "); if(CapsFlag) { ui->Key_A->setText("A"); ui->Key_B->setText("B"); ui->Key_C->setText("C"); ui->Key_D->setText("D"); ui->Key_E->setText("E"); ui->Key_F->setText("F"); ui->Key_G->setText("G"); ui->Key_H->setText("H"); ui->Key_I->setText("I"); ui->Key_J->setText("J"); ui->Key_K->setText("K"); ui->Key_L->setText("L"); ui->Key_M->setText("M"); ui->Key_N->setText("N"); ui->Key_O->setText("O"); ui->Key_P->setText("P"); ui->Key_Q->setText("Q"); ui->Key_R->setText("R"); ui->Key_S->setText("S"); ui->Key_T->setText("T"); ui->Key_U->setText("U"); ui->Key_V->setText("V"); ui->Key_W->setText("W"); ui->Key_X->setText("X"); ui->Key_Y->setText("Y"); ui->Key_Z->setText("Z"); } else { ui->Key_A->setText("a"); ui->Key_B->setText("b"); ui->Key_C->setText("c"); ui->Key_D->setText("d"); ui->Key_E->setText("e"); ui->Key_F->setText("f"); ui->Key_G->setText("g"); ui->Key_H->setText("h"); ui->Key_I->setText("i"); ui->Key_J->setText("j"); ui->Key_K->setText("k"); ui->Key_L->setText("l"); ui->Key_M->setText("m"); ui->Key_N->setText("n"); ui->Key_O->setText("o"); ui->Key_P->setText("p"); ui->Key_Q->setText("q"); ui->Key_R->setText("r"); ui->Key_S->setText("s"); ui->Key_T->setText("t"); ui->Key_U->setText("u"); ui->Key_V->setText("v"); ui->Key_W->setText("w"); ui->Key_X->setText("x"); ui->Key_Y->setText("y"); ui->Key_Z->setText("z"); } #else if(currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH) { if(!shiftFlag) { ui->Key_QuoteLeft->setText(specialKeyMap("`")); ui->Key_one->setText(specialKeyMap("1")); ui->Key_two->setText(specialKeyMap("2")); ui->Key_three->setText(specialKeyMap("3")); ui->Key_four->setText(specialKeyMap("4")); ui->Key_five->setText(specialKeyMap("5")); ui->Key_six->setText(specialKeyMap("6")); ui->Key_seven->setText(specialKeyMap("7")); ui->Key_eight->setText(specialKeyMap("8")); ui->Key_nine->setText(specialKeyMap("9")); ui->Key_zero->setText(specialKeyMap("0")); ui->Key_Minus->setText(specialKeyMap("-")); ui->Key_Equal->setText(specialKeyMap("=")); ui->Key_BracketLeft->setText(specialKeyMap("[")); ui->Key_BracketRight->setText(specialKeyMap("]")); ui->Key_BackSlash->setText(specialKeyMap("\\")); ui->Key_Semicolon->setText(specialKeyMap(";")); ui->Key_Apostrophe->setText(specialKeyMap("'")); ui->Key_Comma->setText(specialKeyMap(",")); ui->Key_Period->setText(specialKeyMap(".")); ui->Key_Slash->setText(specialKeyMap("/")); } else { ui->Key_QuoteLeft->setText("~"); ui->Key_one->setText(specialKeyMap("!")); ui->Key_two->setText(specialKeyMap("@")); ui->Key_three->setText(specialKeyMap("#")); ui->Key_four->setText(specialKeyMap("$")); ui->Key_five->setText(specialKeyMap("%")); ui->Key_six->setText(specialKeyMap("^")); ui->Key_seven->setText(specialKeyMap("&")); ui->Key_eight->setText(specialKeyMap("*")); ui->Key_nine->setText(specialKeyMap("(")); ui->Key_zero->setText(specialKeyMap(")")); ui->Key_Minus->setText(specialKeyMap("_")); ui->Key_Equal->setText(specialKeyMap("+")); ui->Key_BracketLeft->setText(specialKeyMap("{")); ui->Key_BracketRight->setText(specialKeyMap("}")); ui->Key_BackSlash->setText(specialKeyMap("|")); ui->Key_Semicolon->setText(specialKeyMap(":")); ui->Key_Apostrophe->setText(specialKeyMap("\"")); ui->Key_Comma->setText(specialKeyMap("<")); ui->Key_Period->setText(specialKeyMap(">")); ui->Key_Slash->setText(specialKeyMap("?")); } } else { if(!shiftFlag) { ui->Key_QuoteLeft->setText(specialKeyMap("·")); ui->Key_one->setText(specialKeyMap("1")); ui->Key_two->setText(specialKeyMap("2")); ui->Key_three->setText(specialKeyMap("3")); ui->Key_four->setText(specialKeyMap("4")); ui->Key_five->setText(specialKeyMap("5")); ui->Key_six->setText(specialKeyMap("6")); ui->Key_seven->setText(specialKeyMap("7")); ui->Key_eight->setText(specialKeyMap("8")); ui->Key_nine->setText(specialKeyMap("9")); ui->Key_zero->setText(specialKeyMap("0")); ui->Key_Minus->setText(specialKeyMap("-")); ui->Key_Equal->setText(specialKeyMap("=")); ui->Key_BracketLeft->setText(specialKeyMap("【")); ui->Key_BracketRight->setText(specialKeyMap("】")); ui->Key_BackSlash->setText(specialKeyMap("、")); ui->Key_Semicolon->setText(specialKeyMap(";")); ui->Key_Apostrophe->setText(specialKeyMap("‘")); ui->Key_Comma->setText(specialKeyMap(",")); ui->Key_Period->setText(specialKeyMap("。")); ui->Key_Slash->setText(specialKeyMap("/")); } else { ui->Key_QuoteLeft->setText("~"); ui->Key_one->setText(specialKeyMap("!")); ui->Key_two->setText(specialKeyMap("@")); ui->Key_three->setText(specialKeyMap("#")); ui->Key_four->setText(specialKeyMap("¥")); ui->Key_five->setText(specialKeyMap("%")); ui->Key_six->setText(specialKeyMap("…")); ui->Key_seven->setText(specialKeyMap("&")); ui->Key_eight->setText(specialKeyMap("*")); ui->Key_nine->setText(specialKeyMap("(")); ui->Key_zero->setText(specialKeyMap(")")); ui->Key_Minus->setText(specialKeyMap("—")); ui->Key_Equal->setText(specialKeyMap("+")); ui->Key_BracketLeft->setText(specialKeyMap("『")); ui->Key_BracketRight->setText(specialKeyMap("』")); ui->Key_BackSlash->setText(specialKeyMap("|")); ui->Key_Semicolon->setText(specialKeyMap(":")); ui->Key_Apostrophe->setText(specialKeyMap("“")); ui->Key_Comma->setText(specialKeyMap("《")); ui->Key_Period->setText(specialKeyMap("》")); ui->Key_Slash->setText(specialKeyMap("?")); } } ui->Key_Space->setText(" "); if(CapsFlag) { ui->Key_A->setText("A"); ui->Key_B->setText("B"); ui->Key_C->setText("C"); ui->Key_D->setText("D"); ui->Key_E->setText("E"); ui->Key_F->setText("F"); ui->Key_G->setText("G"); ui->Key_H->setText("H"); ui->Key_I->setText("I"); ui->Key_J->setText("J"); ui->Key_K->setText("K"); ui->Key_L->setText("L"); ui->Key_M->setText("M"); ui->Key_N->setText("N"); ui->Key_O->setText("O"); ui->Key_P->setText("P"); ui->Key_Q->setText("Q"); ui->Key_R->setText("R"); ui->Key_S->setText("S"); ui->Key_T->setText("T"); ui->Key_U->setText("U"); ui->Key_V->setText("V"); ui->Key_W->setText("W"); ui->Key_X->setText("X"); ui->Key_Y->setText("Y"); ui->Key_Z->setText("Z"); } else { ui->Key_A->setText("a"); ui->Key_B->setText("b"); ui->Key_C->setText("c"); ui->Key_D->setText("d"); ui->Key_E->setText("e"); ui->Key_F->setText("f"); ui->Key_G->setText("g"); ui->Key_H->setText("h"); ui->Key_I->setText("i"); ui->Key_J->setText("j"); ui->Key_K->setText("k"); ui->Key_L->setText("l"); ui->Key_M->setText("m"); ui->Key_N->setText("n"); ui->Key_O->setText("o"); ui->Key_P->setText("p"); ui->Key_Q->setText("q"); ui->Key_R->setText("r"); ui->Key_S->setText("s"); ui->Key_T->setText("t"); ui->Key_U->setText("u"); ui->Key_V->setText("v"); ui->Key_W->setText("w"); ui->Key_X->setText("x"); ui->Key_Y->setText("y"); ui->Key_Z->setText("z"); } #endif } void InputMethod::onShiftClicked(){ #ifdef EnableArabic if(arabicFlag){ CapsFlag=false; CtrlFlag=false; myInputMethod->getArabicPage(1); showArabicPage1Key(); return; } #endif shiftFlag = shiftFlag?false:true; userPinyinInputAppending = false; switchKeyboardDisplay(); } void InputMethod::onpushButtonCapspressed(){ #ifdef EnableArabic if(arabicFlag){ CapsFlag = true; CtrlFlag=false; myInputMethod->getArabicPage(1); //page1 page2 已合并到一个字体里 showArabicPage2Key(); return; } #endif CapsFlag = CapsFlag?false:true; if(bengalFlag){ if(CapsFlag) switchKeyBoardBengalCapitalLetters(); else switchKeyBoardBengalLowerLetters(); return; } userPinyinInputAppending = false; ui->pushButtonCaps->setText( CapsFlag?tr("小写"):tr("大写")); switchKeyboardDisplay(); } void InputMethod::setHanziLabelVisible(bool enable){ /*---------------------------隐藏掉一些没用的东西---------------------------------------*/ if(hanZiLabelVisibleEnable != enable){ ui->pinyin->setVisible(enable); for(int i = 0; i < HANZI_SELECT_NUM; i++){ hanziDisplayLabels[i]->setVisible(enable); } ui->Key_Last->setVisible(enable); ui->Key_Next->setVisible(enable); } hanZiLabelVisibleEnable = enable; /*------------------------------------------------------------------*/ } #include "dlgselectinputlanguage.h" void InputMethod::onInputMethodClicked(){ #ifdef EnableArabic englishOrArabicFlag=!englishOrArabicFlag; myInputMethod->getEnglishOrAarbic(englishOrArabicFlag); CapsFlag=false; if(englishOrArabicFlag){ arabicFlag=true; showArabicPage1Key(); ui->Key_InputMethodSelect->setText("English"); }else{ arabicFlag=false; showEnglishKey(); ui->Key_InputMethodSelect->setText("Arabic"); } return; #endif /// currentInputMethodType = (currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?INPUT_METHOD_TYPE_CHINESE: //(currentInputMethodType == INPUT_METHOD_TYPE_CHINESE)?INPUT_METHOD_TYPE_VIETNAM: INPUT_METHOD_TYPE_ENGLISH; /// #if 0 DlgSelectInputLanguage dlg; dlg.exec(); currentInputMethodType = dlg.selectIndex; //qDebug()<<"currentInputMethodType"<(sender()); // button->autoDefault(); /* button->setText( (currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH)?tr("英文"): (currentInputMethodType == INPUT_METHOD_TYPE_VIETNAM)?tr("越南文"): tr("中文") ); */ QString filename; if(currentInputMethodType == INPUT_METHOD_TYPE_ENGLISH){ button->setText(tr("英文")); filename = INPUT_FILE_ENGLISH; } else if(currentInputMethodType == INPUT_METHOD_TYPE_VIETNAM){ button->setText(tr("Tiếng Việt")); filename = INPUT_FILE_VIETNAM; } else if(currentInputMethodType == INPUT_METHOD_TYPE_RUSSIAN){ button->setText(tr("Russian")); filename = INPUT_FILE_RUSSIAN; } else if(currentInputMethodType == INPUT_METHOD_TYPE_JAPANESE){ button->setText(tr("Japanese")); filename = INPUT_FILE_JAPANESE; } else{ button->setText("中文"); filename = INPUT_FILE_CHINESE; //INPUT_FILE_ENGLISH WINPY_utf8.txt } //qDebug()<SetInputFile(filename); //SetInputFile(filename); userPinyinInputAppending = false; switchKeyboardDisplay(); currPinyinStr = ""; currPinyinList = 0; fillPinyinLabel(false); // chữ thường 小写字母 //setHanziLabelVisible(currentInputMethodType == INPUT_METHOD_TYPE_CHINESE || currentInputMethodType == INPUT_METHOD_TYPE_VIETNAM ); setHanziLabelVisible(currentInputMethodType != INPUT_METHOD_TYPE_ENGLISH); } void InputMethod::onEnterClicked(){ userInputed("\n"); } void InputMethod::onKeyLastClicked(){ if(currPinyinList){ if(pinyinPage) pinyinPage --; displayHanziToLabel(); } } void InputMethod::onKeyNextClicked(){ if(currPinyinList){ if(pinyinPage < (currPinyinList->size()/HANZI_SELECT_NUM)){ pinyinPage ++; } displayHanziToLabel(); } } void InputMethod::onKeyLeftpressed() { #ifndef Q_OS_WIN32 //emit PicEditKey_Press(1); QWSServer::sendKeyEvent(0,Qt::Key_Left1,Qt::NoModifier,true,false); QWSServer::sendKeyEvent(0,Qt::Key_Left,Qt::NoModifier,true,false); //向系统发送键盘事件 #endif } void InputMethod::onKeyDownpressed() { #ifndef Q_OS_WIN32 QWSServer::sendKeyEvent(0,Qt::Key_Down,Qt::NoModifier,true,false); QWSServer::sendKeyEvent(0,Qt::Key_Down1,Qt::NoModifier,true,false); #endif } void InputMethod::onKeyUppressed() { #ifndef Q_OS_WIN32 QWSServer::sendKeyEvent(0,Qt::Key_Up1,Qt::NoModifier,true,false); QWSServer::sendKeyEvent(0,Qt::Key_Up,Qt::NoModifier,true,false); #endif } void InputMethod::onKeyRightpressed() { #ifndef Q_OS_WIN32 QWSServer::sendKeyEvent(0,Qt::Key_Right1,Qt::NoModifier,true,false); QWSServer::sendKeyEvent(0,Qt::Key_Right,Qt::NoModifier,true,false); #endif } void InputMethod::onKeyHomepressed() { #ifndef Q_OS_WIN32 QWSServer::sendKeyEvent(0,Qt::Key_Home,Qt::NoModifier,true,false); QWSServer::sendKeyEvent(0,Qt::Key_Home1,Qt::NoModifier,true,false); #endif } void InputMethod::onKeyEndpressed() { #ifndef Q_OS_WIN32 QWSServer::sendKeyEvent(0,Qt::Key_End,Qt::NoModifier,true,false); QWSServer::sendKeyEvent(0,Qt::Key_End1,Qt::NoModifier,true,false); #endif } void InputMethod::onKeydeletepressed() { #ifndef Q_OS_WIN32 QWSServer::sendKeyEvent(0,Qt::Key_Delete,Qt::NoModifier,true,false); QWSServer::sendKeyEvent(0,Qt::Key_Delete1,Qt::NoModifier,true,false); #endif #if 0 QTextCursor cursor_ = textCursor(); if( cursor_.hasSelection() ) { // Delete selection cursor_.removeSelectedText(); } else { // Delete right char cursor_.deleteChar(); } setTextCursor( cursor_ ); #endif } // /usr/local/Trolltech/QtEmbedded-4.6.3/lib/fonts/BAK/WenQuanYi Zen Hei.ttf /* 注意:生成图片文件请使用X86版本软件,生成字库文件请使用PC版本软件。 PC版本直接运行。 X86版本需要虚拟环境 */ // ℃℉㎡±ΦφΩ◆✪@☢*✿❧ //° ¥ ℃ ℉ ㎡ ± Φ φ Ω ◆ ✪ @ ☢ * ✿ ❧ Δ δ ζ θ Ψ Σ ι ³ ® static QList specialChars; void InputMethod::onKeySpecialCharpressed() { static bool specialCharsInit = false; if(!specialCharsInit){ specialChars << "²"<<"°"<<"Ω"<<"Φ"<<"¥"<<"φ"<<"㎡"<<"℃"<<"℉"<<"®"<<"±"<<"Σ"<<"Δ"<<"@"<<"Ψ"<<"³"<<"θ"<<"◆"; specialCharsInit = true; } currPinyinList = &specialChars; displayHanziToLabel(); if(currentInputMethodType != INPUT_METHOD_TYPE_CHINESE){ setHanziLabelVisible(!hanZiLabelVisibleEnable); } } void InputMethod::onKeyCtrlpressed(){ #ifdef EnableArabic if(arabicFlag){ CtrlFlag=true; CapsFlag = false; showArabicPage3Key(); return; } #endif if(!ctrlAppending){ ui->Key_A->setText(tr("全选")); ui->Key_C->setText(tr("复制")); ui->Key_V->setText(tr("粘贴")); ui->Key_X->setText(tr("剪切")); ui->Key_Z->setText(tr("后退")); ctrlAppending = true; } else { switchKeyboardDisplay(); if(bengalFlag){ if(CapsFlag) switchKeyBoardBengalCapitalLetters(); else switchKeyBoardBengalLowerLetters(); } } } /* 2013.9.12 括号错位修复 为了节约cpu最好改用映射方式 */ QString InputMethod::specialKeyMap(QString ch){ #if 1 if(ch == "(") return ")"; else if(ch == ")") return "("; else if(ch == "[") return "]"; else if(ch == "]") return "["; else if(ch == "{") return "}"; else if(ch == "}") return "{"; else if(ch == "【") return "】"; else if(ch == "】") return "【"; else if(ch == "『") return "』"; else if(ch == "』") return "『"; else if(ch == "《") return "《"; else if(ch == "》") return "》"; else if(ch == "<") return "<"; else if(ch == ">") return ">"; else if(ch == "&") return "&&"; else if(ch == "&&") return "&"; else if(ch == "(") return ")"; else if(ch == ")") return "("; else return ch; #else #endif } void InputMethod::onKeyPressed(){ QPushButton * button = qobject_cast(sender()); QPoint point = button->mapToGlobal (QPoint(0,0)); QRect buttonGeometry = button->geometry(); int x = point.x() + buttonGeometry.width()/2; int y = point.y() + buttonGeometry.height()/2; QRect rec = QApplication::desktop()->screenGeometry(); x = (x>30)?(x-30):0; x = (x > rec.width() - 60)?(rec.width() - 60):x; y = (y > 80)?(y - 80):(y + 20); labelInputTip.setGeometry(x,y,60,60); QString text=button->text(); labelInputTip.setText(keyMap[button->text()]); //labelInputTip.setText(specialKeyMap(button->text())); //labelInputTip.show(); } void InputMethod::onKeyReleased(){ //QPushButton * button = qobject_cast(sender()); labelInputTip.hide(); } void InputMethod::on_pushBottonHide_pressed() { hide(); } void InputMethod::onHiden(){ if(!labelInputTip.isHidden()) labelInputTip.hide(); if(spaceTimer.isActive()) spaceTimer.stop(); } void InputMethod::on_Key_Backspace_pressed() { backtimer.start(50); } void InputMethod::on_Key_Backspace_released() { backtimer.stop(); back_count_timeout = 0; } void InputMethod::backKeyLongPressed() { if(back_count_timeout > 14) { if(userPinyinInputAppending){ currPinyinList = 0; if(currPinyinStr.size()){ currPinyinStr = currPinyinStr.remove(currPinyinStr.size() - 1, 1); fillPinyinLabel(false); } userPinyinInputAppending = currPinyinStr.size(); displayHanziToLabel(); } else { #ifndef Q_OS_WIN32 QWSServer::sendKeyEvent(0,Qt::Key_Backspace,Qt::NoModifier,true,false); //向系统发送键盘事件 QWSServer::sendKeyEvent(0,Qt::Key_Backspace1,Qt::NoModifier,true,false); //向系统发送键盘事件 #endif } }else { back_count_timeout++; } } void InputMethod::switchKeyBoardBengalDisply(bool flag){ bengalFlag =flag; #ifdef EnableArabic arabicFlag = false; #endif if(bengalFlag){ CapsFlag = false; shiftFlag = false; switchKeyBoardBengalDigit(); switchKeyBoardBengalLowerLetters(); }else{ switchKeyboardDisplay(); } } void InputMethod::switchKeyBoardBengalLowerLetters(){ ui->Key_A->setText("两"); ui->Key_B->setText("严"); ui->Key_C->setText("乓"); ui->Key_D->setText("丧"); ui->Key_E->setText("丨"); ui->Key_F->setText("乔"); ui->Key_G->setText("个"); ui->Key_H->setText("丫"); ui->Key_I->setText("乖"); ui->Key_J->setText("中"); ui->Key_K->setText("乘"); ui->Key_L->setText("乙"); ui->Key_M->setText("丰"); ui->Key_N->setText("九"); ui->Key_O->setText("串"); ui->Key_P->setText("乞"); ui->Key_Q->setText("临"); ui->Key_R->setText("也"); ui->Key_S->setText("习"); ui->Key_T->setText("乡"); ui->Key_U->setText("丸"); ui->Key_V->setText("丹"); ui->Key_W->setText("为"); ui->Key_X->setText("主"); ui->Key_Y->setText("书"); ui->Key_Z->setText("丽"); } void InputMethod::switchKeyBoardBengalCapitalLetters(){ ui->Key_A->setText("上"); ui->Key_B->setText("下"); ui->Key_C->setText("丌"); ui->Key_D->setText("不"); ui->Key_E->setText("与"); ui->Key_F->setText("义"); ui->Key_G->setText("丐"); ui->Key_H->setText("丑"); ui->Key_I->setText("之"); ui->Key_J->setText("专"); ui->Key_K->setText("且"); ui->Key_L->setText("丕"); ui->Key_M->setText("世"); ui->Key_N->setText("乌"); ui->Key_O->setText("丘"); ui->Key_P->setText("丙"); ui->Key_Q->setText("业"); ui->Key_R->setText("丛"); ui->Key_S->setText("东"); ui->Key_T->setText("丝"); ui->Key_U->setText("丞"); ui->Key_V->setText("乎"); ui->Key_W->setText("乏"); ui->Key_X->setText("乐"); ui->Key_Y->setText("丢"); ui->Key_Z->setText("乒"); } void InputMethod::switchKeyBoardBengalDigit(){ ui->Key_one->setText("一"); ui->Key_two->setText("丁"); ui->Key_three->setText("举"); ui->Key_four->setText("七"); ui->Key_five->setText("乃"); ui->Key_six->setText("久"); ui->Key_seven->setText("么"); ui->Key_eight->setText("万"); ui->Key_nine->setText("丈"); ui->Key_zero->setText("三"); } #ifdef EnableArabic void InputMethod::setSwitchArabicFlag(bool flag){ englishOrArabicFlag=false; arabicFlag=true; bengalFlag = false; ui->Key_InputMethodSelect->setEnabled(flag); } void InputMethod::setArabicDisplay(bool flag){ CapsFlag=false; if(flag){ //ui->pushButtonCaps->setEnabled(false); //ui->Key_ShiftLeft->setEnabled(false); // ui->Key_Ctrl->setEnabled(false); arabicFlag=true; //shiftFlag=false; //switchKeyboardDisplay(); showArabicPage1Key(); }else{ arabicFlag=false; englishOrArabicFlag=false; // ui->pushButtonCaps->setEnabled(true); showEnglishKey(); } } void InputMethod::showArabicPage1Key(){ ui->Key_one->setText(keyMap["11"]); //ui->Key_two->setText(keyMap["12"]); ui->Key_two->setText(""); ui->Key_two->setIconSize(QSize(20,20)); ui->Key_two->setIcon(QIcon(":/image/arabic2.png")); ui->Key_three->setText(keyMap["13"]); ui->Key_four->setText(keyMap["14"]); ui->Key_five->setText(keyMap["15"]); ui->Key_six->setText(keyMap["16"]); ui->Key_seven->setText(keyMap["17"]); ui->Key_eight->setText(keyMap["18"]); ui->Key_nine->setText(keyMap["19"]); ui->Key_zero->setText(keyMap["20"]); ui->Key_Equal->setText("۶"); ui->Key_QuoteLeft->setText("۴"); ui->Key_A->setText("ش"); ui->Key_B->setText("υ"); ui->Key_C->setText(""); ui->Key_C->setIconSize(QSize(20,20)); ui->Key_C->setIcon(QIcon(":/image/arabicc.png")); ui->Key_D->setText("ي"); ui->Key_E->setText("ث"); ui->Key_F->setText("ب"); ui->Key_G->setText("ل"); ui->Key_H->setText("ﺍ"); ui->Key_I->setText("ه"); ui->Key_J->setText("ت"); ui->Key_K->setIcon(QIcon("")); ui->Key_K->setIconSize(QSize(0,0)); ui->Key_K->setText("ن"); ui->Key_L->setText("م"); ui->Key_M->setText("ﺓ"); ui->Key_N->setText("ﻯ"); ui->Key_O->setText("خ"); ui->Key_P->setText("ح"); ui->Key_BracketLeft->setText("ج"); ui->Key_Minus->setText("ذ"); ui->Key_Semicolon->setText("ك"); ui->Key_Apostrophe->setText("ط"); ui->Key_Period->setText("ﺯ"); ui->Key_Slash->setText("ﻅ"); ui->Key_Comma->setText("ﻭ"); ui->Key_Q->setText("ض"); ui->Key_R->setText("ق"); ui->Key_S->setText("س"); ui->Key_T->setText("ف"); ui->Key_U->setText("ع"); ui->Key_V->setText("ﺭ"); ui->Key_W->setText("ص"); ui->Key_X->setText("ء"); ui->Key_Y->setText("غ"); ui->Key_Z->setText(""); ui->Key_Z->setIconSize(QSize(20,20)); ui->Key_Z->setIcon(QIcon(":/image/arabicz.png")); ui->Key_ShiftLeft->setText(""); ui->Key_ShiftLeft->setIconSize(QSize(30,30)); ui->Key_ShiftLeft->setIcon(QIcon(":/image/keyboard3.png")); ui->pushButtonCaps->setText(""); ui->pushButtonCaps->setIconSize(QSize(30,30)); ui->pushButtonCaps->setIcon(QIcon(":/image/keyboard2.png")); ui->Key_Ctrl->setText(""); ui->Key_Ctrl->setIconSize(QSize(30,30)); ui->Key_Ctrl->setIcon(QIcon(":/image/keyboard3.png")); } void InputMethod::showArabicPage2Key(){ ui->Key_one->setText(keyMap["11"]); //ui->Key_two->setText(keyMap["12"]); ui->Key_two->setText(""); ui->Key_two->setIconSize(QSize(20,20)); ui->Key_two->setIcon(QIcon(":/image/arabic2.png")); ui->Key_three->setText(keyMap["13"]); ui->Key_four->setText(keyMap["14"]); //ui->Key_four->setText("۴"); ui->Key_five->setText(keyMap["15"]); ui->Key_six->setText(keyMap["16"]); //ui->Key_six->setText("۶"); ui->Key_seven->setText(keyMap["17"]); ui->Key_eight->setText(keyMap["18"]); ui->Key_nine->setText(keyMap["19"]); ui->Key_zero->setText(keyMap["20"]); ui->Key_A->setText("ش"); ui->Key_B->setText("ذ"); ui->Key_C->setIcon(QIcon("")); ui->Key_C->setIconSize(QSize(0,0)); ui->Key_C->setText("ﺯ"); ui->Key_D->setText("ﻯ"); ui->Key_E->setText("ث"); ui->Key_F->setText("ب"); ui->Key_G->setText("ل"); ui->Key_H->setText("ﺍ"); ui->Key_I->setText("ه"); ui->Key_J->setText("ت"); ui->Key_K->setIcon(QIcon("")); ui->Key_K->setIconSize(QSize(0,0)); ui->Key_K->setText("ن"); ui->Key_L->setText("م"); ui->Key_M->setText("پ"); ui->Key_N->setText("د"); ui->Key_O->setText("خ"); ui->Key_P->setText("ح"); ui->Key_BracketLeft->setText("ج"); //ui->Key_Minus->setText("?"); ui->Key_Minus->setText("ذ"); ui->Key_Semicolon->setText("ک"); ui->Key_Apostrophe->setText("گ"); ui->Key_Period->setText("ﺁ"); ui->Key_Slash->setText("°"); ui->Key_Comma->setText("ﻭ"); ui->Key_Q->setText("ض"); ui->Key_R->setText("ق"); ui->Key_S->setText("س"); ui->Key_T->setText("ف"); ui->Key_U->setText("ع"); ui->Key_V->setText("ﺭ"); ui->Key_W->setText("ص"); ui->Key_X->setText("ط"); ui->Key_Y->setText("غ"); ui->Key_Z->setIcon(QIcon("")); ui->Key_Z->setIconSize(QSize(0,0)); ui->Key_Z->setText("ﻅ"); } void InputMethod::showArabicPage3Key(){ myInputMethod->getArabicPage(3); ui->Key_one->setText("'"); ui->Key_two->setText(""); ui->Key_two->setIconSize(QSize(0,0)); ui->Key_two->setText("''"); ui->Key_three->setText("@"); ui->Key_four->setText("#"); ui->Key_five->setText("%"); ui->Key_six->setText("^"); ui->Key_seven->setText(keyMap["&"]); ui->Key_eight->setText("*"); ui->Key_nine->setText("-"); ui->Key_zero->setText("+"); ui->Key_Minus->setText("_"); ui->Key_Equal->setText("="); ui->Key_QuoteLeft->setText("`"); ui->Key_Q->setText("ض"); ui->Key_W->setText("!"); ui->Key_E->setText("?"); ui->Key_R->setText(";"); ui->Key_T->setText(":"); ui->Key_Y->setText(","); ui->Key_U->setText("."); ui->Key_I->setText("~"); ui->Key_O->setText("|"); ui->Key_P->setText("ح"); ui->Key_BracketLeft->setText(keyMap["["]); ui->Key_A->setText("$"); ui->Key_S->setText("€"); ui->Key_D->setText("£"); ui->Key_F->setText("½"); ui->Key_G->setText("°"); ui->Key_H->setText("="); ui->Key_J->setText("μ"); ui->Key_K->setText(" ͣ"); ui->Key_K->setText(""); ui->Key_K->setIconSize(QSize(30,30)); ui->Key_K->setIcon(QIcon(":/image/arabicl.png")); ui->Key_L->setText("¿"); ui->Key_Semicolon->setText("¡"); ui->Key_Apostrophe->setText(keyMap["'"]); ui->Key_Z->setIcon(QIcon("")); ui->Key_Z->setIconSize(QSize(0,0)); ui->Key_Z->setText("\\"); ui->Key_X->setText("/"); ui->Key_C->setIcon(QIcon("")); ui->Key_C->setIconSize(QSize(0,0)); ui->Key_C->setText("["); ui->Key_V->setText("]"); ui->Key_B->setText("<"); ui->Key_N->setText(">"); ui->Key_M->setText("{"); ui->Key_Comma->setText("}"); ui->Key_Period->setText("("); ui->Key_Slash->setText(")"); } void InputMethod::showEnglishKey(){ ui->Key_ShiftLeft->setEnabled(true); ui->Key_Ctrl->setEnabled(true); ui->Key_one->setText(keyMap["1"]); ui->Key_two->setIcon(QIcon("")); ui->Key_two->setIconSize(QSize(0,0)); ui->Key_two->setText(keyMap["2"]); ui->Key_three->setText(keyMap["3"]); ui->Key_four->setText(keyMap["4"]); ui->Key_five->setText(keyMap["5"]); ui->Key_six->setText(keyMap["6"]); ui->Key_seven->setText(keyMap["7"]); ui->Key_eight->setText(keyMap["8"]); ui->Key_nine->setText(keyMap["9"]); ui->Key_zero->setText(keyMap["0"]); ui->Key_Equal->setText("="); ui->Key_QuoteLeft->setText("`"); ui->Key_A->setText("a"); ui->Key_B->setText("b"); ui->Key_C->setIcon(QIcon("")); ui->Key_C->setIconSize(QSize(0,0)); ui->Key_C->setText("c"); ui->Key_D->setText("d"); ui->Key_E->setText("e"); ui->Key_F->setText("f"); ui->Key_G->setText("g"); ui->Key_H->setText("h"); ui->Key_I->setText("i"); ui->Key_J->setText("j"); ui->Key_K->setIcon(QIcon("")); ui->Key_K->setIconSize(QSize(0,0)); ui->Key_K->setText("k"); ui->Key_L->setText("l"); ui->Key_M->setText("m"); ui->Key_N->setText("n"); ui->Key_O->setText("o"); ui->Key_P->setText("p"); ui->Key_BracketLeft->setText(keyMap["["]); ui->Key_Minus->setText("-"); ui->Key_Semicolon->setText(keyMap[";"]); ui->Key_Apostrophe->setText(keyMap["'"]); ui->Key_Period->setText(keyMap["."]); ui->Key_Slash->setText(keyMap["/"]); ui->Key_Comma->setText(keyMap[","]); ui->Key_Q->setText("q"); ui->Key_R->setText("r"); ui->Key_S->setText("s"); ui->Key_T->setText("t"); ui->Key_U->setText("u"); ui->Key_V->setText("v"); ui->Key_W->setText("w"); ui->Key_X->setText("x"); ui->Key_Y->setText("y"); ui->Key_Z->setIcon(QIcon("")); ui->Key_Z->setIconSize(QSize(0,0)); ui->Key_Z->setText("z"); ui->Key_ShiftLeft->setIcon(QIcon("")); ui->Key_ShiftLeft->setIconSize(QSize(0,0)); ui->Key_ShiftLeft->setText("Shift"); ui->pushButtonCaps->setIcon(QIcon("")); ui->pushButtonCaps->setIconSize(QSize(0,0)); ui->pushButtonCaps->setText("Caps\nLOCK"); ui->Key_InputMethodSelect->setIcon(QIcon("")); ui->Key_InputMethodSelect->setIconSize(QSize(0,0)); ui->Key_InputMethodSelect->setText("Arabic"); ui->Key_Ctrl->setIcon(QIcon("")); ui->Key_Ctrl->setIconSize(QSize(0,0)); ui->Key_Ctrl->setText("Ctrl"); } #endif