Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7675743
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: 嵌入式

2012-04-24 08:56:54


点击(此处)折叠或打开

  1. #include "zpinyinwin.h"
  2. #include "t9py.h"
  3. #include <qdatetime.h>

  4. #define MINY 50
  5. #define MAXY 260

  6. zPinYinWin::zPinYinWin(QWidget *parent) :
  7.     QWidget(parent)
  8. {
  9.     zPInitParam();
  10.     zPinitShow();
  11. }

  12. void zPinYinWin::zPInitParam()//初始化参数
  13. {
  14.     zPInput = new QLineEdit(this);
  15.     zPOutput = new QListWidget(this);
  16.     tempList = new QStringList();

  17.     this->zPInput->installEventFilter(this);
  18.     connect(this->zPInput, SIGNAL(textChanged(QString)), this, SLOT(zPInput_Changed(QString)));
  19. }

  20. void zPinYinWin::zPinitShow()//初始化窗体
  21. {
  22.     //this->setWindowFlags(Qt::FramelessWindowHint);
  23.     this->setGeometry(400, 280, 200, MINY);
  24.     this->setMaximumSize(200, MINY);
  25.     this->setMinimumSize(200, MINY);
  26.     this->zPInput->setGeometry(20, 20, 150, 30);
  27.     this->zPOutput->setGeometry(20, 60, 150, 180);
  28. }

  29. void zPinYinWin::zPInput_Changed(QString input)//输入字符改变出发槽
  30. {
  31.     QString temp;

  32.     if(this->zPInput->text() != NULL)
  33.     {
  34.         this->setGeometry(400, 280, 200, MAXY);
  35.         this->setMaximumSize(200, MAXY);
  36.         this->setMinimumSize(200, MAXY);
  37.     }
  38.     else
  39.     {
  40.         this->setGeometry(400, 280, 200, MINY);
  41.         this->setMaximumSize(200, MINY);
  42.         this->setMinimumSize(200, MINY);
  43.     }

  44.     zPOutput->clear();
  45.     tempList->clear();
  46.     Q_CHECK_PTR(&input);
  47.     cpt9PY_Mblen = T9PY_Get_Match_PY_MB(input, cpt9PY_Mb);
  48.     for(int i = 0; i < cpt9PY_Mblen; i++)
  49.     {
  50.         temp += cpt9PY_Mb[i]->PY_mb;
  51.     }
  52.     temp.replace(QString("@"), QString(""));

  53.     for(int i = 0; i < temp.length(); i++)
  54.     {
  55.         tempList->append(temp.at(i));
  56.     }

  57.     if (tempList->count() % 9 == 0)
  58.     { zListNum = tempList->count()/9; }
  59.     else { zListNum = tempList->count()/9 + 1; }
  60.     zPageNum = zListNum;
  61.     zShowCandidate();
  62. }


  63. unsigned char zPinYinWin::T9PY_Get_Match_PY_MB(QString p_PadInput, t9PY_index **List_match_PY_Mb)//拼音识别
  64. {
  65.     struct t9PY_index *p_PY_CurrenIndex, *p_PY_LastIndex, *p_PY_TempIndex;
  66.     unsigned char i, j, cInputStrLength;
  67.     unsigned char T9PY_Match_NUM=0;
  68.     j=0;


  69.     if(p_PadInput == '\0') return(0);
  70.     cInputStrLength = p_PadInput.length(); //获取拼音串长度
  71.     p_PY_CurrenIndex = &(t9PY_info[0]); //p_PY_CurrenIndex为当前拼音索引地址
  72.     p_PY_LastIndex = t9PY_info + sizeof(t9PY_info)/sizeof(t9PY_info[0]); //最后索引地址之后的地址

  73.     while(p_PY_CurrenIndex < p_PY_LastIndex)
  74.     {
  75.         for(i = 0; i < cInputStrLength; i++)
  76.         {
  77.             if(p_PadInput.at(i) != *((*p_PY_CurrenIndex).PY+i))
  78.             {
  79.                 if (i+1 > j)
  80.                 {
  81.                     j=i+1;
  82.                             
  83.                     p_PY_TempIndex = p_PY_CurrenIndex;
  84.                 }
  85.                 break; //不匹配,退出
  86.              }
  87.          }
  88.          if((i == cInputStrLength) && (T9PY_Match_NUM<16))
  89.          {
  90.              List_match_PY_Mb[T9PY_Match_NUM] = p_PY_CurrenIndex;
  91.              T9PY_Match_NUM++;
  92.          }
  93.          p_PY_CurrenIndex++;
  94.     }

  95.     if(j != cInputStrLength)
  96.         List_match_PY_Mb[0] = p_PY_TempIndex;

  97.     return (T9PY_Match_NUM);
  98. }

  99. bool zPinYinWin::eventFilter(QObject *obj, QEvent *e)//重载快捷键,组合键
  100. {
  101.     Q_ASSERT(obj == this->zPInput);

  102.     if (e->type() == QEvent::KeyPress)//切换输入法组合键
  103.     {
  104.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  105.         if (event->key() == Qt::Key_Shift && (event->modifiers() & Qt::ControlModifier))
  106.         {
  107.             zReturnNULL();
  108.             return true;
  109.         }
  110.     }

  111.     if (e->type() == QEvent::KeyPress)//空格键重载
  112.     {
  113.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  114.         if (event->key() == Qt::Key_Space)
  115.         {
  116.             zReturnText();
  117.             return true;
  118.         }
  119.     }

  120.     if (e->type() == QEvent::KeyPress)//重载加号
  121.     {
  122.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  123.         if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Right)
  124.         {
  125.             zPageText(1);
  126.             return true;
  127.         }
  128.     }

  129.     if (e->type() == QEvent::KeyPress)//重载减号
  130.     {
  131.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  132.         if (event->key() == Qt::Key_Down || event->key() == Qt::Key_Left)
  133.         {
  134.             zPageText(2);
  135.             return true;
  136.         }
  137.     }

  138.     if (e->type() == QEvent::KeyPress)
  139.     {
  140.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  141.         if (event->key() == Qt::Key_1)
  142.         {
  143.             zReturnSelected(0);
  144.             return true;
  145.         }
  146.     }

  147.     if (e->type() == QEvent::KeyPress)
  148.     {
  149.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  150.         if (event->key() == Qt::Key_2)
  151.         {
  152.             zReturnSelected(1);
  153.             return true;
  154.         }
  155.     }

  156.     if (e->type() == QEvent::KeyPress)
  157.     {
  158.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  159.         if (event->key() == Qt::Key_3)
  160.         {
  161.             zReturnSelected(2);
  162.             return true;
  163.         }
  164.     }

  165.     if (e->type() == QEvent::KeyPress)
  166.     {
  167.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  168.         if (event->key() == Qt::Key_4)
  169.         {
  170.             zReturnSelected(3);
  171.             return true;
  172.         }
  173.     }

  174.     if (e->type() == QEvent::KeyPress)
  175.     {
  176.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  177.         if (event->key() == Qt::Key_5)
  178.         {
  179.             zReturnSelected(4);
  180.             return true;
  181.         }
  182.     }

  183.     if (e->type() == QEvent::KeyPress)
  184.     {
  185.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  186.         if (event->key() == Qt::Key_6)
  187.         {
  188.             zReturnSelected(5);
  189.             return true;
  190.         }
  191.     }

  192.     if (e->type() == QEvent::KeyPress)//重载7键
  193.     {
  194.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  195.         if (event->key() == Qt::Key_7)
  196.         {
  197.             zReturnSelected(6);
  198.             return true;
  199.         }
  200.     }

  201.     if (e->type() == QEvent::KeyPress)
  202.     {
  203.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  204.         if (event->key() == Qt::Key_8)
  205.         {
  206.             zReturnSelected(7);
  207.             return true;
  208.         }
  209.     }

  210.     if (e->type() == QEvent::KeyPress)//重载9键
  211.     {
  212.         QKeyEvent *event = static_cast<QKeyEvent*>(e);
  213.         if (event->key() == Qt::Key_9)
  214.         {
  215.             zReturnSelected(8);
  216.             return true;
  217.         }
  218.     }

  219.     return false;
  220. }

  221. void zPinYinWin::zShowCandidate()//显示文字
  222. {
  223.     int count;
  224.     QString num;

  225.     if (tempList->count() == 0) return;
  226.     this->zPOutput->clear();
  227.     if (zPageNum <= 1 && tempList->count() != 9)
  228.     { count = tempList->count()%9; }
  229.     else { count = 9;}

  230.     for(int i = 0; i < count; i++)
  231.     {
  232.         num = num.number(i + 1, 10);
  233.         this->zPOutput->addItem(num + "." + tempList->at(i + ((zPageNum - zListNum) * (-9))));
  234.     }
  235. }

  236. void zPinYinWin::zPageText(int i)//翻页
  237. {
  238.     if (i == 1)
  239.     {
  240.         if (zPageNum <= zListNum && zPageNum > 1)
  241.         {
  242.             zPageNum--;
  243.             zShowCandidate();
  244.         }
  245.     }
  246.     else if (i == 2)
  247.     {
  248.         if (zPageNum >= 1 && zPageNum < zListNum)
  249.         {
  250.             zPageNum++;
  251.             zShowCandidate();
  252.         }
  253.     }
  254. }

  255. void zPinYinWin::zReturnNULL()//输入法切换
  256. {
  257.     this->zPInput->setText(NULL);
  258.     this->close();
  259. }

  260. void zPinYinWin::zReturnText()//按空格返回文字
  261. {
  262.     if (tempList->count() == 0)
  263.     {
  264.         emit zGetText(this->zPInput->text());
  265.         this->zPInput->setText(NULL);
  266.         return;
  267.     }
  268.     emit zGetText(this->tempList->at((zPageNum - zListNum) * (-9)));
  269.     this->zPInput->setText(NULL);
  270. }

  271. void zPinYinWin::zReturnSelected(int no)//按序号返回文字
  272. {
  273.     if (tempList->count() == 0)
  274.     {
  275.         emit zGetText(this->zPInput->text());
  276.         this->zPInput->setText(NULL);
  277.         return;
  278.     }
  279.     emit zGetText(this->tempList->at(no + (zPageNum - zListNum) * (-9)));
  280.     this->zPInput->setText(NULL);
  281. }
源码: zPinYin.rar   
阅读(8328) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

fychit2014-05-06 18:07:57

你好,下载了你的QT T9中文输入法,编译成功了,在arm能运行,但是没有字符出来,请问这是怎么回事?