Blame view

app/gui/oven_control/keyboardwidget.cpp 12 KB
92fef6124   고영탁   환경 설정 - 설정 UI 완료
1
2
3
4
  #include <QKeyEvent>
  #include <QDebug>
  #include "keyboardwidget.h"
  #include "ui_keyboardwidget.h"
66e60ceb5   김태훈   모든 버튼에 음향 효과 추가
5
  #include "soundplayer.h"
be7d2a625   고영탁   엔코더 기능 구현
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
  static const QString m_mapKeyboard[] = {
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "0",
      "Q",
      "W",
      "E",
      "R",
      "T",
      "Y",
      "U",
      "I",
      "O",
      "P",
      "A",
      "S",
      "D",
      "F",
      "G",
      "H",
      "J",
      "K",
      "L",
      "Z",
      "X",
      "C",
      "V",
      "B",
      "N",
      "M",
      "-",
      ",",
      " "
  };
92fef6124   고영탁   환경 설정 - 설정 UI 완료
47
48
49
50
51
  KeyboardWidget::KeyboardWidget(QWidget *parent) :
      QWidget(parent),
      ui(new Ui::KeyboardWidget)
  {
      ui->setupUi(this);
be7d2a625   고영탁   엔코더 기능 구현
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
  
      m_pCurCheckedBtn = NULL;
      m_vectorTabOrder.append(ui->pushButton_1);
      m_vectorTabOrder.append(ui->pushButton_2);
      m_vectorTabOrder.append(ui->pushButton_3);
      m_vectorTabOrder.append(ui->pushButton_4);
      m_vectorTabOrder.append(ui->pushButton_5);
      m_vectorTabOrder.append(ui->pushButton_6);
      m_vectorTabOrder.append(ui->pushButton_7);
      m_vectorTabOrder.append(ui->pushButton_8);
      m_vectorTabOrder.append(ui->pushButton_9);
      m_vectorTabOrder.append(ui->pushButton_10);
      m_vectorTabOrder.append(ui->pushButton_11);
      m_vectorTabOrder.append(ui->pushButton_12);
      m_vectorTabOrder.append(ui->pushButton_13);
      m_vectorTabOrder.append(ui->pushButton_14);
      m_vectorTabOrder.append(ui->pushButton_15);
      m_vectorTabOrder.append(ui->pushButton_16);
      m_vectorTabOrder.append(ui->pushButton_17);
      m_vectorTabOrder.append(ui->pushButton_18);
      m_vectorTabOrder.append(ui->pushButton_19);
      m_vectorTabOrder.append(ui->pushButton_20);
      m_vectorTabOrder.append(ui->pushButton_21);
      m_vectorTabOrder.append(ui->pushButton_22);
      m_vectorTabOrder.append(ui->pushButton_23);
      m_vectorTabOrder.append(ui->pushButton_24);
      m_vectorTabOrder.append(ui->pushButton_25);
      m_vectorTabOrder.append(ui->pushButton_26);
      m_vectorTabOrder.append(ui->pushButton_27);
      m_vectorTabOrder.append(ui->pushButton_28);
      m_vectorTabOrder.append(ui->pushButton_29);
      m_vectorTabOrder.append(ui->pushButton_30);
      m_vectorTabOrder.append(ui->pushButton_31);
      m_vectorTabOrder.append(ui->pushButton_32);
      m_vectorTabOrder.append(ui->pushButton_33);
      m_vectorTabOrder.append(ui->pushButton_34);
      m_vectorTabOrder.append(ui->pushButton_35);
      m_vectorTabOrder.append(ui->pushButton_36);
      m_vectorTabOrder.append(ui->pushButton_37);
      m_vectorTabOrder.append(ui->pushButton_38);
      m_vectorTabOrder.append(ui->pushButton_39);
      m_vectorTabOrder.append(ui->pushButton_40);
      m_vectorTabOrder.append(ui->pushButton_41);
      m_vectorTabOrder.append(ui->pushButton_42);
92fef6124   고영탁   환경 설정 - 설정 UI 완료
96
      m_pSignalMapper = new QSignalMapper(this);
be7d2a625   고영탁   엔코더 기능 구현
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
      m_pSignalMapper->setMapping(ui->pushButton_1, 0);
      m_pSignalMapper->setMapping(ui->pushButton_2, 1);
      m_pSignalMapper->setMapping(ui->pushButton_3, 2);
      m_pSignalMapper->setMapping(ui->pushButton_4, 3);
      m_pSignalMapper->setMapping(ui->pushButton_5, 4);
      m_pSignalMapper->setMapping(ui->pushButton_6, 5);
      m_pSignalMapper->setMapping(ui->pushButton_7, 6);
      m_pSignalMapper->setMapping(ui->pushButton_8, 7);
      m_pSignalMapper->setMapping(ui->pushButton_9, 8);
      m_pSignalMapper->setMapping(ui->pushButton_10, 9);
      m_pSignalMapper->setMapping(ui->pushButton_11, 10);
      m_pSignalMapper->setMapping(ui->pushButton_12, 11);
      m_pSignalMapper->setMapping(ui->pushButton_13, 12);
      m_pSignalMapper->setMapping(ui->pushButton_14, 13);
      m_pSignalMapper->setMapping(ui->pushButton_15, 14);
      m_pSignalMapper->setMapping(ui->pushButton_16, 15);
      m_pSignalMapper->setMapping(ui->pushButton_17, 16);
      m_pSignalMapper->setMapping(ui->pushButton_18, 17);
      m_pSignalMapper->setMapping(ui->pushButton_19, 18);
      m_pSignalMapper->setMapping(ui->pushButton_20, 19);
      m_pSignalMapper->setMapping(ui->pushButton_21, 20);
      m_pSignalMapper->setMapping(ui->pushButton_22, 21);
      m_pSignalMapper->setMapping(ui->pushButton_23, 22);
      m_pSignalMapper->setMapping(ui->pushButton_24, 23);
      m_pSignalMapper->setMapping(ui->pushButton_25, 24);
      m_pSignalMapper->setMapping(ui->pushButton_26, 25);
      m_pSignalMapper->setMapping(ui->pushButton_27, 26);
      m_pSignalMapper->setMapping(ui->pushButton_28, 27);
      m_pSignalMapper->setMapping(ui->pushButton_29, 28);
      m_pSignalMapper->setMapping(ui->pushButton_30, 29);
      m_pSignalMapper->setMapping(ui->pushButton_31, 30);
      m_pSignalMapper->setMapping(ui->pushButton_32, 31);
      m_pSignalMapper->setMapping(ui->pushButton_33, 32);
      m_pSignalMapper->setMapping(ui->pushButton_34, 33);
      m_pSignalMapper->setMapping(ui->pushButton_35, 34);
      m_pSignalMapper->setMapping(ui->pushButton_36, 35);
      m_pSignalMapper->setMapping(ui->pushButton_37, 36);
      m_pSignalMapper->setMapping(ui->pushButton_38, 37);
      m_pSignalMapper->setMapping(ui->pushButton_40, 38);
92fef6124   고영탁   환경 설정 - 설정 UI 완료
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
  
  
      connect(ui->pushButton_1,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_2,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_3,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_4,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_5,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_6,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_7,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_8,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_9,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_10,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_11,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_12,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_13,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_14,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_15,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_16,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_17,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_18,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_19,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_20,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_21,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_22,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_23,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_24,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_25,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_26,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_27,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_28,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_29,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_30,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_31,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_32,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_33,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_34,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_35,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_36,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_37,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
      connect(ui->pushButton_38,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
748830a16   김태훈   키보드 동작 개선
176
      connect(ui->pushButton_40,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
92fef6124   고영탁   환경 설정 - 설정 UI 완료
177
be7d2a625   고영탁   엔코더 기능 구현
178
      connect(m_pSignalMapper,SIGNAL(mapped(int)), this, SLOT(onKeyboardClicked(int)));
66e60ceb5   김태훈   모든 버튼에 음향 효과 추가
179
180
181
  
      foreach (QPushButton *button, findChildren<QPushButton *>())
          connect(button, &QPushButton::pressed, SoundPlayer::playClick);
92fef6124   고영탁   환경 설정 - 설정 UI 완료
182
183
184
185
186
187
188
189
190
  }
  
  KeyboardWidget::~KeyboardWidget()
  {
      delete ui;
  }
  
  void KeyboardWidget::on_pushButton_41_clicked()
  {
be7d2a625   고영탁   엔코더 기능 구현
191
192
193
194
      if(m_pCurCheckedBtn != NULL) m_pCurCheckedBtn->setChecked(false);
      m_nCurTabPos = 40;
      m_pCurCheckedBtn = m_vectorTabOrder[m_nCurTabPos];
      m_pCurCheckedBtn->setChecked(true);
92fef6124   고영탁   환경 설정 - 설정 UI 완료
195
196
197
198
199
200
201
      QKeyEvent key(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
      QGuiApplication::sendEvent(QApplication::focusObject(),&key);
      emit onOkKeyClicked();
  }
  
  void KeyboardWidget::on_pushButton_42_clicked()
  {
be7d2a625   고영탁   엔코더 기능 구현
202
203
204
205
206
      if(m_pCurCheckedBtn != NULL) m_pCurCheckedBtn->setChecked(false);
      m_nCurTabPos = 41;
      m_pCurCheckedBtn = m_vectorTabOrder[m_nCurTabPos];
      m_pCurCheckedBtn->setChecked(true);
      if(m_pCurCheckedBtn != NULL) m_pCurCheckedBtn->setChecked(false);
92fef6124   고영탁   환경 설정 - 설정 UI 완료
207
208
209
210
211
      emit onCancelKeyClicked();
  }
  
  void KeyboardWidget::on_pushButton_39_clicked()
  {
be2756ef5   고영탁   패스워드 입력 디자인 변경 외 1건
212
      qDebug() << qApp->focusObject();
be7d2a625   고영탁   엔코더 기능 구현
213
214
215
216
      if(m_pCurCheckedBtn != NULL) m_pCurCheckedBtn->setChecked(false);
      m_nCurTabPos = 38;
      m_pCurCheckedBtn = m_vectorTabOrder[m_nCurTabPos];
      m_pCurCheckedBtn->setChecked(true);
92fef6124   고영탁   환경 설정 - 설정 UI 완료
217
218
219
220
      QKeyEvent key(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
      QGuiApplication::sendEvent(QApplication::focusObject(),&key);
      emit onBackspaceKeyClicked();
  }
be7d2a625   고영탁   엔코더 기능 구현
221
  void KeyboardWidget::onKeyboardClicked(const int in){
92fef6124   고영탁   환경 설정 - 설정 UI 완료
222
      QInputMethodEvent event;
be7d2a625   고영탁   엔코더 기능 구현
223
224
225
226
227
228
229
      qDebug()<< "keyboard clicked" << in;
      event.setCommitString(m_mapKeyboard[in]);
      if(m_pCurCheckedBtn != NULL) m_pCurCheckedBtn->setChecked(false);
      if( in < 38) m_nCurTabPos = in;
      else if( in == 38) m_nCurTabPos = 39;
      m_pCurCheckedBtn = m_vectorTabOrder[m_nCurTabPos];
      m_pCurCheckedBtn->setChecked(true);
92fef6124   고영탁   환경 설정 - 설정 UI 완료
230
      QGuiApplication::sendEvent(QApplication::focusObject(),&event);
be7d2a625   고영탁   엔코더 기능 구현
231
      emit onKeyboardClickSignal(m_mapKeyboard[in]);
92fef6124   고영탁   환경 설정 - 설정 UI 완료
232
233
234
235
236
237
  }
  
  void KeyboardWidget::on_pushButton_40_clicked()
  {
      emit onSpaceKeyClicked();
  }
be7d2a625   고영탁   엔코더 기능 구현
238
239
  
  void KeyboardWidget::keyPressEvent(QKeyEvent *event){
63a45681f   고영탁   엔코더 기능 구현
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
      switch (event->key())
      {
      case 0x01000030:    // Turn left
          if(m_nCurTabPos > 0 ) m_nCurTabPos--;
          else m_nCurTabPos = m_vectorTabOrder.size()-1;
          if(m_pCurCheckedBtn !=NULL) m_pCurCheckedBtn->setChecked(false);
          m_pCurCheckedBtn = m_vectorTabOrder[m_nCurTabPos];
          m_pCurCheckedBtn->setChecked(true);
          break;
      case 0x01000032:    // Turn right
          if(m_nCurTabPos < (m_vectorTabOrder.size() -1)) m_nCurTabPos++;
          else m_nCurTabPos=0;
          if(m_pCurCheckedBtn !=NULL) m_pCurCheckedBtn->setChecked(false);
          m_pCurCheckedBtn = m_vectorTabOrder[m_nCurTabPos];
          m_pCurCheckedBtn->setChecked(true);
          break;
      }
be7d2a625   고영탁   엔코더 기능 구현
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
  }
  
  void KeyboardWidget::keyReleaseEvent(QKeyEvent *event){
      switch (event->key())
      {
      case 0x01000030:    // Turn left
          if(m_nCurTabPos > 0 ) m_nCurTabPos--;
          else m_nCurTabPos = m_vectorTabOrder.size()-1;
          if(m_pCurCheckedBtn !=NULL) m_pCurCheckedBtn->setChecked(false);
          m_pCurCheckedBtn = m_vectorTabOrder[m_nCurTabPos];
          m_pCurCheckedBtn->setChecked(true);
          break;
      case 0x01000031:    // Push
      {
          if(m_pCurCheckedBtn != NULL){
              m_pCurCheckedBtn->click();
          }
          break;
      }
      case 0x01000032:    // Turn right
          if(m_nCurTabPos < (m_vectorTabOrder.size() -1)) m_nCurTabPos++;
          else m_nCurTabPos=0;
          if(m_pCurCheckedBtn !=NULL) m_pCurCheckedBtn->setChecked(false);
          m_pCurCheckedBtn = m_vectorTabOrder[m_nCurTabPos];
          m_pCurCheckedBtn->setChecked(true);
          break;
      }
  }
  
  void KeyboardWidget::focusInKeyboard(){
      m_nCurTabPos = 0;
      if(m_pCurCheckedBtn != NULL) m_pCurCheckedBtn->setChecked(false);
      m_pCurCheckedBtn = m_vectorTabOrder[0];
      m_pCurCheckedBtn->setChecked(true);
      this->grabKeyboard();
  }
  
  void KeyboardWidget::focusOutKeyboard(){
      m_nCurTabPos = 0;
      if(m_pCurCheckedBtn != NULL) m_pCurCheckedBtn->setChecked(false);
      this->releaseKeyboard();
  }