DialogSoftKeyboard.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #ifndef DialogSoftKeyboard_H
  2. #define DialogSoftKeyboard_H
  3. #include <QtGui>
  4. #if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
  5. #include <QtWidgets>
  6. #endif
  7. #include "DialogSoftKeyboardNumber.h"
  8. #include "PinYinChar.h"
  9. #include "PinYinHelper.h"
  10. namespace Ui {
  11. class DialogSoftKeyboard;
  12. }
  13. /// <summary>
  14. /// 软键盘
  15. /// </summary>
  16. class DialogSoftKeyboard : public QWidget
  17. {
  18. Q_OBJECT
  19. public:
  20. //定义友元类 方便直接使用本类的私有变量
  21. friend class DialogSoftKeyboardNumber;
  22. friend class PinYinCustom;
  23. friend class PinYinChar;
  24. friend class PinYinHelper;
  25. //单例模式,保证一个程序只存在一个输入法实例对象
  26. static DialogSoftKeyboard *Instance();
  27. explicit DialogSoftKeyboard(QWidget *parent = 0);
  28. ~DialogSoftKeyboard();
  29. protected:
  30. void showEvent(QShowEvent *);
  31. //事件过滤器
  32. bool eventFilter(QObject *watched, QEvent *event);
  33. private:
  34. Ui::DialogSoftKeyboard *ui;
  35. static DialogSoftKeyboard *self;
  36. //当前大小写状态
  37. bool upper;
  38. //当前字符类型
  39. quint8 charType;
  40. //显示硬键盘汉字标签的数量
  41. int maxCountCh;
  42. //显示汉字的标签的最大数量
  43. int maxCountCn;
  44. //汉字候选面板最大列数
  45. int columnCount;
  46. //面板固定尺寸
  47. int fixedWidth, fixedHeight;
  48. //是否仅仅当做控件使用,后期拓展成支持输入到其他程序
  49. bool onlyControl;
  50. //是否仅仅触摸使用,用来区分按钮按下去后要弹起来的样式
  51. bool onlyTouch;
  52. //是否自动隐藏没有汉字的标签
  53. bool autoHide;
  54. //是否启用硬键盘同步
  55. bool useHardKeyBoard;
  56. //字库文件路径
  57. QString dbPath;
  58. //当前输入法面板位置类型
  59. QString position;
  60. //当前输入法类型
  61. QString inputType;
  62. //当前样式颜色
  63. QString styleName;
  64. //当前样式对应图标的类型
  65. QString iconType;
  66. //使用全键盘的数字面板还是独立的小数字面板
  67. QString numberType;
  68. //数字键盘
  69. DialogSoftKeyboardNumber *inputNumber;
  70. //自定义字符 可拓展为多语言输入
  71. PinYinChar pinyinChar;
  72. //拼音辅助类 查询及显示汉字
  73. PinYinHelper pinyinHelper;
  74. //当前焦点的对象
  75. QWidget *currentWidget;
  76. //固定数量汉字标签数组(硬键盘展示用)
  77. QList<QLabel *>labCh;
  78. //顶部汉字标签数组
  79. QList<QLabel *>labCn;
  80. //更多汉字标签数组
  81. QList<QLabel *>labMore;
  82. //记住颜色用来设置中英切换
  83. QString mainTextColor;
  84. QString btnHoveColor;
  85. //记住最后按下的汉字
  86. QString lastText;
  87. //动画滑动
  88. QPropertyAnimation *animationCn;
  89. QPropertyAnimation *animationMore;
  90. //存储本地选中的字库文件,chinese_select.txt
  91. QStringList selectKey, selectValue;
  92. //存储本地用户自定义的字库文件,chinese_user.txt
  93. QStringList userKey, userValue;
  94. private slots:
  95. //初始化窗体数据
  96. void initForm();
  97. //初始化按钮和属性
  98. void initBtn();
  99. void initBtn(QList<QPushButton *> btns);
  100. //初始化显示汉字的标签
  101. void initLab();
  102. //初始化动画属性用来滑动选择
  103. void initAnimation();
  104. //初始化数字键盘
  105. void initInputNumber();
  106. //初始化友元类
  107. void initClass();
  108. //初始化数据库以及其他
  109. void initData();
  110. //输入法面板按键处理
  111. void btnClicked();
  112. //焦点改变事件槽函数处理
  113. void focusChanged(QWidget *oldWidget, QWidget *nowWidget);
  114. //插入值到当前焦点控件
  115. void insertValue(const QString &value);
  116. //清空值,恢复到初始状态
  117. void clearValue();
  118. //删除当前焦点控件的一个字符
  119. void deleteValue();
  120. //滚动条恢复初始值
  121. void clearScroll();
  122. //显示输入法面板
  123. void showPanel();
  124. //隐藏输入法面板
  125. void hidePanel();
  126. //控制面板隐藏显示
  127. void setWidgetVisible(int indexVisible);
  128. //通用发送模拟事件
  129. void sendEvent(quint8 type, const QString &text);
  130. public Q_SLOTS:
  131. //设置字体名称及大小,包括按钮的字体大小和汉字部分的字体大小
  132. void setFontInfo(const QString &fontName, int btnFontSize, int labFontSize);
  133. //设置固定尺寸大小
  134. void setFixedSize2(int fixedWidth, int fixedHeight);
  135. //设置图标尺寸
  136. void setIconSize(int iconWidth, int iconHeight);
  137. //设置按钮之间的空隙间隔
  138. void setSpacing(int spacing);
  139. //设置顶部汉字区域高度
  140. void setTopHeight(int topHeight);
  141. //设置仅仅当做控件使用
  142. void setOnlyControl(bool onlyControl);
  143. //设置仅仅触摸使用
  144. void setOnlyTouch(bool onlyTouch);
  145. //设置是否启用硬键盘同步
  146. void setUseHardKeyBoard(bool useHardKeyBoard);
  147. //设置汉字面板列数
  148. void setColumnCount(int columnCount);
  149. //设置最大汉字标签数量
  150. void setMaxCount(int maxCountCn);
  151. //设置数字面板方式
  152. void setNumberType(const QString &numberType);
  153. //设置字库路径
  154. void setDbPath(const QString &dbPath);
  155. //设置输入法弹出位置
  156. void setPosition(const QString &position);
  157. //设置当前输入法类型
  158. void setInputType(const QString &inputType);
  159. //改变字母大小写
  160. void setUpper(bool isUpper);
  161. //设置输入法颜色样式
  162. void setStyleName(const QString &styleName);
  163. //改变输入法面板样式
  164. void setColor(const QString &mainBackgroundColor, const QString &mainTextColor,
  165. const QString &btnBackgroundColor, const QString &btnHoveColor,
  166. const QString &btnHoveTextColor, const QString &labHoveColor,
  167. const QString &labHoveTextColor);
  168. signals:
  169. void receiveValue(const QString &value);
  170. };
  171. #endif // DialogSoftKeyboard_H