Blame view

app/gui/oven_control/programmingwindow.cpp 5.8 KB
8597f5496   김태훈   Merge
1
2
  #include "programmingwindow.h"
  #include "ui_programmingwindow.h"
dcfd897f3   김태훈   수동 요리 만들기 추가
3
4
5
6
7
8
  #include <QPainter>
  #include <QtDebug>
  
  #include "programmingmanualwindow.h"
  #include "programmingselectionwindow.h"
  #include "cookprogram.h"
382b586e9   김태훈   프로그래밍 모드 임시 구현
9
10
11
  #include "soundplayer.h"
  #include "confirmpopup.h"
  #include "programmingnamepopup.h"
dcfd897f3   김태훈   수동 요리 만들기 추가
12
8597f5496   김태훈   Merge
13
14
15
16
17
  ProgrammingWindow::ProgrammingWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::ProgrammingWindow)
  {
      ui->setupUi(this);
f588aa273   김태훈   부가 기능 로직 추가
18
19
20
  
      ui->clockContainer->setParent(ui->upperStack);
      setAttribute(Qt::WA_DeleteOnClose);
dcfd897f3   김태훈   수동 요리 만들기 추가
21
22
  
      setupUi();
382b586e9   김태훈   프로그래밍 모드 임시 구현
23
24
25
  
      foreach (QPushButton *button, findChildren<QPushButton *>())
          connect(button, &QPushButton::pressed, SoundPlayer::playClick);
8597f5496   김태훈   Merge
26
27
28
29
30
31
  }
  
  ProgrammingWindow::~ProgrammingWindow()
  {
      delete ui;
  }
f588aa273   김태훈   부가 기능 로직 추가
32
dcfd897f3   김태훈   수동 요리 만들기 추가
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
  void ProgrammingWindow::listAuto()
  {
      if (!ui->autoButton->isChecked())
      {
          ui->autoButton->blockSignals(true);
          ui->autoButton->setChecked(true);
          ui->autoButton->blockSignals(false);
      }
  
      listButtons(CookProgram::listAuto());
  }
  
  void ProgrammingWindow::listManual()
  {
      if (!ui->manualButton->isChecked())
      {
          ui->manualButton->blockSignals(true);
          ui->manualButton->setChecked(true);
          ui->manualButton->blockSignals(false);
      }
  
      listButtons(CookProgram::listManual());
  }
  
  void ProgrammingWindow::setupUi()
  {
      ui->verticalScrollLayout->setAlignment(Qt::AlignTop);
  
      QFont font = ui->addButton->font();
      font.setPixelSize(30);
  
      int textWidth = QFontMetrics(font).width(tr("추가하기"));
  
      QPixmap iconPix(":/images/etc/bar_icon_03.png");
  
      QPixmap pixmap(QSize(iconPix.width() + 20 + textWidth, ui->addButton->height()));
      pixmap.fill(Qt::transparent);
  
      QRect textRect(iconPix.width() + 20, 0, textWidth, pixmap.height());
  
      QPainter painter(&pixmap);
      painter.setFont(font);
      painter.setPen(Qt::white);
      painter.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, tr("추가하기"));
      painter.drawPixmap(0, (pixmap.height() - iconPix.height()) / 2, iconPix);
  
      QIcon icon(pixmap);
      ui->addButton->setIcon(icon);
      ui->addButton->setIconSize(pixmap.size());
      ui->addButton->hide();
  }
  
  void ProgrammingWindow::updateView()
  {
      if (ui->autoButton->isChecked())
          listAuto();
      else if (ui->manualButton->isChecked())
          listManual();
  }
  
  void ProgrammingWindow::listButtons(QList<CookRecord> record)
  {
      clear();
  
      ui->addButton->show();
  
      foreach (CookRecord r, record)
          newButton(r);
  
      ui->scrollAreaWidgetContents->adjustSize();
  }
  
  void ProgrammingWindow::clear()
  {
      lastInfoDisplayed = NULL;
      while (!list.isEmpty())
          list.takeFirst()->deleteLater();
  }
  
  CookPanelButton *ProgrammingWindow::newButton(CookRecord record)
  {
      CookPanelButton *button = new CookPanelButton(record, this);
      connect(button, SIGNAL(infoClicked(CookPanelButton*)), SLOT(onInfoButtonClicked(CookPanelButton*)));
      connect(button, SIGNAL(deleteClicked(CookPanelButton*)), SLOT(onDeleteButtonClicked(CookPanelButton*)));
382b586e9   김태훈   프로그래밍 모드 임시 구현
117
118
119
      connect(button, SIGNAL(longPressed(CookPanelButton*)), SLOT(onLongPressed(CookPanelButton*)));
  
      button->setLongPressEnabled(true);
dcfd897f3   김태훈   수동 요리 만들기 추가
120
121
122
123
124
125
  
      ui->verticalScrollLayout->addWidget(button);
      list.append(button);
  
      return button;
  }
382b586e9   김태훈   프로그래밍 모드 임시 구현
126
127
128
129
130
131
132
133
134
135
  void ProgrammingWindow::back()
  {
      CookProgram::discard();
      close();
  }
  
  void ProgrammingWindow::save()
  {
      CookProgram::save();
  }
dcfd897f3   김태훈   수동 요리 만들기 추가
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
  void ProgrammingWindow::onInfoButtonClicked(CookPanelButton *panelButton)
  {
      if (lastInfoDisplayed)
      {
          if (panelButton == lastInfoDisplayed)
          {
              lastInfoDisplayed->hideInfo();
              lastInfoDisplayed = NULL;
  
              ui->scrollAreaWidgetContents->adjustSize();
          }
          else
          {
              lastInfoDisplayed->hideInfo();
              lastInfoDisplayed = panelButton;
              lastInfoDisplayed->showInfo();
  
              ui->scrollAreaWidgetContents->adjustSize();
              ui->scrollArea->ensureWidgetVisible(lastInfoDisplayed);
          }
      }
      else
      {
          lastInfoDisplayed = panelButton;
          lastInfoDisplayed->showInfo();
  
          ui->scrollAreaWidgetContents->adjustSize();
          ui->scrollArea->ensureWidgetVisible(lastInfoDisplayed);
      }
  }
  
  void ProgrammingWindow::onDeleteButtonClicked(CookPanelButton *panelButton)
  {
      if (panelButton == lastInfoDisplayed)
          lastInfoDisplayed = NULL;
  
      CookProgram::remove(panelButton->record);
  
      list.removeAll(panelButton);
      panelButton->deleteLater();
  }
382b586e9   김태훈   프로그래밍 모드 임시 구현
177
178
179
180
181
182
  void ProgrammingWindow::onLongPressed(CookPanelButton *panelButton)
  {
      ProgrammingNamePopup *p = new ProgrammingNamePopup(this, panelButton->record);
      connect(p, SIGNAL(changed()), SLOT(updateView()));
      p->showFullScreen();
  }
dcfd897f3   김태훈   수동 요리 만들기 추가
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
  void ProgrammingWindow::on_addButton_clicked()
  {
      ProgrammingSelectionWindow *w = new ProgrammingSelectionWindow(this);
  
      if (ui->autoButton->isChecked())
          w->setCookTypeEnabled(true);
      else if (ui->manualButton->isChecked())
          w->setModeEnabled(true);
  
      w->setWindowModality(Qt::WindowModal);
      w->showFullScreen();
      w->raise();
  
      connect(w, SIGNAL(added()), SLOT(updateView()));
  }
  
  void ProgrammingWindow::on_autoButton_toggled(bool checked)
  {
      if (!checked)
          return;
  
      listAuto();
  }
  
  void ProgrammingWindow::on_manualButton_toggled(bool checked)
  {
      if (!checked)
          return;
  
      listManual();
  }
f588aa273   김태훈   부가 기능 로직 추가
214
215
  void ProgrammingWindow::on_backButton_clicked()
  {
382b586e9   김태훈   프로그래밍 모드 임시 구현
216
217
218
219
220
221
222
223
      if (CookProgram::isModified())
      {
          ConfirmPopup *p = new ConfirmPopup(this, "저장하지 않고 돌아가시겠습니까?");
          connect(p, SIGNAL(accepted()), SLOT(back()));
          p->showFullScreen();
      }
      else
          close();
dcfd897f3   김태훈   수동 요리 만들기 추가
224
225
226
227
  }
  
  void ProgrammingWindow::on_saveButton_clicked()
  {
382b586e9   김태훈   프로그래밍 모드 임시 구현
228
229
230
      ConfirmPopup *p = new ConfirmPopup(this, "저장하시겠습니까?");
      connect(p, SIGNAL(accepted()), SLOT(save()));
      p->showFullScreen();
f588aa273   김태훈   부가 기능 로직 추가
231
  }
dcfd897f3   김태훈   수동 요리 만들기 추가
232
233
234
235
236
  
  void ProgrammingWindow::on_helpButton_clicked()
  {
  
  }