-
Notifications
You must be signed in to change notification settings - Fork 8
/
qkeyboardctrl.h
122 lines (103 loc) · 2.87 KB
/
qkeyboardctrl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef Q_KEYBOARDCTRL_H
#define Q_KEYBOARDCTRL_H
#include <QWidget>
#include <QPixmap>
#include <QEvent>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QVector>
// 键盘控件模式
enum KeyBoardMode
{
KBM_LIGHT_NONE = 0,
KBM_LIGHT_STATIC,
KBM_LIGHT_CUSTOM,
KBM_CUSTOMKEY = 100,
};
// 按键信息
struct KEY_INFO
{
int key_index;
int key_value;
QString key_text;
QRect key_rect;
QColor key_color;
bool key_check;
};
class QKeyboardCtrl : public QWidget
{
Q_OBJECT
public:
explicit QKeyboardCtrl(QWidget *parent = 0);
~QKeyboardCtrl();
// 设置键盘背景
void setKeyboardBkg(QString bkg_path);
// 设置键盘类型
void setKeyboardMode(int kb_mode);
// 设置按键选中
void setKeyCheck(int key_value, bool key_check);
// 设置所有按键状态
void setAllKeyCheck(bool key_check);
// 设置按键颜色
void setKeyColor(int key_value, QColor color);
// 设置当前选中按键颜色
void setCheckKeyColor(QColor color);
// 设置灯光颜色
void setLightColor(QColor color);
// 设置按键颜色
void setAllKeysColor(QColor color);
// get key list
QVector<KEY_INFO*> getKeyItems() { return m_vecKey; }
// get key info
KEY_INFO* getKeyInfo(int key_index);
// 清空所有按键
void clearAllKeys();
signals:
void slot_keyboard_mousePressKey(int key_index);
public slots:
protected:
void enterEvent(QEvent *);
void leaveEvent(QEvent *);
void mousePressEvent(QMouseEvent *event);
//void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
void paintEvent(QPaintEvent*);
// 绘制灯光自定义
void paintLightCustom();
// 绘制按键自定义
void paintKeyCustom();
private:
// 初始化键盘按键
void initKeyboardKey();
// 添加键
int addKeyItem(QString key_text, int key_value, QRect key_rect);
private:
// 设备类型
enum DeviceType
{
DT_KB_PRO_87 = 1,
DT_KB_PRO_88 ,
DT_KB_PRO_89,
DT_KB_PRO_91,
DT_KB_TE_87,
DT_KB_TE_88,
DT_KB_TE_89,
DT_KB_TE_91,
DT_KB_MAX,
};
// 键盘图片
QPixmap m_pix_kb_bkg;
int m_kb_width;
int m_kb_height;
int m_kbimagetype;
int m_kb_ctrl_mode;
QColor m_bkgcolor; // 键盘背景颜色
int m_hover_item;
int m_select_item;
bool m_shift_status;
// 按键链表
QVector<KEY_INFO*> m_vecKey;
};
#endif // Q_KEYBOARDCTRL_H