This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
KeyString.cpp
153 lines (142 loc) · 3.41 KB
/
KeyString.cpp
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "KeyString.h"
/*
* Author:qiuzhiqian
* Email:[email protected]
* Github:https://github.com/qiuzhiqian
* Date:2017.07.23
* Description:这个类主要用来转换快捷按键的键值和字符串
**/
KeyString::KeyString()
{
keymap[Qt::Key_Escape]="Esc";
keymap[Qt::Key_Tab]="Tab";
keymap[Qt::Key_Backtab]="Backtab";
keymap[Qt::Key_Backspace]="Backspace";
keymap[Qt::Key_Return]="Return";
keymap[Qt::Key_Insert]="Insert";
keymap[Qt::Key_Delete]="Delete";
keymap[Qt::Key_Pause]="Pause";
keymap[Qt::Key_Home]="Home";
keymap[Qt::Key_End]="End";
keymap[Qt::Key_Left]="Left";
keymap[Qt::Key_Up]="Up";
keymap[Qt::Key_Right]="Right";
keymap[Qt::Key_Down]="Down";
keymap[Qt::Key_PageUp]="PageUp";
keymap[Qt::Key_PageDown]="PageDown";
keymap[Qt::Key_F1]="F1";
keymap[Qt::Key_F2]="F2";
keymap[Qt::Key_F3]="F3";
keymap[Qt::Key_F4]="F4";
keymap[Qt::Key_F5]="F5";
keymap[Qt::Key_F6]="F6";
keymap[Qt::Key_F7]="F7";
keymap[Qt::Key_F8]="F8";
keymap[Qt::Key_F9]="F9";
keymap[Qt::Key_F10]="F10";
keymap[Qt::Key_F11]="F11";
keymap[Qt::Key_F12]="F12";
keymap[Qt::Key_Space]="Space";
keymap[Qt::Key_0]="0";
keymap[Qt::Key_1]="1";
keymap[Qt::Key_2]="2";
keymap[Qt::Key_3]="3";
keymap[Qt::Key_4]="4";
keymap[Qt::Key_5]="5";
keymap[Qt::Key_6]="6";
keymap[Qt::Key_7]="7";
keymap[Qt::Key_8]="8";
keymap[Qt::Key_9]="9";
keymap[Qt::Key_A]="A";
keymap[Qt::Key_B]="B";
keymap[Qt::Key_C]="C";
keymap[Qt::Key_D]="D";
keymap[Qt::Key_E]="E";
keymap[Qt::Key_F]="F";
keymap[Qt::Key_G]="G";
keymap[Qt::Key_H]="F";
keymap[Qt::Key_I]="I";
keymap[Qt::Key_J]="J";
keymap[Qt::Key_K]="K";
keymap[Qt::Key_L]="L";
keymap[Qt::Key_M]="M";
keymap[Qt::Key_N]="N";
keymap[Qt::Key_O]="O";
keymap[Qt::Key_P]="P";
keymap[Qt::Key_Q]="Q";
keymap[Qt::Key_R]="R";
keymap[Qt::Key_S]="S";
keymap[Qt::Key_T]="T";
keymap[Qt::Key_U]="U";
keymap[Qt::Key_V]="V";
keymap[Qt::Key_W]="W";
keymap[Qt::Key_X]="X";
keymap[Qt::Key_Y]="Y";
keymap[Qt::Key_Z]="Z";
}
QString KeyString::Key2String(Qt::Key t_key, Qt::KeyboardModifiers t_mod)
{
QString showtext="";
QString modstr="";
QString keystr="";
switch(t_mod)
{
case Qt::NoModifier:
modstr="";
break;
case Qt::ShiftModifier:
modstr="Shift";
break;
case Qt::ControlModifier:
modstr="Ctrl";
break;
case Qt::AltModifier:
modstr="Atl";
break;
default:
modstr="";
break;
}
keystr=keymap[t_key];
if(modstr!="")
{
showtext=modstr+"+"+keystr;
}
else
{
showtext=keystr;
}
return showtext;
}
void KeyString::String2Key(QString str,Qt::Key &t_key, Qt::KeyboardModifiers &t_mod)
{
QString modstr="";
QString keystr="";
QStringList keyList=str.split('+');
if(keyList.size()==2)
{
modstr=keyList[0];
keystr=keyList[1];
}
else
{
keystr=keyList[0];
}
if(modstr=="")
{
t_mod=Qt::NoModifier;
}
else if(modstr=="Shift")
{
t_mod=Qt::ShiftModifier;
}
else if(modstr=="Ctrl")
{
t_mod=Qt::ControlModifier;
}
else if(modstr=="Atl")
{
t_mod=Qt::AltModifier;
}
t_key=Qt::Key(keymap.keys(keystr)[0]);
}