Murphytalk的qte移植

Murphytalk的qte移植

奇趣qt 2008-03-07 18:21:41 阅读1161 评论5   字号: 订阅

     一年前,就想用这个输入法,可以移植在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 <qapplication.h>
#include <qvbox.h>
#include <qlineedit.h>
#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 <qwindowsystem_qws.h>
#include <qapplication.h>
#include <qlineedit.h>
#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);

 修改比较仓促,不知道功能完不完善,希望有兴趣朋友可以去试验一下,欢迎提出问题!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值