📄 pinyinframe.cpp
字号:
}
}
}
painter.drawText(xx,yy,str);
xx+=hanzi.width()+10;
m_ime_info.candidates_on_page++;
}
if(m_ime_info.next_page_available()){
QPixmap next((const char **)pix_next);
painter.drawPixmap(width-2-next.width(),y+2,next);
}
}
bool QPinyinFrame::prev_page()
{
if(m_ime_info.prev_page_available()){
printX86("prev page,firt visible index %d->",m_ime_info.first_visible);
m_ime_info.first_visible-=m_ime_info.candidates_on_prev_page;
printX86("%d\n",m_ime_info.first_visible);
update();
return true;
}
else{
return false;
}
}
bool QPinyinFrame::next_page()
{
if(m_ime_info.next_page_available()){
printX86("next page,firt visible index %d->",m_ime_info.first_visible);
m_ime_info.candidates_on_prev_page=m_ime_info.candidates_on_page;
m_ime_info.first_visible+=m_ime_info.candidates_on_page;
printX86("%d\n",m_ime_info.first_visible);
update();
return true;
}
else{
return false;
}
}
/*
inline bool shift_pressed(int modifiers)
{
return modifiers & Qt::ShiftButton;
}
*/
int QPinyinFrame::get_charunicode(unsigned int nIndexOnPage)
{
unsigned int index = m_ime_info.first_visible + nIndexOnPage;
printX86("get unicode:first visible index %d,current index %d,global index %d\n",
m_ime_info.first_visible,nIndexOnPage,index);
return (m_engine.get_char(index)).unicode();
}
/*
return true if need to update UI
*/
bool QPinyinFrame::commit_selection(int k)
{
bool bUpdate = false;
unsigned int index = ((k-'0')+9)%10;
if(index<m_ime_info.candidates_on_page){
m_engine.hit(m_ime_info.first_visible+index);
if(m_engine.isPhrase()){
QString phrase=get_phrase(m_ime_info.first_visible+index);
if(m_bMakingPhrase){
m_ime_info.phrase+=phrase;
}
else{
printX86("phrase unicode:");
for(unsigned int i=0;i<phrase.length();i++){
printX86("%04X,",phrase[i].unicode());
SendKey(phrase[i].unicode());
}
printX86("\n");
}
}
else{
if(m_bMakingPhrase){
m_ime_info.phrase+=get_char(m_ime_info.first_visible+index);
}
else{
SendKey(get_charunicode(index));
}
}
resetState();
bUpdate=true;
}
return bUpdate;
}
bool QPinyinFrame::send_hanzi_mark(int ascii_mark)
{
int unicode = 0;
switch(ascii_mark){
case ',':
unicode = COMMA_MARK;
break;
case '.':
unicode = PERIOD_MARK;
break;
case '<':
unicode = BOOK_MARK1;
break;
case '>':
unicode = BOOK_MARK2;
break;
case '?':
unicode = QUESTION_MARK;
break;
case ':':
unicode = COLON_MARK;
break;
}
if(unicode!=0){
SendKey(unicode);
return true;
}
else{
return false;
}
}
bool QPinyinFrame::GetKey(int u, int k/*,int m*/)/*int unicode, int keycode, int modifiers*/
{
printX86("key code is 0x%02X\n",k);
#if 0
if(m_bEnglishMode){
if(u == 9 && k == Qt::Key_Tab){
m_bEnglishMode = false;
update();
}
else{
SendKey(u,k);
}
return true;
}
#endif
bool bUpdate = false;
bool bKeyProcessed = true;
if( k >= '0' && k <= '9'){
commit:
bUpdate=commit_selection(k);
if(!bUpdate){
bKeyProcessed=false;
}
}
else if(k >= 'a' && k <= 'z'){
input:
m_ime_info.pinyin+=(char)k;
search();
bUpdate=true;
}
else if(k >= 'A' && k <= 'Z'){
k = k - 'A'+ 'a';
goto input;
}
else if(k == Qt::Key_Space){
if(m_ime_info.candidates_on_page>0){
k='1';
goto commit;
}
else{
bKeyProcessed=false;
}
}
else if(k == Qt::Key_Right||k == Qt::Key_Down){
if(!next_page()){
bKeyProcessed=false;
}
}
else if(k == Qt::Key_Left||k == Qt::Key_Up){
if(!prev_page()){
bKeyProcessed=false;
}
}
else if( u == 8 && k == Qt::Key_Backspace){
if(m_ime_info.pinyin.size()>0){
String::iterator pos=m_ime_info.pinyin.end()-1;
m_ime_info.pinyin.erase(pos);
search();
bUpdate=true;
}
else{
SendKey(u,k);
}
}
else if(k == Qt::Key_Shift){
if(m_bMakingPhrase){
//commit the new phrase
m_bMakingPhrase=false;
m_engine.append_phrase(m_ime_info.phrase,m_making_phrase_pinyin.c_str());
m_ime_info.phrase="";
resetState();
bUpdate=true;
}
else if(m_ime_info.pinyin.size()==0){
printX86("entering making phrase mode...\n");
m_making_phrase_pinyin="";
m_bMakingPhrase=true;
bUpdate=true;
}
}
else if(u == 9 && k == Qt::Key_Tab){
m_bEnglishMode=true;
bUpdate=true;
}
else if( k == Qt::Key_Escape){
if(m_bMakingPhrase){
m_ime_info.phrase="";
m_bMakingPhrase=false;
}
resetState();
bUpdate=true;
}
else if(!send_hanzi_mark(k)){
bKeyProcessed=false;
}
if(bUpdate){
update();
}
if(!bKeyProcessed){
SendKey(u,k);
}
return true;
}
void QPinyinFrame::show()
{
QFrame::show ();
QPEApplication::grabKeyboard();
qwsServer->setKeyboardFilter (this);
}
void QPinyinFrame::hide()
{
QFrame::hide ();
QPEApplication::ungrabKeyboard();
resetState();
m_engine.save_table();
//qwsServer->setKeyboardFilter (NULL);
}
bool hit_test_helper(int x,int y,QRect& rect)
{
if(x>=rect.left()&&x<=rect.right()&&
y>=rect.top() &&y<=rect.bottom()){
return true;
}
else{
return false;
}
}
void QPinyinFrame::mouseReleaseEvent(QMouseEvent* m)
{
bool bUpdate = false;
int x=m->x();
int y=m->y();
if(hit_test_helper(x,y,m_about_rect)){
//show about infomation
QMessageBox::information(this,"About",
"MurphyTalk Pinyin "VERSION"<br><br>"
"Created by <font color=\"#0000FF\">MurphyTalk</font><br>"
"aka:<font color=\"#0000FF\">DeepWater</font>@<b>Hi-PDA</b> community<br>"
"contact me at <font color=\"#0000FF\">murphytalk@gmail.com</font><br><br>"
"This software is partially based on scim chinese<br>"
"written by James Su(suzhe@tsinghua.org.cn)<br><br>"
"This small piece of cake is released under GPL;)");
}
else if(hit_test_helper(x,y,m_leftbtn_rect)){
prev_page();
}
else if(hit_test_helper(x,y,m_rightbtn_rect)){
next_page();
}
else if(hit_test_helper(x,y,m_indicator_rect)){
//switch between English/Chinese mode
m_bEnglishMode=!m_bEnglishMode;
bUpdate=true;
}
if(bUpdate){
update();
}
}
void QPinyinFrame::keyPressEvent(QKeyEvent*)
{
}
void QPinyinFrame::SendKey(int u , int c)
{
qwsServer->sendKeyEvent ( u , c, 0, true, false);
qwsServer->sendKeyEvent ( u , c, 0, false, false);
}
/*
* Revision history
*
* $Log: PinyinFrame.cpp,v $
* Revision 1.7 2004/07/31 17:20:19 Lu Mu
* support chinese punctuations
*
* Revision 1.6 2004/07/20 11:26:05 Lu Mu
* (1)phrase frequency
* (2)self define phrase
*
* Revision 1.5 2004/07/17 07:11:54 Lu Mu
* 1)phrase support
* 2)candidates sequence number,changed to 1,2,..,9,0
* 3)space key to select first candidate
*
* Revision 1.4 2004/07/15 13:56:17 Lu Mu
* fixed : hanzi candidates overlapped by system task bar while default font is not efont
*
* Revision 1.3 2004/07/10 16:58:11 Lu Mu
* bug fix of displaying hanzi problem after the first page
*
* Revision 1.2 2004/07/10 15:02:23 Lu Mu
* v0.0.1 released
* TODO: phase support
*
* Revision 1.1.1.1 2004/07/07 16:24:13 Lu Mu
* Created
*
*
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -