Blame view

app/gui/oven_control/programmingwindow.cpp 4.77 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"
8597f5496   김태훈   Merge
9
10
11
12
13
  ProgrammingWindow::ProgrammingWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::ProgrammingWindow)
  {
      ui->setupUi(this);
f588aa273   김태훈   부가 기능 로직 추가
14
15
16
  
      ui->clockContainer->setParent(ui->upperStack);
      setAttribute(Qt::WA_DeleteOnClose);
dcfd897f3   김태훈   수동 요리 만들기 추가
17
18
  
      setupUi();
8597f5496   김태훈   Merge
19
20
21
22
23
24
  }
  
  ProgrammingWindow::~ProgrammingWindow()
  {
      delete ui;
  }
f588aa273   김태훈   부가 기능 로직 추가
25
dcfd897f3   김태훈   수동 요리 만들기 추가
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
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
179
180
181
182
183
184
185
186
187
188
189
  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*)));
  
      ui->verticalScrollLayout->addWidget(button);
      list.append(button);
  
      return button;
  }
  
  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();
  }
  
  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   김태훈   부가 기능 로직 추가
190
191
  void ProgrammingWindow::on_backButton_clicked()
  {
dcfd897f3   김태훈   수동 요리 만들기 추가
192
193
194
195
196
197
198
199
      CookProgram::discard();
  
      close();
  }
  
  void ProgrammingWindow::on_saveButton_clicked()
  {
      CookProgram::save();
f588aa273   김태훈   부가 기능 로직 추가
200
201
      close();
  }
dcfd897f3   김태훈   수동 요리 만들기 추가
202
203
204
205
206
  
  void ProgrammingWindow::on_helpButton_clicked()
  {
  
  }