/***************************************************************************
|
**
|
** <SYSZUXpinyin 1.0 , a chinese input method based on Qt for Embedded linux>
|
** Copyright (C) <2010> <Gemfield> <gemfield@civilnet.cn>
|
**
|
** This program is free software: you can redistribute it and/or modify
|
** it under the terms of the GNU General Public License version 3 as published
|
** by the Free Software Foundation.
|
**
|
** This program is distributed in the hope that it will be useful,
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
** GNU General Public License for more details.
|
**
|
** You should have received a copy of the GNU General Public License
|
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
**
|
** If you have questions regarding the use of this file, please contact
|
** Gemfield at gemfield@civilnet.cn or post your questions at
|
** http://civilnet.cn/syszux/bbs
|
**
|
****************************************************************************/
|
|
#include <QtGui>
|
#include "syszuxpinyin.h"
|
#include "Driver/buzzerdrv.h"
|
|
QString numberlist[10]={"1","2","3","4","5","6","7","8","9","0"};
|
QString syszux_lower_letter[26]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u",
|
"v","w","x","y","z"};
|
QString syszux_upper_letter[26]={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U",
|
"V","W","X","Y","Z"};
|
|
//SyszuxPinyin::SyszuxPinyin(QWidget *parent, QLineEdit *edit, Work_Thread *thread) :
|
// QDialog(parent,Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint),
|
// button_group(new QButtonGroup(this)),
|
// input_method(0),
|
// lower_upper(0),
|
// page_count(0)
|
//{
|
// int ret=0;
|
// setupUi(this);
|
// setGeometry(QRect(0,100,800,380));
|
// work_thread = thread;
|
// connect(work_thread,SIGNAL(SentInterface(int)),this,SLOT(UpdateInterface(int)));
|
// lineEdit = edit;
|
// initGb();
|
// QFile file;
|
// file.setFileName(":new/prefix1/syszuxpinyin");
|
// if( !file.open(QFile::ReadOnly))
|
// QMessageBox::warning(0,tr("syszuxpinyin"),tr("can't load"));
|
// QTextStream pinyin_file(&file);
|
|
// regExp.setCaseSensitivity(Qt::CaseSensitive);
|
// regExp.setPattern(QString("([a-z]+)"));
|
|
// while(!pinyin_file.atEnd())
|
// {
|
// QString data = pinyin_file.readLine();//.readLine();
|
// ret = regExp.indexIn(data,0,QRegExp::CaretAtZero);
|
// pinyin_map.insert(regExp.cap(1),data.left(ret));
|
// }
|
// //connect(this,SIGNAL(sendPinyin(QString)),parent,SLOT(confirmString(QString)));
|
|
// lineEdit_ALL->setText(edit->text());
|
// input_method = 0;//0为英文 1为中文
|
// lower_upper = 0;//0为小写 1为大写
|
// pushButton_up->setVisible(false);
|
// pushButton_down->setVisible(false);
|
// ChooseBtnVisible(false);
|
//}
|
|
SyszuxPinyin::SyszuxPinyin(QWidget *parent, QLineEdit *edit) :
|
QDialog(parent,Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint),
|
button_group(new QButtonGroup(this)),
|
input_method(0),
|
lower_upper(1),
|
page_count(0)
|
{
|
int ret=0;
|
setupUi(this);
|
setGeometry(QRect(0,100,800,380));
|
//work_thread = thread;
|
//connect(work_thread,SIGNAL(SentInterface(int)),this,SLOT(UpdateInterface(int)));
|
lineEdit = edit;
|
initGb();
|
QFile file;
|
file.setFileName(":new/prefix1/syszuxpinyin");
|
if( !file.open(QFile::ReadOnly))
|
QMessageBox::warning(0,tr("syszuxpinyin"),tr("can't load"));
|
QTextStream pinyin_file(&file);
|
|
regExp.setCaseSensitivity(Qt::CaseSensitive);
|
regExp.setPattern(QString("([a-z]+)"));
|
|
while(!pinyin_file.atEnd())
|
{
|
QString data = pinyin_file.readLine();//.readLine();
|
ret = regExp.indexIn(data,0,QRegExp::CaretAtZero);
|
pinyin_map.insert(regExp.cap(1),data.left(ret));
|
}
|
//connect(this,SIGNAL(sendPinyin(QString)),parent,SLOT(confirmString(QString)));
|
|
lineEdit_ALL->setText(edit->text());
|
|
if(1 == input_method){//0为英文 1为中文
|
QIcon *icon = new QIcon(":new/prefix1/type_cn.png");
|
pushButton_ENCN->setIcon(*icon);
|
}
|
else{
|
QIcon *icon = new QIcon(":new/prefix1/type_en.png");
|
pushButton_ENCN->setIcon(*icon);
|
}
|
|
if(0 == lower_upper){//0为小写 1为大写
|
QIcon *icon = new QIcon(":new/prefix1/low.png");
|
pushButton_capital->setIcon(*icon);
|
}
|
else{
|
QIcon *icon = new QIcon(":new/prefix1/up.png");
|
pushButton_capital->setIcon(*icon);
|
}
|
|
pushButton_up->setVisible(false);
|
pushButton_down->setVisible(false);
|
ChooseBtnVisible(false);
|
}
|
|
SyszuxPinyin::~SyszuxPinyin()
|
{
|
}
|
void SyszuxPinyin::initGb()
|
{
|
QPushButton *pushButton=new QPushButton(this);
|
pushButton->hide();
|
pushButton=pushButton_up;
|
for(int i=1;i<54;i++)
|
{
|
connect(pushButton,SIGNAL(pressed()),this,SLOT(btn_beep()));
|
button_vector.push_back(pushButton);
|
button_group->addButton(pushButton,i);
|
pushButton=qobject_cast<QPushButton *>(pushButton->nextInFocusChain());
|
}
|
connect(button_group,SIGNAL(buttonClicked(int)),SLOT(buttonClickResponse(int)));
|
}
|
void SyszuxPinyin::buttonClickResponse(int gemfield)
|
{
|
if(gemfield==1)//上页
|
{
|
selectHanziPre();
|
return;
|
}
|
else if(gemfield==2)//下页
|
{
|
selectHanziNext();
|
return;
|
}
|
else if(gemfield==3)//大小写
|
{
|
changeLowerUpper();
|
return;
|
}
|
else if(gemfield==4)//退格
|
{
|
deleteString();
|
return;
|
}
|
else if(gemfield==5)//清空
|
{
|
pushButton_up->setVisible(false);
|
pushButton_down->setVisible(false);
|
ChooseBtnVisible(false);
|
lineEdit_ALL->clear();
|
lineEdit_py->clear();
|
//clearString();
|
return;
|
}
|
else if(gemfield==6)//符号键
|
{
|
lineEdit_py->clear();
|
|
pushButton_up->setVisible(false);
|
pushButton_down->setVisible(false);
|
ChooseBtnVisible(true);
|
pushButton_choose1->setText(",");
|
pushButton_choose2->setText(".");
|
pushButton_choose3->setText("(");
|
pushButton_choose4->setText(")");
|
pushButton_choose5->setText("-");
|
pushButton_choose6->setText("_");
|
pushButton_choose7->setText("/");
|
return;
|
}
|
else if(gemfield==7)//空格键
|
{
|
if(pushButton_choose1->text()!="" && lineEdit_py->text()!="")
|
{
|
lineEdit_ALL->insert(pushButton_choose1->text());
|
}
|
else
|
{
|
event=new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier," ");
|
lineEdit_ALL->setFocus();
|
QApplication::sendEvent(focusWidget(),event);
|
}
|
pushButton_up->setVisible(false);
|
pushButton_down->setVisible(false);
|
ChooseBtnVisible(false);
|
lineEdit_py->clear();
|
//clearString();
|
|
}
|
else if(gemfield==8)//中英切换
|
{
|
changeInputMethod();
|
return;
|
}
|
else if(gemfield==9)//取消键
|
{
|
pushButton_up->setVisible(false);
|
pushButton_down->setVisible(false);
|
ChooseBtnVisible(false);
|
lineEdit_py->clear();
|
//clearString();
|
this->hide();
|
return;
|
}
|
else if(gemfield==10)//确认
|
{
|
affirmString();
|
return;
|
}
|
else if(gemfield<=17)//选字
|
{
|
lineEdit_ALL->insert(button_vector.at(gemfield-1)->text());
|
lineEdit_py->clear();
|
pushButton_up->setVisible(false);
|
pushButton_down->setVisible(false);
|
ChooseBtnVisible(false);
|
//clearString();
|
return;
|
}
|
else if(gemfield>=18 && gemfield<=27)
|
{
|
event=new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier,numberlist[gemfield-18]);
|
lineEdit_ALL->setFocus();
|
QApplication::sendEvent(focusWidget(),event);
|
}
|
else if(gemfield>=28 && gemfield<=53)
|
{
|
if(lower_upper)
|
event=new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier,syszux_upper_letter[gemfield-28]);
|
else
|
event=new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier,syszux_lower_letter[gemfield-28]);
|
if(input_method)//中文
|
{
|
lineEdit_py->setFocus();
|
if(!pushButton_choose1->isVisible())
|
{
|
ChooseBtnVisible(true);
|
}
|
QApplication::sendEvent(focusWidget(),event);
|
matching(lineEdit_py->text());
|
}
|
else
|
{
|
lineEdit_ALL->setFocus();
|
QApplication::sendEvent(focusWidget(),event);
|
}
|
}
|
}
|
void SyszuxPinyin::matching(QString gemfield)
|
{
|
pinyin_list = pinyin_map.values(gemfield);
|
changePage(0);
|
page_count=0;
|
}
|
|
void SyszuxPinyin::changePage(int index)
|
{
|
int count = pinyin_list.size();
|
int i=index*7,j=9;
|
|
while(j++ != 16 )
|
{
|
button_vector.at(j)->setText(tr(pinyin_list.value(count-(++i)).toAscii()));
|
}
|
if(index==0)
|
pushButton_up->setVisible(false);
|
else
|
pushButton_up->setVisible(true);
|
if(pinyin_list.size()>(index*7+7))
|
pushButton_down->setVisible(true);
|
else
|
pushButton_down->setVisible(false);
|
}
|
|
void SyszuxPinyin::selectHanziPre()
|
{
|
changePage(--page_count);
|
}
|
|
void SyszuxPinyin::selectHanziNext()
|
{
|
changePage(++page_count);
|
}
|
void SyszuxPinyin::clearString()
|
{
|
int i=9;
|
while(++i!=17)
|
button_vector.at(i)->setText("");
|
}
|
void SyszuxPinyin::changeInputMethod()
|
{
|
lineEdit_py->clear();
|
if(input_method==0)//英文->中文
|
{
|
if(lower_upper)
|
{
|
lower_upper=0;//大写->小写
|
QIcon *icon = new QIcon(":new/prefix1/low.png");
|
pushButton_capital->setIcon(*icon);
|
int i=26;
|
while(++i!=53)
|
button_vector.at(i)->setText(syszux_lower_letter[i-27]);
|
}
|
input_method=1;
|
QIcon *icon = new QIcon(":new/prefix1/type_cn.png");
|
pushButton_ENCN->setIcon(*icon);
|
}
|
else
|
{
|
pushButton_up->setVisible(false);
|
pushButton_down->setVisible(false);
|
ChooseBtnVisible(false);
|
input_method=0;//中文->英文
|
QIcon *icon = new QIcon(":new/prefix1/type_en.png");
|
pushButton_ENCN->setIcon(*icon);
|
}
|
}
|
void SyszuxPinyin::changeLowerUpper()
|
{
|
if(lower_upper==0)//小写->大写
|
{
|
lower_upper=1;
|
QIcon *icon = new QIcon(":new/prefix1/up.png");
|
pushButton_capital->setIcon(*icon);
|
input_method=0;//设为英文
|
lineEdit_py->clear();
|
pushButton_up->setVisible(false);
|
pushButton_down->setVisible(false);
|
ChooseBtnVisible(false);
|
icon = new QIcon(":new/prefix1/type_en.png");
|
pushButton_ENCN->setIcon(*icon);
|
int i=26;
|
while(++i!=53)
|
button_vector.at(i)->setText(syszux_upper_letter[i-27]);
|
}
|
else
|
{
|
lower_upper=0;//大写->小写
|
QIcon *icon = new QIcon(":new/prefix1/low.png");
|
pushButton_capital->setIcon(*icon);
|
int i=26;
|
while(++i!=53)
|
button_vector.at(i)->setText(syszux_lower_letter[i-27]);
|
}
|
}
|
void SyszuxPinyin::deleteString()
|
{
|
event=new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
|
if(input_method)
|
{
|
lineEdit_py->text().isEmpty()?lineEdit_ALL->setFocus():lineEdit_py->setFocus();
|
QApplication::sendEvent(focusWidget(),event);
|
matching(lineEdit_py->text());
|
}
|
else
|
{
|
lineEdit_ALL->setFocus();
|
QApplication::sendEvent(focusWidget(),event);
|
}
|
}
|
void SyszuxPinyin::affirmString()
|
{
|
//emit sendPinyin(lineEdit_ALL->text());
|
lineEdit->setText(lineEdit_ALL->text());
|
this->hide();
|
}
|
|
void SyszuxPinyin::ChooseBtnVisible(bool en)
|
{
|
pushButton_choose1->setVisible(en);
|
pushButton_choose2->setVisible(en);
|
pushButton_choose3->setVisible(en);
|
pushButton_choose4->setVisible(en);
|
pushButton_choose5->setVisible(en);
|
pushButton_choose6->setVisible(en);
|
pushButton_choose7->setVisible(en);
|
}
|
|
void SyszuxPinyin::btn_beep(void)
|
{
|
BuzzerDrv BD;
|
BD.BuzzerBeep(50);
|
}
|
|
//void SyszuxPinyin::UpdateInterface(int interface)
|
//{
|
// this->close();
|
//}
|