Blame view

app/gui/oven_control/programmedcookpanelbutton.cpp 3.62 KB
097e5e14a   김태훈   프로그래밍 모드 세부 사항 구현
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
  #include "programmedcookpanelbutton.h"
  #include "ui_programmedcookpanelbutton.h"
  
  #include <QKeyEvent>
  
  #include "soundplayer.h"
  
  ProgrammedCookPanelButton::ProgrammedCookPanelButton(CookRecord record, QWidget *parent) :
      QWidget(parent),
      record(record),
      ui(new Ui::ProgrammedCookPanelButton),
      rendered(false),
      longPressEnabled(false)
  {
      ui->setupUi(this);
  
      setText(record.name);
  
      foreach (QPushButton *button, findChildren<QPushButton *>())
          connect(button, &QPushButton::pressed, SoundPlayer::playClick);
  
      longPressedTimer.setSingleShot(true);
      longPressedTimer.setInterval(3000);
      connect(&longPressedTimer, SIGNAL(timeout()), SLOT(emitLongPressed()));
  }
  
  ProgrammedCookPanelButton::~ProgrammedCookPanelButton()
  {
      delete ui;
  }
  
  void ProgrammedCookPanelButton::setText(QString text)
  {
      ui->pushButton->setText(text);
  }
  
  void ProgrammedCookPanelButton::showInfo()
  {
      if (!rendered)
      {
          QPixmap p = CookHistory::render(record);
  
          label = new QLabel(this);
          label->setPixmap(p);
          label->setGeometry((width() - p.width()) / 2, 65, p.width(), p.height());
      }
  
      label->show();
      setMinimumHeight(ui->pushButton->height() + label->height());
  }
  
  void ProgrammedCookPanelButton::hideInfo()
  {
      label->hide();
      setMinimumHeight(ui->pushButton->height());
  }
  
  void ProgrammedCookPanelButton::setLongPressEnabled(bool enabled)
  {
      longPressEnabled = enabled;
  }
  
  QPushButton *ProgrammedCookPanelButton::bar()
  {
      return ui->pushButton;
  }
  
  QPushButton *ProgrammedCookPanelButton::infoButton()
  {
      return ui->showInfoButton;
  }
  
  QPushButton *ProgrammedCookPanelButton::deleteButton()
  {
      return ui->deleteButton;
  }
  
  void ProgrammedCookPanelButton::setEnabled(bool enabled)
  {
      ui->pushButton->setEnabled(enabled);
      ui->showInfoButton->setEnabled(enabled);
      ui->deleteButton->setEnabled(enabled);
  }
  
  void ProgrammedCookPanelButton::keyPressEvent(QKeyEvent *event)
  {
      switch (event->key())
      {
01249f413   김태훈   엔코더 방향 반전. 하드웨어가 변경됨
89
      case 0x01000032:    // Turn left
097e5e14a   김태훈   프로그래밍 모드 세부 사항 구현
90
91
92
93
94
95
96
          event->ignore();
          break;
      case 0x01000031:    // Push
          pushed = focusWidget();
          if (pushed == ui->pushButton)
              on_pushButton_pressed();
          break;
01249f413   김태훈   엔코더 방향 반전. 하드웨어가 변경됨
97
      case 0x01000030:    // Turn right
097e5e14a   김태훈   프로그래밍 모드 세부 사항 구현
98
99
100
101
102
103
104
105
106
          event->ignore();
          break;
      }
  }
  
  void ProgrammedCookPanelButton::keyReleaseEvent(QKeyEvent *event)
  {
      switch (event->key())
      {
01249f413   김태훈   엔코더 방향 반전. 하드웨어가 변경됨
107
      case 0x01000032:    // Turn left
097e5e14a   김태훈   프로그래밍 모드 세부 사항 구현
108
109
110
111
112
113
114
115
116
117
118
          event->ignore();
          break;
      case 0x01000031:    // Push
          if (pushed == ui->pushButton)
              on_pushButton_released();
  
          if (focusWidget() == pushed)
              onEncoderClicked(pushed);
  
          pushed = NULL;
          break;
01249f413   김태훈   엔코더 방향 반전. 하드웨어가 변경됨
119
      case 0x01000030:    // Turn right
097e5e14a   김태훈   프로그래밍 모드 세부 사항 구현
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
          event->ignore();
          break;
      }
  }
  
  void ProgrammedCookPanelButton::onEncoderLeft()
  {
  
  }
  
  void ProgrammedCookPanelButton::onEncoderRight()
  {
  
  }
  
  void ProgrammedCookPanelButton::onEncoderClicked(QWidget *clicked)
  {
      QPushButton *b = qobject_cast<QPushButton *>(clicked);
      if (b)
          b->click();
  }
  
  void ProgrammedCookPanelButton::emitLongPressed()
  {
      emitted = true;
      emit longPressed(this);
  }
  
  void ProgrammedCookPanelButton::on_pushButton_pressed()
  {
      longPressedTimer.start();
      emitted = false;
  }
  
  void ProgrammedCookPanelButton::on_pushButton_released()
  {
      longPressedTimer.stop();
  }
  
  void ProgrammedCookPanelButton::on_pushButton_clicked()
  {
      if (longPressEnabled && emitted)
          return;
  
      emit clicked(this);
  }
  
  void ProgrammedCookPanelButton::on_showInfoButton_clicked()
  {
      emit infoClicked(this);
  }
  
  void ProgrammedCookPanelButton::on_deleteButton_clicked()
  {
      emit deleteClicked(this);
  }