Blame view

app/gui/oven_control/autocookselectionpopup.cpp 4.19 KB
11c611782   김태훈   자동 요리 세부 사항 구현
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
  #include "autocookselectionpopup.h"
  #include "ui_autocookselectionpopup.h"
  
  #include <QSignalMapper>
  #include <QKeyEvent>
  
  #include "soundplayer.h"
  
  AutoCookSelectionPopup::AutoCookSelectionPopup(QWidget *parent, Define::CookType type) :
      QWidget(parent),
      ui(new Ui::AutoCookSelectionPopup),
      type(type), book(CookBook(type))
  {
      ui->setupUi(this);
  
      QSignalMapper *m = new QSignalMapper(this);
      m->setMapping(ui->selection1, 0);
      m->setMapping(ui->selection2, 1);
      m->setMapping(ui->selection3, 2);
      m->setMapping(ui->selection4, 3);
      m->setMapping(ui->selection5, 4);
      m->setMapping(ui->selection6, 5);
      connect(m, SIGNAL(mapped(int)), SLOT(on_clicked(int)));
  
      connect(ui->selection1, SIGNAL(clicked()), m, SLOT(map()));
      connect(ui->selection2, SIGNAL(clicked()), m, SLOT(map()));
      connect(ui->selection3, SIGNAL(clicked()), m, SLOT(map()));
      connect(ui->selection4, SIGNAL(clicked()), m, SLOT(map()));
      connect(ui->selection5, SIGNAL(clicked()), m, SLOT(map()));
      connect(ui->selection6, SIGNAL(clicked()), m, SLOT(map()));
  
      ui->bullets->setBulletPixmap(":/images/auto_popup/bullet.png");
      ui->bullets->setCurrentBulletPixmap(":/images/auto_popup/bullet_selected.png");
      ui->bullets->setMaximum((book.list.size() - 1) / 6);
  
      list();
  
      foreach (QPushButton *button, findChildren<QPushButton *>())
          connect(button, &QPushButton::pressed, SoundPlayer::playClick);
  
      setFocus();
  }
  
  AutoCookSelectionPopup::~AutoCookSelectionPopup()
  {
      delete ui;
  }
  
  void AutoCookSelectionPopup::keyPressEvent(QKeyEvent *event)
  {
      switch (event->key())
      {
01249f413   김태훈   엔코더 방향 반전. 하드웨어가 변경됨
53
      case 0x01000032:    // Turn left
11c611782   김태훈   자동 요리 세부 사항 구현
54
55
56
57
58
          onEncoderLeft();
          break;
      case 0x01000031:    // Push
          pushed = focusWidget();
          break;
01249f413   김태훈   엔코더 방향 반전. 하드웨어가 변경됨
59
      case 0x01000030:    // Turn right
11c611782   김태훈   자동 요리 세부 사항 구현
60
61
62
63
64
65
66
67
68
          onEncoderRight();
          break;
      }
  }
  
  void AutoCookSelectionPopup::keyReleaseEvent(QKeyEvent *event)
  {
      switch (event->key())
      {
01249f413   김태훈   엔코더 방향 반전. 하드웨어가 변경됨
69
      case 0x01000032:    // Turn left
11c611782   김태훈   자동 요리 세부 사항 구현
70
71
72
73
74
75
76
77
          onEncoderLeft();
          break;
      case 0x01000031:    // Push
          if (focusWidget() == pushed)
              onEncoderClicked(pushed);
  
          pushed = NULL;
          break;
01249f413   김태훈   엔코더 방향 반전. 하드웨어가 변경됨
78
      case 0x01000030:    // Turn right
11c611782   김태훈   자동 요리 세부 사항 구현
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
          onEncoderRight();
          break;
      }
  }
  
  void AutoCookSelectionPopup::onEncoderLeft()
  {
      QWidget *focused = focusWidget();
      if (focused == NULL || focused == this || focused == ui->selection1)
          ui->next->setFocus();
      else
          focusPreviousChild();
  }
  
  void AutoCookSelectionPopup::onEncoderRight()
  {
      QWidget *focused = focusWidget();
      if (focused == NULL || focused == this || focused == ui->next)
          ui->selection1->setFocus();
      else
          focusNextChild();
  }
  
  void AutoCookSelectionPopup::onEncoderClicked(QWidget *clicked)
  {
      QPushButton *b = qobject_cast<QPushButton *>(clicked);
      if (b)
          b->click();
  }
  
  void AutoCookSelectionPopup::list()
  {
      int startAt = ui->bullets->currentIndex() * 6;
      for (int i = 0; i < 6; i++)
      {
          QPushButton *b;
          switch (i)
          {
          case 0:
              b = ui->selection1;
              break;
          case 1:
              b = ui->selection2;
              break;
          case 2:
              b = ui->selection3;
              break;
          case 3:
              b = ui->selection4;
              break;
          case 4:
              b = ui->selection5;
              break;
          case 5:
              b = ui->selection6;
              break;
          }
  
          int idx = startAt + i;
          if (idx >= book.list.size())
              b->hide();
          else
          {
              b->show();
              b->setText(book.list.at(idx));
          }
      }
  }
  
  void AutoCookSelectionPopup::on_clicked(int index)
  {
      index += ui->bullets->currentIndex() * 6;
  
      emit selected(book.get(index));
      close();
  }
  
  void AutoCookSelectionPopup::on_prev_clicked()
  {
      ui->bullets->setCurrentIndex(ui->bullets->currentIndex() - 1);
      list();
  }
  
  void AutoCookSelectionPopup::on_next_clicked()
  {
      ui->bullets->setCurrentIndex(ui->bullets->currentIndex() + 1);
      list();
  }
  
  void AutoCookSelectionPopup::on_upperClose_clicked()
  {
      emit canceled();
      close();
  }
  
  void AutoCookSelectionPopup::on_lowerClose_clicked()
  {
      emit canceled();
      close();
  }