📄 murphytalk-patch
字号:
+ if (useOptiKeys)
+ row = keyboard_opti[j];
+ else
+ row = keyboard_standard[j];
+ half=0;
+ }
+
+ if ( !row || !*row ) {
+ return 0;
+ } else if ( row[1] >= 0x80 ) {
+ scancode = row[1];
+ w = (row[0] * w + (half++&1)) / 2;
+ row += 2;
+ return scancode;
+ } else if ( key_i <= 0 ) {
+ key_i = row[0]/2;
+ scancode = row[1];
+ }
+ key_i--;
+ if ( key_i <= 0 )
+ row += 2;
+ return scancode++;
+}
+
+static int keycode( int i2, int j, const uchar **keyboard )
+{
+ if ( j <0 || j >= 5 )
+ return 0;
+
+ const uchar *row = keyboard[j];
+
+ while ( *row && *row <= i2 ) {
+ i2 -= *row;
+ row += 2;
+ }
+
+ if ( !*row ) return 0;
+
+ int k;
+ if ( row[1] >= 0x80 ) {
+ k = row[1];
+ } else {
+ k = row[1]+i2/2;
+ }
+
+ return k;
+}
+
+
+/*
+ Draw the keyboard.
+
+ If key >= 0, only the specified key is drawn.
+*/
+void QPinyinFrame::drawKeyboard( QPainter &p, int key )
+{
+ const bool threeD = FALSE;
+ const QColorGroup& cg = colorGroup();
+ QColor keycolor = // cg.background();
+ QColor(240,240,230); // Beige!
+ QColor keycolor_pressed = cg.mid();
+ QColor keycolor_lo = cg.dark();
+ QColor keycolor_hi = cg.light();
+ QColor textcolor = QColor(0,0,0); // cg.text();
+
+ int margin = threeD ? 1 : 0;
+
+// p.fillRect( 0, , kw-1, keyHeight-2, keycolor_pressed );
+
+ for ( int j = 0; j < 5; j++ ) {
+ int y = j * keyHeight + PickHeight + 1;
+ int x = xoffs;
+ int kw = defaultKeyWidth;
+ int k= getKey( kw, j );
+ while ( k ) {
+ if ( key < 0 || k == key ) {
+ QString s;
+ bool pressed = (k == pressedKey);
+ bool blank = (k == 0223);
+ const char * const * xpm = NULL;
+
+ if ( k >= 0x80 ) {
+ s = specialM[k - 0x80].label;
+
+ xpm = specialM[k - 0x80].xpm;
+
+ if ( k == ShiftCode ) {
+ pressed = shift;
+ } else if ( k == CapsCode ) {
+ pressed = lock;
+ } else if ( k == CtrlCode ) {
+ pressed = ctrl;
+ } else if ( k == AltCode ) {
+ pressed = alt;
+ }
+ } else {
+#if defined(Q_WS_QWS) || defined(_WS_QWS_)
+/*
+ s = QChar( shift^lock ? QWSServer::keyMap()[k].shift_unicode :
+ QWSServer::keyMap()[k].unicode);
+*/
+ // ### Fixme, bad code, needs improving, whole thing needs to
+ // be re-coded to get rid of the way it did things with scancodes etc
+ char shifted = k;
+ if ( !isalpha( k ) ) {
+ for ( unsigned i = 0; i < sizeof(shiftMap)/sizeof(ShiftMap); i++ )
+ if ( shiftMap[i].normal == k )
+ shifted = shiftMap[i].shifted;
+ } else {
+ shifted = toupper( k );
+ }
+ s = QChar( shift^lock ? shifted : k );
+#endif
+ }
+
+ if (!blank) {
+ if ( pressed )
+ p.fillRect( x+margin, y+margin, kw-margin, keyHeight-margin-1, keycolor_pressed );
+ else
+ p.fillRect( x+margin, y+margin, kw-margin, keyHeight-margin-1, keycolor );
+
+ if ( threeD ) {
+ p.setPen(pressed ? keycolor_lo : keycolor_hi);
+ p.drawLine( x, y+1, x, y+keyHeight-2 );
+ p.drawLine( x+1, y+1, x+1, y+keyHeight-3 );
+ p.drawLine( x+1, y+1, x+1+kw-2, y+1 );
+ } else if ( j == 0 ) {
+ p.setPen(pressed ? keycolor_hi : keycolor_lo);
+ p.drawLine( x, y, x+kw, y );
+ }
+
+ // right
+ p.setPen(pressed ? keycolor_hi : keycolor_lo);
+ p.drawLine( x+kw-1, y, x+kw-1, y+keyHeight-2 );
+
+ if ( threeD ) {
+ p.setPen(keycolor_lo.light());
+ p.drawLine( x+kw-2, y+keyHeight-2, x+kw-2, y+1 );
+ p.drawLine( x+kw-2, y+keyHeight-2, x+1, y+keyHeight-2 );
+ }
+
+ if (xpm) {
+ p.drawPixmap( x + 1, y + 2, QPixmap((const char**)xpm) );
+ } else {
+ p.setPen(textcolor);
+ p.drawText( x - 1, y, kw, keyHeight-2, AlignCenter, s );
+ }
+
+ if ( threeD ) {
+ p.setPen(keycolor_hi);
+ p.drawLine( x, y, x+kw-1, y );
+ }
+
+ // bottom
+ p.setPen(keycolor_lo);
+ p.drawLine( x, y+keyHeight-1, x+kw-1, y+keyHeight-1 );
+
+ } else {
+ p.fillRect( x, y, kw, keyHeight, cg.background() );
+ }
+ }
+
+ x += kw;
+ kw = defaultKeyWidth;
+ k = getKey( kw ,-1);
+ }
+ }
+}
+
+
+void QPinyinFrame::clearHighlight()
+{
+ if (m_bShowKeyboard&&( pressedKey >= 0) ) {
+ int tmp = pressedKey;
+ pressedKey = -1;
+ QPainter p(this);
+ drawKeyboard( p, tmp );
+ }
+}
+
+void QPinyinFrame::timerEvent(QTimerEvent*e)
+{
+ if ( e->timerId() == pressTid ) {
+ killTimer(pressTid);
+ pressTid = 0;
+ if ( !pressed )
+ clearHighlight();
+ }
+}
+
+void QPinyinFrame::repeat()
+{
+ repeatTimer->start( 150 );
+ if(m_bEnglishMode) {
+ emit key( unicode, qkeycode, modifiers, true, true );
+ } else
+ GetKey(unicode,qkeycode);
+}
+
+void QPinyinFrame::mousePressEvent(QMouseEvent *e)
+{
+ if(!m_bShowKeyboard) return;
+ printX86("(%d,%d)-height=%d\n",e->x(),e->y(),PickHeight);
+ if(e->y()<=PickHeight) return;
+ clearHighlight(); // typing fast?
+
+ int i2 = ((e->x() - xoffs) * 2) / defaultKeyWidth;
+ int j = (e->y() - PickHeight) / keyHeight;
+
+ int k = keycode( i2, j, (const uchar **)((useOptiKeys) ? keyboard_opti : keyboard_standard) );
+ bool need_repaint = FALSE;
+ unicode = -1;
+ qkeycode = 0;
+ printX86("k=%d\n",k);
+ if ( k >= 0x80 ) {
+ if ( k == ShiftCode ) {
+ shift = !shift;
+ GetKey(unicode,Qt::Key_Shift);
+ need_repaint = TRUE;
+ } else if ( k == AltCode ){
+ alt = !alt;
+ need_repaint = TRUE;
+ } else if ( k == CapsCode ) {
+ lock = !lock;
+ need_repaint = TRUE;
+ } else if ( k == CtrlCode ) {
+ ctrl = !ctrl;
+ need_repaint = TRUE;
+ } else if ( k == 0224 /* Expand */ ) {
+ useLargeKeys = !useLargeKeys;
+ resizeEvent(0);
+ repaint( TRUE ); // need it to clear first
+ } else if ( k == 0225 /* Opti/Toggle */ ) {
+ useOptiKeys = !useOptiKeys;
+ resizeEvent(0);
+ repaint( TRUE ); // need it to clear first
+ } else {
+ qkeycode = specialM[ k - 0x80 ].qcode;
+ unicode = specialM[ k - 0x80 ].unicode;
+ }
+ } else {
+ //due to the way the keyboard is defined, we know that
+ //k is within the ASCII range, and can be directly mapped to
+ //a qkeycode; except letters, which are all uppercase
+ qkeycode = toupper(k);
+ if ( shift^lock ) {
+ if ( !isalpha( k ) ) {
+ for ( unsigned i = 0; i < sizeof(shiftMap)/sizeof(ShiftMap); i++ )
+ if ( shiftMap[i].normal == k ) {
+ unicode = shiftMap[i].shifted;
+ qkeycode = unicode;
+ break;
+ }
+ } else {
+ unicode = toupper( k );
+ }
+ } else {
+ unicode = k;
+ }
+ }
+ if ( unicode != -1 ) {
+ if ( ctrl && unicode >= 'a' && unicode <= 'z' )
+ unicode = unicode - 'a'+1;
+ modifiers = (shift ? Qt::ShiftButton : 0) | (ctrl ? Qt::ControlButton :
+0) |
+ (alt ? Qt::AltButton : 0);
+#if defined(Q_WS_QWS) || defined(_WS_QWS_)
+ if(m_bEnglishMode) {
+ emit key( unicode, qkeycode, modifiers, true, false );
+ } else
+ GetKey(unicode,qkeycode);
+ repeatTimer->start( 500 );
+#endif
+ need_repaint = shift || alt || ctrl;
+ shift = alt = ctrl = FALSE;
+ /*KeyboardConfig *dc = picks->dc;
+
+ if (dc) {
+ if (qkeycode == Qt::Key_Backspace) {
+ dc->input.remove(dc->input.last()); // remove last input
+ dc->decBackspaces();
+ } else if ( k == 0226 || qkeycode == Qt::Key_Return ||
+ qkeycode == Qt::Key_Space ||
+ QChar(unicode).isPunct() ) {
+ dc->input.clear();
+ dc->resetBackspaces();
+ } else {
+ dc->add(QString(QChar(unicode)));
+ dc->incBackspaces();
+ }
+ }*/
+ }
+ pressedKey = k;
+ if ( need_repaint ) {
+ repaint( FALSE );
+ } else {
+ QPainter p(this);
+ drawKeyboard( p, pressedKey );
+ }
+ pressTid = startTimer(80);
+ pressed = TRUE;
+}
+
+
+/*QSize QPinyinFrame::sizeHint() const
+{
+ QFontMetrics fm=fontMetrics();
+ int keyHeight = fm.lineSpacing()+2;
+
+ if (useOptiKeys)
+ keyHeight += 1;
+
+ return QSize( 320, keyHeight * 5 + 32);
+}*/
+
+
/*
* Revision history
*
--- MurphyPinyin/PinyinImpl.cpp 2004-07-10 23:02:23.000000000 +0800+++ mpy/PinyinImpl.cpp 2004-07-30 15:13:09.000000000 +0800@@ -27,24 +27,25 @@
/* XPM of inputmethod*/
static const char * pix_xpm[] = {
-"16 13 3 1",
-" c #FFFFFFFFFFFF",
-"# c #000000000000",
-". c #FFFFFFFFFFFF",
-" ",
-" # #### ",
-" # ....# ",
-" # ....# ",
-" # ....# ",
-" # # ## ",
-" # #...# ",
-" # #...# ",
-" # #### ",
-" # ...# ",
-" # #...# ",
-" # ### ",
-" "};
-
+"26 13 5 1",
+" c None",
+". c #CC0204",
+"+ c #D4DAE4",
+"# c #FFFF00",
+"$ c #000000",
+"++++++++++++++++++++++++++",
+"+++++++++++++++++$++$+++$+",
+"+..............++$+++$+$++",
+"+.....#........$$$$$$$$$$$",
+"+.. #....#.....++$++$++$++",
+"+.#.#.#........++$$+$++$++",
+"+..# #...#.....+$$++$++$++",
+"+.....#........$+$+$$$$$$$",
+"+..............++$++$++$++",
+"+..............++$++$++$++",
+"+..............++$++$++$++",
+"+..............$$$+$+++$++",
+"++++++++++++++++++++++++++"};
QPinyinImpl::QPinyinImpl()
:m_pinyin_frame(0), icn(0), ref(0)
--- MurphyPinyin/PinyinEngine.h 2004-07-18 23:45:10.000000000 +0800+++ mpy/PinyinEngine.h 2004-07-28 23:17:35.000000000 +0800@@ -61,12 +61,12 @@ PinyinTable m_table;
CharVector m_chars;
String m_table_filename;
-
//phrase
PinyinPhraseTable m_phrases_table;
PhraseOffsetFrequencyPairVector m_offset_freq_pairs;
PhraseStringVector m_phrases;
String m_phrase_idx_filename;
+ unsigned char table_changed;
};
#endif
--- MurphyPinyin/PinyinFrame.h 2004-07-19 00:24:58.000000000 +0800+++ mpy/PinyinFrame.h 2004-07-30 10:29:16.000000000 +0800@@ -23,6 +23,7 @@ #include <qwindowsystem_qws.h>
#include "PinyinEngine.h"
+class QTimer;
class QPinyinFrame : public QFrame, public QWSServer::KeyboardFilter
{
Q_OBJECT
@@ -43,23 +44,41 @@ bool GetKey(int,int);
virtual void show();
virtual void hide();
+ //virtual void sizeHint();
void paintEvent(QPaintEvent * e);
+ void drawKeyboard( QPainter &p, int key);
void SendKey ( int , int c = 0);
-
- void mouseReleaseEvent(QMouseEvent*);
- void keyPressEvent(QKeyEvent*);
+ void clearHighlight();
+ void mouseReleaseEvent(QMouseEvent*e);
+ void mousePressEvent(QMouseEvent*e);
+ void keyPressEvent(QKeyEvent*e);
+ void resizeEvent(QResizeEvent*e);
+ void timerEvent(QTimerEvent *e);
signals:
void key( ushort, ushort, ushort, bool, bool );
+private slots:
+ void repeat();
private:
PinyinEngine m_engine;
bool m_bEnglishMode;
bool m_bMakingPhrase;
+ QRect screen_rect;
QRect m_indicator_rect/*for English or Chinese mode*/;
QRect m_about_rect;/*the about text rect*/
- QRect m_leftbtn_rect,m_rightbtn_rect;
+ QRect m_leftbtn_rect,m_rightbtn_rect,m_cand_rect,m_kbd_rect;
+ QRect m_kbdbtn_rect;
+ bool m_bShowKeyboard;
+ short cand_width;
+ //soft keyboard related
+ short keyHeight,PickHeight, xoffs,
+ defaultKeyWidth,pressedKey,
+ shift,ctrl,alt,lock,
+ useLargeKeys,useOptiKeys,modifiers,pressed;
+ int pressTid,qkeycode,unicode;
+ QTimer *repeatTimer;
typedef struct ime_info_struc{
String pinyin;
@@ -102,7 +121,7 @@ m_ime_info.candidates_count=m_engine.search(m_ime_info.pinyin.c_str());
m_ime_info.first_visible=0;
#ifdef X86
- printf("%s,%d matched\n",m_ime_info.pinyin.c_str(),m_ime_info.candidates_count);
+ //printf("%s,%d matched\n",m_ime_info.pinyin.c_str(),m_ime_info.candidates_count);
#endif
}
int init_gui_dimention();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -