📄 murphytalk-patch
字号:
--- MurphyPinyin/PinyinEngine.cpp 2004-07-19 01:48:01.000000000 +0800+++ mpy/PinyinEngine.cpp 2004-07-28 23:20:25.000000000 +0800@@ -26,7 +26,7 @@
PinyinEngine::PinyinEngine(const char *table_file,const char *phrase_index_file)
:m_table(NULL,table_file),m_table_filename(table_file),
- m_phrases_table(phrase_index_file),m_phrase_idx_filename(phrase_index_file)
+ m_phrases_table(phrase_index_file),m_phrase_idx_filename(phrase_index_file),table_changed(0)
{
}
@@ -70,19 +70,24 @@ if(isPhrase()){
m_phrases_table.set_frequency(m_offset_freq_pairs[index].first,
m_offset_freq_pairs[index].second+1);
+ table_changed|=2;
}
else{
PinyinKey& key=m_key.get_key_by_index(0);
uint32 freq=m_table.get_char_frequency(m_chars[index],key)+1;
m_table.set_char_frequency(m_chars[index],freq,key);
+ table_changed|=1;
}
}
void PinyinEngine::save_table()
{
+ if(table_changed&1)
m_table.save_table(m_table_filename.c_str());
+ if(table_changed&2)
m_phrases_table.save_index(m_phrase_idx_filename.c_str());
printX86("table saved\n");
+ table_changed=0;
}
void PinyinEngine::append_phrase(QString& phrase,const char* pinyin)
--- MurphyPinyin/PinyinFrame.cpp 2004-07-19 02:42:21.000000000 +0800+++ mpy/PinyinFrame.cpp 2004-07-30 17:04:18.000000000 +0800@@ -24,13 +24,16 @@ #include <qpainter.h>
#include <qlist.h>
#include <qbitmap.h>
+#include <qfontmetrics.h>
#include <qlayout.h>
+#include <qpalette.h>
#include <qvbox.h>
#include <qhbuttongroup.h>
#include <qpushbutton.h>
#include <qmessagebox.h>
#include <qcolor.h>
#include <qpen.h>
+#include <qtimer.h>
#include <qwindowsystem_qws.h>
#include <qpe/qpeapplication.h>
#include <qnamespace.h>
@@ -40,21 +43,21 @@
const char table_file[]=
#ifdef X86
-"/root/pinyin_table.txt";
+"/home/chyang/zaurus/pinyin_table.txt";
#else
"/home/zaurus/.murphytalk/pinyin_table.txt";
#endif
const char phrase_index_file[]=
#ifdef X86
-"/root/murphytalk_phrase_idx.txt";
+"/home/chyang/zaurus/murphytalk_phrase_idx.txt";
#else
"/home/zaurus/.murphytalk/murphytalk_phrase_idx.txt";
#endif
const char config_file[]=
#ifdef X86
-"/root/murphytalk.conf";
+"/home/chyang/zaurus/murphytalk.conf";
#else
"/etc/murphytalk.conf";
#endif
@@ -62,7 +65,7 @@
/* XPM */
static const char * pix_prev[] = {
-"16 13 3 1",
+"16 11 3 1",
" c #C0C0C0C0C0C0",
"# c #000000000000",
". c #00000000FFFF",
@@ -72,8 +75,6 @@ " #..# ",
" #...# ",
" #....# ",
-" #.....# ",
-" #....# ",
" #...# ",
" #..# ",
" #.# ",
@@ -81,7 +82,7 @@ " # "};
static const char * pix_next[] = {
-"16 13 3 1",
+"16 11 3 1",
" c #C0C0C0C0C0C0",
"# c #000000000000",
". c #00000000FFFF",
@@ -91,8 +92,6 @@ " #..# ",
" #...# ",
" #....# ",
-" #.....# ",
-" #....# ",
" #...# ",
" #..# ",
" #.# ",
@@ -106,14 +105,38 @@ const unsigned short YING = 0x82f1; //Hanzi : English
const char ABOUT[]="About";
+static const char * kb_xpm[] = {
+"28 13 4 1",
+" c None",
+". c #4C4C4C",
+"+ c #FFF7DD",
+"@ c #D6CFBA",
+" .......................... ",
+" .+++.+++.+++.+++.+++.++++. ",
+" .+@@.+@@.+@@.+@@.+@@.+@@@. ",
+" .......................... ",
+" .+++++.+++.+++.+++.++++++. ",
+" .+@@@@.+@@.+@@.+@@.+@@@@@. ",
+" .......................... ",
+" .++++++.+++.+++.+++.+++++. ",
+" .+@@@@@.+@@.+@@.+@@.+@@@@. ",
+" .......................... ",
+" .++++.++++++++++++++.++++. ",
+" .+@@@.+@@@@@@@@@@@@@.+@@@. ",
+" .......................... "};
const char MAKEPHRASE_OPEN [] = "\xe3\x80\x90\xe9\x80\xa0\xe8\xaf\x8d\x20";
const char MAKEPHRASE_CLOSE[] = "\xe3\x80\x91";
QPinyinFrame::QPinyinFrame(QWidget* parent, const char* name, WFlags f) :
QFrame(parent,name,f),m_engine(table_file,phrase_index_file),
- m_bEnglishMode(false),m_bMakingPhrase(false)
+ m_bEnglishMode(false),m_bMakingPhrase(false),m_bShowKeyboard(0),
+ keyHeight(13),PickHeight(32),xoffs(0),pressedKey(-1),
+ shift(0),ctrl(0),alt(0),lock(0),useLargeKeys(TRUE),
+ useOptiKeys(0),modifiers(0),pressed(0),
+ pressTid(0),qkeycode(0),unicode(-1)
{
+ screen_rect=QApplication::desktop()->rect();
(new QHBoxLayout(this))->setAutoAdd(TRUE);
QPEApplication::grabKeyboard();
qwsServer->setKeyboardFilter (this);
@@ -122,16 +145,24 @@
String font_name=config.get_as_string("font");
int font_size=config.get_as_int("font-size");
-
+ m_bShowKeyboard = config.get_as_int("keyboard");
printX86("from config -> font=%s\n",font_name.c_str());
printX86("from config -> font-size=%d\n",font_size);
-
+ printX86("from config -> keyboard=%d\n",m_bShowKeyboard);
+
if(font_name.size()>0){
if(font_size<=0){
font_size=font().pointSize();
}
setFont(QFont(font_name.c_str(),font_size));
}
+
+ defaultKeyWidth=screen_rect.width()/15;
+ m_kbd_rect=QRect(0,32,screen_rect.width(),65);
+ repeatTimer = new QTimer(this);
+
+ QObject::connect ( repeatTimer, SIGNAL(timeout()),this,SLOT(repeat()));
+ setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Preferred));
}
QPinyinFrame::~QPinyinFrame()
@@ -140,6 +171,20 @@ QPEApplication::ungrabKeyboard();
}
+void QPinyinFrame::resizeEvent(QResizeEvent*)
+{
+ int nk;
+ if ( useOptiKeys ) {
+ nk = 15;
+ } else if ( useLargeKeys ) {
+ nk = 15;
+ } else {
+ nk = 19;
+ }
+ defaultKeyWidth = screen_rect.width()/nk;
+ xoffs = (screen_rect.width()-defaultKeyWidth*nk)/2;
+}
+
QSize QPinyinFrame::sizeHint() const
{
QPinyinFrame *This=const_cast<QPinyinFrame*>(this);
@@ -153,100 +198,107 @@ int QPinyinFrame::init_gui_dimention()
{
static int sHeight = -1;
+ int width=screen_rect.width();
- if(sHeight>0) return sHeight;
+ if(sHeight>0)
+ if(m_bShowKeyboard)
+ return sHeight+65;
+ else
+ return sHeight;
#if 0
QPixmap next((const char **)pix_next);
printX86("direction pix (%d,%d)\n",next.width(),next.height());
#endif
- const int pix_width=16,pix_height=13;
+ const int pix_width=16,pix_height=11;
QPainter painter(this);
QFontMetrics metric=painter.fontMetrics();
QRect rect = metric.boundingRect(QChar(ZHONG));
- int width=640;
printX86("text metric is %d,%d\n",rect.width(),rect.height());
int x=PINYIN_X;
int y=PINYIN_Y;
painter.drawText(x,rect.height(),QChar(m_bEnglishMode?YING:ZHONG));
m_indicator_rect=QRect(x,y,rect.width(),rect.height());
- printX86("indicator rect(%d,%d,%d,%d)\n",m_indicator_rect.left(),m_indicator_rect.top(),m_indicator_rect.width(),m_indicator_rect.height());
+ printX86("indicator rect(%d,%d,%d,%d)\n",m_indicator_rect.left(),m_indicator_rect.top(),m_indicator_rect.width(),m_indicator_rect.height());
- //horizonal line which seperates pinyin and hanzi candidates
- y+=rect.height()+2;
- QRect about = metric.boundingRect(QString(ABOUT));
- m_about_rect = QRect(width-2-about.width(),PINYIN_Y,about.width(),about.height());
- printX86("about rect(%d,%d,%d,%d)\n",m_about_rect.left(),m_about_rect.top(),m_about_rect.width(),m_about_rect.height());
+ //horizonal line which seperates pinyin and hanzi candidates
+ y+=rect.height()+2;
+ QRect about = metric.boundingRect(QString(ABOUT));
+ m_about_rect = QRect(width-2-about.width(),PINYIN_Y,about.width(),about.height());
+ m_kbdbtn_rect=QRect(width-2-about.width()-24,PINYIN_Y,28,13);
+ printX86("about rect(%d,%d,%d,%d)\n",m_about_rect.left(),m_about_rect.top(),m_about_rect.width(),m_about_rect.height());
- ///////////////////////////////////////////////
- //the second row -- hanzi candicates
- y+=2;
+ ///////////////////////////////////////////////
+ //the second row -- hanzi candicates
+ y+=3;
- m_leftbtn_rect=QRect(x,y+2,pix_width,pix_height);
- printX86("left btn rect(%d,%d,%d,%d)\n",m_leftbtn_rect.left(),m_leftbtn_rect.top(),m_leftbtn_rect.width(),
- m_leftbtn_rect.height());
-
- m_rightbtn_rect=QRect(width-2-pix_width,y+2,pix_width,pix_height);
- printX86("right btn rect(%d,%d,%d,%d)\n",m_rightbtn_rect.left(),m_rightbtn_rect.top(),m_rightbtn_rect.width(),
- m_rightbtn_rect.height());
-
- sHeight=y+rect.height()+5;
-
- return sHeight;
-}
-
-bool QPinyinFrame::filter (int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat)
-{
- if (!isHidden()&& isPress) {
- if(m_bEnglishMode){
- if(unicode == 9 && keycode == Qt::Key_Tab){
- m_bEnglishMode = false;
- update();
- }
- else{
- SendKey(unicode,keycode);
+ m_leftbtn_rect=QRect(x,y,pix_width,pix_height);
+ printX86("left btn rect(%d,%d,%d,%d)\n",m_leftbtn_rect.left(),m_leftbtn_rect.top(),m_leftbtn_rect.width(),
+ m_leftbtn_rect.height());
+
+ m_rightbtn_rect=QRect(width-2-pix_width,y,pix_width,pix_height);
+ printX86("right btn rect(%d,%d,%d,%d)\n",m_rightbtn_rect.left(),m_rightbtn_rect.top(),m_rightbtn_rect.width(),
+ m_rightbtn_rect.height());
+
+ m_cand_rect=QRect(0,y,width-2,pix_height);
+ sHeight=y+rect.height()+5;
+
+
+ return sHeight;
+ }
+
+ bool QPinyinFrame::filter (int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat)
+ {
+ if (!isHidden()&& isPress) {
+ if(m_bEnglishMode){
+ if(unicode == 9 && keycode == Qt::Key_Tab){
+ m_bEnglishMode = false;
+ update();
+ }
+ else{
+ SendKey(unicode,keycode);
+ }
+ return true;
}
- return true;
- }
- if (GetKey (unicode, keycode))
- return true;
+ if (GetKey (unicode, keycode))
+ return true;
+ else
+ return false;
+ }
else
return false;
- }
- else
- return false;
-}
+ }
-void QPinyinFrame::paintEvent(QPaintEvent * e)
-{
- QFrame::paintEvent(e);
-
- QPainter painter(this);
- painter.setClipRect (e->rect ());
+ void QPinyinFrame::paintEvent(QPaintEvent * e)
+ {
+ unsigned int width = screen_rect.width();
+ QFrame::paintEvent(e);
+
+ QPainter painter(this);
+ painter.setClipRect (e->rect ());
- //FIXME: how to get screen size
- unsigned int width = 640;
+ //FIXME: how to get screen size
- ///////////////////////////////////////////////
- //the first row - pinyin inputed
+ ///////////////////////////////////////////////
+ //the first row - pinyin inputed
- QFontMetrics metric=painter.fontMetrics();
- QRect rect = metric.boundingRect(QChar(ZHONG));
+ QFontMetrics metric=painter.fontMetrics();
+ QRect rect = metric.boundingRect(QChar(ZHONG));
- int x=PINYIN_X;
- int y=PINYIN_Y;
- painter.drawText(x,rect.height(),QChar(m_bEnglishMode?YING:ZHONG));
+ int x=PINYIN_X;
+ int y=PINYIN_Y;
+ painter.drawText(x,rect.height(),QChar(m_bEnglishMode?YING:ZHONG));
- QPen penGray (QColor(128,128,128));
- QPen penWhite(QColor(255,255,255));
- QPen penText (QColor(0,0,0));
- QPen penPage (QColor(0,0,255));
+ QPen penGray (QColor(128,128,128));
+ QPen penWhite(QColor(255,255,255));
+ QPen penText (QColor(0,0,0));
+ QPen penPage (QColor(0,0,255));
- //vertical line which seperates chinese/english indicator with pinyin inputed
+ //vertical line which seperates chinese/english indicator with pinyin inputed
painter.setPen(penGray);
painter.drawLine(x+rect.width()+2,y,x+rect.width()+2,y+rect.height());
painter.setPen(penWhite);
@@ -292,6 +344,8 @@ QRect about = metric.boundingRect(QString(ABOUT));
painter.drawText(width-2-about.width(),rect.height(),QString(ABOUT));
painter.drawLine(width-2-about.width(),rect.height()+1,width-2,rect.height()+1);
+
+ painter.drawPixmap(width-2-about.width()-28,rect.height()-10,QPixmap((const char**)kb_xpm));
///////////////////////////////////////////////
//the second row -- hanzi candicates
@@ -304,7 +358,7 @@
if(m_ime_info.prev_page_available()){
QPixmap prev((const char **)pix_prev);
- painter.drawPixmap(x,y+2,prev);
+ painter.drawPixmap(x,y,prev);
x+=prev.width()+2;
}
@@ -323,29 +377,31 @@ str+=get_char(i);
}
hanzi=metric.boundingRect(str);
-
- if(xx+hanzi.width()>=(unsigned int)m_rightbtn_rect.left()){//no space for this hanzi and right button
+ cand_width=hanzi.width();
+ if(xx+cand_width>=(unsigned int)m_rightbtn_rect.left()){//no space for this hanzi and right button
if(i<m_ime_info.candidates_count-1){ //but we need another page
break; //so give up to draw this hanzi
}
else{
//this is the last page,do not need to show next button
//so just check if the left space is enough to show this hanzi
- if(xx+hanzi.width()>width){
+ if(xx+cand_width>width){
break;//Ooops
}
}
}
painter.drawText(xx,yy,str);
- xx+=hanzi.width()+10;
+ xx+=cand_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);
+ painter.drawPixmap(width-2-next.width(),y,next);
}
+ if(m_bShowKeyboard)
+ drawKeyboard(painter,-1);
}
bool QPinyinFrame::prev_page()
@@ -354,7 +410,8 @@ 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();
+ //update();
+ repaint(0,0,m_cand_rect.right(),m_cand_rect.bottom());
return true;
}
else{
@@ -369,7 +426,8 @@ 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();
+ //update();
+ repaint(0,0,m_cand_rect.right(),m_cand_rect.bottom());
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -