⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pinyinframe.cpp.orig

📁 对MurphyPinyin的改进版
💻 ORIG
📖 第 1 页 / 共 3 页
字号:
				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();
		repaint(0,0,m_cand_rect.right(),m_cand_rect.bottom());
	}
	
	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();
	sched_yield();
	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();

	printX86("x=%d y=%d\n",x,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_cand_rect)) {
		printX86("candrect x %d y %d width %d height %d",m_cand_rect.x(),m_cand_rect.y(),m_cand_rect.width(),m_cand_rect.height());
		int width=0,i=0;	
		if(m_ime_info.prev_page_available())
			width+=m_leftbtn_rect.width();
			
		if(m_ime_info.prev_page_available()&&
			hit_test_helper(x,y,m_leftbtn_rect)){
			prev_page();
		}else if(m_ime_info.next_page_available()&&
			hit_test_helper(x,y,m_rightbtn_rect)){
			next_page();
		}else { //we are hit the number area of the displayed candidates
			if((i=m_ime_info.candidates_on_page)>0){
			width=x-width;
			i=width/(cand_width+10);		
			printX86("index=%d,m_cand_rect.width()=%d,x=%d,m_ime_info.candidates_on_page=%d,cand_width=%d\n",i,width,x,m_ime_info.candidates_on_page,cand_width);
			commit_selection('1'+i);
			bUpdate=true;
			}
		}
	}
	else if(hit_test_helper(x,y,m_indicator_rect)){
		//switch between English/Chinese mode
		m_bEnglishMode=!m_bEnglishMode;
		bUpdate=true;
	}else if(hit_test_helper(x,y,m_kbdbtn_rect)) {
		m_bShowKeyboard=!m_bShowKeyboard;
		Global::hideInputMethod();
		Global::showInputMethod();
	}
	else if(m_bShowKeyboard&&hit_test_helper(x,y,m_kbd_rect)) {
		if(pressTid==0)
			clearHighlight();
#if defined(Q_WS_QWS)|| defined(_WS_QWS_)
		if(unicode!=-1)	{
			emit key(unicode,qkeycode,modifiers,false,false);
			repeatTimer->stop();
		}
#endif
		pressed = FALSE;
	}

	if(bUpdate){
		repaint(0,0,m_cand_rect.right(),m_cand_rect.bottom());
	}
}

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);
}

//PC keyboard layout and scancodes

/*
  Format: length, code, length, code, ..., 0
  
  length is measured in half the width of a standard key.
  If code < 0x80, code gives the ASCII value of the key
  
  If code >= 0x80, the key is looked up in specialM[].
  
 */

static const uchar * const keyboard_opti[5] = { 
    (const uchar *const) "\001\223\003\240\002\20\002\41\002\26\002\62\002\56\002\45\002\54\003\200\001\223\002\226\002\235\002\234\002\236",
    (const uchar *const) "\001\223\003\201\004\207\002\30\002\24\002\43\004\207\003\203\001\223\006\002\002\065",
    (const uchar *const) "\001\223\003\202\002\60\002\37\002\23\002\22\002\36\002\21\002\55\003\203\001\223\006\005\002\055",
    (const uchar *const) "\001\223\003\205\004\207\002\27\002\61\002\40\004\207\003\204\001\223\006\010\002\014",
    (const uchar *const) "\001\223\003\206\002\44\002\31\002\57\002\42\002\46\002\25\002\207\003\204\001\223\002\013\002\064\002\015\002\230"
};


static const uchar * const keyboard_standard[5] = {

#ifdef USE_SMALL_BACKSPACE
    (const uchar *const)"\002\240\002`\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\002\200\002\223\002\215\002\216\002\217",
#else
    (const uchar *const)"\002\051\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\004\200\002\223\002\215\002\216\002\217",
#endif
    //~ + 123...+ BACKSPACE //+ INSERT + HOME + PGUP

    (const uchar *const)"\003\201\002q\002w\002e\002r\002t\002y\002u\002i\002o\002p\002[\002]\002\\\001\224\002\223\002\221\002\220\002\222",
    //TAB + qwerty..  + backslash //+ DEL + END + PGDN

    (const uchar *const)"\004\202\002a\002s\002d\002f\002g\002h\002j\002k\002l\002;\002'\004\203",
    //CAPS + asdf.. + RETURN 

    (const uchar *const)"\005\204\002z\002x\002c\002v\002b\002n\002m\002,\002.\002/\005\204\002\223\002\223\002\211",
    //SHIFT + zxcv... //+ UP

    (const uchar *const)"\003\205\003\206\022\207\003\206\003\205\002\223\002\212\002\213\002\214" 
    //CTRL + ALT + SPACE //+ LEFT + DOWN + RIGHT
    
};


struct ShiftMap {
    char normal;
    char shifted;
};


static const ShiftMap shiftMap[] = {
    { '`', '~' },
    { '1', '!' },
    { '2', '@' },
    { '3', '#' },
    { '4', '$' },
    { '5', '%' },
    { '6', '^' },
    { '7', '&' },
    { '8', '*' },
    { '9', '(' },
    { '0', ')' },
    { '-', '_' },
    { '=', '+' },
    { '\\', '|' },
    { '[', '{' },
    { ']', '}' },
    { ';', ':' },
    { '\'', '"' },
    { ',', '<' },
    { '.', '>' },
    { '/', '?' }
};


/* XPM */
static const char * const uparrow_xpm[]={
"9 9 2 1",
"a c #000000",
". c None",
".........",
"....a....",
"...aaa...",
"..aaaaa..",
"....a....",
"....a....",
"....a....",
"....a....",
"........."};
/* XPM */
static const char * const leftarrow_xpm[]={
"9 9 2 1",
"a c #000000",
". c None",
".........",
".........",
"...a.....",
"..aa.....",
".aaaaaaa.",
"..aa.....",
"...a.....",
".........",
"........."};
/* XPM */
static const char * const downarrow_xpm[]={
"9 9 2 1",
"a c #000000",
". c None",
".........",
"....a....",
"....a....",
"....a....",
"....a....",
"..aaaaa..",
"...aaa...",
"....a....",
"........."};
/* XPM */
static const char * const rightarrow_xpm[]={
"9 9 2 1",
"a c #000000",
". c None",
".........",
".........",
".....a...",
".....aa..",
".aaaaaaa.",
".....aa..",
".....a...",
".........",
"........."};
/* XPM */
static const char * const insert_xpm[]={
"9 9 2 1",
"a c #000000",
". c None",
".........",
"a........",
"a.aaa.aaa",
"a.a.a.a..",
"a.a.a..a.",
"a.a.a...a",
"a.a.a.aaa",
".........",
"........."};
/* XPM */
static const char * const delete_xpm[]={
"9 9 2 1",
"a c #000000",
". c None",
".........",
"aa......a",
"a.a.aaa.a",
"a.a.a.a.a",
"a.a.aaa.a.",
"a.a.a...a",
"aaa.aaa.a",
".........",
"........."};
/* XPM */
static const char * const home_xpm[]={
"9 9 2 1",
"a c #000000",
". c None",
"....a....",
"...a.a...",
"..a...a..",
".a.....a.",
"aa.aaa.aa",
".a.a.a.a.",
".a.a.a.a.",
".aaaaaaa.",
"........."};
/* XPM */
static const char * const end_xpm[]={
"10 9 2 1",
"a c #000000",
". c None",
"..........",
"aa.......a",
"a..aaa.aaa",
"aa.a.a.a.a",
"a..a.a.a.a",
"a..a.a.a.a",
"aa.a.a.aaa",
"..........",
".........."};
/* XPM */
static const char * const pageup_xpm[]={
"9 9 2 1",
"a c #000000",
". c None",
".aaa.aaa.",
".a.a.a.a.",
".aaa..aa.",
".a...aaa.",
".........",
".a.a.aaa.",
".a.a.a.a.",
".aaa.aaa.",
".....a..."};
/* XPM */
static const char * const pagedown_xpm[]={
"9 9 2 1",
"a c #000000",
". c None",
".aaa.aaa.",
".a.a.a.a.",
".aaa..aa.",
".a...aaa.",
".........",
"...a.....",
".aaa.aaa.",
".a.a.a.a.",
".aaa.a.a."};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -