Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3451742
  • 博文数量: 864
  • 博客积分: 14125
  • 博客等级: 上将
  • 技术积分: 10634
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-27 16:53
个人简介

https://github.com/zytc2009/BigTeam_learning

文章分类

全部博文(864)

文章存档

2023年(1)

2021年(1)

2019年(3)

2018年(1)

2017年(10)

2015年(3)

2014年(8)

2013年(3)

2012年(69)

2011年(103)

2010年(357)

2009年(283)

2008年(22)

分类: C/C++

2009-02-03 15:12:08

一年前,就想用这个输入法,可以移植在qtopia上,但是由于板子上没有键盘(当时用的版本不带软键盘

),并且放弃使用 qtopia了 ,所以也没有继续输入法移植工作。

     一年过去了 ,程序写的差不多,由于要板子上测试,又必须要输入法,于是下了带软键盘的代码,改一下,终于移植到qte可以使用。

      首先,把包含QPinyinFrame.cpp里qpe相关头文件全部注释了 ,把相应的 QPEapplication的代码全部注释。

如图

 

我用的qte3.3.6,把注释的 代码,用相应的qte下的代码代替。

QPEApplication::grabKetboard 对应QWidget::grabKeyboard()

QPEApplication::ungrabKetboard 对应QWidget::releaseKeyboard()

这样QPinyinFrame就改好了 。

下面是如何写接口,在qpe中,采用inputmethodface,作为plugins方式来现实,看了下murphytalk代码中的PinyinImpl.cpp 代码中:

void QPinyinImpl::onKeyPress(QObject  *receviter,const char *slot)

{

if(m_pinyin_frame){

QObject::connect(m_pinyin_frame,SIGNAL(key(ushort,ushort,ushort,bool,bool)),

                     receviter,slot);

         }

}

关键就是这个connect,链接了输入法信号key。

所以就可以仿照这个方法来实现输入法接口。

例子代码:如下

//test.h

#include
#include
#include
#include "PinyinFrame.h"

class LineEdit:public QLineEdit
{    Q_OBJECT
public:
    LineEdit(QWidget *parent, const char *name = 0);
 
public slots:
 void interpretKeyPress( ushort unicode, ushort keycode,
     ushort modifiers, bool press, bool repeat );
 
};
class Main: public QVBox
{

public:
   Main(QWidget *parent=0, const char *name=0,WFlags f=0);

private:
     QLineEdit *l;
    QPinyinFrame  *py;
   
};

##########################################
//test.cpp

#include
#include
#include
#include "test.h"
LineEdit::LineEdit(QWidget *parent, const char *name):QLineEdit(parent,name)
{
}
void LineEdit::interpretKeyPress( ushort unicode, ushort keycode,
     ushort modifiers, bool press, bool repeat )
    {    
       if(press)printf("input=%d,keycode=%d,modifiers=%d\n",unicode,keycode);
    
 QKeyEvent ke(press ? QEvent::KeyPress : QEvent::KeyRelease,
  keycode, 0, modifiers, QChar(unicode), repeat);

 if (press)
     keyPressEvent(&ke);
 else
     keyReleaseEvent(&ke);
    }
Main::Main(QWidget *parent,const char *name,WFlags f):QVBox(parent,name,f)
{

l =new LineEdit(this);

py=new QPinyinFrame(this);

QObject::connect(py, SIGNAL(key(ushort, ushort, ushort, bool, bool)),
   l, SLOT(interpretKeyPress(ushort, ushort, ushort, bool, bool)));


}

编译好,效果图如下:

关于输入法有些注意事项:

1。3个文件(pinyin_table.txt,murphytalk_phrase_idx.txt,murphytalk.conf)位置一定按PinyinFrame.cpp里位置放好,1个文件(murphytalk_phrase.dat)位置一定按PinyinPhrase.cpp里位置放好, 你也可以改位置。

2。murphytalk.conf 设置中文字体是efont,由于没有efont,设置为unifont也可以,字体大小size,keyboard=0不显示键盘,=1显示,

3。如果中文无法输入,英文可以的话,就在PinyinFrame.cpp的SendKey(int u, int c)里加一句

emit key(u,c,0,true,false);

 4。如果在输入中文时候会有按键自动重复情况,注释repeatTimer->start(500);

阅读(1340) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-02-25 13:07:29

你好,你上面说:3个文件(pinyin_table.txt,murphytalk_phrase_idx.txt,murphytalk.conf)位置一定按PinyinFrame.cpp里位置放好。 请问一下是根据下面吗? const char table_file[]= #ifdef X86 "/etc/CHInput/pinyin_table.txt"; #else "/etc/CHInput/pinyin_table.txt"; #endif